Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/sql
In directory usw-pr-cvs1:/tmp/cvs-serv21660/src/jdk/common/com/mockobjects/sql
Added Files:
CommonMockConnection.java CommonMockMultiRowResultSet.java
CommonMockPreparedStatement.java
CommonMockSingleRowResultSet.java CommonMockStatement.java
Removed Files:
MockConnection.java MockMultiRowResultSet.java
MockPreparedStatement.java MockResultSetMetaData.java
MockSingleRowResultSet.java MockStatement.java
Log Message:
Added abstraction layer to sql mocks to allow build against jdk1.4
--- NEW FILE: CommonMockConnection.java ---
package com.mockobjects.sql;
import com.mockobjects.*;
import java.sql.*;
import java.util.Map;
public abstract class CommonMockConnection extends MockObject implements Connection {
private ExpectationCounter myCommitCalls = new ExpectationCounter("CommonMockConnection.commit");
private ExpectationCounter myRollbackCalls = new ExpectationCounter("CommonMockConnection.rollback");
private ExpectationCounter myCloseCalls = new ExpectationCounter("CommonMockConnection.close");
private ExpectationCollection myPreparedStatementStrings = new ExpectationList("CommonMockConnection.preparedStatementString");
private ReturnObjectList myPreparedStatements = new ReturnObjectList("statements");
private SQLException myStatementException = null;
private ExpectationCounter myCreateStatementCalls = new ExpectationCounter("CommonMockConnection.createStatement");
private ExpectationValue myAutoCommit = new ExpectationValue("CommonMockConnection.setAutoCommit");
private Statement myStatement;
private boolean myIsClosed;
private SQLException myIsClosedException;
private SQLException myCloseException;
public void setExpectedCloseCalls(int callCount) {
myCloseCalls.setExpected(callCount);
}
public void setExpectedCommitCalls(int callCount) {
myCommitCalls.setExpected(callCount);
}
public void setExpectedCreateStatementCalls(int calls) {
myCreateStatementCalls.setExpected(calls);
}
public void addExpectedPreparedStatementString(String sql) {
myPreparedStatementStrings.addExpected(sql);
}
public void setExpectedRollbackCalls(int callCount) {
myRollbackCalls.setExpected(callCount);
}
public void setupAddPreparedStatement(PreparedStatement prepared) {
myPreparedStatements.addObjectToReturn(prepared);
}
public void setupStatement(Statement statement) {
myStatement = statement;
}
public void setupThrowExceptionOnPrepareOrCreate(SQLException exception) {
myStatementException = exception;
}
public void clearWarnings() throws SQLException {
notImplemented();
}
public void setupCloseException(SQLException aCloseException) {
myCloseException = aCloseException;
}
public void close() throws SQLException {
if(myCloseException != null) {
throw myCloseException;
}
myCloseCalls.inc();
}
public void commit() throws SQLException {
myCommitCalls.inc();
}
public Statement createStatement() throws SQLException {
myCreateStatementCalls.inc();
throwStatementExceptionIfAny();
return myStatement;
}
public Statement createStatement(
int resultSetType,
int resultSetConcurrency)
throws SQLException {
notImplemented();
return null;
}
public boolean getAutoCommit() throws SQLException {
notImplemented();
return false;
}
public String getCatalog() throws SQLException {
notImplemented();
return null;
}
public DatabaseMetaData getMetaData()
throws SQLException {
notImplemented();
return null;
}
public int getTransactionIsolation() throws SQLException {
notImplemented();
return 0;
}
public Map getTypeMap() throws SQLException {
notImplemented();
return null;
}
public SQLWarning getWarnings() throws SQLException {
notImplemented();
return null;
}
public void setupIsClosedException(SQLException aIsClosedException) {
myIsClosedException = aIsClosedException;
}
public void setupIsClose(boolean aIsClosed) {
myIsClosed = aIsClosed;
}
public boolean isClosed() throws SQLException {
if(myIsClosedException != null) {
throw myIsClosedException;
}
return myIsClosed;
}
public boolean isReadOnly() throws SQLException {
notImplemented();
return false;
}
public String nativeSQL(String sql) throws SQLException {
notImplemented();
return null;
}
public CallableStatement prepareCall(String sql)
throws SQLException {
notImplemented();
return null;
}
public CallableStatement prepareCall(
String sql,
int resultSetType,
int resultSetConcurrency)
throws SQLException {
notImplemented();
return null;
}
public PreparedStatement prepareStatement(String sql) throws SQLException {
myPreparedStatementStrings.addActual(sql);
throwStatementExceptionIfAny();
return (PreparedStatement) myPreparedStatements.nextReturnObject();
}
public PreparedStatement prepareStatement(
String sql,
int resultSetType,
int resultSetConcurrency)
throws SQLException {
notImplemented();
return null;
}
public void rollback() throws SQLException {
myRollbackCalls.inc();
}
public void setExpectedAutoCommit(boolean autoCommit) {
myAutoCommit.setExpected(autoCommit);
}
public void setAutoCommit(boolean autoCommit) throws SQLException {
myAutoCommit.setActual(autoCommit);
}
public void setCatalog(String catalog) throws SQLException {
notImplemented();
}
public void setReadOnly(boolean readOnly) throws SQLException {
notImplemented();
}
public void setTransactionIsolation(int level)
throws SQLException {
notImplemented();
}
public void setTypeMap(Map map) throws SQLException {
notImplemented();
}
private void throwStatementExceptionIfAny() throws SQLException {
if(null != myStatementException) {
throw myStatementException;
}
}
}
--- NEW FILE: CommonMockMultiRowResultSet.java ---
package com.mockobjects.sql;
import java.sql.*;
import java.sql.Date;
import java.util.*;
import java.math.BigDecimal;
import java.io.InputStream;
import java.io.Reader;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
import com.mockobjects.*;
/**
* This is a simple implementation of a MockResultSet.
* It returns values for multiple rows.
*/
public abstract class CommonMockMultiRowResultSet extends MockResultSet {
private Object[][] myRows = new Object[0][0];
private String[] myColumnNames;
private int myRowOffset = -1;
private SQLException myGetException = null;
public CommonMockMultiRowResultSet() {
super();
}
public void setupColumnNames(String[] columnNames) {
myColumnNames = columnNames;
}
public void setupRows(Object[][] rows) {
myRows = rows;
}
public void setupThrowExceptionOnGet(SQLException exception) {
myGetException = exception;
}
public Object getObject(int columnIndex) throws SQLException {
throwGetExceptionIfAny();
return myRows[myRowOffset][columnIndex - 1];
}
public Object getObject(String columnName) throws SQLException {
throwGetExceptionIfAny();
return getObject(findIndexForColumnName(columnName));
}
public boolean next() throws SQLException {
myNextCalls.inc();
if (myRowOffset + 1 >= myRows.length) {
return false;
}
myRowOffset++;
return true;
}
public int getRow() throws SQLException {
return myRowOffset + 1;
}
private void throwGetExceptionIfAny() throws SQLException {
if (null != myGetException) {
throw myGetException;
}
}
private int findIndexForColumnName(String columnName) throws SQLException {
for (int i = 0; i < myColumnNames.length; ++i) {
if (myColumnNames[i].equalsIgnoreCase(columnName)) {
return i + 1;
}
}
throw new SQLException("Column name not found");
}
}
--- NEW FILE: CommonMockPreparedStatement.java ---
package com.mockobjects.sql;
import java.sql.*;
import java.util.Calendar;
import java.io.Reader;
import java.math.BigDecimal;
import com.mockobjects.*;
public abstract class CommonMockPreparedStatement extends CommonMockStatement implements
PreparedStatement {
private ExpectationSet mySetParameters =
new ExpectationSet("CommonMockPreparedStatement.setParameters");
private ExpectationCounter myClearParametersCalls =
new ExpectationCounter("CommonMockPreparedStatement.clearParameters() calls");
private ExpectationSet myTargetSQLTypes =
new ExpectationSet("target sql types");
public void addExpectedSetParameter(int parameterIndex, int intValue) {
addExpectedSetParameter(parameterIndex, new Integer(intValue));
}
public void addExpectedTargetSQLType(int aTargetSQLType){
myTargetSQLTypes.addExpected(new Integer(aTargetSQLType));
}
public void addExpectedSetParameter(int parameterIndex, Object parameterValue) {
mySetParameters.addExpected(new MapEntry(new Integer(parameterIndex), parameterValue));
}
public void addExpectedSetParameters(Object[] parameters) {
for (int i = 0; i < parameters.length; ++i) {
addExpectedSetParameter(i + 1, parameters[i]);
}
}
public void clearParameters() throws SQLException {
myClearParametersCalls.inc();
}
public boolean execute() throws SQLException {
innerExecute();
return false;
}
public void setExpectedClearParametersCalls(int callCount) {
myClearParametersCalls.setExpected(callCount);
}
public void setExpectingNoSetParameters() {
mySetParameters.setExpectNothing();
}
public ResultSet executeQuery() throws SQLException {
return executeQuery("");
}
public int executeUpdate() throws SQLException {
return executeUpdate("");
}
public void setInt(int parameterIndex, int x) throws SQLException {
setObject(parameterIndex, new Integer(x));
}
public void setString(int parameterIndex, String x) throws SQLException {
setObject(parameterIndex, x);
}
public void setTimestamp(int param, Timestamp timestamp) throws SQLException {
setObject(param, timestamp);
}
public void setClob(int param, Clob clob) throws SQLException {
setObject(param, clob);
}
public void setLong(int param, long aLong) throws SQLException {
setObject(param, new Long(aLong));
}
public void addBatch() throws SQLException {
notImplemented();
}
public void setNull(int param, int param1) throws SQLException {
setObject(param, null);
}
public void setArray(int param, Array array) throws SQLException {
setObject(param, array);
}
public void setShort(int param, short aShort) throws SQLException {
setObject(param, new Short(aShort));
}
public void setTime(int param, Time time, Calendar calendar) throws SQLException {
setObject(param, time);
}
public void setObject(int param, Object anObject, int targetSqlType, int scale) throws SQLException {
notImplemented();
}
public void setObject(int param, Object anObject, int aTargetSQLType)
throws SQLException {
setObject(param, anObject);
myTargetSQLTypes.addActual(new Integer(aTargetSQLType));
}
public void setRef(int param, Ref ref) throws SQLException {
setObject(param, ref);
}
public void setDate(int param, Date date) throws SQLException {
setObject(param, date);
}
public void setFloat(int param, float aFloat) throws SQLException {
setObject(param, new Float(aFloat));
}
public void setBlob(int param, Blob blob) throws SQLException {
setObject(param, blob);
}
public void setCharacterStream(int param, Reader reader, int length) throws SQLException {
notImplemented();
}
public void setAsciiStream(int param, java.io.InputStream inputStream, int length) throws SQLException {
notImplemented();
}
public void setDate(int param, Date date, Calendar calendar) throws SQLException {
setDate(param, date);
}
public void setBinaryStream(int param, java.io.InputStream inputStream, int length) throws SQLException {
notImplemented();
}
public void setUnicodeStream(int param, java.io.InputStream inputStream, int length) throws SQLException {
notImplemented();
}
public void setBytes(int param, byte[] values) throws SQLException {
setObject(param, values);
}
public void setObject(int param, Object anObject) throws SQLException {
mySetParameters.addActual(new MapEntry(new Integer(param), anObject));
}
public void setByte(int param, byte aByte) throws SQLException {
setObject(param, new Byte(aByte));
}
public void setDouble(int param, double aDouble) throws SQLException {
setObject(param, new Double(aDouble));
}
public ResultSetMetaData getMetaData() throws SQLException {
notImplemented();
return null;
}
public void setTimestamp(int param, Timestamp timestamp, Calendar calendar) throws SQLException {
notImplemented();
}
public void setTime(int param, Time time) throws SQLException {
setObject(param, time);
}
public void setBoolean(int param, boolean aBoolean) throws SQLException {
setObject(param, new Boolean(aBoolean));
}
public void setNull(int param, int param1, String typeName) throws SQLException {
notImplemented();
}
public void setBigDecimal(int param, BigDecimal bigDecimal) throws SQLException {
setObject(param, bigDecimal);
}
}
--- NEW FILE: CommonMockSingleRowResultSet.java ---
package com.mockobjects.sql;
import java.sql.SQLException;
import java.util.*;
/**
* This is a simple implementation of a MockResultSet.
* It verifies that the values fed to it have been retrieved.
* These can be found by either column index or column name.
* For basic java types (e.g. int, boolean), insert an instance of
* the appropriate object (e.g. Integer, Boolean)
* To force throwing a SQLException on a getter, set the corresponding value to be of type SQLException.
*/
public abstract class CommonMockSingleRowResultSet extends MockResultSet {
private ExpectationSqlRow myRow = new ExpectationSqlRow("single row");
private int myNextCallCount = 0;
public CommonMockSingleRowResultSet(Object[] values) {
addExpectedIndexedValues(values);
}
public CommonMockSingleRowResultSet(){
super();
}
public CommonMockSingleRowResultSet(String[] names, Object[] values) {
addExpectedNamedValues(names, values);
}
public CommonMockSingleRowResultSet(Map map) {
addExpectedNamedValues(map);
}
public void addExpectedIndexedValues(Object[] values) {
myRow.addExpectedIndexedValues(values);
}
public void addExpectedNamedValues(String[] names, Object[] values) {
myRow.addExpectedNamedValues(names, values);
}
public void addExpectedNamedValues(Map map) {
myRow.addExpectedNamedValues(map);
}
public boolean next() throws SQLException {
myNextCalls.inc();
myNextCallCount++;
return myNextCallCount == 1;
}
public int getRow() throws SQLException {
return myNextCallCount;
}
public Object getObject(int columnIndex) throws SQLException {
return myRow.get(columnIndex);
}
public Object getObject(String columnName) throws SQLException {
return myRow.get(columnName);
}
}
--- NEW FILE: CommonMockStatement.java ---
package com.mockobjects.sql;
import com.mockobjects.ExpectationCounter;
import com.mockobjects.ExpectationValue;
import com.mockobjects.MockObject;
import com.mockobjects.ReturnObjectList;
import java.sql.*;
public abstract class CommonMockStatement extends MockObject implements Statement {
protected ExpectationCounter myCloseCalls = new ExpectationCounter("CommonMockStatement.closeCalls");
protected ExpectationCounter myExecuteCalls = new ExpectationCounter("CommonMockStatement.executeCalls");
protected ExpectationValue myQueryString = new ExpectationValue("CommonMockStatement.queryString");
protected ReturnObjectList myResultSets = new ReturnObjectList("result set");
private int myUpdateCount = 0;
private SQLException myExecuteException = null;
public void setExpectedExecuteCalls(int callCount) {
myExecuteCalls.setExpected(callCount);
}
public void setExpectedQueryString(String queryString) {
myQueryString.setExpected(queryString);
}
public void setExpectedCloseCalls(int callCount) {
myCloseCalls.setExpected(callCount);
}
public void addResultSet(MockResultSet aResultSet) {
myResultSets.addObjectToReturn(aResultSet);
}
public void setupThrowExceptionOnExecute(SQLException exception) {
myExecuteException = exception;
}
public void setupUpdateCount(int updateCount) {
myUpdateCount = updateCount;
}
protected void innerExecute() throws SQLException {
myExecuteCalls.inc();
if(null != myExecuteException) {
throw myExecuteException;
}
}
public void close() throws SQLException {
myCloseCalls.inc();
}
public boolean execute(String sql) throws SQLException {
notImplemented();
return true;
}
public ResultSet executeQuery(String sql) throws SQLException {
myQueryString.setActual(sql);
innerExecute();
return (ResultSet) myResultSets.nextReturnObject();
}
public int executeUpdate(String sql) throws SQLException {
myQueryString.setActual(sql);
innerExecute();
return myUpdateCount;
}
public int getMaxFieldSize() throws SQLException {
notImplemented();
return 0;
}
public void setMaxFieldSize(int max) throws SQLException {
notImplemented();
}
public int getMaxRows() throws SQLException {
notImplemented();
return 0;
}
public void setMaxRows(int max) throws SQLException {
notImplemented();
}
public void setEscapeProcessing(boolean enable) throws SQLException {
notImplemented();
}
public int getQueryTimeout() throws SQLException {
notImplemented();
return 0;
}
public void setQueryTimeout(int seconds) throws SQLException {
notImplemented();
}
public void cancel() throws SQLException {
notImplemented();
}
public SQLWarning getWarnings() throws SQLException {
notImplemented();
return null;
}
public void clearWarnings() throws SQLException {
notImplemented();
}
public void setCursorName(String name) throws SQLException {
notImplemented();
}
public ResultSet getResultSet() throws SQLException {
notImplemented();
return null;
}
public int getUpdateCount() throws SQLException {
return myUpdateCount;
}
public boolean getMoreResults() throws SQLException {
notImplemented();
return false;
}
public void setFetchDirection(int direction) throws SQLException {
notImplemented();
}
public int getFetchDirection() throws SQLException {
notImplemented();
return 0;
}
public void setFetchSize(int rows) throws SQLException {
notImplemented();
}
public int getFetchSize() throws SQLException {
notImplemented();
return 0;
}
public int getResultSetConcurrency() throws SQLException {
notImplemented();
return 0;
}
public int getResultSetType() throws SQLException {
notImplemented();
return 0;
}
public void addBatch(String sql) throws SQLException {
notImplemented();
}
public void clearBatch() throws SQLException {
notImplemented();
}
public int[] executeBatch() throws SQLException {
notImplemented();
return null;
}
public Connection getConnection() throws SQLException {
notImplemented();
return null;
}
}
--- MockConnection.java DELETED ---
--- MockMultiRowResultSet.java DELETED ---
--- MockPreparedStatement.java DELETED ---
--- MockResultSetMetaData.java DELETED ---
--- MockSingleRowResultSet.java DELETED ---
--- MockStatement.java DELETED ---
|