Repository: commons-dbcp Updated Branches: refs/heads/master f05518d99 -> b383b9c38
Sort members in AB order so it's easier to find stuff. Project: http://git-wip-us.apache.org/repos/asf/commons-dbcp/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-dbcp/commit/b383b9c3 Tree: http://git-wip-us.apache.org/repos/asf/commons-dbcp/tree/b383b9c3 Diff: http://git-wip-us.apache.org/repos/asf/commons-dbcp/diff/b383b9c3 Branch: refs/heads/master Commit: b383b9c38090f9eae7ccc7bd82052141a3eeca60 Parents: f05518d Author: Gary Gregory <garydgreg...@gmail.com> Authored: Sun Jun 17 08:36:03 2018 -0600 Committer: Gary Gregory <garydgreg...@gmail.com> Committed: Sun Jun 17 08:36:03 2018 -0600 ---------------------------------------------------------------------- .../apache/commons/dbcp2/TesterStatement.java | 287 ++++++++++--------- 1 file changed, 144 insertions(+), 143 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/b383b9c3/src/test/java/org/apache/commons/dbcp2/TesterStatement.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbcp2/TesterStatement.java b/src/test/java/org/apache/commons/dbcp2/TesterStatement.java index 361eff6..c4b0a17 100644 --- a/src/test/java/org/apache/commons/dbcp2/TesterStatement.java +++ b/src/test/java/org/apache/commons/dbcp2/TesterStatement.java @@ -27,16 +27,33 @@ import java.sql.Statement; * A dummy {@link Statement}, for testing purposes. */ public class TesterStatement implements Statement { + protected Connection _connection = null; + + protected boolean _open = true; + + protected int _rowsUpdated = 1; + + protected boolean _executeResponse = true; + protected int _maxFieldSize = 1024; + protected int _maxRows = 1024; + protected boolean _escapeProcessing = false; + protected int _queryTimeout = 1000; + protected String _cursorName = null; + protected int _fetchDirection = 1; + protected int _fetchSize = 1; + protected int _resultSetConcurrency = 1; + protected int _resultSetType = 1; + private int _resultSetHoldability = 1; + protected ResultSet _resultSet = null; + public TesterStatement(final Connection conn) { _connection = conn; } - public TesterStatement(final Connection conn, final int resultSetType, final int resultSetConcurrency) { _connection = conn; _resultSetType = resultSetType; _resultSetConcurrency = resultSetConcurrency; } - public TesterStatement(final Connection conn, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) { _connection = conn; @@ -45,50 +62,30 @@ public class TesterStatement implements Statement { _resultSetHoldability = resultSetHoldability; } - protected Connection _connection = null; - protected boolean _open = true; - protected int _rowsUpdated = 1; - protected boolean _executeResponse = true; - protected int _maxFieldSize = 1024; - protected int _maxRows = 1024; - protected boolean _escapeProcessing = false; - protected int _queryTimeout = 1000; - protected String _cursorName = null; - protected int _fetchDirection = 1; - protected int _fetchSize = 1; - protected int _resultSetConcurrency = 1; - protected int _resultSetType = 1; - private int _resultSetHoldability = 1; - protected ResultSet _resultSet = null; + @Override + public void addBatch(final String sql) throws SQLException { + checkOpen(); + } @Override - public ResultSet executeQuery(final String sql) throws SQLException { + public void cancel() throws SQLException { checkOpen(); - if("null".equals(sql)) { - return null; - } - if("invalid".equals(sql)) { - throw new SQLException("invalid query"); - } - if ("broken".equals(sql)) { - throw new SQLException("broken connection"); - } - if("select username".equals(sql)) { - final String userName = ((TesterConnection) _connection).getUserName(); - final Object[][] data = {{userName}}; - return new TesterResultSet(this, data); - } - // Simulate timeout if queryTimout is set to less than 5 seconds - if (_queryTimeout > 0 && _queryTimeout < 5) { - throw new SQLException("query timeout"); + } + + protected void checkOpen() throws SQLException { + if(!_open) { + throw new SQLException("Connection is closed."); } - return new TesterResultSet(this); } @Override - public int executeUpdate(final String sql) throws SQLException { + public void clearBatch() throws SQLException { + checkOpen(); + } + + @Override + public void clearWarnings() throws SQLException { checkOpen(); - return _rowsUpdated; } @Override @@ -106,229 +103,237 @@ public class TesterStatement implements Statement { } @Override - public int getMaxFieldSize() throws SQLException { - checkOpen(); - return _maxFieldSize; + public void closeOnCompletion() throws SQLException { + throw new SQLException("Not implemented."); } @Override - public void setMaxFieldSize(final int max) throws SQLException { + public boolean execute(final String sql) throws SQLException { checkOpen(); - _maxFieldSize = max; + if("invalid".equals(sql)) { + throw new SQLException("invalid query"); + } + return _executeResponse; } @Override - public int getMaxRows() throws SQLException { - checkOpen(); - return _maxRows; + public boolean execute(final String sql, final int autoGeneratedKeys) + throws SQLException { + throw new SQLException("Not implemented."); } @Override - public void setMaxRows(final int max) throws SQLException { - checkOpen(); - _maxRows = max; + public boolean execute(final String sql, final int columnIndexes[]) + throws SQLException { + throw new SQLException("Not implemented."); } @Override - public void setEscapeProcessing(final boolean enable) throws SQLException { - checkOpen(); - _escapeProcessing = enable; + public boolean execute(final String sql, final String columnNames[]) + throws SQLException { + throw new SQLException("Not implemented."); } @Override - public int getQueryTimeout() throws SQLException { + public int[] executeBatch() throws SQLException { checkOpen(); - return _queryTimeout; + return new int[0]; } @Override - public void setQueryTimeout(final int seconds) throws SQLException { + public ResultSet executeQuery(final String sql) throws SQLException { checkOpen(); - _queryTimeout = seconds; + if("null".equals(sql)) { + return null; + } + if("invalid".equals(sql)) { + throw new SQLException("invalid query"); + } + if ("broken".equals(sql)) { + throw new SQLException("broken connection"); + } + if("select username".equals(sql)) { + final String userName = ((TesterConnection) _connection).getUserName(); + final Object[][] data = {{userName}}; + return new TesterResultSet(this, data); + } + // Simulate timeout if queryTimout is set to less than 5 seconds + if (_queryTimeout > 0 && _queryTimeout < 5) { + throw new SQLException("query timeout"); + } + return new TesterResultSet(this); } @Override - public void cancel() throws SQLException { + public int executeUpdate(final String sql) throws SQLException { checkOpen(); + return _rowsUpdated; } @Override - public SQLWarning getWarnings() throws SQLException { - checkOpen(); - return null; + public int executeUpdate(final String sql, final int autoGeneratedKeys) + throws SQLException { + throw new SQLException("Not implemented."); } @Override - public void clearWarnings() throws SQLException { - checkOpen(); + public int executeUpdate(final String sql, final int columnIndexes[]) + throws SQLException { + throw new SQLException("Not implemented."); } @Override - public void setCursorName(final String name) throws SQLException { - checkOpen(); - _cursorName = name; + public int executeUpdate(final String sql, final String columnNames[]) + throws SQLException { + throw new SQLException("Not implemented."); } @Override - public boolean execute(final String sql) throws SQLException { + public Connection getConnection() throws SQLException { checkOpen(); - if("invalid".equals(sql)) { - throw new SQLException("invalid query"); - } - return _executeResponse; + return _connection; } @Override - public ResultSet getResultSet() throws SQLException { + public int getFetchDirection() throws SQLException { checkOpen(); - if (_resultSet == null) { - _resultSet = new TesterResultSet(this); - } - return _resultSet; + return _fetchDirection; } @Override - public int getUpdateCount() throws SQLException { + public int getFetchSize() throws SQLException { checkOpen(); - return _rowsUpdated; + return _fetchSize; } @Override - public boolean getMoreResults() throws SQLException { - checkOpen(); - return false; + public ResultSet getGeneratedKeys() throws SQLException { + return new TesterResultSet(this); } @Override - public void setFetchDirection(final int direction) throws SQLException { + public int getMaxFieldSize() throws SQLException { checkOpen(); - _fetchDirection = direction; + return _maxFieldSize; } @Override - public int getFetchDirection() throws SQLException { + public int getMaxRows() throws SQLException { checkOpen(); - return _fetchDirection; + return _maxRows; } @Override - public void setFetchSize(final int rows) throws SQLException { + public boolean getMoreResults() throws SQLException { checkOpen(); - _fetchSize = rows; + return false; } @Override - public int getFetchSize() throws SQLException { - checkOpen(); - return _fetchSize; + public boolean getMoreResults(final int current) throws SQLException { + throw new SQLException("Not implemented."); } @Override - public int getResultSetConcurrency() throws SQLException { + public int getQueryTimeout() throws SQLException { checkOpen(); - return _resultSetConcurrency; + return _queryTimeout; } @Override - public int getResultSetType() throws SQLException { + public ResultSet getResultSet() throws SQLException { checkOpen(); - return _resultSetType; + if (_resultSet == null) { + _resultSet = new TesterResultSet(this); + } + return _resultSet; } @Override - public void addBatch(final String sql) throws SQLException { + public int getResultSetConcurrency() throws SQLException { checkOpen(); + return _resultSetConcurrency; } @Override - public void clearBatch() throws SQLException { + public int getResultSetHoldability() throws SQLException { checkOpen(); + return _resultSetHoldability; } @Override - public int[] executeBatch() throws SQLException { + public int getResultSetType() throws SQLException { checkOpen(); - return new int[0]; + return _resultSetType; } @Override - public Connection getConnection() throws SQLException { + public int getUpdateCount() throws SQLException { checkOpen(); - return _connection; - } - - protected void checkOpen() throws SQLException { - if(!_open) { - throw new SQLException("Connection is closed."); - } + return _rowsUpdated; } @Override - public boolean getMoreResults(final int current) throws SQLException { - throw new SQLException("Not implemented."); + public SQLWarning getWarnings() throws SQLException { + checkOpen(); + return null; } @Override - public ResultSet getGeneratedKeys() throws SQLException { - return new TesterResultSet(this); + public boolean isClosed() throws SQLException { + return !_open; } @Override - public int executeUpdate(final String sql, final int autoGeneratedKeys) - throws SQLException { + public boolean isCloseOnCompletion() throws SQLException { throw new SQLException("Not implemented."); } @Override - public int executeUpdate(final String sql, final int columnIndexes[]) - throws SQLException { + public boolean isPoolable() throws SQLException { throw new SQLException("Not implemented."); } @Override - public int executeUpdate(final String sql, final String columnNames[]) - throws SQLException { + public boolean isWrapperFor(final Class<?> iface) throws SQLException { throw new SQLException("Not implemented."); } @Override - public boolean execute(final String sql, final int autoGeneratedKeys) - throws SQLException { - throw new SQLException("Not implemented."); + public void setCursorName(final String name) throws SQLException { + checkOpen(); + _cursorName = name; } @Override - public boolean execute(final String sql, final int columnIndexes[]) - throws SQLException { - throw new SQLException("Not implemented."); + public void setEscapeProcessing(final boolean enable) throws SQLException { + checkOpen(); + _escapeProcessing = enable; } - @Override - public boolean execute(final String sql, final String columnNames[]) - throws SQLException { - throw new SQLException("Not implemented."); - } @Override - public int getResultSetHoldability() throws SQLException { + public void setFetchDirection(final int direction) throws SQLException { checkOpen(); - return _resultSetHoldability; + _fetchDirection = direction; } - @Override - public boolean isWrapperFor(final Class<?> iface) throws SQLException { - throw new SQLException("Not implemented."); + public void setFetchSize(final int rows) throws SQLException { + checkOpen(); + _fetchSize = rows; } @Override - public <T> T unwrap(final Class<T> iface) throws SQLException { - throw new SQLException("Not implemented."); + public void setMaxFieldSize(final int max) throws SQLException { + checkOpen(); + _maxFieldSize = max; } @Override - public boolean isClosed() throws SQLException { - return !_open; + public void setMaxRows(final int max) throws SQLException { + checkOpen(); + _maxRows = max; } @Override @@ -337,17 +342,13 @@ public class TesterStatement implements Statement { } @Override - public boolean isPoolable() throws SQLException { - throw new SQLException("Not implemented."); - } - - @Override - public void closeOnCompletion() throws SQLException { - throw new SQLException("Not implemented."); + public void setQueryTimeout(final int seconds) throws SQLException { + checkOpen(); + _queryTimeout = seconds; } @Override - public boolean isCloseOnCompletion() throws SQLException { + public <T> T unwrap(final Class<T> iface) throws SQLException { throw new SQLException("Not implemented."); } }