コード例 #1
0
 public <V> void deleteObject(String tableName, V object, HbaseMapper<V> mapper) throws Exception {
   HTableInterface htable = dataSource.getConnection(tableName);
   Delete delete = mapper.mapDelete(object);
   log.info("delete is -[" + delete + "]");
   htable.delete(delete);
   log.info(
       "delete one object from "
           + tableName
           + ",rowKeyString is -["
           + mapper.generateRowKeyString(object)
           + "] ,delete info -["
           + delete
           + "]");
   htable.close();
 }
コード例 #2
0
 public <V> void addObject(String tableName, V v, HbaseMapper<V> mapper) throws Exception {
   HTableInterface htable = dataSource.getConnection(tableName);
   Put put = mapper.mapPut(v);
   log.info("put is -[" + put + "]");
   htable.put(put);
   log.info("put one object to " + tableName + ", put info -[" + put + "]");
   htable.close();
 }
コード例 #3
0
 public <V> V getObject(String tableName, V v, HbaseMapper<V> mapper) throws Exception {
   HTableInterface htable = dataSource.getConnection(tableName);
   Get get = mapper.mapGet(v);
   log.info("get is -[" + get + "]");
   Result result = htable.get(get);
   V r = null;
   if (!result.isEmpty()) {
     r = mapper.mapApi(result);
     log.info(
         "get one objects from "
             + tableName
             + ",rowKeyString is-["
             + mapper.getRowKeyString(result)
             + "]");
   }
   htable.close();
   return r;
 }
コード例 #4
0
 private <V> List<V> trasfer(ResultScanner resultScanner, HbaseMapper<V> mapper) throws Exception {
   Iterator<Result> it = resultScanner.iterator();
   Result temp = null;
   List<V> result = new ArrayList<V>();
   while (it.hasNext()) {
     temp = it.next();
     result.add(mapper.mapApi(temp));
   }
   return result;
 }
コード例 #5
0
 public <V> List<V> getObjects(String tableName, V object, HbaseMapper<V> mapper)
     throws Exception {
   HTableInterface htable = dataSource.getConnection(tableName);
   Scan scan = mapper.mapScan(object);
   log.info("scan is -[" + scan + "]");
   ResultScanner resultScanner = htable.getScanner(scan);
   List<V> result = trasfer(resultScanner, mapper);
   htable.close();
   log.info("get " + result.size() + " objects from " + tableName + "");
   return result;
 }
コード例 #6
0
 public <V> void addObjects(String tableName, List<V> objects, HbaseMapper<V> mapper)
     throws Exception {
   if (CollectionUtils.isEmpty(objects)) {
     return;
   }
   HTableInterface htable = dataSource.getConnection(tableName);
   List<Put> puts = new ArrayList<Put>();
   for (V v : objects) {
     puts.add(mapper.mapPut(v));
   }
   htable.put(puts);
   log.info("put " + puts.size() + " objects to " + tableName);
   htable.close();
 }
コード例 #7
0
 public <V> void deleteObjects(String tableName, List<V> objects, HbaseMapper<V> mapper)
     throws Exception {
   HTableInterface htable = dataSource.getConnection(tableName);
   if (CollectionUtils.isEmpty(objects)) {
     return;
   }
   List<Delete> deletes = new ArrayList<Delete>();
   for (V v : objects) {
     deletes.add(mapper.mapDelete(v));
   }
   htable.delete(deletes);
   log.info("delete " + deletes.size() + " objects from " + tableName + "");
   htable.close();
 }