Monday, 20 June 2016

Programmatically reading the entity state in Oracle ADF

Entity row has two states one is associated to the transaction and the other is corresponding to the database(post state).
Use getEntityState() to read the Entity state corresponding to the transaction and getPostState() to read the Entity state corresponding to the DB.

Points to be remembered
When you create a new Entity row both the getEntityState() and getPostState() gives you the status as Entity.STATUS_NEW.
When you post the EO to the DB(Without Committing the transaction) the getEntityState() gives you the Entity.STATUS_NEW, whereas the getPostState() returns you the Entity.STATE_UNMODIFIED.
When the transaction is committed the state both returns the Entity_STATE_UNMODIFIED.

You can observe the above points using the below code. Place the below code in the Application Module Implementation class.
Create a EO based on the Department table.
    public void findEntityState() {
        //Get defnition object
        EntityDefImpl departmentEODef = DepartmentEOImpl.getDefinitionObject();
        //Create the entiy instance in the current transaction
        DepartmentEOImpl newDept1 = (DepartmentEOImpl) departmentEODef.createInstance2(this.getDBTransaction(), null);
        newDept1.setDepartmentId(100);
        newDept1.setDepartmentName("Oracle Fusion");
        newDept1.getPostState() // NEW
        newDept1.getEntityState() // NEW
        //Post changes to DB
        getDBTransaction().postChanges();
        newDept1.getPostState() // UNMODIFIED
        newDept1.getEntityState() //NEW
        //Commit the Transaction
        getDBTransaction().commit();
        newDept1.getPostState() // UNMODIFIED
        newDept1.getEntityState() // UNMODIFIED

    }

No comments:

Post a Comment