db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1444210 - in /db/derby/code/trunk/java: client/org/apache/derby/client/net/ engine/org/apache/derby/impl/jdbc/ engine/org/apache/derby/jdbc/ testing/org/apache/derbyTesting/functionTests/tests/jdbc4/
Date Fri, 08 Feb 2013 20:03:40 GMT
Author: rhillegas
Date: Fri Feb  8 20:03:39 2013
New Revision: 1444210

URL: http://svn.apache.org/r1444210
Log:
DERBY-6000: Add support for new JDBC 4.2 methods in ResultSet.

Added:
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet42.java   (with
props)
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet42.java   (with
props)
Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl42.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver42.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/net/ClientJDBCObjectFactoryImpl42.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl42.java?rev=1444210&r1=1444209&r2=1444210&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl42.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl42.java
Fri Feb  8 20:03:39 2013
@@ -25,6 +25,7 @@ import org.apache.derby.client.am.SqlExc
 
 import org.apache.derby.client.ClientPooledConnection;
 import org.apache.derby.client.am.Agent;
+import org.apache.derby.client.am.Cursor;
 import org.apache.derby.client.am.LogicalPreparedStatement;
 import org.apache.derby.client.am.LogicalPreparedStatement42;
 import org.apache.derby.client.am.PreparedStatement;
@@ -86,6 +87,22 @@ public class ClientJDBCObjectFactoryImpl
         return new LogicalPreparedStatement42(ps, stmtKey, cacheInteractor);
     }
     
+    /**
+     * returns an instance of org.apache.derby.client.net.NetResultSet
+     */
+    public org.apache.derby.client.am.ResultSet newNetResultSet(Agent netAgent,
+            org.apache.derby.client.am.MaterialStatement netStatement,
+            Cursor cursor,int qryprctyp,int sqlcsrhld,
+            int qryattscr,int qryattsns,int qryattset,long qryinsid,
+            int actualResultSetType,int actualResultSetConcurrency,
+            int actualResultSetHoldability) throws SqlException {
+        return new NetResultSet42((NetAgent)netAgent,(NetStatement)netStatement,
+                cursor,
+                qryprctyp, sqlcsrhld, qryattscr, qryattsns, qryattset, qryinsid,
+                actualResultSetType,actualResultSetConcurrency,
+                actualResultSetHoldability);
+    }
+
 }
 
     

Added: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet42.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet42.java?rev=1444210&view=auto
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet42.java (added)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet42.java Fri Feb
 8 20:03:39 2013
@@ -0,0 +1,99 @@
+/*
+
+   Derby - Class org.apache.derby.client.net.NetResultSet42
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+*/
+
+package org.apache.derby.client.net;
+
+import java.sql.SQLException;
+import java.sql.SQLType;
+import org.apache.derby.client.am.Cursor;
+import org.apache.derby.client.am.ClientMessageId;
+import org.apache.derby.client.am.SqlException;
+import org.apache.derby.client.am.Utils42;
+import org.apache.derby.shared.common.reference.SQLState;
+
+
+public class NetResultSet42 extends NetResultSet40
+{
+    
+    NetResultSet42(NetAgent netAgent,
+        NetStatement netStatement,
+        Cursor cursor,
+        int qryprctyp,  //protocolType, CodePoint.FIXROWPRC | 
+                        //              CodePoint.LMTBLKPRC
+        int sqlcsrhld, // holdOption, 0xF0 for false (default) | 0xF1 for true.
+        int qryattscr, // scrollOption, 0xF0 for false (default) | 0xF1 for true.
+        int qryattsns, // sensitivity, CodePoint.QRYUNK | 
+                       //              CodePoint.QRYINS | 
+                       //              CodePoint.QRYSNSSTC
+        int qryattset, // rowsetCursor, 0xF0 for false (default) | 0xF1 for true.
+        long qryinsid, // instanceIdentifier, 0 (if not returned, check default) or number
+        int actualResultSetType,
+        int actualResultSetConcurrency,
+        int actualResultSetHoldability) //throws DisconnectException
+    {
+        super(netAgent, netStatement, cursor, qryprctyp, sqlcsrhld, qryattscr,
+              qryattsns, qryattset, qryinsid, actualResultSetType,
+              actualResultSetConcurrency, actualResultSetHoldability);
+    }
+    
+    public void updateObject
+        ( int columnIndex, Object x, SQLType targetSqlType )
+        throws SQLException
+    {
+        checkClosed( "updateObject" );
+        updateObject( columnIndex, x, Utils42.getTypeAsInt( this.agent_, targetSqlType )
);
+    }
+
+    public void updateObject
+        ( int columnIndex, Object x, SQLType targetSqlType, int scaleOrLength )
+        throws SQLException
+    {
+        checkClosed( "updateObject" );
+        updateObject( columnIndex, x, Utils42.getTypeAsInt( this.agent_, targetSqlType )
);
+        // the client driver doesn't seem to adjust the scale, unlike the embedded driver
+    }
+
+    public void updateObject
+        ( String columnName, Object x, SQLType targetSqlType )
+        throws SQLException
+    {
+        checkClosed( "updateObject" );
+        updateObject( columnName, x, Utils42.getTypeAsInt( this.agent_, targetSqlType ) );
+    }
+
+    public void updateObject
+        ( String columnName, Object x, SQLType targetSqlType, int scaleOrLength )
+        throws SQLException
+    {
+        checkClosed( "updateObject" );
+        try {
+            updateObject( findColumnX( columnName, "updateObject" ), x, targetSqlType, scaleOrLength
);
+        } catch (SqlException se) { throw se.getSQLException(); }
+    }
+
+    private void    checkClosed( String methodName )
+        throws SQLException
+    {
+        try { checkForClosedResultSet( methodName ); } catch (SqlException se)
+        { throw se.getSQLException(); }
+    }
+    
+}

