You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "A B (JIRA)" <ji...@apache.org> on 2007/05/09 19:54:15 UTC

[jira] Updated: (DERBY-2631) Expose existing auto-generated key functionality through more JDBC APIs in embedded mode.

     [ https://issues.apache.org/jira/browse/DERBY-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

A B updated DERBY-2631:
-----------------------

    Attachment: d2631_v1.stat
                d2631_v1.patch

Attaching a patch, d2631_v1.patch, which does the following:

  1. Updates the following JDBC methods so that they no longer throw a "Feature
     not implemented" error.  Instead they make calls to an already existing
     internal method and pass in the appropriate arguments:

      Connection.prepareStatement(String sql, String[] columnNames);
      Connection.prepareStatement(String sql, int[] columnIndexes);

      Statement.execute(String sql, String[] columNames);
      Statement.execute(String sql, int[] columIndexes);

      Statement.executeUpdate(String sql, String[] columnNames);
      Statement.executeUpdate(String sql, int[] columnIndexes); 

  2. Changes the (already existing but not currently used) code in
     sql/execute/InsertResultSet that handles autogen column indexes/names
     to throw an error for any target column that is not an auto-increment
     column.  This is because Derby's implementation of getGeneratedKeys()
     internally maps to the IDENTITY_VAL_LOCAL() function, which only returns
     keys for identity (autoincrement) columns.  So if the user specifies
     something else, we'll throw an error.

  3. Changes the names of two existing (but unused) errors to more accurately
     reflect their intended use (they are now called by the changes for #2).
     Also changes the text for those errors as the old text seemed a tad
     awkward.  No regression impact here because the two errors in question
     were never exposed to users before now.

  4. Makes a slight change to jdbcapi/statementJdbc30.java (a test) to
     reflect the new behavior (we no longer throw "Feature not implemented"
     errors).

  5. Adds test cases for the newly supported APIs to the JUnit test
     lang/AutoGenJDBC30Test.java.  This involved adding two more utility
     methods to junit/BaseJDBCTestCase.java, as well.

I ran derbyall and suites.All on SUSE Linux with ibm142 and the only failures were those which also show up in the Tinderbox results.  I.e. they are not caused by these changes.  So I believe this patch is ready for commit.

Review comments or other feedback are appreciated...

> Expose existing auto-generated key functionality through more JDBC APIs in embedded mode.
> -----------------------------------------------------------------------------------------
>
>                 Key: DERBY-2631
>                 URL: https://issues.apache.org/jira/browse/DERBY-2631
>             Project: Derby
>          Issue Type: Improvement
>          Components: JDBC
>    Affects Versions: 10.3.0.0
>         Environment: Embedded mode only.
>            Reporter: A B
>         Assigned To: A B
>            Priority: Minor
>         Attachments: d2631_v1.patch, d2631_v1.stat
>
>
> Derby currently supports the following JDBC methods for auto-generated keys:
>   // Indicate that we want to retrieve auto-generated key values.
>   Connection.prepareStatement(String sql, int autoGeneratedKeys);
>   Statement.execute(String sql, int autoGeneratedKeys);
>   Statement.executeUpdate(String sql, int autoGeneratedKeys);
>   // Retrieve the auto-generated values (only applies to INSERT statements).
>   ResultSet rs = Statement.getGeneratedKeys();
> The current implementation of getGeneratedKeys() internally maps to the "IDENTITY_VAL_LOCAL()" method, which means that Derby's implementation only returns generated keys for autoincrement columns (no other default columns are supported).  Further:
>   1. The generated key result set only ever has a single column.  This is
>      because Derby only allows one autoincrement column per table.
>   2. The type of the single column in the result set will be DECIMAL(31,0).
>      This is defined by IDENTITY_VAL_LOCAL().
>   3. The generated key result set will only ever have a single row.  This is
>      because IDENTITY_VAL_LOCAL() only returns values that were assigned as
>      the result of a *single row* INSERT statement using a VALUES clause.
>      For a single row INSERT statement, at most one autoincrement value
>      will be generated.
> All of that said, JDBC 3.0 also defines the following methods, which allow the user to explicitly indicate, via column position or column name, the columns for which the auto-generated keys should be made available:
>   Connection.prepareStatement(String sql, String[] columnNames);
>   Connection.prepareStatement(String sql, int[] columnIndexes);
>   Statement.execute(String sql, String[] columNames);
>   Statement.execute(String sql, int[] columIndexes);
>   Statement.executeUpdate(String sql, String[] columnNames);
>   Statement.executeUpdate(String sql, int[] columnIndexes);
> Derby currently throws a "Feature not supported" error for all of these methods.  However, it seems like the above methods could be "mapped" onto the existing Derby behavior with relatively little effort (in embedded mode).  Most of the required code is already in place.
> Doing so would make it easier for applications that rely on the columnNames and/or columnIndexes APIs to work with Derby (assuming the app just wants generated keys for identity (autoincrement) columns).
> Note that this Jira does *not* entail removing any of the restrictions nor changing any of the behavior outlined above.  All of that will remain exactly as it is.  This Jira simply exposes the existing functionality (restrictions and all) through additional (standard) API methods. In particular this means that any column specified by index (position) or name must be an auto-increment column for the INSERT table; otherwise Derby should throw an error.  Or put differently, a user who specifies a column name/position will get--in the absence of errors--the *exact* same results as s/he would get from invoking the "(String sql, int autoGeneratedKeys)" method.
> Note also: This Jira is specifically for embedded mode.  I think it would be harder to support these methods for Derby Client and so do not plan to address that.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.