db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1445327 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ engine/org/apache/derby/iapi/jdbc/ engine/org/apache/derby/impl/jdbc/ testing/org/apache/derbyTesting/functionTests/tests/jdbc4/
Date Tue, 12 Feb 2013 19:57:17 GMT
Author: rhillegas
Date: Tue Feb 12 19:57:17 2013
New Revision: 1445327

URL: http://svn.apache.org/r1445327
Log:
DERBY-6000: Add new CallableStatement.setObject() overloads introduced by JDBC 4.2.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement42.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement42.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredCallableStatement42.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement42.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest42.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement42.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement42.java?rev=1445327&r1=1445326&r2=1445327&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement42.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement42.java Tue
Feb 12 19:57:17 2013
@@ -105,19 +105,115 @@ public class CallableStatement42 extends
     public  void registerOutParameter( String parameterName, SQLType sqlType )
         throws SQLException
     {
-        throw jdbcMethodNotImplemented();
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry( this, "registerOutParameter", parameterName,
sqlType );
+                }
+                checkForClosedStatement();
+                registerOutParameter( parameterName, Utils42.getTypeAsInt(agent_, sqlType
) );
+            }
+        }
+        catch ( SqlException se )  { throw se.getSQLException(); }
     }
     
     public  void registerOutParameter( String parameterName, SQLType sqlType, int scale )
         throws SQLException
     {
-        throw jdbcMethodNotImplemented();
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry( this, "registerOutParameter", parameterName,
sqlType, scale );
+                }
+                checkForClosedStatement();
+                registerOutParameter( parameterName, Utils42.getTypeAsInt(agent_, sqlType
), scale );
+            }
+        }
+        catch ( SqlException se )  { throw se.getSQLException(); }
     }
     
     public  void registerOutParameter( String parameterName,  SQLType sqlType, String typeName
)
         throws SQLException
     {
-        throw jdbcMethodNotImplemented();
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry( this, "registerOutParameter", parameterName,
sqlType, typeName );
+                }
+                checkForClosedStatement();
+                registerOutParameter( parameterName, Utils42.getTypeAsInt(agent_, sqlType
), typeName );
+            }
+        }
+        catch ( SqlException se )  { throw se.getSQLException(); }
+    }
+
+    public  void setObject
+        ( int parameterIndex, java.lang.Object x, SQLType sqlType )
+        throws SQLException
+    {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry( this, "setObject", parameterIndex, x, sqlType
);
+                }
+                checkForClosedStatement();
+                setObject( parameterIndex, x, Utils42.getTypeAsInt(agent_, sqlType ) );
+            }
+        }
+        catch ( SqlException se )  { throw se.getSQLException(); }
+    }
+    
+    public void setObject
+        ( int parameterIndex, java.lang.Object x, SQLType sqlType, int scaleOrLength )
+        throws SQLException
+    {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry( this, "setObject", new Integer( parameterIndex
), x, sqlType, new Integer( scaleOrLength ) );
+                }
+                checkForClosedStatement();
+                setObject( parameterIndex, x, Utils42.getTypeAsInt(agent_, sqlType ), scaleOrLength
);
+            }
+        }
+        catch ( SqlException se )  { throw se.getSQLException(); }
+    }
+
+    public  void setObject( String parameterName, Object x, SQLType sqlType )
+        throws SQLException
+    {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry( this, "setObject", parameterName, x, sqlType
);
+                }
+                checkForClosedStatement();
+                setObject( parameterName, x, Utils42.getTypeAsInt(agent_, sqlType ) );
+            }
+        }
+        catch ( SqlException se )  { throw se.getSQLException(); }
+    }
+    
+    public  void setObject( String parameterName, Object x, SQLType sqlType, int scaleOrLength
)
+        throws SQLException
+    {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry( this, "setObject", parameterName, x, sqlType,
scaleOrLength );
+                }
+                checkForClosedStatement();
+                setObject( parameterName, x, Utils42.getTypeAsInt(agent_, sqlType ), scaleOrLength
);
+            }
+        }
+        catch ( SqlException se )  { throw se.getSQLException(); }
     }
 
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement42.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement42.java?rev=1445327&r1=1445326&r2=1445327&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement42.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement42.java
Tue Feb 12 19:57:17 2013
@@ -88,4 +88,29 @@ public class LogicalCallableStatement42 
         ((CallableStatement42)getPhysCs()).registerOutParameter( parameterName, sqlType,
typeName );
     }
 
