mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor
This commit is contained in:
@@ -72,7 +72,7 @@ public class HBaseConnection extends ConnectionBase implements Connection {
|
||||
|
||||
@Override
|
||||
public Statement createStatement() throws SQLException {
|
||||
return new HBaseStatement(this);
|
||||
return new HStatement(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -151,8 +151,8 @@ public class HBaseConnection extends ConnectionBase implements Connection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public HBasePreparedStatement prepareStatement(String sql) throws SQLException {
|
||||
return new HBasePreparedStatement(this, sql);
|
||||
public HPreparedStatement prepareStatement(String sql) throws SQLException {
|
||||
return new HPreparedStatement(this, sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,7 +179,7 @@ public class HBaseConnection extends ConnectionBase implements Connection {
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
|
||||
HBasePreparedStatement stmt = prepareStatement(sql);
|
||||
HPreparedStatement stmt = prepareStatement(sql);
|
||||
stmt.setColumnNames(columnNames);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@@ -17,15 +17,15 @@ import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class HBaseResultSet extends ResultSetBase {
|
||||
|
||||
private HBaseStatementInterface statement;
|
||||
private HStatementInterface statement;
|
||||
private ResultScanner scanner;
|
||||
private HTableInterface htable;
|
||||
private Result result;
|
||||
private byte[] family = Bytes.toBytes("d");
|
||||
|
||||
private HBaseResultSetMetaData metaData;
|
||||
private HResultSetMetaData metaData;
|
||||
|
||||
public HBaseResultSet(HBaseStatementInterface statement, HTableInterface htable, ResultScanner scanner){
|
||||
public HBaseResultSet(HStatementInterface statement, HTableInterface htable, ResultScanner scanner){
|
||||
super(statement);
|
||||
this.statement = statement;
|
||||
this.htable = htable;
|
||||
@@ -48,11 +48,11 @@ public class HBaseResultSet extends ResultSetBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public HBaseResultSetMetaData getMetaData() throws SQLException {
|
||||
public HResultSetMetaData getMetaData() throws SQLException {
|
||||
return metaData;
|
||||
}
|
||||
|
||||
public void setMetaData(HBaseResultSetMetaData metaData) {
|
||||
public void setMetaData(HResultSetMetaData metaData) {
|
||||
this.metaData = metaData;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import java.sql.DriverPropertyInfo;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class HBaseDriver implements Driver {
|
||||
public class HDriver implements Driver {
|
||||
|
||||
public static String PREFIX = "jdbc:druid-hbase:";
|
||||
|
||||
+3
-3
@@ -25,7 +25,7 @@ import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
|
||||
public class HBasePreparedStatement extends PreparedStatementBase implements PreparedStatement, HBaseStatementInterface {
|
||||
public class HPreparedStatement extends PreparedStatementBase implements PreparedStatement, HStatementInterface {
|
||||
|
||||
private final String sql;
|
||||
private String[] columnNames;
|
||||
@@ -34,7 +34,7 @@ public class HBasePreparedStatement extends PreparedStatementBase implements Pre
|
||||
|
||||
private ExecutePlan executePlan;
|
||||
|
||||
public HBasePreparedStatement(HBaseConnection conn, String sql) throws SQLException{
|
||||
public HPreparedStatement(HBaseConnection conn, String sql) throws SQLException{
|
||||
super(conn);
|
||||
this.sql = sql;
|
||||
this.hbaseConnection = conn;
|
||||
@@ -79,7 +79,7 @@ public class HBasePreparedStatement extends PreparedStatementBase implements Pre
|
||||
|
||||
splitCondition(singleTableQueryExecuetePlan.getConditions(), selectQueryBlock.getWhere());
|
||||
|
||||
HBaseResultSetMetaData resultMetaData = new HBaseResultSetMetaData();
|
||||
HResultSetMetaData resultMetaData = new HResultSetMetaData();
|
||||
for (SQLSelectItem selectItem : selectQueryBlock.getSelectList()) {
|
||||
ColumnMetaData columnMetaData = new ColumnMetaData();
|
||||
if (selectItem.getAlias() != null) {
|
||||
+1
-1
@@ -3,6 +3,6 @@ package com.alibaba.druid.hbase;
|
||||
import com.alibaba.druid.common.jdbc.ResultSetMetaDataBase;
|
||||
|
||||
|
||||
public class HBaseResultSetMetaData extends ResultSetMetaDataBase {
|
||||
public class HResultSetMetaData extends ResultSetMetaDataBase {
|
||||
|
||||
}
|
||||
+2
-2
@@ -5,11 +5,11 @@ import java.sql.Statement;
|
||||
|
||||
import com.alibaba.druid.common.jdbc.StatementBase;
|
||||
|
||||
public class HBaseStatement extends StatementBase implements Statement, HBaseStatementInterface {
|
||||
public class HStatement extends StatementBase implements Statement, HStatementInterface {
|
||||
|
||||
private HBaseConnection conn;
|
||||
|
||||
public HBaseStatement(HBaseConnection conn){
|
||||
public HStatement(HBaseConnection conn){
|
||||
super(conn);
|
||||
this.conn = conn;
|
||||
}
|
||||
+1
-1
@@ -3,6 +3,6 @@ package com.alibaba.druid.hbase;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public interface HBaseStatementInterface extends Statement {
|
||||
public interface HStatementInterface extends Statement {
|
||||
HBaseConnection getConnection() throws SQLException;
|
||||
}
|
||||
@@ -2,12 +2,12 @@ package com.alibaba.druid.hbase.exec;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.alibaba.druid.hbase.HBasePreparedStatement;
|
||||
import com.alibaba.druid.hbase.HPreparedStatement;
|
||||
import com.alibaba.druid.hbase.HBaseResultSet;
|
||||
|
||||
public interface ExecutePlan {
|
||||
|
||||
HBaseResultSet executeQuery(HBasePreparedStatement statement) throws SQLException;
|
||||
HBaseResultSet executeQuery(HPreparedStatement statement) throws SQLException;
|
||||
|
||||
boolean execute(HBasePreparedStatement statement) throws SQLException;
|
||||
boolean execute(HPreparedStatement statement) throws SQLException;
|
||||
}
|
||||
|
||||
@@ -2,18 +2,18 @@ package com.alibaba.druid.hbase.exec;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.alibaba.druid.hbase.HBasePreparedStatement;
|
||||
import com.alibaba.druid.hbase.HPreparedStatement;
|
||||
import com.alibaba.druid.hbase.HBaseResultSet;
|
||||
|
||||
public class ExecutePlanAdapter implements ExecutePlan {
|
||||
|
||||
@Override
|
||||
public HBaseResultSet executeQuery(HBasePreparedStatement statement) throws SQLException {
|
||||
public HBaseResultSet executeQuery(HPreparedStatement statement) throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(HBasePreparedStatement statement) throws SQLException {
|
||||
public boolean execute(HPreparedStatement statement) throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.apache.hadoop.hbase.client.Put;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
import com.alibaba.druid.hbase.HBaseConnection;
|
||||
import com.alibaba.druid.hbase.HBasePreparedStatement;
|
||||
import com.alibaba.druid.hbase.HPreparedStatement;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
|
||||
@@ -19,7 +19,7 @@ public class InsertExecutePlan extends SingleTableExecutePlan {
|
||||
private byte[] family = Bytes.toBytes("d");
|
||||
|
||||
@Override
|
||||
public boolean execute(HBasePreparedStatement statement) throws SQLException {
|
||||
public boolean execute(HPreparedStatement statement) throws SQLException {
|
||||
try {
|
||||
HBaseConnection connection = statement.getConnection();
|
||||
String dbType = connection.getConnectProperties().getProperty("dbType");
|
||||
|
||||
@@ -16,9 +16,9 @@ import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
import com.alibaba.druid.hbase.HBaseConnection;
|
||||
import com.alibaba.druid.hbase.HBasePreparedStatement;
|
||||
import com.alibaba.druid.hbase.HPreparedStatement;
|
||||
import com.alibaba.druid.hbase.HBaseResultSet;
|
||||
import com.alibaba.druid.hbase.HBaseResultSetMetaData;
|
||||
import com.alibaba.druid.hbase.HResultSetMetaData;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
|
||||
@@ -32,7 +32,7 @@ public class SingleTableQueryExecutePlan extends SingleTableExecutePlan {
|
||||
|
||||
private byte[] family = Bytes.toBytes("d");
|
||||
|
||||
private HBaseResultSetMetaData resultMetaData;
|
||||
private HResultSetMetaData resultMetaData;
|
||||
|
||||
public List<SQLExpr> getConditions() {
|
||||
return conditions;
|
||||
@@ -50,16 +50,16 @@ public class SingleTableQueryExecutePlan extends SingleTableExecutePlan {
|
||||
return columeNames;
|
||||
}
|
||||
|
||||
public HBaseResultSetMetaData getResultMetaData() {
|
||||
public HResultSetMetaData getResultMetaData() {
|
||||
return resultMetaData;
|
||||
}
|
||||
|
||||
public void setResultMetaData(HBaseResultSetMetaData resultMetaData) {
|
||||
public void setResultMetaData(HResultSetMetaData resultMetaData) {
|
||||
this.resultMetaData = resultMetaData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HBaseResultSet executeQuery(HBasePreparedStatement statement) throws SQLException {
|
||||
public HBaseResultSet executeQuery(HPreparedStatement statement) throws SQLException {
|
||||
try {
|
||||
HBaseConnection connection = statement.getConnection();
|
||||
HTableInterface htable = connection.getHTable(getTableName());
|
||||
|
||||
@@ -10,7 +10,7 @@ import junit.framework.TestCase;
|
||||
public class HBaseDriverInsertTest extends TestCase {
|
||||
|
||||
public void test_select_0() throws Exception {
|
||||
HBaseDriver driver = new HBaseDriver();
|
||||
HDriver driver = new HDriver();
|
||||
Connection conn = driver.connect("jdbc:druid-hbase:10.20.153.63", new Properties());
|
||||
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import junit.framework.TestCase;
|
||||
|
||||
public class HBaseDriverTest extends TestCase {
|
||||
public void test_select_0 () throws Exception {
|
||||
HBaseDriver driver = new HBaseDriver();
|
||||
HDriver driver = new HDriver();
|
||||
Connection conn = driver.connect("jdbc:druid-hbase:10.20.153.63", new Properties());
|
||||
|
||||
PreparedStatement stmt = conn.prepareStatement("SELECT id, name, gender, salary FROM test_user where id >= 3 and id <= ?");
|
||||
|
||||
@@ -10,7 +10,7 @@ import junit.framework.TestCase;
|
||||
|
||||
public class HBaseDriverTest_getIndex extends TestCase {
|
||||
public void test_select_0 () throws Exception {
|
||||
HBaseDriver driver = new HBaseDriver();
|
||||
HDriver driver = new HDriver();
|
||||
Connection conn = driver.connect("jdbc:druid-hbase:10.20.153.63", new Properties());
|
||||
|
||||
PreparedStatement stmt = conn.prepareStatement("SELECT id, name, gender, salary FROM test_user where id >= 3 and id <= ?");
|
||||
|
||||
@@ -10,7 +10,7 @@ import junit.framework.TestCase;
|
||||
|
||||
public class HBaseDriverTest_notRowFilter extends TestCase {
|
||||
public void test_select_0 () throws Exception {
|
||||
HBaseDriver driver = new HBaseDriver();
|
||||
HDriver driver = new HDriver();
|
||||
Connection conn = driver.connect("jdbc:druid-hbase:10.20.153.63", new Properties());
|
||||
|
||||
PreparedStatement stmt = conn.prepareStatement("SELECT id, name, gender, salary FROM test_user where name <= ?");
|
||||
|
||||
Reference in New Issue
Block a user