Friday 20 December 2013

Generate the DB sequence number without loosing

Generally we use sequence number in EntityImpl class create() method using the following code

       SequenceImpl seq=new SequenceImpl("EMPLOYEES_SEQ",getDBTransaction());
        setEmployeeId(seq.getSequenceNumber());

or we will set expression in default attribute of Entity Object xml file. If we follow this approach we will loose the sequence numbers. To avoid this use the following approach

Step 1: Go to entity object xml file  --> select the EmployeeID -- > go to defalu value and set -999 or -9999. Because the sequence number never reach the negetive value.


Step 2: Generate the java class for EO and override the doDML() method

    protected void doDML(int operation, TransactionEvent e) {
     
        if(operation==this.DML_INSERT){
            SequenceImpl seq=new SequenceImpl("EMPLOYEES_SEQ",getDBTransaction());
            this.setEmployeeId(seq.getSequenceNumber().intValue());
        }
        super.doDML(operation, e);
    }
   
Step 3: Run the application

No comments:

Post a Comment