mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
hbase support
This commit is contained in:
@@ -8,6 +8,7 @@ import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.NClob;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLClientInfoException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
@@ -15,12 +16,15 @@ import java.sql.SQLXML;
|
||||
import java.sql.Savepoint;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Struct;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
|
||||
import com.alibaba.druid.common.jdbc.ConnectionBase;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
|
||||
public class HBaseConnection extends ConnectionBase implements Connection {
|
||||
|
||||
@@ -28,7 +32,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);
|
||||
}
|
||||
|
||||
@@ -234,4 +238,16 @@ public class HBaseConnection extends ConnectionBase implements Connection {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ResultSet executeQuery(String sql, List<Object> parameters) throws SQLException {
|
||||
String dbType = this.getConnectProperties().getProperty("dbType");
|
||||
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, dbType);
|
||||
|
||||
if (stmtList.size() != 1) {
|
||||
throw new SQLException("not support multi-statement");
|
||||
}
|
||||
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
|
||||
throw new SQLException("TODO");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -8,12 +8,15 @@ import com.alibaba.druid.common.jdbc.PreparedStatementBase;
|
||||
|
||||
public class HBasePreparedStatement extends PreparedStatementBase implements PreparedStatement {
|
||||
|
||||
private final String sql;
|
||||
private String[] columnNames;
|
||||
private final String sql;
|
||||
private String[] columnNames;
|
||||
|
||||
private HBaseConnection hbaseConnection;
|
||||
|
||||
public HBasePreparedStatement(HBaseConnection conn, String sql){
|
||||
super(conn);
|
||||
this.sql = sql;
|
||||
this.hbaseConnection = conn;
|
||||
}
|
||||
|
||||
public String[] getColumnNames() {
|
||||
@@ -30,8 +33,7 @@ public class HBasePreparedStatement extends PreparedStatementBase implements Pre
|
||||
|
||||
@Override
|
||||
public ResultSet executeQuery() throws SQLException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return hbaseConnection.executeQuery(sql, getParameters());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.alibaba.druid.sql;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.DruidRuntimeException;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
@@ -146,6 +147,10 @@ public class SQLUtils {
|
||||
|
||||
public static List<SQLStatement> parseStatements(String sql, String dbType) {
|
||||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
|
||||
return parser.parseStatementList();
|
||||
List<SQLStatement> stmtList = parser.parseStatementList();
|
||||
if (parser.getLexer().token() != Token.EOF) {
|
||||
throw new DruidRuntimeException("syntax error : " + sql);
|
||||
}
|
||||
return stmtList;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user