From 84d8fddeacfd548cf21425f9667d4944c0af3d9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A9=E5=B0=91?= Date: Sat, 19 May 2012 11:16:19 +0800 Subject: [PATCH] refactor --- .../druid/hbase/HBasePreparedStatement.java | 4 +++ .../druid/hbase/exec/InsertExecutePlan.java | 36 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/alibaba/druid/hbase/HBasePreparedStatement.java b/src/main/java/com/alibaba/druid/hbase/HBasePreparedStatement.java index fd76afbb30..163306de24 100644 --- a/src/main/java/com/alibaba/druid/hbase/HBasePreparedStatement.java +++ b/src/main/java/com/alibaba/druid/hbase/HBasePreparedStatement.java @@ -7,6 +7,7 @@ import java.util.List; import com.alibaba.druid.common.jdbc.PreparedStatementBase; import com.alibaba.druid.hbase.exec.ExecutePlan; +import com.alibaba.druid.hbase.exec.InsertExecutePlan; import com.alibaba.druid.hbase.exec.SingleTableQueryExecutePlan; import com.alibaba.druid.sql.SQLUtils; import com.alibaba.druid.sql.ast.SQLStatement; @@ -59,6 +60,9 @@ public class HBasePreparedStatement extends PreparedStatementBase implements Pre String tableName = ((SQLIdentifierExpr) insertStmt.getTableSource().getExpr()).getName(); + InsertExecutePlan insertExecutePlan = new InsertExecutePlan(); + insertExecutePlan.setTableName(tableName); + throw new SQLException("TODO"); } else { throw new SQLException("TODO"); diff --git a/src/main/java/com/alibaba/druid/hbase/exec/InsertExecutePlan.java b/src/main/java/com/alibaba/druid/hbase/exec/InsertExecutePlan.java index 0665e252db..a8e379d7d7 100644 --- a/src/main/java/com/alibaba/druid/hbase/exec/InsertExecutePlan.java +++ b/src/main/java/com/alibaba/druid/hbase/exec/InsertExecutePlan.java @@ -1,21 +1,47 @@ package com.alibaba.druid.hbase.exec; import java.sql.SQLException; +import java.util.LinkedHashMap; +import java.util.Map; import org.apache.hadoop.hbase.client.HTableInterface; +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.sql.ast.SQLExpr; public class InsertExecutePlan extends SingleTableExecutePlan { + private Map columns = new LinkedHashMap(); + private byte[] family = Bytes.toBytes("d"); + @Override public void execute(HBasePreparedStatement statement) throws SQLException { try { HBaseConnection connection = statement.getConnection(); HTableInterface htable = connection.getHTable(getTableName()); - throw new UnsupportedOperationException(); + Put put = new Put(); + for (int i = 0; i < columns.size(); ++i) { +// String column = columns.get(i); +// Object value = statement.getParameters().get(i); +// +// byte[] qualifier = Bytes.toBytes(column); +// byte[] bytes; +// +// if (value instanceof String) { +// String strValue = (String) value; +// bytes = Bytes.toBytes(strValue); +// } else { +// throw new SQLException("TODO"); // TODO +// } +// +// put.add(family, qualifier, bytes); + } + + htable.put(put); } catch (SQLException e) { throw e; } catch (Exception e) { @@ -23,4 +49,12 @@ public class InsertExecutePlan extends SingleTableExecutePlan { } } + public Map getColumns() { + return columns; + } + + public void setColumns(Map columns) { + this.columns = columns; + } + }