HBaseConvetorUtil 实体转换工具

HBaseConvetorUtil 实体转换工具

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

全栈程序员社区此处内容已经被作者隐藏,请输入验证码查看内容
验证码:
请关注本站微信公众号,回复“验证码”,获取验证码。在微信里搜索“全栈程序员社区”或者“www_javaforall_cn”或者微信扫描右侧二维码都可以关注本站微信公众号。

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
遵循超人学院微通道的二维码:
HBaseConvetorUtil 实体转换工具
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/117846.html原文链接:https://javaforall.net

(0)
上一篇 2021年12月17日 下午7:00
下一篇 2021年12月17日 下午8:00


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号