mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
package com.alibaba.druid.common.jdbc;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLWarning;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class ConnectionBase implements Connection {
|
||||
|
||||
private boolean autoCommit = true;
|
||||
private String catalog;
|
||||
private int transactionIsolation;
|
||||
private int holdability;
|
||||
private Map<String, Class<?>> typeMap = new HashMap<String, Class<?>>();
|
||||
private SQLWarning warings;
|
||||
private boolean readOnly;
|
||||
|
||||
@Override
|
||||
public void setAutoCommit(boolean autoCommit) throws SQLException {
|
||||
this.autoCommit = autoCommit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAutoCommit() throws SQLException {
|
||||
return autoCommit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCatalog(String catalog) throws SQLException {
|
||||
this.catalog = catalog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCatalog() throws SQLException {
|
||||
return catalog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTransactionIsolation(int level) throws SQLException {
|
||||
this.transactionIsolation = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTransactionIsolation() throws SQLException {
|
||||
return transactionIsolation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLWarning getWarnings() throws SQLException {
|
||||
return warings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearWarnings() throws SQLException {
|
||||
this.warings = null;
|
||||
}
|
||||
|
||||
public void setWarings(SQLWarning warings) {
|
||||
this.warings = warings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Class<?>> getTypeMap() throws SQLException {
|
||||
return typeMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
|
||||
this.typeMap = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHoldability(int holdability) throws SQLException {
|
||||
this.holdability = holdability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHoldability() {
|
||||
return holdability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadOnly(boolean readOnly) throws SQLException {
|
||||
this.readOnly = readOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() throws SQLException {
|
||||
return readOnly;
|
||||
}
|
||||
}
|
||||
@@ -11,27 +11,20 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.SQLClientInfoException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.sql.SQLWarning;
|
||||
import java.sql.SQLXML;
|
||||
import java.sql.Savepoint;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Struct;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
|
||||
public class HBaseConnection implements Connection {
|
||||
import com.alibaba.druid.common.jdbc.ConnectionBase;
|
||||
|
||||
private Configuration config;
|
||||
public class HBaseConnection extends ConnectionBase implements Connection {
|
||||
|
||||
private boolean autoCommit = true;
|
||||
private String catalog;
|
||||
private int transactionIsolation;
|
||||
private int holdability;
|
||||
private Map<String, Class<?>> typeMap = new HashMap<String, Class<?>>();
|
||||
private SQLWarning warings;
|
||||
private Configuration config;
|
||||
|
||||
public HBaseConnection(Properties info){
|
||||
config = new Configuration();
|
||||
@@ -85,16 +78,6 @@ public class HBaseConnection implements Connection {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAutoCommit(boolean autoCommit) throws SQLException {
|
||||
this.autoCommit = autoCommit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAutoCommit() throws SQLException {
|
||||
return autoCommit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit() throws SQLException {
|
||||
|
||||
@@ -120,50 +103,6 @@ public class HBaseConnection implements Connection {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadOnly(boolean readOnly) throws SQLException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() throws SQLException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCatalog(String catalog) throws SQLException {
|
||||
this.catalog = catalog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCatalog() throws SQLException {
|
||||
return catalog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTransactionIsolation(int level) throws SQLException {
|
||||
this.transactionIsolation = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTransactionIsolation() throws SQLException {
|
||||
return transactionIsolation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLWarning getWarnings() throws SQLException {
|
||||
return warings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearWarnings() throws SQLException {
|
||||
this.warings = null;
|
||||
}
|
||||
|
||||
public void setWarings(SQLWarning warings) {
|
||||
this.warings = warings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
@@ -180,26 +119,6 @@ public class HBaseConnection implements Connection {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Class<?>> getTypeMap() throws SQLException {
|
||||
return typeMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
|
||||
this.typeMap = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHoldability(int holdability) throws SQLException {
|
||||
this.holdability = holdability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHoldability() {
|
||||
return holdability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Savepoint setSavepoint() throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
|
||||
@@ -26,7 +26,6 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.SQLClientInfoException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.sql.SQLWarning;
|
||||
import java.sql.SQLXML;
|
||||
import java.sql.Savepoint;
|
||||
import java.sql.Statement;
|
||||
@@ -35,17 +34,13 @@ import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class MockConnection implements Connection {
|
||||
import com.alibaba.druid.common.jdbc.ConnectionBase;
|
||||
|
||||
public class MockConnection extends ConnectionBase implements Connection {
|
||||
|
||||
// private final static Log LOG = LogFactory.getLog(MockConnection.class);
|
||||
|
||||
private boolean autoCommit = false;
|
||||
private boolean closed = false;
|
||||
private boolean readOnly = false;
|
||||
private String catalog = null;
|
||||
private int transactionIsolation;
|
||||
private SQLWarning warning;
|
||||
private int holdability;
|
||||
|
||||
private MockDriver driver;
|
||||
|
||||
@@ -60,7 +55,7 @@ public class MockConnection implements Connection {
|
||||
public MockConnection(){
|
||||
this(null, null, null);
|
||||
}
|
||||
|
||||
|
||||
public MockConnection(MockDriver driver, String url, Properties connectProperties){
|
||||
this.driver = driver;
|
||||
this.connectProperties = connectProperties;
|
||||
@@ -164,12 +159,7 @@ public class MockConnection implements Connection {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
|
||||
this.autoCommit = autoCommit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAutoCommit() throws SQLException {
|
||||
return autoCommit;
|
||||
super.setAutoCommit(autoCommit);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -208,46 +198,6 @@ public class MockConnection implements Connection {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadOnly(boolean readOnly) throws SQLException {
|
||||
this.readOnly = readOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() throws SQLException {
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCatalog(String catalog) throws SQLException {
|
||||
this.catalog = catalog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCatalog() throws SQLException {
|
||||
return catalog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTransactionIsolation(int level) throws SQLException {
|
||||
this.transactionIsolation = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTransactionIsolation() throws SQLException {
|
||||
return transactionIsolation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLWarning getWarnings() throws SQLException {
|
||||
return warning;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearWarnings() throws SQLException {
|
||||
warning = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||
if (closed) {
|
||||
@@ -301,16 +251,6 @@ public class MockConnection implements Connection {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHoldability(int holdability) throws SQLException {
|
||||
this.holdability = holdability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHoldability() throws SQLException {
|
||||
return holdability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Savepoint setSavepoint() throws SQLException {
|
||||
if (closed) {
|
||||
|
||||
Reference in New Issue
Block a user