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 km...@apache.org on 2008/02/20 19:35:42 UTC

svn commit: r629566 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ client/org/apache/derby/client/net/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/

Author: kmarsden
Date: Wed Feb 20 10:35:26 2008
New Revision: 629566

URL: http://svn.apache.org/viewvc?rev=629566&view=rev
Log:
DERBY-2653 Expose existing auto-generated key functionality through more JDBC APIs in Derby Client.

Add client support for columnIndex API's:

  Connection.prepareStatement(String sql, int[] columnIndexes);
  Statement.execute(String sql, int[] columIndexes);
  Statement.executeUpdate(String sql, int[] columnIndexes);


Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement40.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement40.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPreparedStatement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatement.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoGenJDBC30Test.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc30Test.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java?rev=629566&r1=629565&r2=629566&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java Wed Feb 20 10:35:26 2008
@@ -88,7 +88,8 @@
                              String sql,
                              int type, int concurrency, int holdability,
                              ClientPooledConnection cpc) throws SqlException {
-        super(agent, connection, sql, type, concurrency, holdability, java.sql.Statement.NO_GENERATED_KEYS, null,cpc);
+        super(agent, connection, sql, type, concurrency, holdability, java.sql.Statement.NO_GENERATED_KEYS, 
+                null, null,cpc);
         initCallableStatement();
     }
 
@@ -96,7 +97,8 @@
                                        Connection connection,
                                        String sql,
                                        int type, int concurrency, int holdability) throws SqlException {
-        super.resetPreparedStatement(agent, connection, sql, type, concurrency, holdability, java.sql.Statement.NO_GENERATED_KEYS, null);
+        super.resetPreparedStatement(agent, connection, sql, type, concurrency, holdability, java.sql.Statement.NO_GENERATED_KEYS, 
+                null,null);
         initCallableStatement();
     }
 

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java?rev=629566&r1=629565&r2=629566&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java Wed Feb 20 10:35:26 2008
@@ -145,6 +145,8 @@
      *                          keys should be returned.
      * @param columnNames an array of column names indicating the columns that
      *                    should be returned from the inserted row or rows.
+     * @param columnIndexes an array of column indexes indicating the columns
+     *                    that should be returned form the inserted row.                   
      * @param cpc The ClientPooledConnection wraps the underlying physical
      *            connection associated with this prepared statement
      *            it is used to pass the Statement closed and the Statement
@@ -156,7 +158,7 @@
     PreparedStatement newPreparedStatement(Agent agent,
             org.apache.derby.client.am.Connection connection,String sql,
             int type,int concurrency,int holdability,int autoGeneratedKeys,
-            String [] columnNames,ClientPooledConnection cpc) 
+            String [] columnNames, int[] columnIndexes, ClientPooledConnection cpc) 
             throws SqlException;
     
     
@@ -284,6 +286,7 @@
      * @param  holdability      int
      * @param autoGeneratedKeys int
      * @param columnNames       String[]
+     * @param columnIndexes     int[]
      * @return a java.sql.Statement implementation 
      * @throws SqlException
      *
