mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed
This commit is contained in:
@@ -53,6 +53,8 @@ public class MockConnection extends ConnectionBase implements Connection {
|
||||
private final long createdTimeMillis = System.currentTimeMillis();
|
||||
private long lastActiveTimeMillis = System.currentTimeMillis();
|
||||
|
||||
private SQLException error;
|
||||
|
||||
public MockConnection(){
|
||||
this(null, null, null);
|
||||
}
|
||||
@@ -67,6 +69,14 @@ public class MockConnection extends ConnectionBase implements Connection {
|
||||
}
|
||||
}
|
||||
|
||||
public SQLException getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public void setError(SQLException error) {
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
public List<Savepoint> getSavepoints() {
|
||||
return savepoints;
|
||||
}
|
||||
@@ -112,9 +122,7 @@ public class MockConnection extends ConnectionBase implements Connection {
|
||||
|
||||
@Override
|
||||
public Statement createStatement() throws SQLException {
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
checkState();
|
||||
|
||||
return createMockStatement();
|
||||
}
|
||||
@@ -128,53 +136,40 @@ public class MockConnection extends ConnectionBase implements Connection {
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql) throws SQLException {
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
checkState();
|
||||
|
||||
return createMockPreparedStatement(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallableStatement prepareCall(String sql) throws SQLException {
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
checkState();
|
||||
|
||||
return createMockCallableStatement(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nativeSQL(String sql) throws SQLException {
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
checkState();
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAutoCommit(boolean autoCommit) throws SQLException {
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
checkState();
|
||||
|
||||
super.setAutoCommit(autoCommit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit() throws SQLException {
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
|
||||
checkState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback() throws SQLException {
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
checkState();
|
||||
|
||||
this.savepoints.clear();
|
||||
}
|
||||
@@ -201,9 +196,7 @@ public class MockConnection extends ConnectionBase implements Connection {
|
||||
|
||||
@Override
|
||||
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
checkState();
|
||||
|
||||
MockStatement stmt = createMockStatement();
|
||||
|
||||
@@ -216,9 +209,7 @@ public class MockConnection extends ConnectionBase implements Connection {
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
|
||||
throws SQLException {
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
checkState();
|
||||
|
||||
MockPreparedStatement stmt = createMockPreparedStatement(sql);
|
||||
|
||||
@@ -230,9 +221,7 @@ public class MockConnection extends ConnectionBase implements Connection {
|
||||
|
||||
@Override
|
||||
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
checkState();
|
||||
|
||||
MockCallableStatement stmt = createMockCallableStatement(sql);
|
||||
|
||||
@@ -254,9 +243,7 @@ public class MockConnection extends ConnectionBase implements Connection {
|
||||
|
||||
@Override
|
||||
public Savepoint setSavepoint() throws SQLException {
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
checkState();
|
||||
|
||||
MockSavepoint savepoint = new MockSavepoint();
|
||||
savepoint.setSavepointId(this.savepointIdSeed++);
|
||||
@@ -267,9 +254,7 @@ public class MockConnection extends ConnectionBase implements Connection {
|
||||
|
||||
@Override
|
||||
public Savepoint setSavepoint(String name) throws SQLException {
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
checkState();
|
||||
|
||||
MockSavepoint savepoint = new MockSavepoint();
|
||||
savepoint.setSavepointId(this.savepointIdSeed++);
|
||||
@@ -279,12 +264,19 @@ public class MockConnection extends ConnectionBase implements Connection {
|
||||
return savepoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback(Savepoint savepoint) throws SQLException {
|
||||
public void checkState() throws SQLException {
|
||||
if (error != null) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback(Savepoint savepoint) throws SQLException {
|
||||
checkState();
|
||||
|
||||
int index = this.savepoints.indexOf(savepoint);
|
||||
if (index == -1) {
|
||||
@@ -297,9 +289,7 @@ public class MockConnection extends ConnectionBase implements Connection {
|
||||
|
||||
@Override
|
||||
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
checkState();
|
||||
|
||||
if (savepoint == null) {
|
||||
throw new SQLException("argument is null");
|
||||
@@ -315,9 +305,7 @@ public class MockConnection extends ConnectionBase implements Connection {
|
||||
@Override
|
||||
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
|
||||
throws SQLException {
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
checkState();
|
||||
|
||||
MockStatement stmt = createMockStatement();
|
||||
|
||||
@@ -331,9 +319,7 @@ public class MockConnection extends ConnectionBase implements Connection {
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
|
||||
int resultSetHoldability) throws SQLException {
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
checkState();
|
||||
|
||||
MockPreparedStatement stmt = createMockPreparedStatement(sql);
|
||||
|
||||
@@ -354,9 +340,7 @@ public class MockConnection extends ConnectionBase implements Connection {
|
||||
@Override
|
||||
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
|
||||
int resultSetHoldability) throws SQLException {
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
checkState();
|
||||
|
||||
MockCallableStatement stmt = createMockCallableStatement(sql);
|
||||
|
||||
@@ -376,27 +360,21 @@ public class MockConnection extends ConnectionBase implements Connection {
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
checkState();
|
||||
|
||||
return createMockPreparedStatement(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
checkState();
|
||||
|
||||
return createMockPreparedStatement(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
|
||||
if (closed) {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
checkState();
|
||||
|
||||
return createMockPreparedStatement(sql);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user