+    public  void setObject
+        ( int parameterIndex, java.lang.Object x, SQLType sqlType )
+        throws SQLException
+    {
+        ((CallableStatement42)getPhysCs()).setObject( parameterIndex, x, sqlType );
+    }
+    
+    public void setObject
+        ( int parameterIndex, java.lang.Object x, SQLType sqlType, int scaleOrLength )
+        throws SQLException
+    {
+        ((CallableStatement42)getPhysCs()).setObject( parameterIndex, x, sqlType, scaleOrLength
);
+    }
+
+    public  void setObject( String parameterName, Object x, SQLType sqlType )
+        throws SQLException
+    {
+        ((CallableStatement42)getPhysCs()).setObject( parameterName, x, sqlType );
+    }
+    
+    public  void setObject( String parameterName, Object x, SQLType sqlType, int scaleOrLength
)
+        throws SQLException
+    {
+        ((CallableStatement42)getPhysCs()).setObject( parameterName, x, sqlType, scaleOrLength
);
+    }
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredCallableStatement42.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredCallableStatement42.java?rev=1445327&r1=1445326&r2=1445327&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredCallableStatement42.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredCallableStatement42.java
Tue Feb 12 19:57:17 2013
@@ -68,4 +68,30 @@ public class BrokeredCallableStatement42
         getCallableStatement().registerOutParameter( parameterName, sqlType, typeName );
     }
     
+    public  void setObject
+        ( int parameterIndex, java.lang.Object x, SQLType sqlType )
+        throws SQLException
+    {
+        getCallableStatement().setObject( parameterIndex, x, sqlType );
+    }
+    
+    public void setObject
+        ( int parameterIndex, java.lang.Object x, SQLType sqlType, int scaleOrLength )
+        throws SQLException
+    {
+        getCallableStatement().setObject( parameterIndex, x, sqlType, scaleOrLength );
+    }
+
+    public  void setObject( String parameterName, Object x, SQLType sqlType )
+        throws SQLException
+    {
+        getCallableStatement().setObject( parameterName, x, sqlType );
+    }
+    
+    public  void setObject( String parameterName, Object x, SQLType sqlType, int scaleOrLength
)
+        throws SQLException
+    {
+        getCallableStatement().setObject( parameterName, x, sqlType, scaleOrLength );
+    }
+
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement42.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement42.java?rev=1445327&r1=1445326&r2=1445327&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement42.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement42.java
Tue Feb 12 19:57:17 2013
@@ -60,19 +60,54 @@ public class EmbedCallableStatement42 ex
     public  void registerOutParameter( String parameterName, SQLType sqlType )
         throws SQLException
     {
-        throw Util.notImplemented();
+        checkStatus();
+        registerOutParameter( parameterName, Util42.getTypeAsInt( this, sqlType ) );
     }
     
     public  void registerOutParameter( String parameterName, SQLType sqlType, int scale )
         throws SQLException
     {
-        throw Util.notImplemented();
+        checkStatus();
+        registerOutParameter( parameterName, Util42.getTypeAsInt( this, sqlType ), scale
);
     }
     
     public  void registerOutParameter( String parameterName,  SQLType sqlType, String typeName
)
         throws SQLException
     {
-        throw Util.notImplemented();
+        checkStatus();
+        registerOutParameter( parameterName, Util42.getTypeAsInt( this, sqlType ), typeName
);
+    }
+
+    public  void setObject
+        ( int parameterIndex, java.lang.Object x, SQLType targetSqlType )
+        throws SQLException
+    {
+        checkStatus();
+        setObject( parameterIndex, x, Util42.getTypeAsInt( this, targetSqlType ) );
+    }
+    
+    public void setObject
+        (
+         int parameterIndex, java.lang.Object x,
+         SQLType targetSqlType, int scaleOrLength
+         )  throws SQLException
+    {
+        checkStatus();
+        setObject( parameterIndex, x, Util42.getTypeAsInt( this, targetSqlType ), scaleOrLength
);
+    }
+
+    public  void setObject( String parameterName, Object x, SQLType sqlType )
+        throws SQLException
+    {
+        checkStatus();
+        setObject( parameterName, x, Util42.getTypeAsInt( this, sqlType ) );
+    }
+    
+    public  void setObject( String parameterName, Object x, SQLType sqlType, int scaleOrLength
)
+        throws SQLException
+    {
+        checkStatus();
+        setObject( parameterName, x, Util42.getTypeAsInt( this, sqlType ), scaleOrLength
);
     }
     
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest42.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest42.java?rev=1445327&r1=1445326&r2=1445327&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest42.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest42.java
Tue Feb 12 19:57:17 2013
@@ -537,6 +537,106 @@ public class PreparedStatementTest42 ext
         assertObjectEquals( _columnDescs[ idx++ ].values[ valueIdx ], cs.getObject( colIdx++
) );
     }
 
