mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
hbase support
This commit is contained in:
@@ -28,7 +28,7 @@ public class HBaseConnection extends ConnectionBase implements Connection {
|
||||
|
||||
public HBaseConnection(String url, Properties info){
|
||||
super(url, info);
|
||||
config = new Configuration();
|
||||
config = new Configuration(false);
|
||||
this.setClientInfo(info);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.alibaba.druid.hbase;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Driver;
|
||||
import java.sql.DriverPropertyInfo;
|
||||
import java.sql.SQLException;
|
||||
@@ -8,10 +7,18 @@ import java.util.Properties;
|
||||
|
||||
public class HBaseDriver implements Driver {
|
||||
|
||||
private String prefix = "jdbc:druid-hbase:";
|
||||
public static String PREFIX = "jdbc:druid-hbase:";
|
||||
|
||||
@Override
|
||||
public Connection connect(String url, Properties info) throws SQLException {
|
||||
public HBaseConnection connect(String url, Properties info) throws SQLException {
|
||||
if (!acceptsURL(url)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String rest = url.substring(PREFIX.length());
|
||||
|
||||
info.put("hbase.zookeeper.quorum", rest);
|
||||
|
||||
return new HBaseConnection(url, info);
|
||||
}
|
||||
|
||||
@@ -20,8 +27,8 @@ public class HBaseDriver implements Driver {
|
||||
if (url == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return url.startsWith(prefix);
|
||||
|
||||
return url.startsWith(PREFIX);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,14 +11,14 @@ public class HBaseConnectTest extends TestCase {
|
||||
|
||||
public void test_connection() throws Exception {
|
||||
Configuration config = new Configuration();//HBaseConfiguration.create();
|
||||
config.set("dfs.support.append", "true");
|
||||
config.set("hbase.rootdir", "hdfs://10.20.153.63:9000/hbase");
|
||||
config.set("hbase.cluster.distributed", "true");
|
||||
config.set("hbase.master", "10.20.153.63:60000");
|
||||
// config.set("dfs.support.append", "true");
|
||||
// config.set("hbase.rootdir", "hdfs://10.20.153.63:9000/hbase");
|
||||
// config.set("hbase.cluster.distributed", "true");
|
||||
// config.set("hbase.master", "10.20.153.63:60000");
|
||||
config.set("hbase.zookeeper.quorum", "10.20.153.63");
|
||||
config.set("zookeeper.session.timeout", "30000");
|
||||
config.set("hbase.regionserver.handler.count", "100");
|
||||
config.set("hbase.client.keyvalue.maxsize", "67108864");
|
||||
// config.set("zookeeper.session.timeout", "30000");
|
||||
// config.set("hbase.regionserver.handler.count", "100");
|
||||
// config.set("hbase.client.keyvalue.maxsize", "67108864");
|
||||
|
||||
// config = HBaseConfiguration.create();
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.alibaba.druid.hbase;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
public class HBaseDriverTest extends TestCase {
|
||||
public void test_0 () throws Exception {
|
||||
HBaseDriver driver = new HBaseDriver();
|
||||
Connection conn = driver.connect("jdbc:druid-hbase::10.20.153.63", new Properties());
|
||||
|
||||
PreparedStatement stmt = conn.prepareStatement("SELECT * FROM test");
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
@@ -27,5 +27,6 @@ log4j.category.org.codehaus.xfire=INFO
|
||||
log4j.category.httpclient=INFO
|
||||
log4j.category.org.apache.struts.action.ActionServlet=ERROR
|
||||
log4j.category.com.alibaba.druid.mock=ERROR
|
||||
log4j.category.org.apache.hadoop.conf.Configuration=INFO
|
||||
|
||||
log4j.rootLogger=TRACE,CONSOLE
|
||||
|
||||
Reference in New Issue
Block a user