From: <Aar...@vo...> - 2001-11-30 03:51:43
|
I have modified a few classes in the java.sql package to give better integration of the Statement and ResultSet implementations. To summarize the changes I have made: * MockPreparedStatement.execute() returns true if a ResultSet has been set via setupResultSet(), otherwise false. * MockStatement.getResultSet returns the ResultSet that was set via setupResultSet() and also sets the ResultSet to null (so the next call does not get the same ResultSet again). * MockPreparedStatement.setupResultSet() now calls MockResultSet.setupStatement(this) * PreparedStatement.setObject(int index, Object obj, int Type) now works. It also tests to see that the specified object can be mapped to the specified type without some kind of conversion (so no longs going into TINYINT fields, but bytes into INTEGER fields are OK). The Mapping could be done better (and may not be entirely correct) but it is a start. Here are the diffs for the changed files. The extra file is attached. Let me know the format you would prefer contributions in for next time. Cheers ADK (See attached file: SQLTypeMap.java) --- MockStatement.java Fri Nov 30 15:06:48 2001 +++ /d/temp/mockobjects-0.01-orig/src/com/mockobjects/sql/MockStatement.java Sun Aug 12 22:52:50 2001 @@ -30,7 +30,6 @@ } public void setupResultSet(MockResultSet aResultSet) { - aResultSet.setupStatement(this); myResultSet = aResultSet; } @@ -42,13 +41,11 @@ myUpdateCount = updateCount; } - protected boolean innerExecute() throws SQLException { + protected void innerExecute() throws SQLException { myExecuteCalls.inc(); if (null != myExecuteException) { throw myExecuteException; } - - return (myResultSet != null); } public void close() throws SQLException { @@ -116,9 +113,7 @@ } public ResultSet getResultSet() throws SQLException { - ResultSet result = myResultSet; - myResultSet = null; - return result; + throw new UnsupportedOperationException(); } public int getUpdateCount() throws SQLException { --- MockPreparedStatement.java Fri Nov 30 13:46:15 2001 +++ /d/temp/mockobjects-0.01-orig/src/com/mockobjects/sql/MockPreparedStatement.java Sun Aug 12 22:52:50 2001 @@ -9,8 +9,7 @@ public class MockPreparedStatement extends MockStatement implements PreparedStatement { private ExpectationSet mySetParameters = new ExpectationSet ("MockPreparedStatement.setParameters"); private ExpectationCounter myClearParametersCalls = new ExpectationCounter("MockPreparedStatement.clearParameters() calls"); - private SQLTypeMap mySQLTypeMap = new SQLTypeMap(); - + public MockPreparedStatement() { super(); } @@ -41,7 +40,8 @@ } public boolean execute() throws SQLException { - return innerExecute(); + innerExecute(); + return false; } public void setExpectedClearParametersCalls(int callCount) { @@ -105,12 +105,7 @@ } public void setObject(int param, Object obj, int targetSqlType) throws SQLException { - assertTrue("Invalid type mapping: " + obj.getClass().getName() + " to: " + targetSqlType, mySQLTypeMap.canMap(obj.getClass(), targetSqlType)); - mySetParameters.addActual(new MapEntry(new Integer(param), obj)); - } - - public void setObject(int param, Object obj) throws SQLException { - mySetParameters.addActual(new MapEntry(new Integer(param), obj)); + throw new UnsupportedOperationException(); } public void setRef(int param, Ref ref) throws SQLException { @@ -151,6 +146,10 @@ public void setBytes(int param, byte[] values) throws SQLException { setObject(param, values); + } + + public void setObject(int param, Object obj) throws SQLException { + mySetParameters.addActual(new MapEntry(new Integer(param), obj)); } public void setByte(int param, byte aByte) throws SQLException { CAUTION: This correspondence is confidential and intended for the named recipient(s) only. If you are not the named recipient and receive this correspondence in error, you must not copy, distribute or take any action in reliance on it and you should delete it from your system and notify the sender immediately. Thank you. Unless otherwise stated, any views or opinions expressed are solely those of the author and do not represent those of Vodafone New Zealand Limited. Vodafone New Zealand Limited 21 Pitt Street, Private Bag 92161, Auckland, 1020, New Zealand Telephone + 64 9 357 5100 Facsimile + 64 9 377 0962 |