hbase support

This commit is contained in:
温少
2012-05-19 09:36:59 +08:00
parent 421820bfcb
commit 7ac9fb060f
7 changed files with 87 additions and 14 deletions
@@ -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;
@@ -0,0 +1,25 @@
package com.alibaba.druid.hbase;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Properties;
import junit.framework.TestCase;
public class HBaseDriverInsertTest extends TestCase {
public void test_select_0() throws Exception {
HBaseDriver driver = new HBaseDriver();
Connection conn = driver.connect("jdbc:druid-hbase:10.20.153.63", new Properties());
PreparedStatement stmt = conn.prepareStatement("INSERT INTO test_user (id, name) VALUES (?, ?)");
stmt.setInt(1, 33);
stmt.setString(2, "ljw");
stmt.execute();
stmt.close();
conn.close();
}
}