package tw.kewang.hbase;

public class UserDao {

}

@@ -23,30 +23,1943 @@
 e;%0A%0A
-public class UserDao %7B%0A%0A%7D%0A
+import java.io.IOException;%0A%0Aimport org.apache.hadoop.hbase.client.Get;%0Aimport org.apache.hadoop.hbase.client.HConnection;%0Aimport org.apache.hadoop.hbase.client.HTableInterface;%0Aimport org.apache.hadoop.hbase.client.Result;%0Aimport org.apache.hadoop.hbase.util.Bytes;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport tw.kewang.hbase.annotations.Table;%0Aimport tw.kewang.hbase.dao.Constants;%0Aimport tw.kewang.hbase.dao.HConnectionHolder;%0A%0A@Table(name = %22User%22)%0Apublic class UserDao %7B%0A%09private static final Table TABLE = getTableAnnotation();%0A%09private static final Logger LOG = LoggerFactory.getLogger(UserDao.class);%0A%09private static final HConnection CONNECTION = HConnectionHolder%0A%09%09%09.getInstance().getHConnection();%0A%0A%09public User1 getByRowkey(String rowkey) %7B%0A%09%09HTableInterface hTableInterface = null;%0A%0A%09%09try %7B%0A%09%09%09hTableInterface = CONNECTION.getTable(TABLE.name());%0A%0A%09%09%09Result results = hTableInterface.get(buildGet(rowkey));%0A%0A%09%09%09if (!results.isEmpty()) %7B%0A%0A%09%09%09%7D%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09LOG.error(Constants.EXCEPTION_PREFIX, e);%0A%09%09%7D catch (Error e) %7B%0A%09%09%09LOG.error(Constants.EXCEPTION_PREFIX, e);%0A%09%09%7D finally %7B%0A%09%09%09closeHTable(hTableInterface);%0A%09%09%7D%0A%0A%09%09return null;%0A%09%7D%0A%0A%09private static Table getTableAnnotation() %7B%0A%09%09Class%3C?%3E clazz = UserDao.class;%0A%0A%09%09Table table = clazz.getAnnotation(Table.class);%0A%0A%09%09if (table == null) %7B%0A%09%09%09throw new RuntimeException(%22No table annotation%22);%0A%09%09%7D%0A%0A%09%09return table;%0A%09%7D%0A%0A%09private Get buildGet(String rowkey) %7B%0A%09%09Get get = new Get(Bytes.toBytes(rowkey));%0A%0A%09%09try %7B%0A%09%09%09get.setMaxVersions(TABLE.maxVersions());%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09LOG.error(Constants.EXCEPTION_PREFIX, e);%0A%09%09%7D%0A%0A%09%09return get;%0A%09%7D%0A%0A%09private void closeHTable(HTableInterface hTableInterface) %7B%0A%09%09if (hTableInterface != null) %7B%0A%09%09%09try %7B%0A%09%09%09%09hTableInterface.close();%0A%09%09%09%7D catch (Exception e) %7B%0A%09%09%09%09LOG.error(Constants.EXCEPTION_PREFIX, e);%0A%09%09%09%7D catch (Error e) %7B%0A%09%09%09%09LOG.error(Constants.EXCEPTION_PREFIX, e);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%7D

Add getByRowkey @ Dao (uncomplete)