zoukankan      html  css  js  c++  java
  • HBaseConvetorUtil 实体转换工具

    HBaseConvetorUtil 实体转换工具类
    public class HBaseConvetorUtil {
           /**
       * @Titleconvetor
       * @Description传入hbase返回结果值。返回实例集合
       * @param
       * @return
       * @throws
        */
       public static <T> List<T>convetor(Class<T> cla,ResultScanner resultScanner) throws Exception{
          List<T> list = new ArrayList<T>();
          for (Result result :resultScanner) {
             Field []fileds=cla.getDeclaredFields();
             T t = cla.newInstance();
             for(Field field:fileds){
    field.setAccessible(true);
                String fileName=field.getName();
                if(result.containsColumn(Bytes.toBytes("BASEINFO"), Bytes.toBytes(fileName.toUpperCase()))){
                   if(result.getValue(Bytes.toBytes("BASEINFO"), Bytes.toBytes(fileName.toUpperCase())).length==0){
                      continue;
                   }
                   String value=Bytes.toString(result.getValue(Bytes.toBytes("BASEINFO"), Bytes.toBytes(fileName.toUpperCase())));
                   field.set(t, value);
                }
             }
             list.add(t);
          }
          return list;
       }
       
       /**
       * @Titleconvetor
       * @Description传入hbase返回结果值,返回实例
       * @param
       * @return
       * @throws
        */
       public static <T> Tconvetor(Class<T> cla,Result result) throws Exception{
             Field []fileds=cla.getDeclaredFields();
             T t = cla.newInstance();
             for(Field field:fileds){
    field.setAccessible(true);
                String fileName=field.getName();
                if(result.containsColumn(Bytes.toBytes("BASEINFO"), Bytes.toBytes(fileName.toUpperCase()))){
                   if(result.getValue(Bytes.toBytes("BASEINFO"), Bytes.toBytes(fileName.toUpperCase())).length==0){
                      continue;
                   }
                   String value=Bytes.toString(result.getValue(Bytes.toBytes("BASEINFO"), Bytes.toBytes(fileName.toUpperCase())));
                   field.set(t, value);
                }
             }
          return t;
       }
       
       /**
       * @Titleconvetor
       * @Description传入保存实例和主键ID,返回PutDelete
       * @param
       * @return
       * @throws
        */
       public static <T> PutDeleteconvetor(T t,String id) throws Exception {
          Put put=new Put(Bytes.toBytes(id));
          Delete delete=new Delete(Bytes.toBytes(id));
          Field [] fileds=t.getClass().getDeclaredFields();
          for(Field field:fileds){
              field.setAccessible(true);
             StringfieldName=field.getName();
             Object value =field.get(t);
             if(null==value){
                delete.deleteColumn(Bytes.toBytes("BASEINFO"), Bytes.toBytes(fieldName.toUpperCase()));
                continue;
             }
             put.add(Bytes.toBytes("BASEINFO"), Bytes.toBytes(fieldName.toUpperCase()), Bytes.toBytes((String)value));
          }
          PutDelete putdelete = new PutDelete();
          putdelete.setPut(put);
          putdelete.setDelete(delete);
          return putdelete;
       }
          
    }

    很多其它精彩内请注意内容:http://bbs.superwu.cn
    遵循超人学院微通道的二维码:
  • 相关阅读:
    npm ERR! code EINTEGRITY npm ERR! sha1- 报错解决办法
    create-react-app创建项目报错SyntaxError: Unexpected end of JSON input while parsing near '...ttachment":false,"tar' npm代理
    七大设计原则
    UML类图和时序图
    linux环境下排查cpu占比高的MySQL数据库sql语句
    Angular 2 imooc 学习笔记
    angular JS 学习笔记
    Hibernate HQL基础
    Hibernate注解
    Hibernate多对多映射
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4580446.html
Copyright © 2011-2022 走看看