You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2006/04/26 13:59:46 UTC
svn commit: r397186 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/jdbc/
testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
Author: kahatlen
Date: Wed Apr 26 04:59:43 2006
New Revision: 397186
URL: http://svn.apache.org/viewcvs?rev=397186&view=rev
Log:
DERBY-1234 (partial): Verify that we raise SQLException when calling
methods on closed java.sql objects
Added checkStatus() to the EmbedXXXStatement methods that don't check
whether the statement is closed.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement20.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement40.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement40.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement40.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement20.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement20.java?rev=397186&r1=397185&r2=397186&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement20.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement20.java Wed Apr 26 04:59:43 2006
@@ -132,6 +132,7 @@
*/
public Object getObject (int i, java.util.Map map) throws SQLException
{
+ checkStatus();
if( map == null)
throw Util.generateCsSQLException(SQLState.INVALID_API_PARAMETER,map,"map",
"java.sql.CallableStatement.getObject");
@@ -968,6 +969,7 @@
public Object getObject(String parameterName)
throws SQLException
{
+ checkStatus();
throw Util.notImplemented();
}
@@ -985,6 +987,7 @@
public Object getObject(String parameterName, Map map)
throws SQLException
{
+ checkStatus();
if( map == null)
throw Util.generateCsSQLException(SQLState.INVALID_API_PARAMETER,map,"map",
"java.sql.CallableStatement.getObject");
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement40.java?rev=397186&r1=397185&r2=397186&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement40.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement40.java Wed Apr 26 04:59:43 2006
@@ -208,6 +208,7 @@
* with the given interface.
*/
public boolean isWrapperFor(Class<?> interfaces) throws SQLException {
+ checkStatus();
return interfaces.isInstance(this);
}
@@ -221,6 +222,7 @@
*/
public <T> T unwrap(java.lang.Class<T> interfaces)
throws SQLException{
+ checkStatus();
try {
return interfaces.cast(this);
} catch (ClassCastException cce) {
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java?rev=397186&r1=397185&r2=397186&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java Wed Apr 26 04:59:43 2006
@@ -632,6 +632,7 @@
java.io.Reader reader,
int length) throws SQLException
{
+ checkStatus();
int jdbcTypeId = getParameterJDBCType(parameterIndex);
switch (jdbcTypeId) {
case Types.CHAR:
@@ -647,15 +648,13 @@
setCharacterStreamInternal(parameterIndex, reader, length);
}
- protected void setCharacterStreamInternal(int parameterIndex,
+ private void setCharacterStreamInternal(int parameterIndex,
Reader reader, long length)
throws SQLException
{
// check for -ve length
if (length < 0)
throw newSQLException(SQLState.NEGATIVE_STREAM_LENGTH);
-
- checkStatus();
int jdbcTypeId = getParameterJDBCType(parameterIndex);
@@ -749,6 +748,8 @@
throws SQLException
{
+ checkStatus();
+
int jdbcTypeId = getParameterJDBCType(parameterIndex);
switch (jdbcTypeId) {
case Types.BINARY:
@@ -763,7 +764,7 @@
setBinaryStreamInternal(parameterIndex, x, length);
}
- protected void setBinaryStreamInternal(int parameterIndex, InputStream x,
+ private void setBinaryStreamInternal(int parameterIndex, InputStream x,
long length)
throws SQLException
{
@@ -771,7 +772,6 @@
if ( length < 0 )
throw newSQLException(SQLState.NEGATIVE_STREAM_LENGTH);
- checkStatus();
int jdbcTypeId = getParameterJDBCType(parameterIndex);
if (x == null) {
setNull(parameterIndex, jdbcTypeId);
@@ -1223,6 +1223,7 @@
public void setBlob (int i, Blob x)
throws SQLException
{
+ checkStatus();
int colType;
synchronized (getConnectionSynchronization())
{
@@ -1256,6 +1257,7 @@
public void setClob (int i, Clob x)
throws SQLException
{
+ checkStatus();
int colType;
synchronized (getConnectionSynchronization())
{
@@ -1539,6 +1541,7 @@
public void setClob(int parameterIndex, Reader reader, long length)
throws SQLException{
+ checkStatus();
int colType;
synchronized(getConnectionSynchronization()) {
colType = getParameterJDBCType(parameterIndex);
@@ -1566,6 +1569,7 @@
public void setBlob(int parameterIndex, InputStream inputStream, long length)
throws SQLException{
+ checkStatus();
int colType;
synchronized (getConnectionSynchronization()) {
colType = getParameterJDBCType(parameterIndex);
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement40.java?rev=397186&r1=397185&r2=397186&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement40.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement40.java Wed Apr 26 04:59:43 2006
@@ -96,6 +96,7 @@
* with the given interface.
*/
public boolean isWrapperFor(Class<?> interfaces) throws SQLException {
+ checkStatus();
return interfaces.isInstance(this);
}
@@ -109,6 +110,7 @@
*/
public <T> T unwrap(java.lang.Class<T> interfaces)
throws SQLException{
+ checkStatus();
try {
return interfaces.cast(this);
} catch (ClassCastException cce) {
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java?rev=397186&r1=397185&r2=397186&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java Wed Apr 26 04:59:43 2006
@@ -401,6 +401,7 @@
* @exception SQLException thrown on failure.
*/
public final int getQueryTimeout() throws SQLException {
+ checkStatus();
return timeoutSeconds;
}
@@ -541,14 +542,12 @@
private boolean execute(String sql, boolean executeQuery, boolean executeUpdate,
int autoGeneratedKeys, int[] columnIndexes, String[] columnNames) throws SQLException
{
-
- // if sql is null, raise an error
- if (sql == null)
- throw newSQLException(SQLState.NULL_SQL_TEXT);
-
synchronized (getConnectionSynchronization()) {
checkExecStatus();
+ if (sql == null) {
+ throw newSQLException(SQLState.NULL_SQL_TEXT);
+ }
checkIfInMiddleOfBatch();
clearResultSets(); // release the last statement executed, if any.
@@ -1078,6 +1077,7 @@
* @exception SQLException if a database access error occurs
*/
public final java.sql.ResultSet getGeneratedKeys() throws SQLException {
+ checkStatus();
if (autoGeneratedKeysResultSet == null)
return null;
else {
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement40.java?rev=397186&r1=397185&r2=397186&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement40.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement40.java Wed Apr 26 04:59:43 2006
@@ -55,6 +55,7 @@
* with the given interface.
*/
public boolean isWrapperFor(Class<?> interfaces) throws SQLException {
+ checkStatus();
return interfaces.isInstance(this);
}
@@ -68,6 +69,7 @@
*/
public <T> T unwrap(java.lang.Class<T> interfaces)
throws SQLException{
+ checkStatus();
try {
return interfaces.cast(this);
} catch (ClassCastException cce) {
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest.java?rev=397186&r1=397185&r2=397186&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest.java Wed Apr 26 04:59:43 2006
@@ -166,18 +166,12 @@
if (! isDerbyNet)
{
+ // DerbyNet and DerbyNetClient don't throw exception
try {
- // currently derby only supports returning 0 in this case.
-
- int qry_timeout = s.getQueryTimeout();
-
- if (qry_timeout != 0)
- System.out.println("Statement Test failed, must return 0.");
- }
- catch(SQLException e)
- {
- System.out.println("Statement Test failed (9) " + e.toString());
+ s.getQueryTimeout();
+ System.out.println("Statement Test failed (9)");
}
+ catch(SQLException e) { }
}
try {
s.setQueryTimeout(20);
@@ -426,18 +420,12 @@
if (! isDerbyNet)
{
+ // DerbyNet and DerbyNetClient don't throw exception
try {
- // currently derby only supports returning 0 in this case.
-
- int qry_timeout = ps.getQueryTimeout();
-
- if (qry_timeout != 0)
- System.out.println("Statement Test failed, must return 0.");
- }
- catch(SQLException e)
- {
- System.out.println("Statement Test failed");
+ ps.getQueryTimeout();
+ System.out.println("Prepared Statement Test failed");
}
+ catch(SQLException e) { }
}
try {
@@ -714,18 +702,12 @@
if (! isDerbyNet)
{
+ // DerbyNet and DerbyNetClient don't throw exception
try {
- // currently derby only supports returning 0 in this case.
-
- int qry_timeout = cs.getQueryTimeout();
-
- if (qry_timeout != 0)
- System.out.println("Statement Test failed, must return 0.");
- }
- catch(SQLException e)
- {
- System.out.println("Statement Test failed");
+ cs.getQueryTimeout();
+ System.out.println("Callable Statement Test failed");
}
+ catch(SQLException e) { }
}
try {