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.



Tuesday, December 31, 2013

ADF resource bundles

When you add any UI hints the project level resource bundles are getting created.We can access the resource bundle properties from the project properties dialog

Custom settings are not recorded with the project and cannot be shared with other users who use this project.You can note the basic configuration preferences options above.Resource bundle types are Properties Bundle which is the default option ,List resource bundle and Xliff resource bundel

Properties Resource bundle 

Create a new .properties file from the New Gallery option.Add name value pair for the property file.We can add the resource bundle from the "Bundle Search" tab.
From the UI hints section you can search fro the new Properties Bundle created.

List Resource Bundle 

Create a java class

import java.util.ListResourceBundle;

public class TestListResBundle  extends ListResourceBundle {

    @Override
    protected Object[][] getContents() {
        // TODO Implement this method
        return contents;
    }
    static final Object[][] contents = {
          {"key1", "Cabinet {0} contains {1} folders."},
          {"key2", "Folder {0} contains " +
                    "{1,choice,0#no files|1#one file|1<{1,number,integer} files}."},
          {"key3", "Folder \'{0}\' is empty."},                     
          {"key4", "File \"My Stuff\" deleted."},                    
          {"key5", "Added {0,number} files."},            
          {"key6", "Testr"},
          {"key7", "No files were removed while processing " +
                         "current folder."}
      };

    }
Add the resource bundle to the project 
Select the resource bundle from the list resource bundle 

Xliff Resource bundle 

Create a .xlf file 
<?xml version="1.0" encoding="windows-1252" ?>
<xliff version="1.1" xmlns="urn:oasis:names:tc:xliff:document:1.1">
  <file source-language="en" original="myResources" datatype="xml">
    <body>
      <trans-unit id="NAME">
        <source>Name</source>
        <target/>
        <note>Name of employee</note>
      </trans-unit>
      <trans-unit id="HOME_ADDRESS">
        <source>Home Address</source>
        <target/>
        <note>Adress of employee</note>
      </trans-unit>
      <trans-unit id="OFFICE_ADDRESS">
        <source>Office Address</source>
        <target/>
        <note>Office building </note>
      </trans-unit>
    </body>
  </file>
</xliff>
Add xlf resource bundle as other resource bundles.Select the resource bundle for UI hints properties from xlf resource bundle 

Format Mask in ADF UI hints

Format mask requires for data type like date.
C:\\JDeveloper\system12.1.2.0.40.66.68\o.BC4J\formatinfo.xml  file stores the formats of datatypes.
Sample formatter is here
<DOMAIN CLASS="java.sql.Timestamp">
      <FORMATTER name="Simple Date" class="oracle.jbo.format.DefaultDateFormatter">
         <FORMAT text="yyyy-MM-dd" />
         <FORMAT text="hh:mm:ss"  />
         <FORMAT text="yyyy-MM-dd G 'at' hh:mm:ss"  />
         <FORMAT text="EEE, MMM d, ''yy"  />
         <FORMAT text="dd-MM-yy" />
         <FORMAT text="dd-MMM-yyyy" />
         <FORMAT text="dd/MMM/yyyy" />
         <FORMAT text="MM/dd/yyyy" />
      </FORMATTER>
   </DOMAIN>
Custom formatters can be created by extending oracle.jbo.format.Formatter class.