+    /**
+     * <p>
+     * Test the CallableStatement.setObject() overloads added by JDBC 4.2.
+     * </p>
+     */
+    public  void    test_03_setObject() throws Exception
+    {
+        Connection conn = getConnection();
+
+        callableStatementSetObjectTest( conn );
+    }
+    public  static  void    callableStatementSetObjectTest( Connection conn ) throws Exception
+    {
+        createSetObjectSchemaObjects( conn );
+        vetSetObjectProc( conn );
+    }
+    private static void    createSetObjectSchemaObjects( Connection conn ) throws Exception
+    {
+        setupPrice( conn );
+        createSetObjectProc( conn );
+    }
+    private static void    createSetObjectProc( Connection conn ) throws Exception
+    {
+        StringBuilder   buffer = new StringBuilder();
+
+        buffer.append( "create procedure packAllTypes( in valueIdx int" );
+        
+        for ( int i = 0; i < _columnDescs.length; i++ )
+        {
+            ColumnDesc  cd = _columnDescs[ i ];
+            String  parameterName = "param" + (i+1);
+            String  parameterType = cd.sqlType;
+            buffer.append( ", in " + parameterName + " " + parameterType );
+        }
+        
+        buffer.append( " ) language java parameter style java no sql\n" );
+        buffer.append( "external name 'org.apache.derbyTesting.functionTests.tests.jdbc4.PreparedStatementTest42.packAllTypes'"
);
+
+        String  sqlText = buffer.toString();
+        println( sqlText );
+
+        conn.prepareStatement( sqlText ).execute();
+    }
+    private static void    vetSetObjectProc( Connection conn ) throws Exception
+    {
+        StringBuilder   buffer = new StringBuilder();
+        buffer.append( "call packAllTypes( ?" );
+        for ( int i = 0; i < _columnDescs.length; i++ ) { buffer.append( ", ?" ); }
+        buffer.append( " )" );
+        String  sqlText = buffer.toString();
+        println( sqlText );
+
+        CallableStatement   cs = conn.prepareCall( sqlText );
+        int     valueIdx;
+        int     param;
+
+        // setObject( int, Object, SQLType )
+        valueIdx = 0;
+        param = 1;
+        cs.setInt( param++, valueIdx );
+        for ( int i = 0; i < _columnDescs.length; i++ )
+        {
+            ColumnDesc  cd = _columnDescs[ i ];
+            cs.setObject( param++, cd.values[ valueIdx ], cd.jdbcType );
+        }
+        cs.execute();
+
+        // setObject( int, Object, SQLType, int )
+        valueIdx = 1;
+        param = 1;
+        cs.setInt( param++, valueIdx );
+        for ( int i = 0; i < _columnDescs.length; i++ )
+        {
+            ColumnDesc  cd = _columnDescs[ i ];
+            cs.setObject( param++, cd.values[ valueIdx ], cd.jdbcType, 0 );
+        }
+        cs.execute();
+
+        // setObject( String, Object, SQLType )
+        try {
+            ColumnDesc  cd = _columnDescs[ 0 ];
+            cs.setObject( "param1", cd.values[ 0 ], cd.jdbcType );
+            fail( "Expected unimplemented feature." );
+        }
+        catch (SQLException se)
+        {
+            assertSQLState( UNIMPLEMENTED_FEATURE, se );
+        }
+
+        // setObject( String, Object, SQLType, int )
+        try {
+            ColumnDesc  cd = _columnDescs[ 0 ];
+            cs.setObject( "param1", cd.values[ 0 ], cd.jdbcType, 0 );
+            fail( "Expected unimplemented feature." );
+        }
+        catch (SQLException se)
+        {
+            assertSQLState( UNIMPLEMENTED_FEATURE, se );
+        }
+    }
 
     //////////////////////////////////////////////////////////
     //
@@ -595,6 +695,58 @@ public class PreparedStatementTest42 ext
         varbinaryValue[ 0 ] = (byte[]) _columnDescs[ colIdx++ ].values[ valueIdx ];
     }
 
+    public  static  void    packAllTypes
+        (
+         int valueIdx,
+         Long    bigintValue,
+         Blob   blobValue,
+         Boolean booleanValue,
+         String  charValue,
+         byte[]  binaryValue,
+         Clob    clobValue,
+         Date    dateValue,
+         BigDecimal  decimalValue,
+         Double  doubleValue,
+         Double  floatValue,
+         Integer intValue,
+         String  longVarcharValue,
+         byte[]  longVarbinaryValue,
+         BigDecimal  numericValue,
+         Float   realValue,
+         Integer   smallintValue,
+         Time    timeValue,
+         Timestamp  timestampValue,
+         Price   priceValue,
+         String  varcharValue,
+         byte[]  varbinaryValue
+         )
+        throws Exception
+    {
+        int     colIdx = 0;
+        
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], bigintValue );
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], blobValue );
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], booleanValue );
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], charValue );
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], binaryValue );
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], clobValue );
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], dateValue );
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], decimalValue );
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], doubleValue );
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], floatValue );
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], intValue );
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], longVarcharValue
);
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], longVarbinaryValue
);
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], numericValue );
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], realValue );
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], smallintValue );
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], timeValue );
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], timestampValue );
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], priceValue );
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], varcharValue );
+        assertObjectEquals( _columnDescs[ colIdx++ ].values[ valueIdx ], varbinaryValue );
+    }
+
     //////////////////////////////////////////////////////////
     //
     // MINIONS



Mime
View raw message