web server - Borland Technical Publications

web server - Borland Technical Publications web server - Borland Technical Publications

techpubs.borland.com
from techpubs.borland.com More from this publisher
12.11.2014 Views

Implementing primary key generation by the CMP engine JDataStore JDBC3: using useGetGeneratedKeys Borland's JDataStore supports the new JDBC3 method java.sql.Statement.getGeneratedKeys(). This method is used to obtain primary key values from newly inserted rows. No additional coding is necessary, but note that this method is unsupported in other databases and is recommended for use only with Borland JDataStore. To use this method, set the boolean property useGetGeneratedKeys to True. Automatic primary key generation using named sequence tables Note A named sequence table is used to support auto primary key generation when the underlying database (such as Oracle SEQUENCE) and the JDBC driver (AUTOINCREMENT in JDBC 3.0) do not support key generation. The named sequence table allows you to specify a table that holds a key to use for primary key generation. The container uses this table to generate the keys. The table must contain a single row with a single column To use the name sequence table your table must have a single row with a single column that is an integer (for the sequence values). You must create a table with one column named “SEQUENCE” with any initial value. For example: CREATE TABLE TAB_A_SEQ (SEQUENCE int); INSERT into TAB_A_SEQ values (10); In this example key generation starts from value 10. To enable this feature, set it in in ejb-borland.xml: TABLE_A ID autoPkGenerator java.lang.String NAMEDSEQUENCETABLE namedSequenceTableName java.lang.String TAB_A_SEQ keyCacheSize java.lang.Integer 2 ...... Note that “ID” is the primary key column, which is marked for auto Pk Generation using NAMEDSEQUENCETABLE. The table used is TAB_A_SEQ. Set the ejb.CacheCreate property to false while using getPrimaryKeyAfterInsert or useGetGeneratedKeys. The container needs to know the primary key to dispatch calls to the bean instance. Therefore, it needs to know the primary key at the same time the Create method returns. Chapter 18: Generating Entity Bean Primary Keys 165

Implementing primary key generation by the CMP engine Note Key cache size When generating the primary key, the container fetches the key from the table in the database. You can improve performance by reducing trips to the database by specifying a key cache size. To use this feature, in the ejb-borland.xml file, you set the element to specify how many primary key values the database will fetch. The container will cache the number of keys used for primary key generation when the value of the cache size is > 1. The default value for key cache size, if not specified, is 1. Although key cache size is optional, it is recommended you specify a value > 1 to utilize performance optimization. There may be gaps in the keys generated if the container is rebooted or used in a clustered mode. 166 BES Developer’s Guide

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

Note<br />

Key cache size<br />

When generating the primary key, the container fetches the key from the table in the<br />

database. You can improve performance by reducing trips to the database by<br />

specifying a key cache size. To use this feature, in the ejb-borland.xml file, you set the<br />

element to specify how many primary key values the database will<br />

fetch. The container will cache the number of keys used for primary key generation<br />

when the value of the cache size is > 1.<br />

The default value for key cache size, if not specified, is 1. Although key cache size is<br />

optional, it is recommended you specify a value > 1 to utilize performance optimization.<br />

There may be gaps in the keys generated if the container is rebooted or used in a<br />

clustered mode.<br />

166 BES Developer’s Guide

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

Saved successfully!

Ooh no, something went wrong!