@@ -291,7 +294,8 @@
      Statement newStatement(Agent agent, 
                      org.apache.derby.client.am.Connection connection, int type, 
                      int concurrency, int holdability,
-                     int autoGeneratedKeys, String[] columnNames) 
+                     int autoGeneratedKeys, String[] columnNames,
+                     int[] columnIndexes) 
                      throws SqlException;
      
     /**

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java?rev=629566&r1=629565&r2=629566&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java Wed Feb 20 10:35:26 2008
@@ -411,7 +411,7 @@
                     java.sql.ResultSet.CONCUR_READ_ONLY,
                     holdability(),
                     java.sql.Statement.NO_GENERATED_KEYS,
-                    null);
+                    null, null);
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceExit(this, "prepareStatement", ps);
             }
@@ -460,7 +460,8 @@
     }
 
     synchronized PreparedStatement prepareDynamicCatalogQuery(String sql) throws SqlException {
-        PreparedStatement ps = newPreparedStatement_(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY, holdability(), java.sql.Statement.NO_GENERATED_KEYS, null);
+        PreparedStatement ps = newPreparedStatement_(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY, holdability(), java.sql.Statement.NO_GENERATED_KEYS, null,
+                null);
         ps.isCatalogQuery_ = true;
         ps.prepare();
         openStatements_.put(ps, null);
@@ -1207,7 +1208,7 @@
                     resultSetConcurrency,
                     holdability(),
                     java.sql.Statement.NO_GENERATED_KEYS,
-                    null);
+                    null, null);
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceExit(this, "prepareStatement", ps);
             }
@@ -1614,7 +1615,7 @@
                     resultSetConcurrency,
                     resultSetHoldability,
                     java.sql.Statement.NO_GENERATED_KEYS,
-                    null);
+                    null, null);
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceExit(this, "prepareStatement", ps);
             }
@@ -1632,10 +1633,12 @@
                                         int resultSetConcurrency,
                                         int resultSetHoldability,
                                         int autoGeneratedKeys,
-                                        String[] columnNames) throws SqlException {
+                                        String[] columnNames,
+                                        int[] columnIndexes) throws SqlException {
         checkForClosedConnection();
         resultSetType = downgradeResultSetType(resultSetType);
-        PreparedStatement ps = newPreparedStatement_(sql, resultSetType, resultSetConcurrency, resultSetHoldability, autoGeneratedKeys, columnNames);
+        PreparedStatement ps = newPreparedStatement_(sql, resultSetType, resultSetConcurrency, resultSetHoldability, autoGeneratedKeys, columnNames,
+                columnIndexes);
         ps.cursorAttributesToSendOnPrepare_ = ps.cacheCursorAttributesToSendOnPrepare();
         ps.prepare();
         openStatements_.put(ps,null);
@@ -1647,7 +1650,8 @@
     // to send different attributes, i.e. SENSITIVE DYNAMIC, instead of SENSITIVE STATIC.
     protected void resetPrepareStatement(PreparedStatement ps) throws SqlException {
         String cursorAttributesToSendOnPrepare = ps.cursorAttributesToSendOnPrepare_;
-        resetPreparedStatement_(ps, ps.sql_, ps.resultSetType_, ps.resultSetConcurrency_, ps.resultSetHoldability_, ps.autoGeneratedKeys_, ps.generatedKeysColumnNames_);
+        resetPreparedStatement_(ps, ps.sql_, ps.resultSetType_, ps.resultSetConcurrency_, ps.resultSetHoldability_, ps.autoGeneratedKeys_, ps.generatedKeysColumnNames_,
+                ps.generatedKeysColumnIndexes_);
         ps.cursorAttributesToSendOnPrepare_ = cursorAttributesToSendOnPrepare;
         ps.prepare();
     }
@@ -1704,7 +1708,7 @@
                     java.sql.ResultSet.CONCUR_READ_ONLY,
                     holdability(),
                     autoGeneratedKeys,
-                    null);
+                    null, null);
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceExit(this, "prepareStatement", ps);
             }
@@ -1722,10 +1726,20 @@
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceEntry(this, "prepareStatement", sql, columnIndexes);
             }
-            checkForClosedConnection();
-            throw new SqlException(agent_.logWriter_, 
-                new ClientMessageId (SQLState.NOT_IMPLEMENTED),
-                "prepareStatement(String, int[])");
+            int genKeys = (columnIndexes == null ||
+                    columnIndexes.length == 0
+                    ? Statement.NO_GENERATED_KEYS: 
+                Statement.RETURN_GENERATED_KEYS);
+            PreparedStatement ps = prepareStatementX(sql,
+                    java.sql.ResultSet.TYPE_FORWARD_ONLY,
+                    java.sql.ResultSet.CONCUR_READ_ONLY,
+                    holdability(),
+                    genKeys,
+                    null, columnIndexes);
+            if (agent_.loggingEnabled()) {
+                agent_.logWriter_.traceExit(this, "prepareStatement", ps);
+            } 
+            return ps;
         }
         catch ( SqlException se )
         {
@@ -1748,7 +1762,7 @@
                     java.sql.ResultSet.CONCUR_READ_ONLY,
                     holdability(),
                     genKeys,
-                    columnNames);
+                    columnNames, null);
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceExit(this, "prepareStatement", ps);
             }
@@ -1794,7 +1808,7 @@
                                                                int concurrency,
                                                                int holdability,
                                                                int autoGeneratedKeys,
-                                                               String[] columnNames) throws SqlException;
+                                                               String[] columnNames, int[] columnIndexes) throws SqlException;
 
     protected abstract void resetPreparedStatement_(PreparedStatement ps,
                                                     String sql,
@@ -1802,7 +1816,8 @@
                                                     int resultSetConcurrency,
                                                     int resultSetHoldability,
                                                     int autoGeneratedKeys,
-                                                    String[] columnNames) throws SqlException;
+                                                    String[] columnNames,
+                                                    int[] columnIndexes) throws SqlException;
 
     protected abstract CallableStatement newCallableStatement_(String sql,
                                                                int type,

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java?rev=629566&r1=629565&r2=629566&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java Wed Feb 20 10:35:26 2008
@@ -2727,7 +2727,7 @@
                         java.sql.ResultSet.CONCUR_READ_ONLY,
                         connection_.holdability(),
                         java.sql.Statement.NO_GENERATED_KEYS,
-                        null);
+                        null, null);
         return ps;
     }
 

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java?rev=629566&r1=629565&r2=629566&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java Wed Feb 20 10:35:26 2008
@@ -195,6 +195,8 @@
      *                          keys should be returned.
      * @param columnNames an array of column names indicating the columns that
      *                    should be returned from the inserted row or rows.
+     * @param columnIndexes an array of column names indicating the columns that
+     *                   should be returned from the inserted row.                   
      * @param cpc The ClientPooledConnection wraps the underlying physical
      *            connection associated with this prepared statement
      *            it is used to pass the Statement closed and the Statement
@@ -207,10 +209,11 @@
                              String sql,
                              int type, int concurrency, int holdability, 
                              int autoGeneratedKeys, String[] columnNames,
+                             int[] columnIndexes,
                              ClientPooledConnection cpc) 
                              throws SqlException {
         super(agent, connection, type, concurrency, holdability, 
-              autoGeneratedKeys, columnNames);
+              autoGeneratedKeys, columnNames, columnIndexes);
         // PreparedStatement is poolable by default
         isPoolable = true;
         initPreparedStatement(sql);
@@ -221,8 +224,10 @@
     public void resetPreparedStatement(Agent agent,
                                        Connection connection,
                                        String sql,
-                                       int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNames) throws SqlException {
-        super.resetStatement(agent, connection, type, concurrency, holdability, autoGeneratedKeys, columnNames);
+                                       int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNames,
+                                       int[] columnIndexes) throws SqlException {
+        super.resetStatement(agent, connection, type, concurrency, holdability, autoGeneratedKeys, 
+                columnNames, columnIndexes);
         initPreparedStatement();
         initPreparedStatement(sql);
     }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement40.java?rev=629566&r1=629565&r2=629566&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement40.java Wed Feb 20 10:35:26 2008
@@ -82,6 +82,8 @@
      *                          keys should be returned.
      * @param columnNames an array of column names indicating the columns that
      *                    should be returned from the inserted row or rows.
+     * @param columnIndexes an array of column indexes indicating the columns
+     *                  that should be returned from the inserted row.                   
      * @param cpc The ClientPooledConnection wraps the underlying physical
      *            connection associated with this prepared statement
      *            it is used to pass the Statement closed and the Statement
@@ -92,8 +94,10 @@
     public PreparedStatement40(Agent agent,
         Connection connection,
         String sql,
-        int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNames,ClientPooledConnection cpc) throws SqlException {
-        super(agent, connection, sql, type, concurrency, holdability, autoGeneratedKeys, columnNames, cpc);
+        int type, int concurrency, int holdability, int autoGeneratedKeys, 
+        String[] columnNames, int[] columnIndexes, ClientPooledConnection cpc) throws SqlException {
+        super(agent, connection, sql, type, concurrency, holdability, autoGeneratedKeys,
+                columnNames, columnIndexes, cpc);
     }
     
     

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java?rev=629566&r1=629565&r2=629566&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java Wed Feb 20 10:35:26 2008
@@ -183,6 +183,8 @@
     public PreparedStatement preparedStatementForAutoGeneratedKeys_;
     public ResultSet generatedKeysResultSet_;
     public String[] generatedKeysColumnNames_;
+    public int[] generatedKeysColumnIndexes_;
+    
     public int autoGeneratedKeys_ = java.sql.Statement.NO_GENERATED_KEYS;
 
     // This flag makes sure that only one copy of this statement
@@ -266,6 +268,7 @@
         preparedStatementForAutoGeneratedKeys_ = null;
         generatedKeysResultSet_ = null;
         generatedKeysColumnNames_ = null;
+        generatedKeysColumnIndexes_ = null;
         autoGeneratedKeys_ = java.sql.Statement.NO_GENERATED_KEYS;
 
         // these members were not initialized
@@ -306,19 +309,21 @@
 
     // For jdbc 2 statements with scroll attributes
     public Statement(Agent agent, Connection connection, int type, int concurrency, int holdability,
-                     int autoGeneratedKeys, String[] columnNames) throws SqlException {
+                     int autoGeneratedKeys, String[] columnNames, int[] columnIndexes) throws SqlException {
         this(agent, connection);
-        initStatement(type, concurrency, holdability, autoGeneratedKeys, columnNames);
+        initStatement(type, concurrency, holdability, autoGeneratedKeys, columnNames,
+                columnIndexes);
     }
 
     public void resetStatement(Agent agent, Connection connection, int type, int concurrency, int holdability,
-                               int autoGeneratedKeys, String[] columnNames) throws SqlException {
+                               int autoGeneratedKeys, String[] columnNames, int[] columnIndexes) throws SqlException {
         resetStatement(agent, connection);
-        initStatement(type, concurrency, holdability, autoGeneratedKeys, columnNames);
+        initStatement(type, concurrency, holdability, autoGeneratedKeys, columnNames, columnIndexes);
     }
 
     private void initStatement(int type, int concurrency, int holdability,
-                               int autoGeneratedKeys, String[] columnNames) throws SqlException {
+                               int autoGeneratedKeys, String[] columnNames,
+                               int[] columnIndexes) throws SqlException {
         switch (type) {
         case java.sql.ResultSet.TYPE_FORWARD_ONLY:
         case java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE:
@@ -368,6 +373,7 @@
         }
 
         generatedKeysColumnNames_ = columnNames;
+        generatedKeysColumnIndexes_ = columnIndexes;
     }
 
     /* (non-Javadoc)
@@ -1190,13 +1196,19 @@
     public int executeUpdate(String sql, int columnIndexes[]) throws SQLException {
         try
         {
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "executeUpdate", sql, columnIndexes);
+            synchronized (connection_) {  
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "executeUpdate", sql, columnIndexes);
+                }
+                if (columnIndexes != null && columnIndexes.length > 0)
+                    autoGeneratedKeys_ = Statement.RETURN_GENERATED_KEYS;
+                generatedKeysColumnIndexes_ = columnIndexes;
+                int updateValue = executeUpdateX(sql);
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "executeUpdate", updateValue);
+                }
+                return updateValue;
             }
-            checkForClosedStatement();
-            throw new SqlException(agent_.logWriter_, 
-                new ClientMessageId(SQLState.NOT_IMPLEMENTED),
-                "executeUpdate(String, int[])");
         }
         catch ( SqlException se )
         {
@@ -1251,13 +1263,19 @@
     public boolean execute(String sql, int columnIndexes[]) throws SQLException {
         try
         {
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "execute", sql, columnIndexes);
+            synchronized(connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "execute", sql, columnIndexes);
+                }             
+                if (columnIndexes != null && columnIndexes.length > 0)
+                    autoGeneratedKeys_ = Statement.RETURN_GENERATED_KEYS;
+                generatedKeysColumnIndexes_ = columnIndexes;
+                boolean b = executeX(sql);
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "execute", b);
+                }
+                return b;
             }
-            checkForClosedStatement();
-            throw new SqlException(agent_.logWriter_, 
-                new ClientMessageId(SQLState.NOT_IMPLEMENTED),
-                "execute(String, int[])");
         }
         catch ( SqlException se )
         {
@@ -2656,7 +2674,7 @@
                             java.sql.ResultSet.CONCUR_READ_ONLY,
                             java.sql.ResultSet.HOLD_CURSORS_OVER_COMMIT,
                             java.sql.Statement.NO_GENERATED_KEYS,
-                            null);
+                            null, null);
             // need a special case for Derby, since the attribute has to go through the wire.
             // This same special casing for Derby is already in place in method PS.cacheCursorAttributesToSendOnPrepare() as called by prepareStatementX().
             //  We need to figure how some way to get code reuse here, ie. to consolidate to just one special casing rather than two?
@@ -2691,14 +2709,22 @@
                 "Statement.execute()/executeQuery()");
         }
 
-        
-        if (sqlUpdateMode_ == isInsertSql__ && 
-                generatedKeysColumnNames_ != null && 
+        if (sqlUpdateMode_ == isInsertSql__)
+        {
+        if (generatedKeysColumnNames_ != null && 
                 generatedKeysColumnNames_.length > 1) {
             throw new SqlException(agent_.logWriter_,
                     new ClientMessageId(SQLState.INVALID_COLUMN_ARRAY_LENGTH),
                     new Integer(generatedKeysColumnNames_.length));
-        }  
+            }
+        
+        if (generatedKeysColumnIndexes_ != null && 
+                generatedKeysColumnIndexes_.length > 1) {
+            throw new SqlException(agent_.logWriter_,
+                    new ClientMessageId(SQLState.INVALID_COLUMN_ARRAY_LENGTH),
+                    new Integer(generatedKeysColumnIndexes_.length));
+            }
+        }
     
     }
 

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement40.java?rev=629566&r1=629565&r2=629566&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement40.java Wed Feb 20 10:35:26 2008
@@ -49,15 +49,17 @@
      * @param holdability       int
      * @param autoGeneratedKeys int
      * @param columnNames       String[]
+     * @param columnIndexes     int[]
      * @throws SqlException
      *
      */
     public Statement40(Agent agent, Connection connection, int type, 
                      int concurrency, int holdability,
-                     int autoGeneratedKeys, String[] columnNames) 
+                     int autoGeneratedKeys, String[] columnNames,
+                     int[]  columnIndexes) 
                      throws SqlException {
         super(agent,connection,type,concurrency,holdability,autoGeneratedKeys,
-                columnNames);
+                columnNames, columnIndexes);
     }
     
     /**

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java?rev=629566&r1=629565&r2=629566&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java Wed Feb 20 10:35:26 2008
@@ -175,10 +175,11 @@
             org.apache.derby.client.am.Connection connection,
             String sql,int type,int concurrency,int holdability,
             int autoGeneratedKeys,String [] columnNames,
+            int[] columnIndexes,
             ClientPooledConnection cpc)
             throws SqlException {
         return new PreparedStatement(agent,connection,sql,type,concurrency,
-                holdability,autoGeneratedKeys,columnNames,cpc);
+                holdability,autoGeneratedKeys,columnNames, columnIndexes, cpc);
     }
 
     /**
@@ -311,6 +312,7 @@
      * @param  holdability      int
      * @param autoGeneratedKeys int
      * @param columnNames       String[]
+     * @param columnIndexes     int[]
      * @return a java.sql.Statement implementation 
      * @throws SqlException
      *
@@ -318,10 +320,11 @@
      public Statement newStatement(Agent agent, 
                      org.apache.derby.client.am.Connection connection, int type, 
                      int concurrency, int holdability,
-                     int autoGeneratedKeys, String[] columnNames) 
+                     int autoGeneratedKeys, String[] columnNames,
+                     int[] columnIndexes) 
                      throws SqlException {
          return new Statement(agent,connection,type,concurrency,holdability,
-                 autoGeneratedKeys,columnNames);
+                 autoGeneratedKeys,columnNames, columnIndexes);
      }
      
      /**

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java?rev=629566&r1=629565&r2=629566&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java Wed Feb 20 10:35:26 2008
@@ -158,6 +158,8 @@
      *                          keys should be returned.
      * @param columnNames an array of column names indicating the columns that
      *                    should be returned from the inserted row or rows.
+     * @param columnIndexes an array of column indexes indicating the columns
+     *                  that should be returned from the inserted row.                   
      * @param cpc The ClientPooledConnection wraps the underlying physical
      *            connection associated with this prepared statement
      *            it is used to pass the Statement closed and the Statement
@@ -171,10 +173,11 @@
             org.apache.derby.client.am.Connection connection,
             String sql,int type,int concurrency,
             int holdability,int autoGeneratedKeys,
-            String [] columnNames,ClientPooledConnection cpc) 
+            String [] columnNames,
+            int[] columnIndexes, ClientPooledConnection cpc) 
             throws SqlException {
         return new PreparedStatement40(agent,connection,sql,type,concurrency,
-                holdability,autoGeneratedKeys,columnNames,cpc);
+                holdability,autoGeneratedKeys,columnNames,columnIndexes, cpc);
     }
 
     
@@ -308,6 +311,7 @@
      * @param  holdability      int
      * @param autoGeneratedKeys int
      * @param columnNames       String[]
+     * @param columnIndexes     int[]
      * @return a java.sql.Statement implementation 
      * @throws SqlException
      *
@@ -315,10 +319,11 @@
      public Statement newStatement(Agent agent, 
                      org.apache.derby.client.am.Connection connection, int type, 
                      int concurrency, int holdability,
-                     int autoGeneratedKeys, String[] columnNames) 
+                     int autoGeneratedKeys, String[] columnNames,
+                     int[] columnIndexes) 
                      throws SqlException {
          return new Statement40(agent,connection,type,concurrency,holdability,
-                 autoGeneratedKeys,columnNames);
+                 autoGeneratedKeys,columnNames, columnIndexes);
      }
      
      /**

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java?rev=629566&r1=629565&r2=629566&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java Wed Feb 20 10:35:26 2008
@@ -1074,11 +1074,13 @@
         return new NetPreparedStatement(netAgent_, this, sql, section,pooledConnection_).preparedStatement_;
     }
 
-    protected PreparedStatement newPreparedStatement_(String sql, int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNames) throws SqlException {
+    protected PreparedStatement newPreparedStatement_(String sql, int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNames,
+            int[] columnIndexes) throws SqlException {
         
         //passing the pooledConnection_ object which will be used to raise 
         //StatementEvents to the PooledConnection
-        return new NetPreparedStatement(netAgent_, this, sql, type, concurrency, holdability, autoGeneratedKeys, columnNames,pooledConnection_).preparedStatement_;
+        return new NetPreparedStatement(netAgent_, this, sql, type, concurrency, holdability, autoGeneratedKeys, columnNames,
+                columnIndexes, pooledConnection_).preparedStatement_;
     }
 
     protected void resetPreparedStatement_(PreparedStatement ps,
@@ -1087,8 +1089,10 @@
                                            int resultSetConcurrency,
                                            int resultSetHoldability,
                                            int autoGeneratedKeys,
-                                           String[] columnNames) throws SqlException {
-        ((NetPreparedStatement) ps.materialPreparedStatement_).resetNetPreparedStatement(netAgent_, this, sql, resultSetType, resultSetConcurrency, resultSetHoldability, autoGeneratedKeys, columnNames);
+                                           String[] columnNames,
+                                           int[] columnIndexes) throws SqlException {
+        ((NetPreparedStatement) ps.materialPreparedStatement_).resetNetPreparedStatement(netAgent_, this, sql, resultSetType, resultSetConcurrency, 
+                resultSetHoldability, autoGeneratedKeys, columnNames, columnIndexes);
     }
 
 

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPreparedStatement.java?rev=629566&r1=629565&r2=629566&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPreparedStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPreparedStatement.java Wed Feb 20 10:35:26 2008
@@ -80,6 +80,9 @@
      * @param columnNames A String array of column names indicating
      *                    the columns that should be returned
      *                    from the inserted row or rows.
+     * @param columnIndexes An int array of column indexes indicating
+     *                    the column that should be returned from 
+     *                    the inserted row.                   
      * @param cpc The ClientPooledConnection wraps the underlying physical
      *            connection associated with this prepared statement
      *            it is used to pass the Statement closed and the Statement
@@ -88,17 +91,20 @@
      * @throws SqlException
      *
      */
