|
From: Verma, N. (C. G. L529706) <Nit...@ge...> - 2002-01-08 21:59:32
|
package com.mockobjects.sql;
import java.sql.*;
import java.util.ArrayList;
import java.util.Map;
import junit.framework.AssertionFailedError;
import com.mockobjects.MockObject;
import com.mockobjects.ExpectationCounter;
import com.mockobjects.ExpectationCollection;
import com.mockobjects.ExpectationList;
import com.mockobjects.ExpectationValue;
/**
* Trial version
* @author Nitin Verma, Sridhar
* @version 1.0 24 Dec 2001
*/
public class MockConnection extends MockObject implements Connection{
/* Nested MockObjects */
private MockCallableStatement myCallableStatement;
/*Expectations objects that can be set */
private ExpectationCounter myCommitCalls = new
ExpectationCounter("MockConnection.commit");
private ExpectationCounter myRollbackCalls = new
ExpectationCounter("MockConnection.rollback");
private ExpectationCounter myCloseCalls = new
ExpectationCounter("MockConnection.close");
private ExpectationValue myPrepareCallString = new
ExpectationValue("MockConnection.prepareCallString");
private ExpectationCollection myPreparedStatementStrings = new
ExpectationList("MockConnection.preparedStatementString");
private ExpectationCounter myCreateStatementCalls = new
ExpectationCounter("MockConnection.createStatement");
private ExpectationValue myAutoCommit = new
ExpectationValue("MockConnection.setAutoCommit");
/*Other objects*/
private Statement myStatement;
private ArrayList myPreparedStatements = new ArrayList();
private SQLException myStatementException = null;
private int myHoldability = 0;
/* Methods for mockobject's internal use only */
/* Methods wrapped*/
public MockConnection() {
super();
}
public void clearWarnings() throws SQLException {
}
public void close() throws SQLException {
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 {
throw new UnsupportedOperationException();
}
public boolean getAutoCommit() throws SQLException {
throw new UnsupportedOperationException();
}
public String getCatalog() throws SQLException {
throw new UnsupportedOperationException();
}
public DatabaseMetaData getMetaData()
throws SQLException {
throw new UnsupportedOperationException();
}
public int getTransactionIsolation() throws SQLException {
throw new UnsupportedOperationException();
}
public Map getTypeMap() throws SQLException {
throw new UnsupportedOperationException();
}
public SQLWarning getWarnings() throws SQLException {
throw new UnsupportedOperationException();
}
public boolean isClosed() throws SQLException {
throw new UnsupportedOperationException();
}
public boolean isReadOnly() throws SQLException {
throw new UnsupportedOperationException();
}
public String nativeSQL(String sql) throws SQLException {
throw new UnsupportedOperationException();
}
// Implementation provided as this method is called in
executeStoredProcedure(TSFStdSP) of TSFDatabase
public CallableStatement prepareCall(String sql)
throws SQLException {
myPrepareCallString.setActual(sql);
throwStatementExceptionIfAny();
return myCallableStatement;
}
public CallableStatement prepareCall(
String sql,
int resultSetType,
int resultSetConcurrency)
throws SQLException {
throw new UnsupportedOperationException();
}
public PreparedStatement prepareStatement(String sql) throws
SQLException {
myPreparedStatementStrings.addActual(sql);
throwStatementExceptionIfAny();
return (PreparedStatement) myPreparedStatements.remove(0);
}
public PreparedStatement prepareStatement(
String sql,
int resultSetType,
int resultSetConcurrency)
throws SQLException {
throw new UnsupportedOperationException();
}
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 {
throw new UnsupportedOperationException();
}
public void setReadOnly(boolean readOnly) throws SQLException {
throw new UnsupportedOperationException();
}
public void setTransactionIsolation(int level)
throws SQLException {
throw new UnsupportedOperationException();
}
public void setTypeMap(Map map) throws SQLException {
throw new UnsupportedOperationException();
}
//--------------------------JDBC 3.0-----------------------------
public void setHoldability(int holdability) throws SQLException{
myHoldability = holdability;
}
public int getHoldability() throws SQLException{
return myHoldability;
}
public Savepoint setSavepoint() throws SQLException{ throw new
AssertionFailedError("Not Implemented"); }
public Savepoint setSavepoint(String name) throws SQLException{ throw
new AssertionFailedError("Not Implemented"); }
public void rollback(Savepoint savepoint) throws SQLException{ throw new
AssertionFailedError("Not Implemented"); }
public void releaseSavepoint(Savepoint savepoint) throws SQLException{
throw new AssertionFailedError("Not Implemented"); }
public Statement createStatement(int resultSetType, int
resultSetConcurrency,
int resultSetHoldability) throws SQLException{
throw new AssertionFailedError("Not Implemented"); }
public PreparedStatement prepareStatement(String sql, int resultSetType,
int resultSetConcurrency, int
resultSetHoldability)
throws SQLException{ throw new AssertionFailedError("Not
Implemented"); }
public CallableStatement prepareCall(String sql, int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) throws
SQLException{ throw new AssertionFailedError("Not Implemented"); }
public PreparedStatement prepareStatement(String sql, int
autoGeneratedKeys)
throws SQLException{ throw new AssertionFailedError("Not
Implemented"); }
public PreparedStatement prepareStatement(String sql, int
columnIndexes[])
throws SQLException{ throw new AssertionFailedError("Not
Implemented"); }
public PreparedStatement prepareStatement(String sql, String
columnNames[])
throws SQLException{ throw new AssertionFailedError("Not
Implemented"); }
/* Methods only to be called inside test classes */
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 addExpectedPrepareCallString(String sql) {
myPrepareCallString.setExpected(sql);
}
public void setExpectedRollbackCalls(int callCount) {
myRollbackCalls.setExpected(callCount);
}
public void setupAddPreparedStatement(PreparedStatement prepared) {
myPreparedStatements.add(prepared);
}
public void setupStatement(Statement statement) {
myStatement = statement;
}
public void setupThrowExceptionOnPrepareOrCreate(SQLException exception)
{
myStatementException = exception;
}
private void throwStatementExceptionIfAny() throws SQLException {
if (null != myStatementException) {
throw myStatementException;
}
}
}
"THIS E-MAIL MESSAGE ALONG WITH ANY ATTACHMENTS IS INTENDED ONLY FOR THE
ADDRESSEE and may contain confidential and privileged information.
If the reader of this message is not the intended recipient,
you are notified that any dissemination, distribution or copy of this
communication is strictly Prohibited.
If you have received this message by error, please notify us
immediately, return the original mail to the sender and delete the
message from your system."
|