Pages

Thursday, April 10, 2014

Business Logic Groups in oracle ADF BC

Business logic groups allow you to encapsulate a set of related control hints, default values, and validation logic. A business logic group is maintained separate from the base entity in its own file.

Business logic units are more useful when you are doing a enterprise based applications.

Each business logic group contains a set of business logic units. Each unit identifies the set of business logic that is loaded for the entity, based on the value of the attribute associated with the business logic group.

To create a business logic unit: Open the entity object -> General Tab -> Expand the Business logic Groups.

Click on the Add button and provide the relevant group name and select the attribute. You will only view the attributes which are allowed to create a business group.

Once the Group is created then you can create business logic unit.

Right click on entity object -> Select the new business logic unit - > Provide the Unit Name and Package. Jdev will automatically append the Entity object name and Group name.




Open the created business logic unit and select the attribute and click the "Override" button or right top.
And create you validations (Same as your entity business rules).





 And you can change all the UI Hints like label, Tool Tip and all.








Sample Code.

Wednesday, April 9, 2014

Effective Dated Entity Objects - with Modes and Example

Effective dated tables are used to provide a view into the data set pertaining to a specific point in time. Effective dated tables are widely used in application.

There are two variations in effective dated entity, One that allows multiple changes in a single day, and the other one which does not.  To make an entity object effective dated, you need to mark the entity object as Effective Dated, as shown below:

to do this we need two Date attributes (Start Date Attribute and  End Date Attribute) , to do multiple changes in a day then one number attribute (Effective Date Sequence) and one string attribute (Effective Date Sequence Flag).

  • For Start Date Attribute, select the attribute that corresponds to the start date.
  • For End Date Attribute, select the attribute that corresponds to the end date.
  • For Effective Date Sequence, select the attribute that stores the sequence of changes.
  • For Effective Date Sequence Flag, select the attribute that stores a flag indicating the most recent change in the sequence.
Create a simple Model project based on the fallowing data base table .

            CREATE TABLE EMP_DATE_EFF
            (
              EMP_ID NUMBER NOT NULL
            , EMP_NAME VARCHAR2(30) NOT NULL
            , START_DATE DATE NOT NULL
            , END_DATE DATE NOT NULL
            , CREATED_BY VARCHAR2(20) NOT NULL
            , MODIFIED_BY VARCHAR2(20) NOT NULL
            , CREATED_DATE DATE NOT NULL
            , MODIFIED_DATE DATE NOT NULL
            , EFF_DATE_SEQ NUMBER NOT NULL
            , EFF_DATE_FLAG VARCHAR2(20)
            , CONSTRAINT EMP_DATE_EFF_PK PRIMARY KEY
              (
                EMP_ID
              , START_DATE
              , END_DATE
              , EFF_DATE_SEQ
              )
              ENABLE
            );



To make an entity object as date effective. Open the EO -> Click on General Tab -> Open property inspector -> Click on Type Tab -> Right click on " Effective Date Type" -> Select "EffectiveDated".

 Than select the appropriate attributes from drop down.


Created a simple application module method to change the data in this table.

In this method i am taking Mode as a parameter, Based on the param i will change the mode or the date effective data.

EX:

        EFFDT_NONE_MODE = -1;
        EFFDT_EXPERT_MODE = 0;
        EFFDT_UPDATE_CORRECTION = 1;
        EFFDT_UPDATE_MODE = 2;
        EFFDT_UPDATE_OVERRIDE_MODE = 3;
        EFFDT_UPDATE_CHANGE_INSERT_MODE = 4;
        EFFDT_UPDATE_NEW_EARLIEST_CHANGE_MODE = 5;
        EFFDT_DELETE_MODE = 6;
        EFFDT_DELETE_THIS_CHANGE_MODE = 7;
        EFFDT_DELETE_NEXT_CHANGE_MODE = 8;
        EFFDT_DELETE_FUTURE_CHANGE_MODE = 9;
        EFFDT_DELETE_ZAP_MODE = 10;


EFFDT_DELETE_FUTURE_CHANGE_MODE
    When an effective dated row is deleted in "delete future change" mode, the end date of the row is set to the end of time and all the future rows for the same key values are deleted.
EFFDT_DELETE_MODE
    When an effective dated row is deleted in "delete" mode, the end date of the row is set to the row's effective date and all the future rows for the same key values are deleted.
EFFDT_DELETE_NEXT_CHANGE_MODE
    When an effective dated row is deleted in "delete next change" mode, the end date of the row is set to the end date of adjoining row and the adjoining row is deleted.
