Wednesday, January 15, 2014

Trigger assigned Primary Key values from the DB sequence

Create a table :


CREATE TABLE tbl_trg_key
(
   tbl_id    NUMBER,
   tbl_msg   VARCHAR2 (500),
   CONSTRAINT tbl1_trg_key_pk PRIMARY KEY (tbl_id)
);

Create a sequence :


CREATE SEQUENCE tbl_trg_key_s MINVALUE 1
                              MAXVALUE 999999999999999999999999999
                              INCREMENT BY 1
                              START WITH 100
                              NOORDER
                              NOCYCLE;
Create the trigger :


CREATE OR REPLACE TRIGGER primary_key_trg
   BEFORE INSERT
   ON tbl_trg_key
   FOR EACH ROW
BEGIN
   IF :new.tbl_id IS NULL OR :new.tbl_id < 0
   THEN
      SELECT tbl_trg_key_s.NEXTVAL INTO :new.tbl_id FROM DUAL;
   END IF;
END;
/

Create the Entity Object on the table tbl_trg_key.From the entity object , select the primary key. From the details tab change the type to DBSequence and provide the Sequence Name.Following diagram show the settings :
Refresh on Insert option is set.Give the sequence name and starts at value.Run BC tester and commit after adding row



Setting Entity Object's attribute properties

Database and Java datatypes for an entity object attribute is as below


- Options for Persistence either in Database or Transient attributes
- Options to set Column type and Java Type
- Java Object type should be serializable
-  Options to set Data types Length type and precision
- Updatability options for an attribute
  •   Always
  • Never 
  • While New - Creates the entity row for the first time after successfully committed to db attribute 
- Options to set attributes mandatory and primary key
- Options to set single and multi attribute key
getkey() - Key object contain the value of primary key
Multiple Key - key objects contain value of all keys in order

- Options to define static and default values . Default value can set by literals or using groovy expressions






ADF Update Batching in Entity Objects

Update Batching feature is used to reduce number of DML statement issued with multiple entity notifications . If in a transaction we are using multiple entities we can use multiple batching features.

The batch update feature doesnt work for :
 1) Entity Objects has attributes of BLOB or CLOB .Batch statement with streaming data is not supported
2) Batch updates are not supported with attributes are set with Refresh After Insert and Refresh after update
3) Entity objects created from the table which doesn't have primary key.

 Check the checkbox for Use Update Batching and specify appropriate threshold




ADF Entity Object Declarative Options

We can configure runtime behavior of entity object from the over view editor of Entity Object.
Alternate key- Other than we define in the db we can have alternate keys defined
Tuning - Tuning options make the database operations more efficient
Custom Properties - We can define custom properties and that can be accessed runtime on entity
Security- Options to define role based updatability permissions for entity objects
Business logic groups - Business Logic groups are used to group business validations rules

Attribute tab - Attribute tab is used for create/delete attributes of an entity
Business Rule tab- This tab is used for defining validations
Java Tab - This used to generate Impl classes for Entity objects
Business Events - This tab is used to notify others of interesting changes in the state
View Accessors- To create and manage view accessors

Tuesday, January 7, 2014

ADF Buisiness Logic groups

Business Logical groups consists of set of business logic units. Each business logic units has set of validations.Business logical groups encapsulates set of related control groups.

Double click on the entity object you want to define business logic group.From the general tab create a new business logical group
Right click on the entity object and create a business logic unit.
 Enter Logic business unit attribute values
Note the unit name should reflect the group discriminator value. That means the validation is only applied to the value "TestValidationUnit" of the attrMsg field.Double click on the logic unit. Select the attribute and click on override button 

Select an attribute and add validation rule to this attribute.
For the validation rule give an error message

See the validation rule is added
Run the BC tester and check the validation .Enter a value <10 for attId.