HBaseConvetorUtil 实体转换工具类
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了HBaseConvetorUtil 实体转换工具类,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2441字,纯文字阅读大概需要4分钟。
内容图文
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 关注超人学院微信二维码: |
原文:http://my.oschina.net/crxy/blog/466123
内容总结
以上是互联网集市为您收集整理的HBaseConvetorUtil 实体转换工具类全部内容,希望文章能够帮你解决HBaseConvetorUtil 实体转换工具类所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。