mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
hbase support
This commit is contained in:
@@ -12,6 +12,7 @@ import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
|
||||
@@ -53,6 +54,12 @@ public class HBasePreparedStatement extends PreparedStatementBase implements Pre
|
||||
singleTableQueryExecuetePlan.setTableName(tableName);
|
||||
|
||||
this.executePlan = singleTableQueryExecuetePlan;
|
||||
} else if (sqlStmt instanceof SQLInsertStatement) {
|
||||
SQLInsertStatement insertStmt = (SQLInsertStatement) sqlStmt;
|
||||
|
||||
String tableName = ((SQLIdentifierExpr) insertStmt.getTableSource().getExpr()).getName();
|
||||
|
||||
throw new SQLException("TODO");
|
||||
} else {
|
||||
throw new SQLException("TODO");
|
||||
}
|
||||
|
||||
@@ -6,5 +6,8 @@ import com.alibaba.druid.hbase.HBasePreparedStatement;
|
||||
import com.alibaba.druid.hbase.HBaseResultSet;
|
||||
|
||||
public interface ExecutePlan {
|
||||
|
||||
HBaseResultSet executeQuery(HBasePreparedStatement statement) throws SQLException;
|
||||
|
||||
void execute(HBasePreparedStatement statement);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.alibaba.druid.hbase.exec;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.alibaba.druid.hbase.HBasePreparedStatement;
|
||||
import com.alibaba.druid.hbase.HBaseResultSet;
|
||||
|
||||
public class ExecutePlanAdapter implements ExecutePlan {
|
||||
|
||||
@Override
|
||||
public HBaseResultSet executeQuery(HBasePreparedStatement statement) throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(HBasePreparedStatement statement) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.alibaba.druid.hbase.exec;
|
||||
|
||||
import com.alibaba.druid.hbase.HBasePreparedStatement;
|
||||
|
||||
|
||||
|
||||
public class InsertExecutePlan extends SingleTableExecutePlan {
|
||||
|
||||
@Override
|
||||
public void execute(HBasePreparedStatement statement) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.alibaba.druid.hbase.exec;
|
||||
|
||||
|
||||
public class SingleTableExecutePlan extends ExecutePlanAdapter {
|
||||
private String tableName;
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
}
|
||||
@@ -10,27 +10,17 @@ import com.alibaba.druid.hbase.HBaseConnection;
|
||||
import com.alibaba.druid.hbase.HBasePreparedStatement;
|
||||
import com.alibaba.druid.hbase.HBaseResultSet;
|
||||
|
||||
public class SingleTableQueryExecutePlan implements ExecutePlan {
|
||||
|
||||
private String tableName;
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
public class SingleTableQueryExecutePlan extends SingleTableExecutePlan {
|
||||
|
||||
@Override
|
||||
public HBaseResultSet executeQuery(HBasePreparedStatement statement) throws SQLException {
|
||||
try {
|
||||
HBaseConnection connection = statement.getConnection();
|
||||
HTableInterface htable = connection.getHTable(tableName);
|
||||
|
||||
HTableInterface htable = connection.getHTable(getTableName());
|
||||
|
||||
Scan scan = new Scan();
|
||||
ResultScanner scanner = htable.getScanner(scan);
|
||||
|
||||
|
||||
return new HBaseResultSet(statement, htable, scanner);
|
||||
} catch (SQLException e) {
|
||||
throw e;
|
||||
|
||||
Reference in New Issue
Block a user