-    NetPreparedStatement(NetAgent netAgent, NetConnection netConnection, String sql, int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNames, ClientPooledConnection cpc) throws SqlException {
+    NetPreparedStatement(NetAgent netAgent, NetConnection netConnection, String sql, int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNames, 
+            int[] columnIndexes,  ClientPooledConnection cpc) throws SqlException {
         this(ClientDriver.getFactory().newPreparedStatement(netAgent,
                 netConnection, sql, type, concurrency, holdability,
-                autoGeneratedKeys, columnNames, cpc),
+                autoGeneratedKeys, columnNames, columnIndexes, cpc),
                 netAgent,
                 netConnection
                 );
     }
 
-    void resetNetPreparedStatement(NetAgent netAgent, NetConnection netConnection, String sql, int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNames) throws SqlException {
-        preparedStatement_.resetPreparedStatement(netAgent, netConnection, sql, type, concurrency, holdability, autoGeneratedKeys, columnNames);
+    void resetNetPreparedStatement(NetAgent netAgent, NetConnection netConnection, String sql, int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNames, 
+            int[] columnIndexes) throws SqlException {
+        preparedStatement_.resetPreparedStatement(netAgent, netConnection, sql, type, concurrency, holdability, autoGeneratedKeys, 
+                columnNames, columnIndexes);
         resetNetPreparedStatement(preparedStatement_, netAgent, netConnection);
     }
 

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatement.java?rev=629566&r1=629565&r2=629566&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatement.java Wed Feb 20 10:35:26 2008
@@ -92,13 +92,16 @@
 
     // Called by abstract Connection.createStatement().newStatement() for jdbc 2 statements with scroll attributes
     NetStatement(NetAgent netAgent, NetConnection netConnection, int type, int concurrency, int holdability) throws SqlException {
-        this(ClientDriver.getFactory().newStatement(netAgent, netConnection, type, concurrency, holdability, java.sql.Statement.NO_GENERATED_KEYS, null),
+        this(ClientDriver.getFactory().newStatement(netAgent, netConnection, type, concurrency, holdability, java.sql.Statement.NO_GENERATED_KEYS, 
+                null,null
+                ),
                 netAgent,
                 netConnection);
     }
 
     void resetNetStatement(NetAgent netAgent, NetConnection netConnection, int type, int concurrency, int holdability) throws SqlException {
-        statement_.resetStatement(netAgent, netConnection, type, concurrency, holdability, java.sql.Statement.NO_GENERATED_KEYS, null);
+        statement_.resetStatement(netAgent, netConnection, type, concurrency, holdability, java.sql.Statement.NO_GENERATED_KEYS, 
+                null, null);
         resetNetStatement(statement_, netAgent, netConnection);
     }
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoGenJDBC30Test.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoGenJDBC30Test.java?rev=629566&r1=629565&r2=629566&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoGenJDBC30Test.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoGenJDBC30Test.java Wed Feb 20 10:35:26 2008
@@ -959,58 +959,6 @@
     }
 
     /**
-     * Verifies that an exception is raised if a columnIndexes array is passed, 
-     * which signals the driver that the auto-generated keys indicated in the 
-     * given array should be made available for retrieval (feature not 
-     * supported).
-     * Old master Test21, Test21ps
-     * Expected result: Exception 0A000 should occur.
-     * @throws SQLException 
-     */
-    public void testColumnIndexesNotImpl() throws SQLException
-    {
-        /* As of DERBY-2631 we support this with embedded.  So do nothing
-         * for this test fixture; we'll test the functionality as part
-         * of a separate fixture.
-         */
-        if (usingEmbedded())
-            return;
-
-        Statement s = createStatement();
-        int colPositions[] = new int[1];
-        colPositions[0] = 1;
-
-        String sql="insert into t11_AutoGen(c11) " +
-            "select c21 from t21_noAutoGen";
-
-        try {
-            s.execute(sql, colPositions);
-            fail("Expected s.execute to fail");
-        } catch (SQLException se) {
-            assertSQLState("0A000", se.getSQLState(), se);
-        }
-
-        try {
-            s.executeUpdate(sql, colPositions);
-            fail("Expected s.executeUpdate to fail");
-        } catch (SQLException se) {
-            assertSQLState("0A000", se.getSQLState(), se);
-        }
-
-        try {
-            /* Deliberately not adding this prepareStatement wrapper to
-             * BaseJDBCTestCase.java because Derby doesn't support passing
-             * the array.
-             */
-            Connection conn = getConnection();
-            PreparedStatement ps=conn.prepareStatement(sql, colPositions);
-            fail("Expected prepareStatement to fail");
-        } catch (SQLException se) {
-            assertSQLState("0A000", se.getSQLState(), se);
-        }
-    }
-
-    /**
      * Test that use of columnIndexes to indicate which keys should be
      * made available works as expected.
      *
@@ -1018,20 +966,26 @@
      */
     public void testColumnIndexes() throws SQLException
     {
-        /* Not supported for Derby client.  We check the "not supported"
-         * error message as part of a different fixture.
-         */
-        if (usingDerbyNetClient())
-            return;
 
         // Valid (typical) usage.
 
         int [] colIndexes = new int [] { 2 };
         testUserGivenColumns(colIndexes, null, 1);
+        
 
-        // Non-existent column index.
+        // Mulitple columns. one not an identity column.
+        colIndexes = new int[] {1,2};
+        testUserGivenColumnsError(colIndexes, null);
+        
+        
+        // Derby client can't differentiate between
+        // valid and invalid identity columns. So the
+        // other tests do not apply.  
+        if (usingDerbyNetClient())
+            return;
 
-        colIndexes[0] = 100;
+        // Non-existent column index.
+        colIndexes = new int[] {100};
         testUserGivenColumnsError(colIndexes, null);
 
         // Valid column index but not an auto-gen column.
@@ -1052,10 +1006,6 @@
         colIndexes[1] = 100;
         testUserGivenColumnsError(colIndexes, null);
 
-        // Multiple col indexes, one of which is not an auto-gen column.
-
-        colIndexes[1] = 1;
-        testUserGivenColumnsError(colIndexes, null);
 
         /* Multiple col indexes, one of which is invalid and another
          * of which is not an auto-gen column.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc30Test.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc30Test.java?rev=629566&r1=629565&r2=629566&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc30Test.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc30Test.java Wed Feb 20 10:35:26 2008
@@ -236,13 +236,10 @@
      * @param ex
      */
     private void assertFailedExecuteUpdateForColumnIndex(SQLException ex) {
-        /*
-         * DERBY-2943 -- execute() and executeUpdate() return different
-         * SQLState in embedded and network client
-         * 
-         */
+        // In network client we only check columnIndex array length,
+        // so throw a different error.
         if (usingDerbyNetClient()) {
-            assertSQLState("0A000", ex);
+            assertSQLState("X0X0D", ex);
         } else {
             assertSQLState("X0X0E", ex);
         }