Fusion applications Primary key OR Unique id generation can be done in 3 different ways.
1. Using Standard Fusion Concept.
ADF BC's unique id generation feature uses a database table to specify the range of ids that may be used, as well as the latest id in the sequence. Create a database table named S_ROW_ID and add one row of data to the table, using the following format:
In the Application Module -> Configurations section -> Edit local configuration -> Properties tab
Provide the Database connection name where the S_ROW_ID table is created jbo.rowid_am_conn_name.
In your Entity object, Under attribute properties select the Default value as Expression and provide this "oracle.jbo.server.uniqueid.UniqueIdHelper.getNextId()".
Sample Screen Shots:
The EmpId is Generated from the Id helper.
2. Generate Primary Key using Default Value Expression
To do this we need a Database sequence. When user creates new row in the Entity object we will get the nextValue from the DB sequence.
Select the primary key attribute in the Entity object, In the properties section change the "Updatable property to While New". Change the Default Value to Expression and provide value as "adf.object.nextVal("UNIQUEIDTESTTABLE_1_SEQ");".
In the Entityimpl create a method nextValue as
Sample Screen shots:
When you click on the new record the Empid is pre-populated.
3. Generate Primary Key using Database Triggers
To do with database Tiggers and DBsequence data type. when an entity object's primary key attribute is of
Crated a database Trigger.
CREATE TABLE UNIQUEIDTESTTABLE_2
(
EMPID NUMBER NOT NULL
, EMPNAME VARCHAR2(30 BYTE)
, EMPLOCATION VARCHAR2(30 BYTE)
, CONSTRAINT UNIQUEITTESTTABLE_2_PK PRIMARY KEY
(
EMPID
)
ENABLE
);
CREATE OR REPLACE TRIGGER UNIQUEIDTESTTABLE_2_ins_trig BEFORE
INSERT ON UNIQUEIDTESTTABLE_2 REFERENCING NEW AS NEW FOR EACH ROW
BEGIN
SELECT UNIQUEIDTESTTABLE_1_SEQ.nextval INTO :NEW.EMPID FROM dual;
END; /
In the Entity object change the primary key attribute data type to DBSequence. This will automatically change other properties like
Sample Screen Shots:
When you click on new record the adf will automatically create a negative unique number. and when click on commit button then the actual primary key will be added to the record.
Sample Code.
1. Using Standard Fusion Concept.
ADF BC's unique id generation feature uses a database table to specify the range of ids that may be used, as well as the latest id in the sequence. Create a database table named S_ROW_ID and add one row of data to the table, using the following format:
Column Name | Data Type | Comments |
START_ID | NUMERIC(38,0) | Starting id in the range. To avoid duplicate key errors, you must make sure this value is higher than any existing primary key values in your database. |
NEXT_ID | NUMERIC(38,0) | Next available id within current range (optional). |
MAX_ID | NUMERIC(38,0) | Maximum id in the range |
AUX_START_ID | NUMERIC(38,0) | Starting id in auxiliary block range (use 0 if no auxiliary block is available). |
AUX_MAX_ID | NUMERIC(38,0) | Maximum id in the auxiliary block range (use 0 if no auxiliary block is available). |
CREATE TABLE S_ROW_ID ( START_ID NUMBER , NEXT_ID NUMBER , MAX_ID NUMBER , AUX_START_ID NUMBER , AUX_MAX_ID NUMBER ); insert into "S_ROW_ID" ( "START_ID" , "NEXT_ID" , "MAX_ID" , "AUX_START_ID" , "AUX_MAX_ID" ) values (1,1,9999999999999999999,0,0);
In the Application Module -> Configurations section -> Edit local configuration -> Properties tab
Provide the Database connection name where the S_ROW_ID table is created jbo.rowid_am_conn_name.
In your Entity object, Under attribute properties select the Default value as Expression and provide this "oracle.jbo.server.uniqueid.UniqueIdHelper.getNextId()".
Sample Screen Shots:
The EmpId is Generated from the Id helper.
2. Generate Primary Key using Default Value Expression
To do this we need a Database sequence. When user creates new row in the Entity object we will get the nextValue from the DB sequence.
Select the primary key attribute in the Entity object, In the properties section change the "Updatable property to While New". Change the Default Value to Expression and provide value as "adf.object.nextVal("UNIQUEIDTESTTABLE_1_SEQ");".
In the Entityimpl create a method nextValue as
protected oracle.jbo.domain.Number nextVal(String sequenceName) { SequenceImpl s = new SequenceImpl(sequenceName, getDBTransaction()); return s.getSequenceNumber(); }
Sample Screen shots:
When you click on the new record the Empid is pre-populated.
3. Generate Primary Key using Database Triggers
To do with database Tiggers and DBsequence data type. when an entity object's primary key attribute is of
DBSequence
type, during the transaction in which it is created, its numerical
value is a unique, temporary negative number. If you create a number of
associated entities in the same transaction, the relationships between
them are based on this temporary negative key value. When the entity
objects with DBSequence
-value primary keys are posted, their primary key is refreshed to reflect the correct database-assigned sequence number.Crated a database Trigger.
(
EMPID NUMBER NOT NULL
, EMPNAME VARCHAR2(30 BYTE)
, EMPLOCATION VARCHAR2(30 BYTE)
, CONSTRAINT UNIQUEITTESTTABLE_2_PK PRIMARY KEY
(
EMPID
)
ENABLE
);
CREATE OR REPLACE TRIGGER UNIQUEIDTESTTABLE_2_ins_trig BEFORE
INSERT ON UNIQUEIDTESTTABLE_2 REFERENCING NEW AS NEW FOR EACH ROW
BEGIN
SELECT UNIQUEIDTESTTABLE_1_SEQ.nextval INTO :NEW.EMPID FROM dual;
END;
In the Entity object change the primary key attribute data type to DBSequence. This will automatically change other properties like
- Updatable to While New
- Checked Refresh on Insert
- Default value to Literal and Value is some thing like @0
Sample Screen Shots:
When you click on new record the adf will automatically create a negative unique number. and when click on commit button then the actual primary key will be added to the record.
Sample Code.
This comment has been removed by the author.
ReplyDelete