You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by st...@apache.org on 2003/02/02 17:54:53 UTC
cvs commit: jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/mockdriver MockConnection.java MockDriver.java MockPreparedStatement.java MockResultSet.java MockStatement.java
stevencaswell 2003/02/02 08:54:53
Added: dbutils/src/java/org/apache/commons/dbutils/mockdriver
MockConnection.java MockDriver.java
MockPreparedStatement.java MockResultSet.java
MockStatement.java
Log:
initial import
Revision Changes Path
1.1 jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/mockdriver/MockConnection.java
Index: MockConnection.java
===================================================================
package org.apache.commons.dbutils.mockdriver;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.util.Map;
/**
* A mock {@link Connection}, useful for testing purposes.
*
* @author Rodney Waldhoff
* @version $Id: MockConnection.java,v 1.1 2003/02/02 16:54:53 stevencaswell Exp $
*/
public class MockConnection implements Connection {
protected boolean _open = true;
protected boolean _autoCommit = true;
protected int _transactionIsolation = 1;
protected DatabaseMetaData _metaData = null;
protected String _catalog = null;
protected Map _typeMap = null;
protected boolean _readOnly = false;
public void clearWarnings() throws SQLException {
checkOpen();
}
public void close() throws SQLException {
checkOpen();
_open = false;
}
public void commit() throws SQLException {
checkOpen();
}
public Statement createStatement() throws SQLException {
checkOpen();
return new MockStatement(this);
}
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
checkOpen();
return new MockStatement(this);
}
public boolean getAutoCommit() throws SQLException {
checkOpen();
return _autoCommit;
}
public String getCatalog() throws SQLException {
checkOpen();
return _catalog;
}
public DatabaseMetaData getMetaData() throws SQLException {
checkOpen();
return _metaData;
}
public int getTransactionIsolation() throws SQLException {
checkOpen();
return _transactionIsolation;
}
public Map getTypeMap() throws SQLException {
checkOpen();
return _typeMap;
}
public SQLWarning getWarnings() throws SQLException {
checkOpen();
return null;
}
public boolean isClosed() throws SQLException {
return !_open;
}
public boolean isReadOnly() throws SQLException {
checkOpen();
return _readOnly;
}
public String nativeSQL(String sql) throws SQLException {
checkOpen();
return sql;
}
public CallableStatement prepareCall(String sql) throws SQLException {
checkOpen();
return null;
}
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
checkOpen();
return null;
}
public PreparedStatement prepareStatement(String sql) throws SQLException {
checkOpen();
return new MockPreparedStatement(this, sql);
}
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
checkOpen();
return new MockPreparedStatement(this, sql);
}
public void rollback() throws SQLException {
checkOpen();
}
public void setAutoCommit(boolean autoCommit) throws SQLException {
checkOpen();
_autoCommit = autoCommit;
}
public void setCatalog(String catalog) throws SQLException {
checkOpen();
_catalog = catalog;
}
public void setReadOnly(boolean readOnly) throws SQLException {
checkOpen();
_readOnly = readOnly;
}
public void setTransactionIsolation(int level) throws SQLException {
checkOpen();
_transactionIsolation = level;
}
public void setTypeMap(Map map) throws SQLException {
checkOpen();
_typeMap = map;
}
protected void checkOpen() throws SQLException {
if(!_open) {
throw new SQLException("Connection is closed.");
}
}
// ------------------- JDBC 3.0 -----------------------------------------
// Will be uncommented by the build process on a JDBC 3.0 system
/* JDBC_3_ANT_KEY
public int getHoldability() throws SQLException {
throw new SQLException("Not implemented.");
}
public void setHoldability(int holdability) throws SQLException {
throw new SQLException("Not implemented.");
}
public java.sql.Savepoint setSavepoint() throws SQLException {
throw new SQLException("Not implemented.");
}
public java.sql.Savepoint setSavepoint(String name) throws SQLException {
throw new SQLException("Not implemented.");
}
public void rollback(java.sql.Savepoint savepoint) throws SQLException {
throw new SQLException("Not implemented.");
}
public void releaseSavepoint(java.sql.Savepoint savepoint) throws SQLException {
throw new SQLException("Not implemented.");
}
public Statement createStatement(int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
throws SQLException {
throw new SQLException("Not implemented.");
}
public PreparedStatement prepareStatement(String sql, int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
throws SQLException {
throw new SQLException("Not implemented.");
}
public CallableStatement prepareCall(String sql, int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
throws SQLException {
throw new SQLException("Not implemented.");
}
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
throws SQLException {
throw new SQLException("Not implemented.");
}
public PreparedStatement prepareStatement(String sql, int columnIndexes[])
throws SQLException {
throw new SQLException("Not implemented.");
}
public PreparedStatement prepareStatement(String sql, String columnNames[])
throws SQLException {
throw new SQLException("Not implemented.");
}
JDBC_3_ANT_KEY */
}
1.1 jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/mockdriver/MockDriver.java
Index: MockDriver.java
===================================================================
package org.apache.commons.dbutils.mockdriver;
/*
* $Id: MockDriver.java,v 1.1 2003/02/02 16:54:53 stevencaswell Exp $
* $Revision: 1.1 $
* $Date: 2003/02/02 16:54:53 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.util.Properties;
public class MockDriver implements Driver {
static {
try {
DriverManager.registerDriver(new MockDriver());
} catch(Exception e) {
}
}
public boolean acceptsURL(String url) throws SQLException {
try {
return url.equals(CONNECT_STRING);
} catch(NullPointerException e) {
return false;
}
}
public Connection connect(String url, Properties info) throws SQLException {
if(acceptsURL(url)) {
return new MockConnection();
} else {
return null;
}
}
public int getMajorVersion() {
return MAJOR_VERSION;
}
public int getMinorVersion() {
return MINOR_VERSION;
}
public boolean jdbcCompliant() {
return true;
}
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) {
return new DriverPropertyInfo[0];
}
protected static String CONNECT_STRING = "jdbc:apache:commons:mockdriver";
// version numbers
protected static int MAJOR_VERSION = 1;
protected static int MINOR_VERSION = 0;
}
1.1 jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/mockdriver/MockPreparedStatement.java
Index: MockPreparedStatement.java
===================================================================
package org.apache.commons.dbutils.mockdriver;
/*
* $Id: MockPreparedStatement.java,v 1.1 2003/02/02 16:54:53 stevencaswell Exp $
* $Revision: 1.1 $
* $Date: 2003/02/02 16:54:53 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Ref;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Calendar;
public class MockPreparedStatement extends MockStatement implements PreparedStatement {
private ResultSetMetaData _resultSetMetaData = null;
private String _sql = null;
public MockPreparedStatement(Connection conn) {
super(conn);
}
public MockPreparedStatement(Connection conn, String sql) {
super(conn);
_sql = sql;
}
public ResultSet executeQuery(String sql) throws SQLException {
checkOpen();
if("null".equals(sql)) {
return null;
} else {
return new MockResultSet(this);
}
}
public int executeUpdate(String sql) throws SQLException {
checkOpen();
return _rowsUpdated;
}
public ResultSet executeQuery() throws SQLException {
checkOpen();
if("null".equals(_sql)) {
return null;
} else {
return new MockResultSet(this);
}
}
public int executeUpdate() throws SQLException {
checkOpen();
return _rowsUpdated;
}
public void setNull(int parameterIndex, int sqlType) throws SQLException {
checkOpen();
}
public void setBoolean(int parameterIndex, boolean x) throws SQLException {
checkOpen();
}
public void setByte(int parameterIndex, byte x) throws SQLException {
checkOpen();
}
public void setShort(int parameterIndex, short x) throws SQLException {
checkOpen();
}
public void setInt(int parameterIndex, int x) throws SQLException {
checkOpen();
}
public void setLong(int parameterIndex, long x) throws SQLException {
checkOpen();
}
public void setFloat(int parameterIndex, float x) throws SQLException {
checkOpen();
}
public void setDouble(int parameterIndex, double x) throws SQLException {
checkOpen();
}
public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
checkOpen();
}
public void setString(int parameterIndex, String x) throws SQLException {
checkOpen();
}
public void setBytes(int parameterIndex, byte x[]) throws SQLException {
checkOpen();
}
public void setDate(int parameterIndex, java.sql.Date x) throws SQLException {
checkOpen();
}
public void setTime(int parameterIndex, java.sql.Time x) throws SQLException {
checkOpen();
}
public void setTimestamp(int parameterIndex, java.sql.Timestamp x) throws SQLException {
checkOpen();
}
public void setAsciiStream(int parameterIndex, java.io.InputStream x, int length) throws SQLException {
checkOpen();
}
/** @deprecated */
public void setUnicodeStream(int parameterIndex, java.io.InputStream x, int length) throws SQLException {
checkOpen();
}
public void setBinaryStream(int parameterIndex, java.io.InputStream x, int length) throws SQLException {
checkOpen();
}
public void clearParameters() throws SQLException {
checkOpen();
}
public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException {
checkOpen();
}
public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
checkOpen();
}
public void setObject(int parameterIndex, Object x) throws SQLException {
checkOpen();
}
public boolean execute() throws SQLException {
checkOpen();
return true;
}
public void addBatch() throws SQLException {
checkOpen();
}
public void setCharacterStream(int parameterIndex, java.io.Reader reader, int length) throws SQLException {
checkOpen();
}
public void setRef (int i, Ref x) throws SQLException {
checkOpen();
}
public void setBlob (int i, Blob x) throws SQLException {
checkOpen();
}
public void setClob (int i, Clob x) throws SQLException {
checkOpen();
}
public void setArray (int i, Array x) throws SQLException {
checkOpen();
}
public ResultSetMetaData getMetaData() throws SQLException {
checkOpen();
return _resultSetMetaData;
}
public void setDate(int parameterIndex, java.sql.Date x, Calendar cal) throws SQLException {
checkOpen();
}
public void setTime(int parameterIndex, java.sql.Time x, Calendar cal) throws SQLException {
checkOpen();
}
public void setTimestamp(int parameterIndex, java.sql.Timestamp x, Calendar cal) throws SQLException {
checkOpen();
}
public void setNull (int paramIndex, int sqlType, String typeName) throws SQLException {
checkOpen();
}
// ------------------- JDBC 3.0 -----------------------------------------
// Will be uncommented by the build process on a JDBC 3.0 system
/* JDBC_3_ANT_KEY
public boolean getMoreResults(int current) throws SQLException {
throw new SQLException("Not implemented.");
}
public ResultSet getGeneratedKeys() throws SQLException {
throw new SQLException("Not implemented.");
}
public int executeUpdate(String sql, int autoGeneratedKeys)
throws SQLException {
throw new SQLException("Not implemented.");
}
public int executeUpdate(String sql, int columnIndexes[])
throws SQLException {
throw new SQLException("Not implemented.");
}
public int executeUpdate(String sql, String columnNames[])
throws SQLException {
throw new SQLException("Not implemented.");
}
public boolean execute(String sql, int autoGeneratedKeys)
throws SQLException {
throw new SQLException("Not implemented.");
}
public boolean execute(String sl, int columnIndexes[])
throws SQLException {
throw new SQLException("Not implemented.");
}
public boolean execute(String sql, String columnNames[])
throws SQLException {
throw new SQLException("Not implemented.");
}
public int getResultSetHoldability() throws SQLException {
throw new SQLException("Not implemented.");
}
public void setURL(int parameterIndex, java.net.URL x)
throws SQLException {
throw new SQLException("Not implemented.");
}
public ParameterMetaData getParameterMetaData() throws SQLException {
throw new SQLException("Not implemented.");
}
JDBC_3_ANT_KEY */
}
1.1 jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/mockdriver/MockResultSet.java
Index: MockResultSet.java
===================================================================
package org.apache.commons.dbutils.mockdriver;
/*
* $Id: MockResultSet.java,v 1.1 2003/02/02 16:54:53 stevencaswell Exp $
* $Revision: 1.1 $
* $Date: 2003/02/02 16:54:53 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
import java.math.BigDecimal;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Ref;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.util.Calendar;
public class MockResultSet implements ResultSet {
public MockResultSet(Statement stmt) {
_statement = stmt;
}
protected Statement _statement = null;
protected int _fetchSize = 0;
protected int _rowCount = 2;
protected int _row = 0;
protected boolean _open = true;
protected int _fetchDirection = ResultSet.FETCH_FORWARD;
public boolean next() throws SQLException {
checkOpen();
if(_row < _rowCount) {
++_row;
return true;
} else {
_row = _rowCount + 1;
return false;
}
}
public void close() throws SQLException {
_open = false;
}
public boolean wasNull() throws SQLException {
checkOpen();
return false;
}
public String getString(int columnIndex) throws SQLException {
checkOpen();
return "String" + columnIndex;
}
public boolean getBoolean(int columnIndex) throws SQLException {
checkOpen();
return true;
}
public byte getByte(int columnIndex) throws SQLException {
checkOpen();
return (byte)columnIndex;
}
public short getShort(int columnIndex) throws SQLException {
checkOpen();
return (short)columnIndex;
}
public int getInt(int columnIndex) throws SQLException {
checkOpen();
return (int)columnIndex;
}
public long getLong(int columnIndex) throws SQLException {
checkOpen();
return (long)columnIndex;
}
public float getFloat(int columnIndex) throws SQLException {
checkOpen();
return (float)columnIndex;
}
public double getDouble(int columnIndex) throws SQLException {
checkOpen();
return (double)columnIndex;
}
/** @deprecated */
public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
checkOpen();
return new BigDecimal((double)columnIndex);
}
public byte[] getBytes(int columnIndex) throws SQLException {
checkOpen();
return new byte[] { (byte)columnIndex };
}
public java.sql.Date getDate(int columnIndex) throws SQLException {
checkOpen();
return null;
}
public java.sql.Time getTime(int columnIndex) throws SQLException {
checkOpen();
return null;
}
public java.sql.Timestamp getTimestamp(int columnIndex) throws SQLException {
checkOpen();
return null;
}
public java.io.InputStream getAsciiStream(int columnIndex) throws SQLException {
checkOpen();
return null;
}
/** @deprecated */
public java.io.InputStream getUnicodeStream(int columnIndex) throws SQLException {
checkOpen();
return null;
}
public java.io.InputStream getBinaryStream(int columnIndex) throws SQLException {
checkOpen();
return null;
}
public String getString(String columnName) throws SQLException {
checkOpen();
return columnName;
}
public boolean getBoolean(String columnName) throws SQLException {
checkOpen();
return true;
}
public byte getByte(String columnName) throws SQLException {
checkOpen();
return (byte)(columnName.hashCode());
}
public short getShort(String columnName) throws SQLException {
checkOpen();
return (short)(columnName.hashCode());
}
public int getInt(String columnName) throws SQLException {
checkOpen();
return (columnName.hashCode());
}
public long getLong(String columnName) throws SQLException {
checkOpen();
return (long)(columnName.hashCode());
}
public float getFloat(String columnName) throws SQLException {
checkOpen();
return (float)(columnName.hashCode());
}
public double getDouble(String columnName) throws SQLException {
checkOpen();
return (double)(columnName.hashCode());
}
/** @deprecated */
public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException {
checkOpen();
return new BigDecimal((double)columnName.hashCode());
}
public byte[] getBytes(String columnName) throws SQLException {
checkOpen();
return columnName.getBytes();
}
public java.sql.Date getDate(String columnName) throws SQLException {
checkOpen();
return null;
}
public java.sql.Time getTime(String columnName) throws SQLException {
checkOpen();
return null;
}
public java.sql.Timestamp getTimestamp(String columnName) throws SQLException {
checkOpen();
return null;
}
public java.io.InputStream getAsciiStream(String columnName) throws SQLException {
checkOpen();
return null;
}
/** @deprecated */
public java.io.InputStream getUnicodeStream(String columnName) throws SQLException {
checkOpen();
return null;
}
public java.io.InputStream getBinaryStream(String columnName) throws SQLException {
checkOpen();
return null;
}
public SQLWarning getWarnings() throws SQLException {
checkOpen();
return null;
}
public void clearWarnings() throws SQLException {
checkOpen();
}
public String getCursorName() throws SQLException {
checkOpen();
return null;
}
public ResultSetMetaData getMetaData() throws SQLException {
checkOpen();
return null;
}
public Object getObject(int columnIndex) throws SQLException {
checkOpen();
return new Object();
}
public Object getObject(String columnName) throws SQLException {
checkOpen();
return columnName;
}
public int findColumn(String columnName) throws SQLException {
checkOpen();
return 1;
}
public java.io.Reader getCharacterStream(int columnIndex) throws SQLException {
checkOpen();
return null;
}
public java.io.Reader getCharacterStream(String columnName) throws SQLException {
checkOpen();
return null;
}
public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
checkOpen();
return new BigDecimal((double)columnIndex);
}
public BigDecimal getBigDecimal(String columnName) throws SQLException {
checkOpen();
return new BigDecimal((double)columnName.hashCode());
}
public boolean isBeforeFirst() throws SQLException {
checkOpen();
return _row == 0;
}
public boolean isAfterLast() throws SQLException {
checkOpen();
return _row > _rowCount;
}
public boolean isFirst() throws SQLException {
checkOpen();
return _row == 1;
}
public boolean isLast() throws SQLException {
checkOpen();
return _row == _rowCount;
}
public void beforeFirst() throws SQLException {
checkOpen();
_row = 0;
}
public void afterLast() throws SQLException {
checkOpen();
_row = 0;
}
public boolean first() throws SQLException {
checkOpen();
_row = 1;
return true;
}
public boolean last() throws SQLException {
checkOpen();
_row = _rowCount;
return true;
}
public int getRow() throws SQLException {
checkOpen();
return _row;
}
public boolean absolute( int row ) throws SQLException {
checkOpen();
if(row < 0) {
_row = (_rowCount + row) + 1;
if(_row < 0) {
_row = 0;
}
}
else if(row > _rowCount) {
_row = _rowCount + 1;
}
else {
_row = row;
}
return true;
}
public boolean relative( int rows ) throws SQLException {
checkOpen();
if(rows > 0) {
for(int i = 0; i < rows; i++) {
this.next();
}
}
else if(rows < 0) {
for(int i = rows; i < 0; i++) {
this.previous();
}
}
return true;
}
public boolean previous() throws SQLException {
checkOpen();
if(_row > 0) {
--_row;
return true;
}
else {
return false;
}
}
public void setFetchDirection(int direction) throws SQLException {
checkOpen();
if(direction != ResultSet.FETCH_FORWARD &&
direction != ResultSet.FETCH_REVERSE &&
direction != ResultSet.FETCH_UNKNOWN) {
throw new SQLException("Invalid fetch direction.");
}
_fetchDirection = direction;
}
public int getFetchDirection() throws SQLException {
checkOpen();
return _fetchDirection;
}
public void setFetchSize(int rows) throws SQLException {
checkOpen();
if(rows < 0 ||
rows > _statement.getMaxRows()) {
throw new SQLException("Invalid fetch size.");
}
_fetchSize = rows;
}
public int getFetchSize() throws SQLException {
checkOpen();
return _fetchSize;
}
public int getType() throws SQLException {
return ResultSet.TYPE_SCROLL_INSENSITIVE;
}
public int getConcurrency() throws SQLException {
return ResultSet.CONCUR_READ_ONLY;
}
public boolean rowUpdated() throws SQLException {
checkOpen();
return false;
}
public boolean rowInserted() throws SQLException {
checkOpen();
return false;
}
public boolean rowDeleted() throws SQLException {
checkOpen();
return false;
}
public void updateNull(int columnIndex) throws SQLException {
checkOpen();
}
public void updateBoolean(int columnIndex, boolean x) throws SQLException {
checkOpen();
}
public void updateByte(int columnIndex, byte x) throws SQLException {
checkOpen();
}
public void updateShort(int columnIndex, short x) throws SQLException {
checkOpen();
}
public void updateInt(int columnIndex, int x) throws SQLException {
checkOpen();
}
public void updateLong(int columnIndex, long x) throws SQLException {
checkOpen();
}
public void updateFloat(int columnIndex, float x) throws SQLException {
checkOpen();
}
public void updateDouble(int columnIndex, double x) throws SQLException {
checkOpen();
}
public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
checkOpen();
}
public void updateString(int columnIndex, String x) throws SQLException {
checkOpen();
}
public void updateBytes(int columnIndex, byte x[]) throws SQLException {
checkOpen();
}
public void updateDate(int columnIndex, java.sql.Date x) throws SQLException {
checkOpen();
}
public void updateTime(int columnIndex, java.sql.Time x) throws SQLException {
checkOpen();
}
public void updateTimestamp(int columnIndex, java.sql.Timestamp x) throws SQLException {
checkOpen();
}
public void updateAsciiStream(int columnIndex,
java.io.InputStream x,
int length) throws SQLException {
checkOpen();
}
public void updateBinaryStream(int columnIndex,
java.io.InputStream x,
int length) throws SQLException {
checkOpen();
}
public void updateCharacterStream(int columnIndex,
java.io.Reader x,
int length) throws SQLException {
checkOpen();
}
public void updateObject(int columnIndex, Object x, int scale)
throws SQLException {
checkOpen();
}
public void updateObject(int columnIndex, Object x) throws SQLException {
checkOpen();
}
public void updateNull(String columnName) throws SQLException {
checkOpen();
}
public void updateBoolean(String columnName, boolean x) throws SQLException {
checkOpen();
}
public void updateByte(String columnName, byte x) throws SQLException {
checkOpen();
}
public void updateShort(String columnName, short x) throws SQLException {
checkOpen();
}
public void updateInt(String columnName, int x) throws SQLException {
checkOpen();
}
public void updateLong(String columnName, long x) throws SQLException {
checkOpen();
}
public void updateFloat(String columnName, float x) throws SQLException {
checkOpen();
}
public void updateDouble(String columnName, double x) throws SQLException {
checkOpen();
}
public void updateBigDecimal(String columnName, BigDecimal x) throws SQLException {
checkOpen();
}
public void updateString(String columnName, String x) throws SQLException {
checkOpen();
}
public void updateBytes(String columnName, byte x[]) throws SQLException {
checkOpen();
}
public void updateDate(String columnName, java.sql.Date x) throws SQLException {
checkOpen();
}
public void updateTime(String columnName, java.sql.Time x) throws SQLException {
checkOpen();
}
public void updateTimestamp(String columnName, java.sql.Timestamp x)
throws SQLException {
checkOpen();
}
public void updateAsciiStream(String columnName,
java.io.InputStream x,
int length) throws SQLException {
checkOpen();
}
public void updateBinaryStream(String columnName,
java.io.InputStream x,
int length) throws SQLException {
checkOpen();
}
public void updateCharacterStream(String columnName,
java.io.Reader reader,
int length) throws SQLException {
checkOpen();
}
public void updateObject(String columnName, Object x, int scale)
throws SQLException {
checkOpen();
}
public void updateObject(String columnName, Object x) throws SQLException {
checkOpen();
}
public void insertRow() throws SQLException {
checkOpen();
}
public void updateRow() throws SQLException {
checkOpen();
}
public void deleteRow() throws SQLException {
checkOpen();
}
public void refreshRow() throws SQLException {
checkOpen();
}
public void cancelRowUpdates() throws SQLException {
checkOpen();
}
public void moveToInsertRow() throws SQLException {
checkOpen();
}
public void moveToCurrentRow() throws SQLException {
checkOpen();
}
public Statement getStatement() throws SQLException {
checkOpen();
return _statement;
}
public Object getObject(int i, java.util.Map map) throws SQLException {
checkOpen();
return new Object();
}
public Ref getRef(int i) throws SQLException {
checkOpen();
return null;
}
public Blob getBlob(int i) throws SQLException {
checkOpen();
return null;
}
public Clob getClob(int i) throws SQLException {
checkOpen();
return null;
}
public Array getArray(int i) throws SQLException {
checkOpen();
return null;
}
public Object getObject(String colName, java.util.Map map) throws SQLException {
checkOpen();
return colName;
}
public Ref getRef(String colName) throws SQLException {
checkOpen();
return null;
}
public Blob getBlob(String colName) throws SQLException {
checkOpen();
return null;
}
public Clob getClob(String colName) throws SQLException {
checkOpen();
return null;
}
public Array getArray(String colName) throws SQLException {
checkOpen();
return null;
}
public java.sql.Date getDate(int columnIndex, Calendar cal) throws SQLException {
checkOpen();
return null;
}
public java.sql.Date getDate(String columnName, Calendar cal) throws SQLException {
checkOpen();
return null;
}
public java.sql.Time getTime(int columnIndex, Calendar cal) throws SQLException {
checkOpen();
return null;
}
public java.sql.Time getTime(String columnName, Calendar cal) throws SQLException {
checkOpen();
return null;
}
public java.sql.Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
checkOpen();
return null;
}
public java.sql.Timestamp getTimestamp(String columnName, Calendar cal)
throws SQLException {
checkOpen();
return null;
}
protected void checkOpen() throws SQLException {
if(!_open) {
throw new SQLException("Connection is closed.");
}
}
// ------------------- JDBC 3.0 -----------------------------------------
// Will be uncommented by the build process on a JDBC 3.0 system
/* JDBC_3_ANT_KEY
public java.net.URL getURL(int columnIndex) throws SQLException {
throw new SQLException("Not implemented.");
}
public java.net.URL getURL(String columnName) throws SQLException {
throw new SQLException("Not implemented.");
}
public void updateRef(int columnIndex, java.sql.Ref x)
throws SQLException {
throw new SQLException("Not implemented.");
}
public void updateRef(String columnName, java.sql.Ref x)
throws SQLException {
throw new SQLException("Not implemented.");
}
public void updateBlob(int columnIndex, java.sql.Blob x)
throws SQLException {
throw new SQLException("Not implemented.");
}
public void updateBlob(String columnName, java.sql.Blob x)
throws SQLException {
throw new SQLException("Not implemented.");
}
public void updateClob(int columnIndex, java.sql.Clob x)
throws SQLException {
throw new SQLException("Not implemented.");
}
public void updateClob(String columnName, java.sql.Clob x)
throws SQLException {
throw new SQLException("Not implemented.");
}
public void updateArray(int columnIndex, java.sql.Array x)
throws SQLException {
throw new SQLException("Not implemented.");
}
public void updateArray(String columnName, java.sql.Array x)
throws SQLException {
throw new SQLException("Not implemented.");
}
JDBC_3_ANT_KEY */
}
1.1 jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/mockdriver/MockStatement.java
Index: MockStatement.java
===================================================================
package org.apache.commons.dbutils.mockdriver;
/*
* $Id: MockStatement.java,v 1.1 2003/02/02 16:54:53 stevencaswell Exp $
* $Revision: 1.1 $
* $Date: 2003/02/02 16:54:53 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.util.Calendar;
public class MockStatement implements Statement {
public MockStatement(Connection conn) {
_connection = conn;
}
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 = ResultSet.CONCUR_READ_ONLY;
protected int _resultSetType = ResultSet.TYPE_SCROLL_INSENSITIVE;
public ResultSet executeQuery(String sql) throws SQLException {
checkOpen();
if("null".equals(sql)) {
return null;
} else {
return new MockResultSet(this);
}
}
public int executeUpdate(String sql) throws SQLException {
checkOpen();
return _rowsUpdated;
}
public void close() throws SQLException {
checkOpen();
_open = false;
}
public int getMaxFieldSize() throws SQLException {
checkOpen();
return _maxFieldSize;
}
public void setMaxFieldSize(int max) throws SQLException {
checkOpen();
_maxFieldSize = max;
}
public int getMaxRows() throws SQLException {
checkOpen();
return _maxRows;
}
public void setMaxRows(int max) throws SQLException {
checkOpen();
_maxRows = max;
}
public void setEscapeProcessing(boolean enable) throws SQLException {
checkOpen();
_escapeProcessing = enable;
}
public int getQueryTimeout() throws SQLException {
checkOpen();
return _queryTimeout;
}
public void setQueryTimeout(int seconds) throws SQLException {
checkOpen();
_queryTimeout = seconds;
}
public void cancel() throws SQLException {
checkOpen();
}
public SQLWarning getWarnings() throws SQLException {
checkOpen();
return null;
}
public void clearWarnings() throws SQLException {
checkOpen();
}
public void setCursorName(String name) throws SQLException {
checkOpen();
_cursorName = name;
}
public boolean execute(String sql) throws SQLException {
checkOpen();
return _executeResponse;
}
public ResultSet getResultSet() throws SQLException {
checkOpen();
return new MockResultSet(this);
}
public int getUpdateCount() throws SQLException {
checkOpen();
return _rowsUpdated;
}
public boolean getMoreResults() throws SQLException {
checkOpen();
return false;
}
public void setFetchDirection(int direction) throws SQLException {
checkOpen();
_fetchDirection = direction;
}
public int getFetchDirection() throws SQLException {
checkOpen();
return _fetchDirection;
}
public void setFetchSize(int rows) throws SQLException {
checkOpen();
_fetchSize = rows;
}
public int getFetchSize() throws SQLException {
checkOpen();
return _fetchSize;
}
public int getResultSetConcurrency() throws SQLException {
checkOpen();
return _resultSetConcurrency;
}
public int getResultSetType() throws SQLException {
checkOpen();
return _resultSetType;
}
public void addBatch(String sql) throws SQLException {
checkOpen();
}
public void clearBatch() throws SQLException {
checkOpen();
}
public int[] executeBatch() throws SQLException {
checkOpen();
return new int[0];
}
public Connection getConnection() throws SQLException {
checkOpen();
return _connection;
}
protected void checkOpen() throws SQLException {
if(!_open) {
throw new SQLException("Connection is closed.");
}
}
// ------------------- JDBC 3.0 -----------------------------------------
// Will be uncommented by the build process on a JDBC 3.0 system
/* JDBC_3_ANT_KEY
public boolean getMoreResults(int current) throws SQLException {
throw new SQLException("Not implemented.");
}
public ResultSet getGeneratedKeys() throws SQLException {
throw new SQLException("Not implemented.");
}
public int executeUpdate(String sql, int autoGeneratedKeys)
throws SQLException {
throw new SQLException("Not implemented.");
}
public int executeUpdate(String sql, int columnIndexes[])
throws SQLException {
throw new SQLException("Not implemented.");
}
public int executeUpdate(String sql, String columnNames[])
throws SQLException {
throw new SQLException("Not implemented.");
}
public boolean execute(String sql, int autoGeneratedKeys)
throws SQLException {
throw new SQLException("Not implemented.");
}
public boolean execute(String sql, int columnIndexes[])
throws SQLException {
throw new SQLException("Not implemented.");
}
public boolean execute(String sql, String columnNames[])
throws SQLException {
throw new SQLException("Not implemented.");
}
public int getResultSetHoldability() throws SQLException {
checkOpen();
throw new SQLException("Not implemented.");
}
JDBC_3_ANT_KEY */
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org