From daf1021632d1d71fa4ccc716e4b70bf7bba66bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A9=E5=B0=91?= Date: Fri, 18 May 2012 22:49:09 +0800 Subject: [PATCH] hbase support --- .../druid/common/jdbc/ResultSetBase.java | 1160 +++++++++++++++++ .../alibaba/druid/hbase/HBaseConnection.java | 42 +- .../com/alibaba/druid/hbase/HBaseDriver.java | 2 +- .../druid/hbase/HBasePreparedStatement.java | 9 +- .../alibaba/druid/hbase/HBaseResultSet.java | 82 ++ .../alibaba/druid/hbase/HBaseStatement.java | 150 +-- .../druid/hbase/HBaseStatementInterface.java | 8 + .../com/alibaba/druid/mock/MockResultSet.java | 1143 +--------------- .../alibaba/druid/hbase/HBaseDriverTest.java | 2 +- src/test/resources/log4j.properties | 3 +- 10 files changed, 1303 insertions(+), 1298 deletions(-) create mode 100644 src/main/java/com/alibaba/druid/common/jdbc/ResultSetBase.java create mode 100644 src/main/java/com/alibaba/druid/hbase/HBaseResultSet.java create mode 100644 src/main/java/com/alibaba/druid/hbase/HBaseStatementInterface.java diff --git a/src/main/java/com/alibaba/druid/common/jdbc/ResultSetBase.java b/src/main/java/com/alibaba/druid/common/jdbc/ResultSetBase.java new file mode 100644 index 0000000000..bdccdcde20 --- /dev/null +++ b/src/main/java/com/alibaba/druid/common/jdbc/ResultSetBase.java @@ -0,0 +1,1160 @@ +package com.alibaba.druid.common.jdbc; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.NClob; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Statement; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.Calendar; +import java.util.Map; + +public abstract class ResultSetBase implements ResultSet { + + protected boolean closed = false; + private boolean wasNull = false; + private SQLWarning warning; + private String cursorName; + private int fetchSize = 0; + private int fetchDirection = 0; + + private Statement statement; + + public ResultSetBase(Statement statement){ + super(); + this.statement = statement; + } + + @Override + public boolean isClosed() throws SQLException { + return closed; + } + + @Override + public void updateNString(int columnIndex, String x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateNString(String columnLabel, String x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateNClob(int columnIndex, NClob x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateNClob(String columnLabel, NClob x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public NClob getNClob(int columnIndex) throws SQLException { + return (NClob) getObject(columnIndex); + } + + @Override + public NClob getNClob(String columnLabel) throws SQLException { + return (NClob) getObject(columnLabel); + } + + @Override + public SQLXML getSQLXML(int columnIndex) throws SQLException { + return (SQLXML) getObject(columnIndex); + } + + @Override + public SQLXML getSQLXML(String columnLabel) throws SQLException { + return (SQLXML) getObject(columnLabel); + } + + @Override + public void updateSQLXML(int columnIndex, SQLXML x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateSQLXML(String columnLabel, SQLXML x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public String getNString(int columnIndex) throws SQLException { + return (String) getObject(columnIndex); + } + + @Override + public String getNString(String columnLabel) throws SQLException { + return (String) getObject(columnLabel); + } + + @Override + public Reader getNCharacterStream(int columnIndex) throws SQLException { + return (Reader) getObject(columnIndex); + } + + @Override + public Reader getNCharacterStream(String columnLabel) throws SQLException { + return (Reader) getObject(columnLabel); + } + + @Override + public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateNCharacterStream(String columnLabel, Reader x, long length) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateCharacterStream(String columnLabel, Reader x, long length) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateBlob(int columnIndex, InputStream x, long length) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateBlob(String columnLabel, InputStream x, long length) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateClob(int columnIndex, Reader x, long length) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateClob(String columnLabel, Reader x, long length) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateNClob(int columnIndex, Reader x, long length) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateNClob(String columnLabel, Reader x, long length) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateNCharacterStream(String columnLabel, Reader x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateCharacterStream(String columnLabel, Reader x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateBlob(int columnIndex, InputStream x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateBlob(String columnLabel, InputStream x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateClob(int columnIndex, Reader x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateClob(String columnLabel, Reader x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateNClob(int columnIndex, Reader x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateNClob(String columnLabel, Reader x) throws SQLException { + updateObject(columnLabel, x); + } + + public T getObject(int columnIndex, Class type) throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + public T getObject(String columnLabel, Class type) throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + @SuppressWarnings("unchecked") + @Override + public T unwrap(Class iface) throws SQLException { + if (iface == null) { + return null; + } + + if (iface.isInstance(this)) { + return (T) this; + } + + return null; + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + if (iface == null) { + return false; + } + + if (iface.isInstance(this)) { + return true; + } + + return false; + } + + @Override + public void close() throws SQLException { + this.closed = true; + } + + @Override + public boolean wasNull() throws SQLException { + if (closed) { + throw new SQLException(); + } + + return wasNull; + } + + public abstract Object getObjectInternal(int columnIndex); + + @Override + public Object getObject(int columnIndex) throws SQLException { + Object obj = getObjectInternal(columnIndex); + + wasNull = (obj == null); + + return obj; + } + + @Override + public Object getObject(String columnLabel) throws SQLException { + return getObject(findColumn(columnLabel)); + } + + @Override + public int findColumn(String columnLabel) throws SQLException { + return Integer.parseInt(columnLabel); + } + + @Override + public Reader getCharacterStream(int columnIndex) throws SQLException { + return (Reader) getObject(columnIndex); + } + + @Override + public Reader getCharacterStream(String columnLabel) throws SQLException { + return (Reader) getObject(columnLabel); + } + + @Override + public BigDecimal getBigDecimal(int columnIndex) throws SQLException { + return (BigDecimal) getObject(columnIndex); + } + + @Override + public BigDecimal getBigDecimal(String columnLabel) throws SQLException { + return getBigDecimal(Integer.parseInt(columnLabel)); + } + + @Override + public void clearWarnings() throws SQLException { + if (closed) { + throw new SQLException(); + } + + warning = null; + } + + public void setWarning(SQLWarning warning) { + this.warning = warning; + } + + @Override + public String getCursorName() throws SQLException { + if (closed) { + throw new SQLException(); + } + + return cursorName; + } + + public void setCursorName(String cursorName) { + this.cursorName = cursorName; + } + + @Override + public SQLWarning getWarnings() throws SQLException { + if (closed) { + throw new SQLException(); + } + + return warning; + } + + @Override + public void setFetchDirection(int direction) throws SQLException { + if (closed) { + throw new SQLException(); + } + + this.fetchDirection = direction; + } + + @Override + public int getFetchDirection() throws SQLException { + if (closed) { + throw new SQLException(); + } + + return fetchDirection; + } + + @Override + public void setFetchSize(int rows) throws SQLException { + if (closed) { + throw new SQLException(); + } + + this.fetchSize = rows; + } + + @Override + public int getFetchSize() throws SQLException { + if (closed) { + throw new SQLException(); + } + + return fetchSize; + } + + @Override + public boolean rowUpdated() throws SQLException { + if (closed) { + throw new SQLException(); + } + + return false; + } + + @Override + public boolean rowInserted() throws SQLException { + if (closed) { + throw new SQLException(); + } + + return false; + } + + @Override + public boolean rowDeleted() throws SQLException { + if (closed) { + throw new SQLException(); + } + + return false; + } + + @Override + public void updateNull(int columnIndex) throws SQLException { + updateObject(columnIndex, null); + } + + @Override + public void updateBoolean(int columnIndex, boolean x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateByte(int columnIndex, byte x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateShort(int columnIndex, short x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateInt(int columnIndex, int x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateLong(int columnIndex, long x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateFloat(int columnIndex, float x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateDouble(int columnIndex, double x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateString(int columnIndex, String x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateBytes(int columnIndex, byte[] x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateDate(int columnIndex, Date x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateTime(int columnIndex, Time x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateNull(String columnLabel) throws SQLException { + updateObject(columnLabel, null); + } + + @Override + public void updateBoolean(String columnLabel, boolean x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateByte(String columnLabel, byte x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateShort(String columnLabel, short x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateInt(String columnLabel, int x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateLong(String columnLabel, long x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateFloat(String columnLabel, float x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateDouble(String columnLabel, double x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateString(String columnLabel, String x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateBytes(String columnLabel, byte[] x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateDate(String columnLabel, Date x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateTime(String columnLabel, Time x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException { + updateObject(columnLabel, reader); + } + + @Override + public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateObject(String columnLabel, Object x) throws SQLException { + updateObject(Integer.parseInt(columnLabel), x); + } + + @Override + public void insertRow() throws SQLException { + if (closed) { + throw new SQLException("resultSet closed"); + } + } + + @Override + public void updateRow() throws SQLException { + if (closed) { + throw new SQLException("resultSet closed"); + } + } + + @Override + public void deleteRow() throws SQLException { + if (closed) { + throw new SQLException("resultSet closed"); + } + } + + @Override + public void refreshRow() throws SQLException { + if (closed) { + throw new SQLException("resultSet closed"); + } + } + + @Override + public void cancelRowUpdates() throws SQLException { + if (closed) { + throw new SQLException("resultSet closed"); + } + } + + @Override + public void moveToInsertRow() throws SQLException { + if (closed) { + throw new SQLException("resultSet closed"); + } + } + + @Override + public void moveToCurrentRow() throws SQLException { + if (closed) { + throw new SQLException("resultSet closed"); + } + } + + @Override + public Statement getStatement() throws SQLException { + if (closed) { + throw new SQLException("resultSet closed"); + } + return statement; + } + + @Override + public Object getObject(int columnIndex, Map> map) throws SQLException { + return getObject(columnIndex); + } + + @Override + public Ref getRef(int columnIndex) throws SQLException { + return (Ref) getObject(columnIndex); + } + + @Override + public Blob getBlob(int columnIndex) throws SQLException { + return (Blob) getObject(columnIndex); + } + + @Override + public Clob getClob(int columnIndex) throws SQLException { + return (Clob) getObject(columnIndex); + } + + @Override + public Array getArray(int columnIndex) throws SQLException { + return (Array) getObject(columnIndex); + } + + @Override + public Object getObject(String columnLabel, Map> map) throws SQLException { + return getObject(columnLabel); + } + + @Override + public Ref getRef(String columnLabel) throws SQLException { + return (Ref) getObject(columnLabel); + } + + @Override + public Blob getBlob(String columnLabel) throws SQLException { + return (Blob) getObject(columnLabel); + } + + @Override + public Clob getClob(String columnLabel) throws SQLException { + return (Clob) getObject(columnLabel); + } + + @Override + public Array getArray(String columnLabel) throws SQLException { + return (Array) getObject(columnLabel); + } + + @Override + public Date getDate(int columnIndex, Calendar cal) throws SQLException { + return (Date) getObject(columnIndex); + } + + @Override + public Date getDate(String columnLabel, Calendar cal) throws SQLException { + return (Date) getObject(columnLabel); + } + + @Override + public Time getTime(int columnIndex, Calendar cal) throws SQLException { + return (Time) getObject(columnIndex); + } + + @Override + public Time getTime(String columnLabel, Calendar cal) throws SQLException { + return (Time) getObject(columnLabel); + } + + @Override + public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { + return (Timestamp) getObject(columnIndex); + } + + @Override + public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { + return (Timestamp) getObject(columnLabel); + } + + @Override + public URL getURL(int columnIndex) throws SQLException { + return (URL) getObject(columnIndex); + } + + @Override + public URL getURL(String columnLabel) throws SQLException { + return (URL) getObject(columnLabel); + } + + @Override + public void updateRef(int columnIndex, Ref x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateRef(String columnLabel, Ref x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateBlob(int columnIndex, Blob x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateBlob(String columnLabel, Blob x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateClob(int columnIndex, Clob x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateClob(String columnLabel, Clob x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public void updateArray(int columnIndex, Array x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateArray(String columnLabel, Array x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public RowId getRowId(int columnIndex) throws SQLException { + return (RowId) getObject(columnIndex); + } + + @Override + public RowId getRowId(String columnLabel) throws SQLException { + return (RowId) getObject(columnLabel); + } + + @Override + public void updateRowId(int columnIndex, RowId x) throws SQLException { + updateObject(columnIndex, x); + } + + @Override + public void updateRowId(String columnLabel, RowId x) throws SQLException { + updateObject(columnLabel, x); + } + + @Override + public int getHoldability() throws SQLException { + if (closed) { + throw new SQLException("resultSet closed"); + } + + return 0; + } + + @Override + public String getString(int columnIndex) throws SQLException { + return (String) getObject(columnIndex); + } + + @Override + public boolean getBoolean(int columnIndex) throws SQLException { + Object obj = getObject(columnIndex); + + if (obj == null) { + return false; + } + + return ((Boolean) obj).booleanValue(); + } + + @Override + public byte getByte(int columnIndex) throws SQLException { + Number number = (Number) getObject(columnIndex); + + if (number == null) { + return 0; + } + + return number.byteValue(); + } + + @Override + public short getShort(int columnIndex) throws SQLException { + Number number = (Number) getObject(columnIndex); + + if (number == null) { + return 0; + } + + return number.shortValue(); + } + + @Override + public int getInt(int columnIndex) throws SQLException { + Number number = (Number) getObject(columnIndex); + + if (number == null) { + return 0; + } + + return number.intValue(); + } + + @Override + public long getLong(int columnIndex) throws SQLException { + Number number = (Number) getObject(columnIndex); + + if (number == null) { + return 0; + } + + return number.longValue(); + } + + @Override + public float getFloat(int columnIndex) throws SQLException { + Number number = (Number) getObject(columnIndex); + + if (number == null) { + return 0; + } + + return number.floatValue(); + } + + @Override + public double getDouble(int columnIndex) throws SQLException { + Number number = (Number) getObject(columnIndex); + + if (number == null) { + return 0; + } + + return number.doubleValue(); + } + + @Override + public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { + return (BigDecimal) getObject(columnIndex); + } + + @Override + public byte[] getBytes(int columnIndex) throws SQLException { + return (byte[]) getObject(columnIndex); + } + + @Override + public Date getDate(int columnIndex) throws SQLException { + return (Date) getObject(columnIndex); + } + + @Override + public Time getTime(int columnIndex) throws SQLException { + return (Time) getObject(columnIndex); + } + + @Override + public Timestamp getTimestamp(int columnIndex) throws SQLException { + return (Timestamp) getObject(columnIndex); + } + + @Override + public InputStream getAsciiStream(int columnIndex) throws SQLException { + return (InputStream) getObject(columnIndex); + } + + @Override + public InputStream getUnicodeStream(int columnIndex) throws SQLException { + return (InputStream) getObject(columnIndex); + } + + @Override + public InputStream getBinaryStream(int columnIndex) throws SQLException { + return (InputStream) getObject(columnIndex); + } + + @Override + public String getString(String columnLabel) throws SQLException { + return getString(Integer.parseInt(columnLabel)); + } + + @Override + public boolean getBoolean(String columnLabel) throws SQLException { + return getBoolean(Integer.parseInt(columnLabel)); + } + + @Override + public byte getByte(String columnLabel) throws SQLException { + return getByte(Integer.parseInt(columnLabel)); + } + + @Override + public short getShort(String columnLabel) throws SQLException { + return getShort(Integer.parseInt(columnLabel)); + } + + @Override + public int getInt(String columnLabel) throws SQLException { + return getInt(Integer.parseInt(columnLabel)); + } + + @Override + public long getLong(String columnLabel) throws SQLException { + return getLong(Integer.parseInt(columnLabel)); + } + + @Override + public float getFloat(String columnLabel) throws SQLException { + return getFloat(Integer.parseInt(columnLabel)); + } + + @Override + public double getDouble(String columnLabel) throws SQLException { + return getDouble(Integer.parseInt(columnLabel)); + } + + @Override + public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException { + return getBigDecimal(Integer.parseInt(columnLabel), scale); + } + + @Override + public byte[] getBytes(String columnLabel) throws SQLException { + return getBytes(Integer.parseInt(columnLabel)); + } + + @Override + public Date getDate(String columnLabel) throws SQLException { + return getDate(Integer.parseInt(columnLabel)); + } + + @Override + public Time getTime(String columnLabel) throws SQLException { + return getTime(Integer.parseInt(columnLabel)); + } + + @Override + public Timestamp getTimestamp(String columnLabel) throws SQLException { + return getTimestamp(Integer.parseInt(columnLabel)); + } + + @Override + public InputStream getAsciiStream(String columnLabel) throws SQLException { + return getAsciiStream(Integer.parseInt(columnLabel)); + } + + @Override + public InputStream getUnicodeStream(String columnLabel) throws SQLException { + return getUnicodeStream(Integer.parseInt(columnLabel)); + } + + @Override + public InputStream getBinaryStream(String columnLabel) throws SQLException { + return getBinaryStream(Integer.parseInt(columnLabel)); + } + + @Override + public boolean isBeforeFirst() throws SQLException { + if (closed) { + throw new SQLException(); + } + + return false; + } + + @Override + public boolean isAfterLast() throws SQLException { + if (closed) { + throw new SQLException(); + } + return false; + } + + @Override + public boolean isFirst() throws SQLException { + if (closed) { + throw new SQLException(); + } + + return false; + } + + @Override + public boolean isLast() throws SQLException { + if (closed) { + throw new SQLException(); + } + + return false; + } + + @Override + public void beforeFirst() throws SQLException { + if (closed) { + throw new SQLException(); + } + + } + + @Override + public void afterLast() throws SQLException { + if (closed) { + throw new SQLException(); + } + + } + + @Override + public boolean first() throws SQLException { + if (closed) { + throw new SQLException(); + } + + return false; + } + + @Override + public boolean last() throws SQLException { + if (closed) { + throw new SQLException(); + } + + return false; + } + + @Override + public int getRow() throws SQLException { + if (closed) { + throw new SQLException(); + } + + return 0; + } + + @Override + public boolean absolute(int row) throws SQLException { + if (closed) { + throw new SQLException(); + } + + return false; + } + + @Override + public boolean relative(int rows) throws SQLException { + if (closed) { + throw new SQLException(); + } + + return false; + } + + @Override + public int getType() throws SQLException { + if (closed) { + throw new SQLException(); + } + + return 0; + } + + @Override + public int getConcurrency() throws SQLException { + if (closed) { + throw new SQLException(); + } + + return 0; + } +} diff --git a/src/main/java/com/alibaba/druid/hbase/HBaseConnection.java b/src/main/java/com/alibaba/druid/hbase/HBaseConnection.java index 54fd17dd90..593cff4bae 100644 --- a/src/main/java/com/alibaba/druid/hbase/HBaseConnection.java +++ b/src/main/java/com/alibaba/druid/hbase/HBaseConnection.java @@ -21,10 +21,17 @@ import java.util.Map; import java.util.Properties; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.client.HTable; +import org.apache.hadoop.hbase.client.ResultScanner; +import org.apache.hadoop.hbase.client.Scan; import com.alibaba.druid.common.jdbc.ConnectionBase; 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.SQLSelectQueryBlock; +import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; public class HBaseConnection extends ConnectionBase implements Connection { @@ -238,16 +245,31 @@ public class HBaseConnection extends ConnectionBase implements Connection { return null; } - public ResultSet executeQuery(String sql, List parameters) throws SQLException { - String dbType = this.getConnectProperties().getProperty("dbType"); - List stmtList = SQLUtils.parseStatements(sql, dbType); - - if (stmtList.size() != 1) { - throw new SQLException("not support multi-statement"); + public ResultSet executeQuery(HBaseStatementInterface jdbcHbaseStmt, String sql, List parameters) throws SQLException { + try { + String dbType = this.getConnectProperties().getProperty("dbType"); + List stmtList = SQLUtils.parseStatements(sql, dbType); + + if (stmtList.size() != 1) { + throw new SQLException("not support multi-statement"); + } + + SQLSelectStatement stmt = (SQLSelectStatement) stmtList.get(0); + SQLSelectQueryBlock selectQueryBlock = (SQLSelectQueryBlock) stmt.getSelect().getQuery(); + + SQLExprTableSource tableSource = (SQLExprTableSource) selectQueryBlock.getFrom(); + String tableName = ((SQLIdentifierExpr) tableSource.getExpr()).getName(); + + HTable htable = new HTable(config, tableName); + + Scan scan = new Scan(); + ResultScanner scanner = htable.getScanner(scan); + + return new HBaseResultSet(jdbcHbaseStmt, scanner); + } catch (SQLException ex) { + throw ex; + } catch (Exception ex) { + throw new SQLException("executeQuery error", ex); } - - SQLStatement stmt = stmtList.get(0); - - throw new SQLException("TODO"); } } diff --git a/src/main/java/com/alibaba/druid/hbase/HBaseDriver.java b/src/main/java/com/alibaba/druid/hbase/HBaseDriver.java index 4fa5951148..cdd8a2a718 100644 --- a/src/main/java/com/alibaba/druid/hbase/HBaseDriver.java +++ b/src/main/java/com/alibaba/druid/hbase/HBaseDriver.java @@ -15,7 +15,7 @@ public class HBaseDriver implements Driver { return null; } - String rest = url.substring(PREFIX.length()); + String rest = url.substring(PREFIX.length() + 1); info.put("hbase.zookeeper.quorum", rest); diff --git a/src/main/java/com/alibaba/druid/hbase/HBasePreparedStatement.java b/src/main/java/com/alibaba/druid/hbase/HBasePreparedStatement.java index 790d9106a8..854f5c9826 100644 --- a/src/main/java/com/alibaba/druid/hbase/HBasePreparedStatement.java +++ b/src/main/java/com/alibaba/druid/hbase/HBasePreparedStatement.java @@ -6,7 +6,7 @@ import java.sql.SQLException; import com.alibaba.druid.common.jdbc.PreparedStatementBase; -public class HBasePreparedStatement extends PreparedStatementBase implements PreparedStatement { +public class HBasePreparedStatement extends PreparedStatementBase implements PreparedStatement, HBaseStatementInterface { private final String sql; private String[] columnNames; @@ -31,9 +31,14 @@ public class HBasePreparedStatement extends PreparedStatementBase implements Pre return sql; } + @Override + public HBaseConnection getConnection() throws SQLException { + return hbaseConnection; + } + @Override public ResultSet executeQuery() throws SQLException { - return hbaseConnection.executeQuery(sql, getParameters()); + return hbaseConnection.executeQuery(this, sql, getParameters()); } @Override diff --git a/src/main/java/com/alibaba/druid/hbase/HBaseResultSet.java b/src/main/java/com/alibaba/druid/hbase/HBaseResultSet.java new file mode 100644 index 0000000000..674a0804ce --- /dev/null +++ b/src/main/java/com/alibaba/druid/hbase/HBaseResultSet.java @@ -0,0 +1,82 @@ +package com.alibaba.druid.hbase; + +import java.io.IOException; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; + +import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.client.ResultScanner; +import org.apache.hadoop.hbase.util.Bytes; + +import com.alibaba.druid.common.jdbc.ResultSetBase; + +public class HBaseResultSet extends ResultSetBase { + + private HBaseStatementInterface statement; + private ResultScanner scanner; + private Result result; + + public HBaseResultSet(HBaseStatementInterface statement, ResultScanner scanner){ + super(statement); + this.statement = statement; + this.scanner = scanner; + } + + @Override + public Statement getStatement() throws SQLException { + return statement; + } + + @Override + public boolean next() throws SQLException { + try { + result = scanner.next(); + return result != null && !result.isEmpty(); + } catch (IOException ex) { + throw new SQLException("read next error", ex); + } + } + + @Override + public ResultSetMetaData getMetaData() throws SQLException { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean previous() throws SQLException { + // TODO Auto-generated method stub + return false; + } + + @Override + public void updateObject(int columnIndex, Object x) throws SQLException { + // TODO Auto-generated method stub + + } + + @Override + public Object getObjectInternal(int columnIndex) { + return null; + } + + @Override + public String getString(String columnName) throws SQLException { + byte[] qualifier = Bytes.toBytes(columnName); + byte[] family = Bytes.toBytes("d"); + byte[] value = result.getValue(family, qualifier); + return Bytes.toString(value); + } + + @Override + public void close() throws SQLException { + try { + scanner.close(); + } catch (Exception ex) { + throw new SQLException("close error", ex); + } + super.close(); + } + +} diff --git a/src/main/java/com/alibaba/druid/hbase/HBaseStatement.java b/src/main/java/com/alibaba/druid/hbase/HBaseStatement.java index 1286070160..2d667b86a8 100644 --- a/src/main/java/com/alibaba/druid/hbase/HBaseStatement.java +++ b/src/main/java/com/alibaba/druid/hbase/HBaseStatement.java @@ -1,13 +1,11 @@ package com.alibaba.druid.hbase; -import java.sql.Connection; -import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import com.alibaba.druid.common.jdbc.StatementBase; -public class HBaseStatement extends StatementBase implements Statement { +public class HBaseStatement extends StatementBase implements Statement, HBaseStatementInterface { private HBaseConnection conn; @@ -17,154 +15,10 @@ public class HBaseStatement extends StatementBase implements Statement { } @Override - public T unwrap(Class iface) throws SQLException { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean isWrapperFor(Class iface) throws SQLException { - // TODO Auto-generated method stub - return false; - } - - @Override - public ResultSet executeQuery(String sql) throws SQLException { - // TODO Auto-generated method stub - return null; - } - - @Override - public int executeUpdate(String sql) throws SQLException { - // TODO Auto-generated method stub - return 0; - } - - @Override - public void close() throws SQLException { - // TODO Auto-generated method stub - - } - - @Override - public void cancel() throws SQLException { - - } - - @Override - public boolean execute(String sql) throws SQLException { - // TODO Auto-generated method stub - return false; - } - - @Override - public ResultSet getResultSet() throws SQLException { - // TODO Auto-generated method stub - return null; - } - - @Override - public int getUpdateCount() throws SQLException { - // TODO Auto-generated method stub - return 0; - } - - @Override - public boolean getMoreResults() throws SQLException { - // TODO Auto-generated method stub - return false; - } - - @Override - public void addBatch(String sql) throws SQLException { - // TODO Auto-generated method stub - - } - - @Override - public void clearBatch() throws SQLException { - // TODO Auto-generated method stub - - } - - @Override - public int[] executeBatch() throws SQLException { - // TODO Auto-generated method stub - return null; - } - - @Override - public Connection getConnection() throws SQLException { + public HBaseConnection getConnection() throws SQLException { return conn; } - @Override - public boolean getMoreResults(int current) throws SQLException { - // TODO Auto-generated method stub - return false; - } - - @Override - public ResultSet getGeneratedKeys() throws SQLException { - // TODO Auto-generated method stub - return null; - } - - @Override - public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { - // TODO Auto-generated method stub - return 0; - } - - @Override - public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { - // TODO Auto-generated method stub - return 0; - } - - @Override - public int executeUpdate(String sql, String[] columnNames) throws SQLException { - // TODO Auto-generated method stub - return 0; - } - - @Override - public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean execute(String sql, int[] columnIndexes) throws SQLException { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean execute(String sql, String[] columnNames) throws SQLException { - // TODO Auto-generated method stub - return false; - } - - - @Override - public boolean isClosed() throws SQLException { - // TODO Auto-generated method stub - return false; - } - - @Override - public void setPoolable(boolean poolable) throws SQLException { - // TODO Auto-generated method stub - - } - - @Override - public boolean isPoolable() throws SQLException { - // TODO Auto-generated method stub - return false; - } - public void checkOpen() { } diff --git a/src/main/java/com/alibaba/druid/hbase/HBaseStatementInterface.java b/src/main/java/com/alibaba/druid/hbase/HBaseStatementInterface.java new file mode 100644 index 0000000000..4c13b29281 --- /dev/null +++ b/src/main/java/com/alibaba/druid/hbase/HBaseStatementInterface.java @@ -0,0 +1,8 @@ +package com.alibaba.druid.hbase; + +import java.sql.SQLException; +import java.sql.Statement; + +public interface HBaseStatementInterface extends Statement { + HBaseConnection getConnection() throws SQLException; +} diff --git a/src/main/java/com/alibaba/druid/mock/MockResultSet.java b/src/main/java/com/alibaba/druid/mock/MockResultSet.java index 25c2908b4e..a4286f6ebf 100644 --- a/src/main/java/com/alibaba/druid/mock/MockResultSet.java +++ b/src/main/java/com/alibaba/druid/mock/MockResultSet.java @@ -15,72 +15,30 @@ */ package com.alibaba.druid.mock; -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; -import java.sql.Array; -import java.sql.Blob; -import java.sql.Clob; -import java.sql.Date; -import java.sql.NClob; -import java.sql.Ref; import java.sql.ResultSet; import java.sql.ResultSetMetaData; -import java.sql.RowId; import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.sql.SQLWarning; -import java.sql.SQLXML; import java.sql.Statement; -import java.sql.Time; -import java.sql.Timestamp; import java.util.ArrayList; -import java.util.Calendar; import java.util.List; -import java.util.Map; -public class MockResultSet implements ResultSet { +import com.alibaba.druid.common.jdbc.ResultSetBase; - private int rowIndex = -1; - private Statement statement; - private List rows = new ArrayList(); +public class MockResultSet extends ResultSetBase implements ResultSet { - private boolean wasNull = false; + private int rowIndex = -1; + private List rows = new ArrayList(); - private MockResultSetMetaData metaData = new MockResultSetMetaData(); - private boolean closed = false; - private int fetchSize = 0; - private int fetchDirection = 0; - private SQLWarning warning; - private String cursorName; + private MockResultSetMetaData metaData = new MockResultSetMetaData(); public MockResultSet(Statement statement){ - super(); - this.statement = statement; + super(statement); } public List getRows() { return rows; } - @SuppressWarnings("unchecked") - @Override - public T unwrap(Class iface) throws SQLException { - if (iface == MockResultSet.class || iface == ResultSet.class) { - return (T) this; - } - return null; - } - - @Override - public boolean isWrapperFor(Class iface) throws SQLException { - if (iface == MockResultSet.class || iface == ResultSet.class) { - return true; - } - return false; - } - @Override public synchronized boolean next() throws SQLException { if (closed) { @@ -94,257 +52,7 @@ public class MockResultSet implements ResultSet { return false; } - @Override - public void close() throws SQLException { - this.closed = true; - } - - @Override - public boolean wasNull() throws SQLException { - if (closed) { - throw new SQLException(); - } - - return wasNull; - } - - @Override - public String getString(int columnIndex) throws SQLException { - return (String) getObject(columnIndex); - } - - @Override - public boolean getBoolean(int columnIndex) throws SQLException { - Object obj = getObject(columnIndex); - - if (obj == null) { - return false; - } - - return ((Boolean) obj).booleanValue(); - } - - @Override - public byte getByte(int columnIndex) throws SQLException { - Number number = (Number) getObject(columnIndex); - - if (number == null) { - return 0; - } - - return number.byteValue(); - } - - @Override - public short getShort(int columnIndex) throws SQLException { - Number number = (Number) getObject(columnIndex); - - if (number == null) { - return 0; - } - - return number.shortValue(); - } - - @Override - public int getInt(int columnIndex) throws SQLException { - Number number = (Number) getObject(columnIndex); - - if (number == null) { - return 0; - } - - return number.intValue(); - } - - @Override - public long getLong(int columnIndex) throws SQLException { - Number number = (Number) getObject(columnIndex); - - if (number == null) { - return 0; - } - - return number.longValue(); - } - - @Override - public float getFloat(int columnIndex) throws SQLException { - Number number = (Number) getObject(columnIndex); - - if (number == null) { - return 0; - } - - return number.floatValue(); - } - - @Override - public double getDouble(int columnIndex) throws SQLException { - Number number = (Number) getObject(columnIndex); - - if (number == null) { - return 0; - } - - return number.doubleValue(); - } - - @Override - public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { - return (BigDecimal) getObject(columnIndex); - } - - @Override - public byte[] getBytes(int columnIndex) throws SQLException { - return (byte[]) getObject(columnIndex); - } - - @Override - public Date getDate(int columnIndex) throws SQLException { - return (Date) getObject(columnIndex); - } - - @Override - public Time getTime(int columnIndex) throws SQLException { - return (Time) getObject(columnIndex); - } - - @Override - public Timestamp getTimestamp(int columnIndex) throws SQLException { - return (Timestamp) getObject(columnIndex); - } - - @Override - public InputStream getAsciiStream(int columnIndex) throws SQLException { - return (InputStream) getObject(columnIndex); - } - - @Override - public InputStream getUnicodeStream(int columnIndex) throws SQLException { - return (InputStream) getObject(columnIndex); - } - - @Override - public InputStream getBinaryStream(int columnIndex) throws SQLException { - return (InputStream) getObject(columnIndex); - } - - @Override - public String getString(String columnLabel) throws SQLException { - return getString(Integer.parseInt(columnLabel)); - } - - @Override - public boolean getBoolean(String columnLabel) throws SQLException { - return getBoolean(Integer.parseInt(columnLabel)); - } - - @Override - public byte getByte(String columnLabel) throws SQLException { - return getByte(Integer.parseInt(columnLabel)); - } - - @Override - public short getShort(String columnLabel) throws SQLException { - return getShort(Integer.parseInt(columnLabel)); - } - - @Override - public int getInt(String columnLabel) throws SQLException { - return getInt(Integer.parseInt(columnLabel)); - } - - @Override - public long getLong(String columnLabel) throws SQLException { - return getLong(Integer.parseInt(columnLabel)); - } - - @Override - public float getFloat(String columnLabel) throws SQLException { - return getFloat(Integer.parseInt(columnLabel)); - } - - @Override - public double getDouble(String columnLabel) throws SQLException { - return getDouble(Integer.parseInt(columnLabel)); - } - - @Override - public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException { - return getBigDecimal(Integer.parseInt(columnLabel), scale); - } - - @Override - public byte[] getBytes(String columnLabel) throws SQLException { - return getBytes(Integer.parseInt(columnLabel)); - } - - @Override - public Date getDate(String columnLabel) throws SQLException { - return getDate(Integer.parseInt(columnLabel)); - } - - @Override - public Time getTime(String columnLabel) throws SQLException { - return getTime(Integer.parseInt(columnLabel)); - } - - @Override - public Timestamp getTimestamp(String columnLabel) throws SQLException { - return getTimestamp(Integer.parseInt(columnLabel)); - } - - @Override - public InputStream getAsciiStream(String columnLabel) throws SQLException { - return getAsciiStream(Integer.parseInt(columnLabel)); - } - - @Override - public InputStream getUnicodeStream(String columnLabel) throws SQLException { - return getUnicodeStream(Integer.parseInt(columnLabel)); - } - - @Override - public InputStream getBinaryStream(String columnLabel) throws SQLException { - return getBinaryStream(Integer.parseInt(columnLabel)); - } - - @Override - public SQLWarning getWarnings() throws SQLException { - if (closed) { - throw new SQLException(); - } - - return warning; - } - - @Override - public void clearWarnings() throws SQLException { - if (closed) { - throw new SQLException(); - } - - warning = null; - } - - public void setWarning(SQLWarning warning) { - this.warning = warning; - } - - @Override - public String getCursorName() throws SQLException { - if (closed) { - throw new SQLException(); - } - - return cursorName; - } - - public void setCursorName(String cursorName) { - this.cursorName = cursorName; - } - + @Override public ResultSetMetaData getMetaData() throws SQLException { if (closed) { @@ -358,142 +66,12 @@ public class MockResultSet implements ResultSet { return metaData; } - @Override - public Object getObject(int columnIndex) throws SQLException { + public Object getObjectInternal(int columnIndex) { Object[] row = rows.get(rowIndex); Object obj = row[columnIndex - 1]; - - wasNull = (obj == null); - return obj; } - @Override - public Object getObject(String columnLabel) throws SQLException { - return getObject(findColumn(columnLabel)); - } - - @Override - public int findColumn(String columnLabel) throws SQLException { - return Integer.parseInt(columnLabel); - } - - @Override - public Reader getCharacterStream(int columnIndex) throws SQLException { - return (Reader) getObject(columnIndex); - } - - @Override - public Reader getCharacterStream(String columnLabel) throws SQLException { - return (Reader) getObject(columnLabel); - } - - @Override - public BigDecimal getBigDecimal(int columnIndex) throws SQLException { - return (BigDecimal) getObject(columnIndex); - } - - @Override - public BigDecimal getBigDecimal(String columnLabel) throws SQLException { - return getBigDecimal(Integer.parseInt(columnLabel)); - } - - @Override - public boolean isBeforeFirst() throws SQLException { - if (closed) { - throw new SQLException(); - } - - return false; - } - - @Override - public boolean isAfterLast() throws SQLException { - if (closed) { - throw new SQLException(); - } - return false; - } - - @Override - public boolean isFirst() throws SQLException { - if (closed) { - throw new SQLException(); - } - - return false; - } - - @Override - public boolean isLast() throws SQLException { - if (closed) { - throw new SQLException(); - } - - return false; - } - - @Override - public void beforeFirst() throws SQLException { - if (closed) { - throw new SQLException(); - } - - } - - @Override - public void afterLast() throws SQLException { - if (closed) { - throw new SQLException(); - } - - } - - @Override - public boolean first() throws SQLException { - if (closed) { - throw new SQLException(); - } - - return false; - } - - @Override - public boolean last() throws SQLException { - if (closed) { - throw new SQLException(); - } - - return false; - } - - @Override - public int getRow() throws SQLException { - if (closed) { - throw new SQLException(); - } - - return 0; - } - - @Override - public boolean absolute(int row) throws SQLException { - if (closed) { - throw new SQLException(); - } - - return false; - } - - @Override - public boolean relative(int rows) throws SQLException { - if (closed) { - throw new SQLException(); - } - - return false; - } - @Override public synchronized boolean previous() throws SQLException { if (closed) { @@ -507,715 +85,10 @@ public class MockResultSet implements ResultSet { return false; } - @Override - public void setFetchDirection(int direction) throws SQLException { - if (closed) { - throw new SQLException(); - } - - this.fetchDirection = direction; - } - - @Override - public int getFetchDirection() throws SQLException { - if (closed) { - throw new SQLException(); - } - - return fetchDirection; - } - - @Override - public void setFetchSize(int rows) throws SQLException { - if (closed) { - throw new SQLException(); - } - - this.fetchSize = rows; - } - - @Override - public int getFetchSize() throws SQLException { - if (closed) { - throw new SQLException(); - } - - return fetchSize; - } - - @Override - public int getType() throws SQLException { - if (closed) { - throw new SQLException(); - } - - return 0; - } - - @Override - public int getConcurrency() throws SQLException { - if (closed) { - throw new SQLException(); - } - - return 0; - } - - @Override - public boolean rowUpdated() throws SQLException { - if (closed) { - throw new SQLException(); - } - - return false; - } - - @Override - public boolean rowInserted() throws SQLException { - if (closed) { - throw new SQLException(); - } - - return false; - } - - @Override - public boolean rowDeleted() throws SQLException { - if (closed) { - throw new SQLException(); - } - - return false; - } - - @Override - public void updateNull(int columnIndex) throws SQLException { - updateObject(columnIndex, null); - } - - @Override - public void updateBoolean(int columnIndex, boolean x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateByte(int columnIndex, byte x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateShort(int columnIndex, short x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateInt(int columnIndex, int x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateLong(int columnIndex, long x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateFloat(int columnIndex, float x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateDouble(int columnIndex, double x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateString(int columnIndex, String x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateBytes(int columnIndex, byte[] x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateDate(int columnIndex, Date x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateTime(int columnIndex, Time x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException { - updateObject(columnIndex, x); - } - @Override public void updateObject(int columnIndex, Object x) throws SQLException { Object[] row = rows.get(rowIndex); row[columnIndex - 1] = x; } - @Override - public void updateNull(String columnLabel) throws SQLException { - updateObject(columnLabel, null); - } - - @Override - public void updateBoolean(String columnLabel, boolean x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateByte(String columnLabel, byte x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateShort(String columnLabel, short x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateInt(String columnLabel, int x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateLong(String columnLabel, long x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateFloat(String columnLabel, float x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateDouble(String columnLabel, double x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateString(String columnLabel, String x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateBytes(String columnLabel, byte[] x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateDate(String columnLabel, Date x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateTime(String columnLabel, Time x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException { - updateObject(columnLabel, reader); - } - - @Override - public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateObject(String columnLabel, Object x) throws SQLException { - updateObject(Integer.parseInt(columnLabel), x); - } - - @Override - public void insertRow() throws SQLException { - if (closed) { - throw new SQLException("resultSet closed"); - } - } - - @Override - public void updateRow() throws SQLException { - if (closed) { - throw new SQLException("resultSet closed"); - } - } - - @Override - public void deleteRow() throws SQLException { - if (closed) { - throw new SQLException("resultSet closed"); - } - } - - @Override - public void refreshRow() throws SQLException { - if (closed) { - throw new SQLException("resultSet closed"); - } - } - - @Override - public void cancelRowUpdates() throws SQLException { - if (closed) { - throw new SQLException("resultSet closed"); - } - } - - @Override - public void moveToInsertRow() throws SQLException { - if (closed) { - throw new SQLException("resultSet closed"); - } - } - - @Override - public void moveToCurrentRow() throws SQLException { - if (closed) { - throw new SQLException("resultSet closed"); - } - } - - @Override - public Statement getStatement() throws SQLException { - if (closed) { - throw new SQLException("resultSet closed"); - } - return statement; - } - - @Override - public Object getObject(int columnIndex, Map> map) throws SQLException { - return getObject(columnIndex); - } - - @Override - public Ref getRef(int columnIndex) throws SQLException { - return (Ref) getObject(columnIndex); - } - - @Override - public Blob getBlob(int columnIndex) throws SQLException { - return (Blob) getObject(columnIndex); - } - - @Override - public Clob getClob(int columnIndex) throws SQLException { - return (Clob) getObject(columnIndex); - } - - @Override - public Array getArray(int columnIndex) throws SQLException { - return (Array) getObject(columnIndex); - } - - @Override - public Object getObject(String columnLabel, Map> map) throws SQLException { - return getObject(columnLabel); - } - - @Override - public Ref getRef(String columnLabel) throws SQLException { - return (Ref) getObject(columnLabel); - } - - @Override - public Blob getBlob(String columnLabel) throws SQLException { - return (Blob) getObject(columnLabel); - } - - @Override - public Clob getClob(String columnLabel) throws SQLException { - return (Clob) getObject(columnLabel); - } - - @Override - public Array getArray(String columnLabel) throws SQLException { - return (Array) getObject(columnLabel); - } - - @Override - public Date getDate(int columnIndex, Calendar cal) throws SQLException { - return (Date) getObject(columnIndex); - } - - @Override - public Date getDate(String columnLabel, Calendar cal) throws SQLException { - return (Date) getObject(columnLabel); - } - - @Override - public Time getTime(int columnIndex, Calendar cal) throws SQLException { - return (Time) getObject(columnIndex); - } - - @Override - public Time getTime(String columnLabel, Calendar cal) throws SQLException { - return (Time) getObject(columnLabel); - } - - @Override - public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { - return (Timestamp) getObject(columnIndex); - } - - @Override - public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { - return (Timestamp) getObject(columnLabel); - } - - @Override - public URL getURL(int columnIndex) throws SQLException { - return (URL) getObject(columnIndex); - } - - @Override - public URL getURL(String columnLabel) throws SQLException { - return (URL) getObject(columnLabel); - } - - @Override - public void updateRef(int columnIndex, Ref x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateRef(String columnLabel, Ref x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateBlob(int columnIndex, Blob x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateBlob(String columnLabel, Blob x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateClob(int columnIndex, Clob x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateClob(String columnLabel, Clob x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateArray(int columnIndex, Array x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateArray(String columnLabel, Array x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public RowId getRowId(int columnIndex) throws SQLException { - return (RowId) getObject(columnIndex); - } - - @Override - public RowId getRowId(String columnLabel) throws SQLException { - return (RowId) getObject(columnLabel); - } - - @Override - public void updateRowId(int columnIndex, RowId x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateRowId(String columnLabel, RowId x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public int getHoldability() throws SQLException { - if (closed) { - throw new SQLException("resultSet closed"); - } - - return 0; - } - - @Override - public boolean isClosed() throws SQLException { - return closed; - } - - @Override - public void updateNString(int columnIndex, String x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateNString(String columnLabel, String x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateNClob(int columnIndex, NClob x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateNClob(String columnLabel, NClob x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public NClob getNClob(int columnIndex) throws SQLException { - return (NClob) getObject(columnIndex); - } - - @Override - public NClob getNClob(String columnLabel) throws SQLException { - return (NClob) getObject(columnLabel); - } - - @Override - public SQLXML getSQLXML(int columnIndex) throws SQLException { - return (SQLXML) getObject(columnIndex); - } - - @Override - public SQLXML getSQLXML(String columnLabel) throws SQLException { - return (SQLXML) getObject(columnLabel); - } - - @Override - public void updateSQLXML(int columnIndex, SQLXML x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateSQLXML(String columnLabel, SQLXML x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public String getNString(int columnIndex) throws SQLException { - return (String) getObject(columnIndex); - } - - @Override - public String getNString(String columnLabel) throws SQLException { - return (String) getObject(columnLabel); - } - - @Override - public Reader getNCharacterStream(int columnIndex) throws SQLException { - return (Reader) getObject(columnIndex); - } - - @Override - public Reader getNCharacterStream(String columnLabel) throws SQLException { - return (Reader) getObject(columnLabel); - } - - @Override - public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateNCharacterStream(String columnLabel, Reader x, long length) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateCharacterStream(String columnLabel, Reader x, long length) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateBlob(int columnIndex, InputStream x, long length) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateBlob(String columnLabel, InputStream x, long length) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateClob(int columnIndex, Reader x, long length) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateClob(String columnLabel, Reader x, long length) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateNClob(int columnIndex, Reader x, long length) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateNClob(String columnLabel, Reader x, long length) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateNCharacterStream(String columnLabel, Reader x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateCharacterStream(String columnLabel, Reader x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateBlob(int columnIndex, InputStream x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateBlob(String columnLabel, InputStream x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateClob(int columnIndex, Reader x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateClob(String columnLabel, Reader x) throws SQLException { - updateObject(columnLabel, x); - } - - @Override - public void updateNClob(int columnIndex, Reader x) throws SQLException { - updateObject(columnIndex, x); - } - - @Override - public void updateNClob(String columnLabel, Reader x) throws SQLException { - updateObject(columnLabel, x); - } - - public T getObject(int columnIndex, Class type) throws SQLException { - throw new SQLFeatureNotSupportedException(); - } - - public T getObject(String columnLabel, Class type) throws SQLException { - throw new SQLFeatureNotSupportedException(); - } - } diff --git a/src/test/java/com/alibaba/druid/hbase/HBaseDriverTest.java b/src/test/java/com/alibaba/druid/hbase/HBaseDriverTest.java index 099935729a..8820f9da57 100644 --- a/src/test/java/com/alibaba/druid/hbase/HBaseDriverTest.java +++ b/src/test/java/com/alibaba/druid/hbase/HBaseDriverTest.java @@ -16,7 +16,7 @@ public class HBaseDriverTest extends TestCase { PreparedStatement stmt = conn.prepareStatement("SELECT * FROM test"); ResultSet rs = stmt.executeQuery(); while (rs.next()) { - + System.out.print(rs.getString("id")); } rs.close(); stmt.close(); diff --git a/src/test/resources/log4j.properties b/src/test/resources/log4j.properties index f897cf40e9..425c169e0c 100644 --- a/src/test/resources/log4j.properties +++ b/src/test/resources/log4j.properties @@ -27,6 +27,7 @@ log4j.category.org.codehaus.xfire=INFO log4j.category.httpclient=INFO log4j.category.org.apache.struts.action.ActionServlet=ERROR log4j.category.com.alibaba.druid.mock=ERROR -log4j.category.org.apache.hadoop.conf.Configuration=INFO +log4j.category.org.apache.hadoop=WARN +log4j.category.org.apache.zookeeper=ERROR log4j.rootLogger=TRACE,CONSOLE