<dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase-client</artifactId> <version>0.96.2-hadoop2</version> </dependency>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!--<property>-->
<!--<name>hbase.rootdir</name>-->
<!--<value>hdfs://ns1/hbase</value>-->
<!--</property>-->
<property>
<name>hbase.client.write.buffer</name>
<value>62914560</value>
</property>
<property>
<name>hbase.client.pause</name>
<value>1000</value>
</property>
<property>
<name>hbase.client.retries.number</name>
<value>10</value>
</property>
<property>
<name>hbase.client.scanner.caching</name>
<value>1</value>
</property>
<property>
<name>hbase.client.keyvalue.maxsize</name>
<value>6291456</value>
</property>
<property>
<name>hbase.rpc.timeout</name>
<value>60000</value>
</property>
<property>
<name>hbase.security.authentication</name>
<value>simple</value>
</property>
<property>
<name>zookeeper.session.timeout</name>
<value>60000</value>
</property>
<property>
<name>zookeeper.znode.parent</name>
<value>ZooKeeper中的HBase的根ZNode</value>
</property>
<property>
<name>zookeeper.znode.rootserver</name>
<value>root-region-server</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>zookeeper集群</value>
</property>
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>2181</value>
</property>
</configuration>
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:hdp="http://www.springframework.org/schema/hadoop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/hadoop
http://www.springframework.org/schema/hadoop/spring-hadoop.xsd
">
<hdp:configuration resources="classpath:spring/hbase-site.xml" />
<hdp:hbase-configuration configuration-ref="hadoopConfiguration" />
<bean id="htemplate" class="org.springframework.data.hadoop.hbase.HbaseTemplate">
<!--注意到没有,spring的一贯风格,正如我们在mongodb篇讲到的一样,xxxTemplate封装-->
<property name="configuration" ref="hbaseConfiguration">
</property>
</bean>
<bean class="com..HbaseDaoImpl" id="hbaseDao">
<constructor-arg ref="htemplate"/>
</bean>
</beans>
public class HbaseDaoImpl{
private HbaseTemplate hbaseTemplate;
private HConnection hconnection = null;
public HbaseDaoImpl(HbaseTemplate htemplate) throws Exception {
if (hconnection == null) {
hconnection = HConnectionManager.createConnection(htemplate.getConfiguration());
}
if (this.hbaseTemplate == null) {
this.hbaseTemplate = htemplate;
}
}
public void writeDataOrderinfo(final OrderInfo orderInfo) {
HTableInterface table = null;
try {
table = hconnection.getTable(Bytes.toBytes("prism:orderInfo"));
Put p = new Put(Bytes.toBytes( orderInfo.getHistoryId()));
p.add(Bytes.toBytes("f"), Bytes.toBytes("id"), Bytes.toBytes(orderInfo.getId()));
p.add(Bytes.toBytes("f"), Bytes.toBytes("historyId"), Bytes.toBytes(orderInfo.getHistoryId()));
p.add(Bytes.toBytes("f"), Bytes.toBytes("orderId"), Bytes.toBytes(orderInfo.getOrderId()));
p.add(Bytes.toBytes("f"), Bytes.toBytes("orderDirection"), Bytes.toBytes(orderInfo.getOrderDirection()));
p.add(Bytes.toBytes("f"), Bytes.toBytes("overStatus"), Bytes.toBytes(orderInfo.getOverStatus()));
p.add(Bytes.toBytes("f"), Bytes.toBytes("orgArea"), Bytes.toBytes(orderInfo.getOrgArea()));
table.put(p);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (table != null) {
try {
table.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public OrderInfo getOrderInfoByRowkey(String rowKey) {
Get get = new Get(Bytes.toBytes(rowKey));
Scan scan = new Scan(get);
List<OrderInfo> list = hbaseTemplate.find("prism:orderInfo", scan, new RowMapper<OrderInfo>() {
@Override
public OrderInfo mapRow(Result result, int rowNum) throws Exception {
OrderInfo orderInfo = new OrderInfo();
orderInfo.setId(Bytes.toString(result.getValue(Bytes.toBytes("f"), Bytes.toBytes("id"))));
orderInfo.setHistoryId(Bytes.toString(result.getValue(Bytes.toBytes("f"), Bytes.toBytes("historyId"))));
orderInfo.setOrderId(Bytes.toLong(result.getValue(Bytes.toBytes("f"), Bytes.toBytes("orderId"))));
return orderInfo;
}
});
if(list.size() > 0){
return list.get(0);
}else{
return null;
}
}
public List<OrderInfo> getOrderInfoByRange(String start_rowKey,String stop_rowKey) {
Scan scan = new Scan();
scan.setStartRow(Bytes.toBytes(start_rowKey));
scan.setStopRow(Bytes.toBytes(stop_rowKey));
HTableInterface table = null;
ResultScanner rs = null;
List<OrderInfo> list = new ArrayList<OrderInfo>();
try {
table = hconnection.getTable(Bytes.toBytes("prism:orderInfo"));
rs = table.getScanner(scan);
for(Result result : rs){
OrderInfo orderInfo = new OrderInfo();
orderInfo.setId(Bytes.toString(result.getValue(Bytes.toBytes("f"), Bytes.toBytes("id"))));
orderInfo.setHistoryId(Bytes.toString(result.getValue(Bytes.toBytes("f"), Bytes.toBytes("historyId"))));
orderInfo.setOrderId(Bytes.toLong(result.getValue(Bytes.toBytes("f"), Bytes.toBytes("orderId"))));
orderInfo.setOrderDirection(Bytes.toString(result.getValue(Bytes.toBytes("f"), Bytes.toBytes("orderDirection"))));
list.add(orderInfo);
}
} catch (IOException e) {
e.printStackTrace();
}finally{
rs.close();
}
return list;
}
public HbaseTemplate getHbaseTemplate() {
return hbaseTemplate;
}
public void setHbaseTemplate(HbaseTemplate hbaseTemplate) {
this.hbaseTemplate = hbaseTemplate;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有