Propchange: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet42.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java?rev=1444210&r1=1444209&r2=1444210&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java Fri Feb
 8 20:03:39 2013
@@ -3056,6 +3056,17 @@ public class EmbedResultSet extends Conn
 	public void updateObject(int columnIndex, Object x, int scale)
 			throws SQLException {
 		updateObject(columnIndex, x);
+        adjustScale( columnIndex, scale );
+	}
+
+    /**
+     * <p>
+     * Adjust the scale of a type.
+     * </p>
+     */
+    protected   void    adjustScale( int columnIndex, int scale )
+        throws SQLException
+    {
 		/*
 		* If the parameter type is DECIMAL or NUMERIC, then
 		* we need to set them to the passed scale.
@@ -3078,7 +3089,7 @@ public class EmbedResultSet extends Conn
 				throw EmbedResultSet.noStateChangeException(t);
 			}
 		}
-	}
+    }
 
 	/**
 	 * JDBC 2.0

Added: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet42.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet42.java?rev=1444210&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet42.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet42.java Fri Feb
 8 20:03:39 2013
@@ -0,0 +1,78 @@
+/*
+ 
+   Derby - Class org.apache.derby.impl.jdbc.EmbedResultSet42
+ 
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+ 
+      http://www.apache.org/licenses/LICENSE-2.0
+ 
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+ 
+ */
+
+package org.apache.derby.impl.jdbc;
+
+import org.apache.derby.iapi.sql.ResultSet;
+
+import java.sql.JDBCType;
+import java.sql.SQLException;
+import java.sql.SQLType;
+
+import org.apache.derby.iapi.reference.SQLState;
+
+/**
+ * JDBC 4.2 specific methods that cannot be implemented in superclasses.
+ */
+public class EmbedResultSet42 extends org.apache.derby.impl.jdbc.EmbedResultSet40
+{
+    
+    /** Creates a new instance of EmbedResultSet42 */
+    public EmbedResultSet42(org.apache.derby.impl.jdbc.EmbedConnection conn,
+        ResultSet resultsToWrap,
+        boolean forMetaData,
+        org.apache.derby.impl.jdbc.EmbedStatement stmt,
+        boolean isAtomic)
+        throws SQLException {
+        
+        super(conn, resultsToWrap, forMetaData, stmt, isAtomic);
+    }
+    
+    public void updateObject
+        ( int columnIndex, Object x, SQLType targetSqlType )
+        throws SQLException
+    {
+        updateObject( columnIndex, x, Util42.getTypeAsInt( this, targetSqlType ) );
+    }
+
+    public void updateObject
+        ( int columnIndex, Object x, SQLType targetSqlType, int scaleOrLength )
+        throws SQLException
+    {
+        updateObject( columnIndex, x, Util42.getTypeAsInt( this, targetSqlType ) );
+        adjustScale( columnIndex, scaleOrLength );
+    }
+
+    public void updateObject
+        ( String columnName, Object x, SQLType targetSqlType )
+        throws SQLException
+    {
+        updateObject( columnName, x, Util42.getTypeAsInt( this, targetSqlType ) );
+    }
+
+    public void updateObject
+        ( String columnName, Object x, SQLType targetSqlType, int scaleOrLength )
+        throws SQLException
+    {
+        updateObject( findColumnName( columnName ), x, targetSqlType, scaleOrLength );
+    }
+    
+}

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet42.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver42.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver42.java?rev=1444210&r1=1444209&r2=1444210&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver42.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver42.java Fri Feb  8 20:03:39
2013
@@ -27,11 +27,14 @@ import java.sql.SQLException;
 import org.apache.derby.iapi.jdbc.BrokeredConnection;
 import org.apache.derby.iapi.jdbc.BrokeredConnectionControl;
 import org.apache.derby.iapi.jdbc.BrokeredConnection42;
+import org.apache.derby.iapi.sql.ResultSet;
 
 import org.apache.derby.iapi.services.sanity.SanityManager;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.impl.jdbc.EmbedPreparedStatement42;
 import org.apache.derby.impl.jdbc.EmbedConnection;
+import org.apache.derby.impl.jdbc.EmbedResultSet;
+import org.apache.derby.impl.jdbc.EmbedResultSet42;
 
 /**
  * <p>
@@ -72,4 +75,14 @@ public class Driver42 extends Driver40
         return new BrokeredConnection42(control);
     }
     
+    public EmbedResultSet newEmbedResultSet
+        (
+         EmbedConnection conn, ResultSet results, boolean forMetaData,
+         org.apache.derby.impl.jdbc.EmbedStatement statement,
+         boolean isAtomic
+         ) throws SQLException
+    {
+        return new EmbedResultSet42( conn, results, forMetaData, statement, isAtomic );
+    }
+
 }

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=1444210&r1=1444209&r2=1444210&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
Fri Feb  8 20:03:39 2013
@@ -179,6 +179,7 @@ public class PreparedStatementTest42 ext
         makeTable( conn );
         populateTable( conn );
         vetTableContents( conn );
+        updateColumns( conn );
     }
     private void    makeTable( Connection conn ) throws Exception
     {
@@ -204,36 +205,11 @@ public class PreparedStatementTest42 ext
     }
     private void    populateTable( Connection conn ) throws Exception
     {
-        StringBuilder   columnBuffer = new StringBuilder();
-        StringBuilder   valuesBuffer = new StringBuilder();
-
-        columnBuffer.append( "( " );
-        valuesBuffer.append( "( " );
-        for ( int i = 0; i < _columnDescs.length; i++ )
-        {
-            String  columnName = "col" + (i+1);
-            if ( i > 0 )
-            {
-                columnBuffer.append( ", " );
-                valuesBuffer.append( ", " );
-            }
-            columnBuffer.append( columnName );
-            valuesBuffer.append( "?" );
-        }
-        columnBuffer.append( " )" );
-        valuesBuffer.append( " )" );
-
-        PreparedStatement   insert = conn.prepareStatement
-            ( "insert into allTypes " + columnBuffer.toString() + " values " + valuesBuffer.toString()
);
+        PreparedStatement   insert = prepareInsert( conn );
 
         for ( int rowIdx = 0; rowIdx < ColumnDesc.VALUE_COUNT; rowIdx++ )
         {
-            for ( int colIdx = 0; colIdx < _columnDescs.length; colIdx++ )
-            {
-                ColumnDesc  cd = _columnDescs[ colIdx ];
-                insert.setObject( colIdx + 1, cd.values[ rowIdx ], cd.jdbcType );
-            }
-            insert.executeUpdate();
+            insertRow( insert, rowIdx );
         }
 
         for ( int rowIdx = 0; rowIdx < ColumnDesc.VALUE_COUNT; rowIdx++ )
@@ -261,6 +237,41 @@ public class PreparedStatementTest42 ext
 
         insert.close();
     }
+    private PreparedStatement   prepareInsert( Connection conn ) throws Exception
+    {
+        StringBuilder   columnBuffer = new StringBuilder();
+        StringBuilder   valuesBuffer = new StringBuilder();
+
+        columnBuffer.append( "( " );
+        valuesBuffer.append( "( " );
+        for ( int i = 0; i < _columnDescs.length; i++ )
+        {
+            String  columnName = "col" + (i+1);
+            if ( i > 0 )
+            {
+                columnBuffer.append( ", " );
+                valuesBuffer.append( ", " );
+            }
+            columnBuffer.append( columnName );
+            valuesBuffer.append( "?" );
+        }
+        columnBuffer.append( " )" );
+        valuesBuffer.append( " )" );
+
+        PreparedStatement   insert = conn.prepareStatement
+            ( "insert into allTypes " + columnBuffer.toString() + " values " + valuesBuffer.toString()
);
+
+        return insert;
+    }
+    private void    insertRow( PreparedStatement insert, int rowIdx ) throws Exception
+    {
+        for ( int colIdx = 0; colIdx < _columnDescs.length; colIdx++ )
+        {
+            ColumnDesc  cd = _columnDescs[ colIdx ];
+            insert.setObject( colIdx + 1, cd.values[ rowIdx ], cd.jdbcType );
+        }
+        insert.executeUpdate();
+    }
     private void    vetTableContents( Connection conn ) throws Exception
     {
         PreparedStatement   selectPS = conn.prepareStatement( "select * from allTypes order
by col0" );
@@ -285,6 +296,98 @@ public class PreparedStatementTest42 ext
         selectRS.close();
         selectPS.close();
     }
+    // test the behavior of the new ResultSet methods added by JDBC 4.2
+    private void    updateColumns( Connection conn ) throws Exception
+    {
+        PreparedStatement forUpdatePS = conn.prepareStatement
+            ( "select * from allTypes for update", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE
);
+        ResultSet   updateRS = null;
+
+        // ResultSet.updateObject( int, Object, SQLType )
+        prepTable( conn, 0 );
+        updateRS = forUpdatePS.executeQuery();
+        updateRS.next();
+        for ( int colIdx = 0; colIdx < _columnDescs.length; colIdx++ )
+        {
+            ColumnDesc  cd = _columnDescs[ colIdx ];
+            updateRS.updateObject( colIdx + 2, cd.values[ 1 ], cd.jdbcType );
+        }
+        updateRS.updateRow();
+        updateRS.close();
+        vetTable( conn, 1, 1 );
+
+        // ResultSet.updateObject( int, Object, SQLType, int )
+        prepTable( conn, 0 );
+        updateRS = forUpdatePS.executeQuery();
+        updateRS.next();
+        for ( int colIdx = 0; colIdx < _columnDescs.length; colIdx++ )
+        {
+            ColumnDesc  cd = _columnDescs[ colIdx ];
+            updateRS.updateObject( colIdx + 2, cd.values[ 1 ], cd.jdbcType, 0 );
+        }
+        updateRS.updateRow();
+        updateRS.close();
+        vetTable( conn, 1, 1 );
+
+        // ResultSet.updateObject( String, Object, SQLType )
+        prepTable( conn, 0 );
+        updateRS = forUpdatePS.executeQuery();
+        updateRS.next();
+        for ( int colIdx = 0; colIdx < _columnDescs.length; colIdx++ )
+        {
+            ColumnDesc  cd = _columnDescs[ colIdx ];
+            updateRS.updateObject( "col" + (colIdx+1), cd.values[ 1 ], cd.jdbcType );
+        }
+        updateRS.updateRow();
+        updateRS.close();
+        vetTable( conn, 1, 1 );
+
+        // ResultSet.updateObject( String, Object, SQLType, int )
+        prepTable( conn, 0 );
+        updateRS = forUpdatePS.executeQuery();
+        updateRS.next();
+        for ( int colIdx = 0; colIdx < _columnDescs.length; colIdx++ )
+        {
+            ColumnDesc  cd = _columnDescs[ colIdx ];
+            updateRS.updateObject( "col" + (colIdx+1), cd.values[ 1 ], cd.jdbcType, 0 );
+        }
+        updateRS.updateRow();
+        updateRS.close();
+        vetTable( conn, 1, 1 );
+    }
+    private void    prepTable( Connection conn, int rowIdx ) throws Exception
+    {
+        conn.prepareStatement( "truncate table allTypes" ).execute();
+
+        PreparedStatement   insert = prepareInsert( conn );
+
+        insertRow( insert, rowIdx );
+        vetTable( conn,rowIdx, 1 );
+    }
+    private void    vetTable( Connection conn, int rowIdx, int expectedRowCount ) throws
Exception
+    {
+        PreparedStatement   selectPS = conn.prepareStatement( "select * from allTypes order
by col0" );
+        ResultSet               selectRS = selectPS.executeQuery();
+        int                     actualRowCount = 0;
+
+        while( selectRS.next() )
+        {
+            for ( int colIdx = 0; colIdx < _columnDescs.length; colIdx++ )
+            {
+                Object          expected = _columnDescs[ colIdx ].values[ rowIdx ];
+
+                // skip the first column, the primary key
+                assertObjectEquals( expected, selectRS.getObject( colIdx + 2 ) );
+            }
+
+            actualRowCount++;
+        }
+
+        assertEquals( expectedRowCount, actualRowCount );
+        
+        selectRS.close();
+        selectPS.close();
+    }
 
     //////////////////////////////////////////////////////////
     //



Mime
View raw message