Wednesday, December 18, 2013

Force another EO to execute before an EO

Today, I experienced an interesting problem, I want to post another EO while executing an EO.

Example Problem is,

Consider a table Employee & EmployeeRel

Here while creating the an EmployeeRel record, I may choose an existing employee or create a new employee and set the s_empId., But If we do so, we will get the Integrity constraint exception, because the EmployeeRel record insert query is executed before the new Employee insert query.(We are not using association here for the new Employee)

So, We need to execute the new Employee insert query before EmployeeRel record. ADF framework allows us to use the life cycle method PostChanges() to forece the new Employee insert query execution. 

So override the postChanges() in the EmployeeRelImpl as follows,

    public void postChanges(TransactionEvent e) {
      if ((getPostState() == STATUS_NEW) || (getPostState() == STATUS_MODIFIED)) {
        EmployeeImpl secondEmp = getSecondEmployee(this.getSEmpId());
        if (secondEmp != null) {
          if (secondEmp .getPostState() == STATUS_NEW) {
            secondEmp .postChanges(e);
          }
        }
      }
      super.postChanges(e);
    }
    
    private PartyImpl getSecondEmployee(Number secondEmpId){
        Key key=EmployeeImpl .createPrimaryKey(secondEmpId);
        return (EmployeeImpl )EmployeeImpl .getDefinitionObject().findByPrimaryKey(getDBTransaction(), key);            
    }


Here is the sample DB script, I've used for my sample.

create table Emp(name varchar(20),emp_id number(10) primary key);
create table Emp_rel(rel_id number(10),f_empid number(10) REFERENCES Emp(emp_id),s_empid number(10) references Emp(emp_id));



  

Monday, December 9, 2013

ADF Association composition behaviors


If we select Implement cascade delete operation,
  • First it will generate delete query on the child entities and invoke the delete query.
  • Next it will generate delete query on the parent entity and invoke the delete query.
  • Then it will issue commit.

If we select optimize for Database cascade delete operation and in the foreign key ON DELETE CASCADE
  •  First it will generate delete query on the parent entity and invoke the delete query
  •  While deleting the parent record, it will delete child the child records at the DB level as we have implemented ON DELETE CASCADE.
  • It will issue commit.
  • It will clear the child entities from the cache for that parent record.

If we select optimize for Database cascade delete operation and in the foreign key we don’t set ON DELETE CASCADE
  • First It will generate delete query on the parent entity and invoke the delete query.
  • While deleting the parent record, it will throw Database constraint exception as we have not implemented ON DELETE CASCADE and SQL Exception will be thrown.

If we select Cascade update key attributes,
·         When updating the parent key attributes, it will update the child record’s foreign key attributes.

If we don’t select Cascade update key attributes, it will throw exceptions while trying to update the parent records primary key.

If we select update Top level history columns, it will update the parent records history columns when we are trying to add/update child records.

If we select Lock level to Lock Container, While updating the child record it will lock the immediate parent record.

If we select Lock level to Lock Container, While updating the child record it will lock the all the parent records in the hierarchy.

Sunday, December 1, 2013

Refactoring DataBindings.cpx file and Having Multiple cpx files

I found some interesting facts while I was playing with DataBindings.cpx file this weekend and I'm blogging them now after a long time.
  • Renaming the default DataBindings.cpx file.
  • Having more than one DataBindings file in a project.
       As you know the DataBindings.cpx file plays a vital role in the ADF Model layer, which is used to create the BindingContext for the Web Application by ADFBindingFilter and this stores the meta info about page defintions mappings to create the Binding Container for ADF data bound pages and DataControl usages to find the appropriate AppModules and ErrorHanler config,etc.

       JDeveloper does not provide declarative facility to rename or move the DataBindings.cpx file. To rename or move the DataBindings.cpx file, just create the new one and delete the existing one. While doing this don't forgot to update the adfm.xml file which is the registry of registries and always have the id property is same as the DataBindings cpx file name otherwise you will get error message  "DataControl is not found".

For example if you are renaming the cpx file from DataBindings.cpx to MyDataBindings.cpx, update the id as follows.

DataBindings.cpx file

<?xml version="1.0" encoding="UTF-8" ?>

<Application xmlns="http://xmlns.oracle.com/adfm/application"
             version="11.1.1.61.92" id="DataBindings" SeparateXMLFiles="false"
             Package="view" ClientType="Generic">
