12.11.2014 Views

web server - Borland Technical Publications

web server - Borland Technical Publications

web server - Borland Technical Publications

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Implementing primary key generation by the CMP engine<br />

JDataStore JDBC3: using useGetGeneratedKeys<br />

<strong>Borland</strong>'s JDataStore supports the new JDBC3 method<br />

java.sql.Statement.getGeneratedKeys(). This method is used to obtain primary key<br />

values from newly inserted rows. No additional coding is necessary, but note that this<br />

method is unsupported in other databases and is recommended for use only with<br />

<strong>Borland</strong> JDataStore. To use this method, set the boolean property useGetGeneratedKeys<br />

to True.<br />

Automatic primary key generation using named sequence tables<br />

Note<br />

A named sequence table is used to support auto primary key generation when the<br />

underlying database (such as Oracle SEQUENCE) and the JDBC driver (AUTOINCREMENT in<br />

JDBC 3.0) do not support key generation. The named sequence table allows you to<br />

specify a table that holds a key to use for primary key generation. The container uses<br />

this table to generate the keys.<br />

The table must contain a single row with a single column<br />

To use the name sequence table your table must have a single row with a single<br />

column that is an integer (for the sequence values). You must create a table with one<br />

column named “SEQUENCE” with any initial value. For example:<br />

CREATE TABLE TAB_A_SEQ (SEQUENCE int);<br />

INSERT into TAB_A_SEQ values (10);<br />

In this example key generation starts from value 10.<br />

To enable this feature, set it in in ejb-borland.xml:<br />

<br />

TABLE_A<br />

<br />

ID<br />

<br />

autoPkGenerator<br />

java.lang.String<br />

NAMEDSEQUENCETABLE<br />

<br />

<br />

namedSequenceTableName<br />

java.lang.String<br />

TAB_A_SEQ<br />

<br />

<br />

keyCacheSize<br />

java.lang.Integer<br />

2<br />

<br />

<br />

......<br />

<br />

Note that “ID” is the primary key column, which is marked for auto Pk Generation using<br />

NAMEDSEQUENCETABLE. The table used is TAB_A_SEQ.<br />

Set the ejb.CacheCreate property to false while using getPrimaryKeyAfterInsert or<br />

useGetGeneratedKeys. The container needs to know the primary key to dispatch calls to<br />

the bean instance. Therefore, it needs to know the primary key at the same time the<br />

Create method returns.<br />

Chapter 18: Generating Entity Bean Primary Keys 165

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!