mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor
This commit is contained in:
@@ -21,7 +21,6 @@ import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.client.HTableInterface;
|
||||
|
||||
import com.alibaba.druid.hdriver.HConnection;
|
||||
import com.alibaba.druid.hdriver.HPreparedStatement;
|
||||
import com.alibaba.druid.hdriver.HStatement;
|
||||
import com.alibaba.druid.hdriver.impl.mapping.HMapping;
|
||||
import com.alibaba.druid.util.jdbc.ConnectionBase;
|
||||
@@ -159,7 +158,12 @@ public class HBaseConnectionImpl extends ConnectionBase implements HConnection {
|
||||
|
||||
@Override
|
||||
public HPreparedStatementImpl prepareStatement(String sql) throws SQLException {
|
||||
return new HPreparedStatementImpl(this, sql);
|
||||
return prepareStatement(sql, (HMapping) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HPreparedStatementImpl prepareStatement(String sql, HMapping mapping) throws SQLException {
|
||||
return new HPreparedStatementImpl(this, sql, mapping);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -252,9 +256,4 @@ public class HBaseConnectionImpl extends ConnectionBase implements HConnection {
|
||||
return engine.getHTable(tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HPreparedStatement prepareStatement(String sql, HMapping mapping) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.alibaba.druid.hdriver.impl.execute.InsertExecutePlan;
|
||||
import com.alibaba.druid.hdriver.impl.execute.ShowTablesPlan;
|
||||
import com.alibaba.druid.hdriver.impl.execute.SingleTableQueryExecutePlan;
|
||||
import com.alibaba.druid.hdriver.impl.hbql.ast.HBQLShowStatement;
|
||||
import com.alibaba.druid.hdriver.impl.mapping.HMapping;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
@@ -38,10 +39,13 @@ public class HPreparedStatementImpl extends PreparedStatementBase implements HPr
|
||||
|
||||
private String dbType = "hbase";
|
||||
|
||||
public HPreparedStatementImpl(HBaseConnectionImpl conn, String sql) throws SQLException{
|
||||
private HMapping mapping;
|
||||
|
||||
public HPreparedStatementImpl(HBaseConnectionImpl conn, String sql, HMapping mapping) throws SQLException{
|
||||
super(conn);
|
||||
this.sql = sql;
|
||||
this.hbaseConnection = conn;
|
||||
this.mapping = mapping;
|
||||
|
||||
init();
|
||||
}
|
||||
@@ -58,6 +62,10 @@ public class HPreparedStatementImpl extends PreparedStatementBase implements HPr
|
||||
conditions.add(expr);
|
||||
}
|
||||
|
||||
public HMapping getMapping() {
|
||||
return mapping;
|
||||
}
|
||||
|
||||
public void init() throws SQLException {
|
||||
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, dbType);
|
||||
|
||||
@@ -78,6 +86,7 @@ public class HPreparedStatementImpl extends PreparedStatementBase implements HPr
|
||||
String tableName = ((SQLIdentifierExpr) tableSource.getExpr()).getName();
|
||||
|
||||
SingleTableQueryExecutePlan singleTableQueryExecuetePlan = new SingleTableQueryExecutePlan();
|
||||
singleTableQueryExecuetePlan.setMapping(mapping);
|
||||
singleTableQueryExecuetePlan.setTableName(tableName);
|
||||
|
||||
splitCondition(singleTableQueryExecuetePlan.getConditions(), selectQueryBlock.getWhere());
|
||||
|
||||
+7
-7
@@ -19,7 +19,7 @@ import com.alibaba.druid.hdriver.impl.HBaseConnectionImpl;
|
||||
import com.alibaba.druid.hdriver.impl.HPreparedStatementImpl;
|
||||
import com.alibaba.druid.hdriver.impl.HResultSetMetaDataImpl;
|
||||
import com.alibaba.druid.hdriver.impl.HScannerResultSetImpl;
|
||||
import com.alibaba.druid.hdriver.impl.mapping.HMappingTable;
|
||||
import com.alibaba.druid.hdriver.impl.mapping.HMapping;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
|
||||
@@ -28,24 +28,24 @@ import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
|
||||
public class SingleTableQueryExecutePlan extends SingleTableExecutePlan {
|
||||
|
||||
private List<String> columeNames = new ArrayList<String>();
|
||||
private List<SQLExpr> conditions = new ArrayList<SQLExpr>();
|
||||
private List<String> columeNames = new ArrayList<String>();
|
||||
private List<SQLExpr> conditions = new ArrayList<SQLExpr>();
|
||||
|
||||
private byte[] family = Bytes.toBytes("d");
|
||||
private byte[] family = Bytes.toBytes("d");
|
||||
|
||||
private HResultSetMetaDataImpl resultMetaData;
|
||||
|
||||
private HMappingTable mapping;
|
||||
private HMapping mapping;
|
||||
|
||||
public SingleTableQueryExecutePlan(){
|
||||
|
||||
}
|
||||
|
||||
public HMappingTable getMapping() {
|
||||
public HMapping getMapping() {
|
||||
return mapping;
|
||||
}
|
||||
|
||||
public void setMapping(HMappingTable mapping) {
|
||||
public void setMapping(HMapping mapping) {
|
||||
this.mapping = mapping;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user