Generating Unique Values Using a Component

Previous Next

At domain level, you can specify that an external component must generate the unique values for a domain.

1. In the Generate Unique Values drop-down list, specify: Component.
2. In the field to the right of the drop-down list, specify the component name, or use the lookup button.

When a primary key column is based on this domain, a <TableName>GETSEQUENCENUMBER method is added to the component definition. Parameters are added for the other primary key columns.

3. (Re-)write the <TableName>GetSequenceNumber() method in the component code, and let this method provide the sequence value.

This method is invoked when inserting a record.

Example

Consider an ORDERLINES component table with three columns:

· ORDER_ID, a primary key column with Generate Unique Values set to No.

 

· ORDERLINE_ID, a primary key column with Generate Unique Values set to the ORDERLINES component.

 

· AMOUNT, a number column.

The ORDERLINES component gets an ORDERLINESGETSEQUENCENUMBER method with two parameters:

1. ORDER_ID, Mode: In, Data Type: Long Integer.
2. ORDERLINE_ID, Mode: Out, Data Type: Long Integer.

If the following SQL statement is executed:

INSERT INTO ORDERLINES( order_id, amount )

VALUES( 3341, 159.95 )

The ORDERLINESGETSEQUENCENUMBER method of the ORDERLINES table component is invoked to get a new orderline_id within order 3341:

OrderlinesGetSequenceNumber(3341, NULL)

NOTE:

You can also have a component generate the unique values for a DATABASE table. This way, you can program your own sequence generation, and you can use non-integer data types.