First page Back Continue Last page Text

oracle adf workshop


Example: Eagerly Assigning Values from a Database Sequence

As you learned in an earlier lesson, you can declaratively assign the DBSequence type for primary key attributes whose values are populated by a database trigger at commit time. However, you can also eagerly allocate a sequence number to use as a default value for an attribute so that:

The user can see its value

The value does not change when the data is saved

To accomplish this, use the SequenceImpl helper class in the oracle.jbo.server package:

1. You override the initDefaults() method, as shown in the example in the slide. It shows code from the Java class of a ProductEO entity object.

2. Call the initDefaults()method of the parent class.

3. Create a new instance of the SequenceImpl object to get a handle to the database sequence.

4. Obtain the next number from the database sequence.

5. Assign the next sequence number to the ProdId.

The disadvantage of using a database sequence in this manner is that it results in more gaps in the numbers assigned to primary keys, because if the user does not commit the record, the sequence number is wasted.