package com.lyq.hbase.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;


public class HBaseConfigUtils {

 public static Configuration getHBaseConfig(){
  Configuration conf = HBaseConfiguration.create();
  conf.set("hbase.zookeeper.quorum", "master129,slave130,slave131,slave132");
  return conf;
 }
 
 @SuppressWarnings("deprecation")
 public static void main(String[] args) {
  List<Map<String,String>> list = new ArrayList<Map<String,String>>();
  Map<String,String> map = new HashMap<String,String>();
  try {
   HTable table = new HTable(getHBaseConfig(),"test");
   Scan scan = new Scan();
   ResultScanner rs = table.getScanner(scan);
   for(Result r:rs){
     System.out.println("rowkey:"+Bytes.toString(r.getRow()));
     map.put("rowkey", Bytes.toString(r.getRow()));
     for(KeyValue kv:r.raw()){
      System.out.println(Bytes.toString(kv.getQualifier())+":"+Bytes.toString(kv.getValue()));
      map.put(Bytes.toString(kv.getQualifier()), Bytes.toString(kv.getValue()));
     }
     list.add(map);
     System.out.println("==========");
   }
  } catch (IOException e) {
   e.printStackTrace();
  }  
 }
}