.........................
.........................
</Application>

MyDataBindings.cpx

<?xml version="1.0" encoding="UTF-8" ?>
<Application xmlns="http://xmlns.oracle.com/adfm/application"
             version="11.1.1.61.92" id="MyDataBindings" SeparateXMLFiles="false"
             Package="view" ClientType="Generic">
.........................
.........................
</Application>

         If you want to have more than one DataBindings.cpx file in a project, then  add the entries in the adfm.xml file, because ADFBindingFilter looks for the cpx files in the adfm.xml file. Cpx file names should be unique within the project.

Sample adfm.xml for multiple cpx files.

<?xml version="1.0" encoding="UTF-8" ?>

<MetadataDirectory xmlns="http://xmlns.oracle.com/adfm/metainf"                                      
                                                             version="11.1.1.0.0">
  <DataBindingRegistry path="view/DataBind1.cpx"/>
  <DataBindingRegistry path="view/DataBind1.cpx"/>
  <DataBindingRegistry path="view1/DataBind2.cpx"/>
</MetadataDirectory>



Note:  It is best practice to have cpx file name as DataBindings.cpx and having only one cpx file if we don't have special use cases.



Wednesday, March 28, 2012

ADF client side validations with inbuilt validation tags


Validate maximum length;
<af:inputText id="id0" value="12A" label="Maximum length validator">
<af:validateLength maximum="5"/>
</af:inputText>
Validate minimum length;
<af:inputText id="id00" value="12A" label="Minimum length validator">
<af:validateLength minimum="3"/>
</af:inputText>
Validate length range;
<af:inputText id="id01" value="12A" label="Length Range Validator">
<af:validateLength minimum="1" maximum="5"/>
</af:inputText>
Validate long range;
<af:inputText id="id2" value="10" label="Long Range Validator">
<af:validateLongRange minimum="5" maximum="50"/>
</af:inputText>
Validate double range;
<af:inputText id="id3" value="8.6" label="Double Range Validator">
<af:validateDoubleRange minimum="4.1" maximum="8.9"/>
</af:inputText>
Validate regular expression;
<af:inputText id="id4" value="9999" label="Regular Expression validation">
<af:validateRegExp pattern="[9]*"/ >
</af:inputText>
Date validation with filter condition;
<af:inputDate id="id5" value="2011-05-21"
label="Select a date, but not a Friday">
<af:convertDateTime pattern="yyyy-MM-dd"/>
<af:validateDateRestriction invalidDaysOfWeek="Fri"/>
</af:inputDate>
Validate date range;
<af:inputDate id="mdf3ee" value="2011-11-25" label="Submission period">
<af:convertDateTime pattern="yyyy-MM-dd"/>
<!-- Supports ISO date format strings of the form "yyyy-MM-dd" -->
<af:validateDateTimeRange minimum="2011-11-16" maximum="2011-12-16"/>
</af:inputDate>

Saturday, January 21, 2012

Set and get object into/from session

/**
* Method for setting an object in session
* @param name
* @param value
* @return null
*/
public static void setSessionValue(String name, Object value) {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request =
(HttpServletRequest)context.getExternalContext().getRequest();
HttpSession httpSession = request.getSession(false);
httpSession.setAttribute(name, value);
}
/**
* Method for getting an object from session
* @param null
* @return Object
*/
public static Object getSessionValue(String attName) {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request =
(HttpServletRequest)context.getExternalContext().getRequest();
HttpSession httpSession = request.getSession(false);
return httpSession.getAttribute(attName);
}

Friday, January 20, 2012

Some more usefull methods in ViewObjectImpl

1.getFilteredRows(java.lang.String attrName, java.lang.Object attrValue)
          Returns all rows in this collection whose attribute value matches the value being passed in attrValue.

 2.getRow(Key key)
          Returns the first row matching a given key.

 3.setCurrentRow(Row row)
          Designates a given row as the current row.
 getCurrentRow()
          Returns the current row of the iterator.

for more info
ViewObjectImpl API

Sunday, January 8, 2012

jdevloper not taking the latest changes – what to do?

Sometime when you do the changes and run the application the latest changes are not updated while running the application.
The culprit is the system folder.
{user_home}\system11.1.1.4.37.57.75\o.j2ee\drs\
has the exploded war file which will have the classes that is old. deleting the classes from the exploded directory would definitely fix the issue.