From c9204dc18af0988b10ee8ca582a0111bdfda5662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A9=E5=B0=91?= Date: Fri, 18 May 2012 20:34:27 +0800 Subject: [PATCH] hbase support --- .../druid/common/jdbc/StatementBase.java | 86 ++++++++++++++ .../alibaba/druid/hbase/HBaseStatement.java | 111 +----------------- .../com/alibaba/druid/mock/MockStatement.java | 87 +------------- 3 files changed, 92 insertions(+), 192 deletions(-) diff --git a/src/main/java/com/alibaba/druid/common/jdbc/StatementBase.java b/src/main/java/com/alibaba/druid/common/jdbc/StatementBase.java index 94042fa4c0..d2a562a5db 100644 --- a/src/main/java/com/alibaba/druid/common/jdbc/StatementBase.java +++ b/src/main/java/com/alibaba/druid/common/jdbc/StatementBase.java @@ -2,6 +2,7 @@ package com.alibaba.druid.common.jdbc; import java.sql.Connection; import java.sql.SQLException; +import java.sql.SQLWarning; import java.sql.Statement; public abstract class StatementBase implements Statement { @@ -12,6 +13,12 @@ public abstract class StatementBase implements Statement { private int resultSetType; private int resultSetConcurrency; private int resultSetHoldability; + private int maxFieldSize; + private int maxRows; + private int queryTimeout; + private boolean escapeProcessing; + private String cursorName; + private SQLWarning warnings; public StatementBase(Connection connection){ super(); @@ -84,4 +91,83 @@ public abstract class StatementBase implements Statement { public void setResultSetHoldability(int resultSetHoldability) { this.resultSetHoldability = resultSetHoldability; } + + @Override + public int getMaxFieldSize() throws SQLException { + checkOpen(); + + return maxFieldSize; + } + + @Override + public void setMaxFieldSize(int max) throws SQLException { + checkOpen(); + + this.maxFieldSize = max; + } + + @Override + public int getMaxRows() throws SQLException { + checkOpen(); + + return maxRows; + } + + @Override + public void setMaxRows(int max) throws SQLException { + checkOpen(); + + this.maxRows = max; + } + + @Override + public void setEscapeProcessing(boolean enable) throws SQLException { + checkOpen(); + this.escapeProcessing = enable; + } + + public boolean isEscapeProcessing() { + return escapeProcessing; + } + + @Override + public int getQueryTimeout() throws SQLException { + checkOpen(); + return queryTimeout; + } + + @Override + public void setQueryTimeout(int seconds) throws SQLException { + checkOpen(); + this.queryTimeout = seconds; + } + + @Override + public void setCursorName(String name) throws SQLException { + checkOpen(); + + cursorName = name; + } + + public String getCursorName() { + return cursorName; + } + + @Override + public SQLWarning getWarnings() throws SQLException { + checkOpen(); + + return warnings; + } + + @Override + public void clearWarnings() throws SQLException { + checkOpen(); + + warnings = null; + } + + public void setWarning(SQLWarning warning) { + this.warnings = warning; + } } diff --git a/src/main/java/com/alibaba/druid/hbase/HBaseStatement.java b/src/main/java/com/alibaba/druid/hbase/HBaseStatement.java index d3e59c50a3..1286070160 100644 --- a/src/main/java/com/alibaba/druid/hbase/HBaseStatement.java +++ b/src/main/java/com/alibaba/druid/hbase/HBaseStatement.java @@ -3,15 +3,16 @@ package com.alibaba.druid.hbase; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; -import java.sql.SQLWarning; import java.sql.Statement; -public class HBaseStatement implements Statement { +import com.alibaba.druid.common.jdbc.StatementBase; + +public class HBaseStatement extends StatementBase implements Statement { private HBaseConnection conn; public HBaseStatement(HBaseConnection conn){ - super(); + super(conn); this.conn = conn; } @@ -45,69 +46,8 @@ public class HBaseStatement implements Statement { } - @Override - public int getMaxFieldSize() throws SQLException { - // TODO Auto-generated method stub - return 0; - } - - @Override - public void setMaxFieldSize(int max) throws SQLException { - // TODO Auto-generated method stub - - } - - @Override - public int getMaxRows() throws SQLException { - // TODO Auto-generated method stub - return 0; - } - - @Override - public void setMaxRows(int max) throws SQLException { - // TODO Auto-generated method stub - - } - - @Override - public void setEscapeProcessing(boolean enable) throws SQLException { - // TODO Auto-generated method stub - - } - - @Override - public int getQueryTimeout() throws SQLException { - // TODO Auto-generated method stub - return 0; - } - - @Override - public void setQueryTimeout(int seconds) throws SQLException { - // TODO Auto-generated method stub - - } - @Override public void cancel() throws SQLException { - // TODO Auto-generated method stub - - } - - @Override - public SQLWarning getWarnings() throws SQLException { - // TODO Auto-generated method stub - return null; - } - - @Override - public void clearWarnings() throws SQLException { - // TODO Auto-generated method stub - - } - - @Override - public void setCursorName(String name) throws SQLException { - // TODO Auto-generated method stub } @@ -135,42 +75,6 @@ public class HBaseStatement implements Statement { return false; } - @Override - public void setFetchDirection(int direction) throws SQLException { - // TODO Auto-generated method stub - - } - - @Override - public int getFetchDirection() throws SQLException { - // TODO Auto-generated method stub - return 0; - } - - @Override - public void setFetchSize(int rows) throws SQLException { - // TODO Auto-generated method stub - - } - - @Override - public int getFetchSize() throws SQLException { - // TODO Auto-generated method stub - return 0; - } - - @Override - public int getResultSetConcurrency() throws SQLException { - // TODO Auto-generated method stub - return 0; - } - - @Override - public int getResultSetType() throws SQLException { - // TODO Auto-generated method stub - return 0; - } - @Override public void addBatch(String sql) throws SQLException { // TODO Auto-generated method stub @@ -242,11 +146,6 @@ public class HBaseStatement implements Statement { return false; } - @Override - public int getResultSetHoldability() throws SQLException { - // TODO Auto-generated method stub - return 0; - } @Override public boolean isClosed() throws SQLException { @@ -267,6 +166,6 @@ public class HBaseStatement implements Statement { } public void checkOpen() { - + } } diff --git a/src/main/java/com/alibaba/druid/mock/MockStatement.java b/src/main/java/com/alibaba/druid/mock/MockStatement.java index 5afde063aa..1c123f9d60 100644 --- a/src/main/java/com/alibaba/druid/mock/MockStatement.java +++ b/src/main/java/com/alibaba/druid/mock/MockStatement.java @@ -19,7 +19,6 @@ import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; -import java.sql.SQLWarning; import java.sql.Statement; import com.alibaba.druid.common.jdbc.StatementBase; @@ -31,12 +30,7 @@ public class MockStatement extends StatementBase implements Statement { protected boolean closed = false; protected MockConnection mockConnection; - private int maxFieldSize; - private int maxRows; - private int queryTimeout; - private boolean escapeProcessing; - private SQLWarning warnings; - private String cursorName; + private int updateCount; public MockStatement(Connection connection){ @@ -120,90 +114,11 @@ public class MockStatement extends StatementBase implements Statement { this.closed = true; } - @Override - public int getMaxFieldSize() throws SQLException { - checkOpen(); - - return maxFieldSize; - } - - @Override - public void setMaxFieldSize(int max) throws SQLException { - checkOpen(); - - this.maxFieldSize = max; - } - - @Override - public int getMaxRows() throws SQLException { - checkOpen(); - - return maxRows; - } - - @Override - public void setMaxRows(int max) throws SQLException { - checkOpen(); - - this.maxRows = max; - } - - @Override - public void setEscapeProcessing(boolean enable) throws SQLException { - checkOpen(); - this.escapeProcessing = enable; - } - - public boolean isEscapeProcessing() { - return escapeProcessing; - } - - @Override - public int getQueryTimeout() throws SQLException { - checkOpen(); - return queryTimeout; - } - - @Override - public void setQueryTimeout(int seconds) throws SQLException { - checkOpen(); - this.queryTimeout = seconds; - } - @Override public void cancel() throws SQLException { checkOpen(); } - @Override - public SQLWarning getWarnings() throws SQLException { - checkOpen(); - - return warnings; - } - - @Override - public void clearWarnings() throws SQLException { - checkOpen(); - - warnings = null; - } - - public void setWarning(SQLWarning warning) { - this.warnings = warning; - } - - @Override - public void setCursorName(String name) throws SQLException { - checkOpen(); - - cursorName = name; - } - - public String getCursorName() { - return cursorName; - } - @Override public boolean execute(String sql) throws SQLException { checkOpen();