hbase support

This commit is contained in:
温少
2012-05-19 23:47:14 +08:00
parent 4580108a02
commit 5897efbe5a
3 changed files with 23 additions and 6 deletions
@@ -8,11 +8,13 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.HTablePool;
import com.alibaba.druid.hbase.mapping.HMapping;
import com.alibaba.druid.logging.Log;
import com.alibaba.druid.logging.LogFactory;
public class HEngine {
private final static Log LOG = LogFactory.getLog(HEngine.class);
private final static Log LOG = LogFactory.getLog(HEngine.class);
private static ConcurrentMap<String, HEngine> engines = new ConcurrentHashMap<String, HEngine>();
@@ -28,11 +30,12 @@ public class HEngine {
// =============================
private final String url;
private final String url;
private HTablePool tablePool;
private int htablePoolMaxSize = 256;
private Configuration config;
private HTablePool tablePool;
private int htablePoolMaxSize = 256;
private Configuration config;
private ConcurrentMap<String, HMapping> mappings = new ConcurrentHashMap<String, HMapping>();
public HEngine(String url, Properties connectProperties){
super();
@@ -64,6 +67,10 @@ public class HEngine {
return config;
}
public ConcurrentMap<String, HMapping> getMappings() {
return mappings;
}
public synchronized HTableInterface getHTable(String tableName) {
if (tablePool == null) {
tablePool = new HTablePool(config, htablePoolMaxSize);
@@ -62,7 +62,6 @@ public class SingleTableQueryExecutePlan extends SingleTableExecutePlan {
public HBaseResultSet executeQuery(HPreparedStatement statement) throws SQLException {
try {
HBaseConnection connection = statement.getConnection();
HTableInterface htable = connection.getHTable(getTableName());
String dbType = connection.getConnectProperties().getProperty("dbType");
Scan scan = new Scan();
@@ -109,6 +108,7 @@ public class SingleTableQueryExecutePlan extends SingleTableExecutePlan {
}
}
HTableInterface htable = connection.getHTable(getTableName());
ResultScanner scanner = htable.getScanner(scan);
HBaseResultSet resultSet = new HBaseResultSet(statement, htable, scanner);
@@ -7,9 +7,19 @@ import java.util.Map;
public class HMapping {
private String tableName;
private Map<String, HMappingColumn> columns = new LinkedHashMap<String, HMappingColumn>();
private HMappingColumn keyColumn;
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public Collection<HMappingColumn> getColumns() {
return Collections.unmodifiableCollection(columns.values());
}