EFFDT_DELETE_THIS_CHANGE_MODE
    When an effective dated row is deleted in "delete this change" mode, the current row is removed.
EFFDT_DELETE_ZAP_MODE
    When an effective dated row is deleted in "zap" mode, all the effective dated rows with the same key values are deleted.
EFFDT_EXPERT_MODE
    If the row is in a expert mode, the runtime will not carry out any effective date specific logic for row modifications.
EFFDT_NONE_MODE
    Default state of the effective date mode on the row.
EFFDT_UPDATE_CHANGE_INSERT_MODE
    When an effective dated row is updated in "change insert" mode, the modified row is end dated on the effective date and a new row is inserted that fits between the effective date and the start date of the next row in the effective date time line.
EFFDT_UPDATE_CORRECTION
    When an effective dated row is updated in "correction" mode, the effective start date and effective end date is left unchanged.
EFFDT_UPDATE_MODE
    When an effective dated row is updated in "update" mode, the modified row is end dated on the effective date and a new row is created with the changed values.
EFFDT_UPDATE_NEW_EARLIEST_CHANGE_MODE
    Updating in "new earliest change" mode is supported only in Multiple Changes Per Day.
EFFDT_UPDATE_OVERRIDE_MODE
    When an effective dated row is updated in "override" mode, the modified row is end dated on the effective date and the start date of the next row in the effective date time line is set to effective date + 1 day.




Case -1

i update the employee data in EFFDT_UPDATE_MODE (mode -2), by changing the employee name to "Krishna". Then it created the second row and update the Name.


Case -2

i update the employee data in EFFDT_UPDATE_CORRECTION (mode -1), by changing the employee name to "Sundar Krishna" and date as "2013-09-09". Then it modified(Corrected) the existing record.



Note:
Because the date-effective view object must be based on an date-effective entity object, setting a view object's Effective Dated property to True without an underlying date-effective entity object, will result in a runtime exception.

End of your application if you turn off your "date effective" in entity object then, then complete effective dated features are ignored.

For effective date, It first obtained from the driving row(current row). If it is not available, then it is obtained from the property EFF_DT_PROPERTY_STR of the root application module. If you do not set EFF_DT_PROPERTY_STR for the application module, the current date is used in the query filter

Business Components Objects in Groovy Expressions

Oracle allowing Groovy expressions to be used in attribute validation and as a source for attribute values.


Entity Object Attribute and Raise error Groovy

The validation provides implicit object to access information contained within. Two of these information is oldValue and newValue, which gives you a handle to the value as it was before and after update.
 .
If you want to raise a error message for high salary and low salary then you can use single validation to raise these error messages.

EX: in Create a attribute level script validation in the EO.

if(newValue > 10000)
{
      adf.error.raise("EMPLOYEE_SALARY_IS_TOO_HIGH")
      return false
}
if(newValue < 999)
{
      adf.error.raise("EMPLOYEE_SALARY_IS_TOO_LOW")
      return false
}

return true

Create these "EMPLOYEE_SALARY_IS_TOO_HIGH" and "EMPLOYEE_SALARY_IS_TOO_LOW" in the resource bundle.

Note: if you want raise a warning message use "adf.error.warn()".


Referencing custom methods in the EntityImpl class

If you have defined a method in your EntityImpl class, then this can be called as part of your expression for an attribute default:

adf.object.<your_custom_method>

Unlike when referencing an attribute of the entity object, which can be done by simply

referencing the attribute name, when referencing a method, you are required to prefix the method name with
adf.object

If you want to reference the same method from a validator, you have to use the source prefix.
source.<your_custom_method>

To access the next sequence value  adf.object.nextVal("YOUR_SEQUENCE_NAME");

Of course, in practice you might create an EntityImpl helper method:
    protected oracle.jbo.domain.Number nextVal(String sequenceName) {
        SequenceImpl s = new SequenceImpl(sequenceName, getDBTransaction());
        return s.getSequenceNumber();
    }
-OR-
(new  oracle.jbo.server.SequenceImpl("EMPLOYEES_SEQ",adf.object.getDBTransaction())).getSequenceNumber()

To access the Attribute Labels adf.object.hints.LastName.label
Access Session

adf.context.current.sessionScope.get('test')

ADFContext.getCurrent().getSessionScope().get("test");

Date and time

To access the current date and time adf.currentDate and adf.currentDateTime 

Security Context

To get the username from security context adf.context.securityContext.userName




Groovy Expressions White Paper and Sample Code.