当前位置: 首页 > news >正文

HBaseConvetorUtil 实体转换工具类

为什么80%的码农都做不了架构师?>>>   hot3.png

HBaseConvetorUtil 实体转换工具类

public class HBaseConvetorUtil {

       /**

   * @Title: convetor

   * @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;

   }

   

   /**

   * @Title: convetor

   * @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;

   }

   

   /**

   * @Title: convetor

   * @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

关注超人学院微信二维码:

转载于:https://my.oschina.net/crxy/blog/466123

相关文章:

  • vue路由懒加载
  • python之文件和素材
  • LAMP --Apache的源码部署安装
  • Java Thread join() 的用法
  • Airbnb个性化搜索服务架构
  • Skype for Business Server 2015-10-ADFS-2-配置
  • JAVA中的数据结构 - 真正的去理解红黑树
  • ViewPager+seekBar的联动效果
  • Babel 手记
  • 【Spring学习笔记-MVC-10】Spring MVC之数据校验
  • 为什么使用MAVEN 3.2.1会有版本问题?
  • ng6--错误信息小结(持续更新)
  • org.tinygroup.context2object-参数对象构建
  • 思考 | 云计算 + 区块链 = ?
  • devexpress表格控件gridcontrol设置隔行变色、焦点行颜色、设置(改变)显示值、固定列不移动(附源码)...
  • JS 中的深拷贝与浅拷贝
  • 《网管员必读——网络组建》(第2版)电子课件下载
  • 「译」Node.js Streams 基础
  • 【跃迁之路】【735天】程序员高效学习方法论探索系列(实验阶段492-2019.2.25)...
  • 2018天猫双11|这就是阿里云!不止有新技术,更有温暖的社会力量
  • AngularJS指令开发(1)——参数详解
  • Computed property XXX was assigned to but it has no setter
  • CSS居中完全指南——构建CSS居中决策树
  • ES6 学习笔记(一)let,const和解构赋值
  • Js基础知识(一) - 变量
  • JS正则表达式精简教程(JavaScript RegExp 对象)
  • mac修复ab及siege安装
  • react-core-image-upload 一款轻量级图片上传裁剪插件
  • Sublime Text 2/3 绑定Eclipse快捷键
  • Transformer-XL: Unleashing the Potential of Attention Models
  • 从零开始学习部署
  • 多线程事务回滚
  • 开放才能进步!Angular和Wijmo一起走过的日子
  • 快速体验 Sentinel 集群限流功能,只需简单几步
  • 前端
  • 区块链共识机制优缺点对比都是什么
  • 微服务框架lagom
  • 小李飞刀:SQL题目刷起来!
  • elasticsearch-head插件安装
  • ​​​​​​​​​​​​​​Γ函数
  • ​低代码平台的核心价值与优势
  • #《AI中文版》V3 第 1 章 概述
  • #我与Java虚拟机的故事#连载10: 如何在阿里、腾讯、百度、及字节跳动等公司面试中脱颖而出...
  • (10)工业界推荐系统-小红书推荐场景及内部实践【排序模型的特征】
  • (42)STM32——LCD显示屏实验笔记
  • (Redis使用系列) SpringBoot中Redis的RedisConfig 二
  • (多级缓存)多级缓存
  • (附源码)springboot掌上博客系统 毕业设计063131
  • (附源码)ssm考生评分系统 毕业设计 071114
  • (亲测)设​置​m​y​e​c​l​i​p​s​e​打​开​默​认​工​作​空​间...
  • (转)用.Net的File控件上传文件的解决方案
  • .NET Core WebAPI中使用swagger版本控制,添加注释
  • .NET 编写一个可以异步等待循环中任何一个部分的 Awaiter
  • .NET/MSBuild 中的发布路径在哪里呢?如何在扩展编译的时候修改发布路径中的文件呢?
  • .NET简谈互操作(五:基础知识之Dynamic平台调用)