ADF Application Module (AM) properties and Performance Tuning:

Performance Tuning:
Programatically created AM Instances must be released after the usage.
ApplicationModule am = Configuration.createRootApplicationModule(amDefName, configName);
//logic
if(am!=null){
Configuration.releaseRootApplicationModule(am, true);
}

AM Properties:

  • The No of AMs that should be kept available during Noraml/ light use: jbo.ampool.minavailablesize
  • The No of AMs that should be kept available during High use: jbo.ampool.maxavailablesize
    [Recommended to keep it 20% more than Noraml usage value]
  • AM Pool clean up frequency is decided by: jbo.ampool.monitorsleepinterval (Default 600000ms or 10 minutes)
  • AM Pool Max inactive age of AM instancce: jbo.ampool.maxinactiveage (Default 600000ms or 10 minutes)
  • AM pool monitor removes all unused AM instances which have been living more than 1 hour: jbo.ampool.timetolive
    If the value set to -1 then removal of AM based on this property will be prevented.
  • property ‘jbo.ampool.maxinactiveage’ will remove the number of Inactive AM instances above the value of ‘jbo.ampool.minavailablesize’
    [if the ‘jbo.ampool.minavailablesize’ value is 10 & assume there are 25 current inactive AM instances, then only 15 inactive AM instances
    will be cleared by AM Pool Monitor]
  • property ‘jbo.ampool.timetolive’ if not set to -1, then it removes all the inactive AM instances (more than 1 hr) irrespective of the
    proeprty ‘jbo.ampool.minavailablesize’

FetchSize: Decides No of records read from DB in one round trip.
Recommended The value of FetchSize should be = Range Size of Interator(defined in page definition) + 3
The Max value of Fetchsize = Max value of Iterator size.
For UI bound View Objects keep fetchsize less than 30.

Maximum FetchSize:  Total no of records that a VO can retrieve from DB.
RangeSize: Decides no of records read into middle tier for a single data access.
——————————-
Popup: [use property contentDelivery=”lazyUncached” in a case that when you open popup enterred values,
click on cancel and reopen popup. Generally the previously entered values will be shown though not submitted.
To get fields cleared every time click on cancel button use proeprty  contentDelivery=”lazyUncached” for a popup].
Every time you raise the popup, lazyUncached will be in place an the data will be fetched from the DB.
——————————-
When you Access a page from browser:
Server recieves the request, Request is intercepted by ADF BindingFilter and Initialses BindingContext
[which is runtime represenation of DataBindings.cpx]

 

Advertisements

ADF Lifecycle & Immediate, Auto Submit, Partial Submit properties behaviour

ADF Cycle is and extended version of JSF Lifecycle. For each request from client to server, application invokes ADF Page lifecycle.

Below are the phases of ADF Page Life Cycle.

1)
Restore View: The component tree for the page will be restored. page URL will be passed to bindingContext object  which will find its page definition file.
Init Context: BindingContainer object will be initialized (which is runtime representation for pageDefinition file).
Prepare Model: Methods in Executables section will be executed whose refresh property set to: ‘Prepare Model’.
And also Input parameters will be applied/evaluated.

2)
Apply Request Values: Input values will be stored to temporary location and initialized.

3)
Process Validation: The input values will be converted to underlying data types [e.g.: string to date] and validations will be applied.

4)
Update Model values: The local values (temp) will be discarded and updated in the Model.
Validate Model updates: updated model values will be validated. (Validation happens on updated values at EO level)

5)
Invoke Application: Action bindings will be executed in this phase.
Commit Metadata: Changes to the runtime metadata will be committed. Also here in this phase runtime changes will be stored using MDS (Meta Data Service)

6)
Prepare Render/ Render Model: Binding Container will be refreshed (So that it allows for any changes that may have occurred in the Apply Request Values or Validation phases).
Render Response: Finally the page will be appeared with updated values.

(If the page is navigating to another page then in this step the phases will be ‘Init context’, ‘Prepare Model’, ‘Prepare Render’ ‘Render Response’)

Refresh Condition: For Executables like Iterators, methods if the default ‘Refresh’ condition is ‘Deferred’ which means only the required will executed at ‘Render Response’ phase which have UI Dependency.
If you set Refresh property forcefully to ‘Prepare Model’ or ‘PrepareRender’ then always that method will be executed during that phase. (irrespective of UI dependency)

First time page load: When the page is loaded for the first time, it’ll go through first phase which is ‘Restore View’, in this phase the view state of the current page will be checked and as the page is loaded for the first time, there won’t be any view state. If there is no view state, then it skips next phases and directly enters ‘Render Response’ state, as it is not required to validate/update anything. From the next subsequent requests from this page, it’ll go thought first phase ‘restore view’ where the current view state will be compared with the previous view state, and if there is a difference between view states then it’ll go though all the phases. Otherwise it’ll again directly enters Render Response phase.

Immediate:

On Command Button: [If you set for Command button it skips validations]

  • When Immediate=”true” property is set for a command button, it means that the action/action listener for that button will be executed immediately. (generally if you won’t set, then all the input fields and other component values present in the page will be validated and updated through multiple phase of Life cycle).
  • So by keeping the Immediate property value to ‘true’ then action/actionListener will be invoked during second phase (Apply request values) and it skips all other phases (3,4,5) and only ‘Restore view’, ‘Apply Request Values’, ‘Render Response’ phases will be invoked.
  • A general real time example would be setting ‘Immediate’ property to true for ‘Cancel’ button for a form. As when cancel is invoked actually we won’t bother about validation of entered input values.

On Input Component:

  • If you set the Immediate property to Input field component, then what happens? One line answer would be the local format conversion and validation will happen during second phase ‘Apply Request Values’ instead in the third phase ‘Process Validation’ to make the values available for button’s action/actionListener methods whose Immediate property is true [those methods executed during second phase when Immediate is true for buttons, and values of input fields will not available by then in this phase if immediate for input fields is not set to True].
  •  Let’s take InputA whose autoSubmit property is not set to ‘true’, CommandBtnB whose Immediate property is set to ‘true’. Enter some value into InputA and click on CommandBtnB then as Immediate property is set action Listener will be invoked during second phase ‘Apply Request Values’ and it skips the next steps process validation, Modal Updates, Invoke Application. Suppose if you want to get the value of InputA in the actionListener, it will not be available by then as InputA value will be converted& validated in the Third phases ‘Process Vlidation’ which is getting skipped because of Immediate property on ComandBtnB.  When you give ‘Immediate’ property to true for InputA, then that component value is converted and validated during the second phase ‘Apply Request Values’. So the entered value of InputA will be available in the actionListener method when Immediate property for InputA is set to ‘true’.
  • This property is Available to both Command Button and Input field components.

Auto Submit:

  • When AutoSubmit=”true” property is set for an input text field, then only that component will go through the Life Cycle event when curser is removed/ tab out from that input text field. Though other fields have values entered and which are not valid, it won’t throw any error.
  • So when this property is set for a field, that filed value will be submitted, validated and updated in the Model and finally component will be refreshed.
  • If you set the partialTriggers property for other components pointing to this command component whose AutoSubmit is true then those properties will also under go validation and re render phases.
  • E.g.1 : InputA whose autoSubmit is ‘true’ & InputB which has required validation as ‘true’. Now on entering value to InputA and tab out, will not give any validation error on InputB though the value of InputB is null.
  • E.g.2 : InputA whose autoSubmit is ‘true’ & InputB which has required validation as ‘true’ & partialTriggers property point to InputA comp Id. Now on entering value to InputA and tab out, will give validation error on InputB. 
  • This property is Available only for Input components to get validated and post their data to model. This property is NOT available to command button component.

ValueChangeListener:

  • If you want to call a method and execute some java code when the value of a filed is changed, then you just need to set the ‘ValueChangeListener’ property’s value for that field to required method.
  • ValueChangeListener event is triggered during the 3rd phase of ADF Life cycle (Process Validations phase)

Partial Submit:  [To avoid full page refresh]

  • If you set PartialSubmit property to a command button in form then entire form will be submitted. All the fields will under go validations. And entire page will NOT be refreshed.
  • If don’t set this property value to ‘true’ then entire page will be refreshed. Instead by setting this property we can avoid refresh of the page. If you want to refresh any component then you can do it by using partialTriggers property.
  • This property is Available to only Command Button. And is NOT Available to Input field components as similar property to it, autoSubmit is available to them.

PartialSubmit vs AutoSubmit:

  • PartialSubmit property will be given to command buttons. Which generally used to submit the form and to avoid full page refresh after that.
  • AutoSubmit property will be given to Input component which will validate, model update & re render that component on tab out from that component. It doesn’t care about other components.
  • Now similarity is If you set these properties to respective components [PartialSubmit to command button, auto submit to Input text], then these will refresh the other components which uses partialTriggers property pointing these component Ids.
  • So you can also call autoSubmit for input component as partial submit as it does the same functionality.

 

lifecycle.png

 

More info: http://krishnaprathi.blogspot.in/2015/08/adf-life-cycle.html

 

 

JPA vs ADF-BC(BC4J)

In ADF, for creating Business services related to DB we generally use ADF – BC (EO, VO, AM), but we can also use JPA(Java Persistence API) Entities. Which option to choose is completely your choice as there won’t be any difference if you create data controls out of them in terms of performance. But you can note few points that ADF-BC provides default List of Values and validations options. If you are familiar with using Hibernate (But not with ADF-BC) then you are good to go with using JPA Entities.

JPA Entity:

JPA

You can find the below sample JPA entity created for Departments table.


package model;

import java.io.Serializable;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

@Entity
@NamedQueries({ @NamedQuery(name = "Departments.findAll", query = "select o from Departments o") })
public class Departments implements Serializable {
private static final long serialVersionUID = -1771169464233198257L;

@Id
@Column(name = "DEPARTMENT_ID", nullable = false)
private Integer departmentId;

@Column(name = "DEPARTMENT_NAME", nullable = false, length = 30)
private String departmentName;

@Column(name = "LOCATION_ID")
private Integer locationId;

@ManyToOne
@JoinColumn(name = "MANAGER_ID")
private Employees employees1;

@OneToMany(mappedBy = "departments", cascade = { CascadeType.PERSIST, CascadeType.MERGE })
private List<Employees> employeesList1;

public Departments() {
}

public Departments(Integer departmentId, String departmentName, Integer locationId, Employees employees1) {
this.departmentId = departmentId;
this.departmentName = departmentName;
this.locationId = locationId;
this.employees1 = employees1;
}

public Integer getDepartmentId() {
return departmentId;
}

public void setDepartmentId(Integer departmentId) {
this.departmentId = departmentId;
}

public String getDepartmentName() {
return departmentName;
}

public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}

public Integer getLocationId() {
return locationId;
}

public void setLocationId(Integer locationId) {
this.locationId = locationId;
}

&nbsp;

public Employees getEmployees1() {
return employees1;
}

public void setEmployees1(Employees employees1) {
this.employees1 = employees1;
}

public List<Employees> getEmployeesList1() {
return employeesList1;
}

public void setEmployeesList1(List<Employees> employeesList1) {
this.employeesList1 = employeesList1;
}

public Employees addEmployees(Employees employees) {
getEmployeesList1().add(employees);
employees.setDepartments(this);
return employees;
}

public Employees removeEmployees(Employees employees) {
getEmployeesList1().remove(employees);
employees.setDepartments(null);
return employees;
}
}

 

Build Tools (Ant, Maven)

  • In this post I’ll discuss why build tools are required and how they really work in top level.
  • For a specific build tool it expects the project to be in specific structure. E.g: web.xml and lib folder should be present only in WEB-INF folder. Then only it’ll be able to build and deploy. Like that each build tool have their own standards of default project structure. Another example is Maven expects pom.xml to be present in the project in the root directory.

Why Ant or Maven scripts are required?

  • So far we discussed that each build tool expects project to be in specific structure then only it can be able to build and deploy. If your project is not in specific structure which the build tool is expecting, then you can write a script (Ant script, Maven script) by giving the paths of required folders in the script, which makes the script to build and deploy the project.
  • Another reason for writing scripts is that, if you want to deploy the project with out manual process, you can write the script and prepare a batch file to do that job.

Sample Ant script:

you can find sample ANT script from below website:

https://docs.spring.io/docs/Spring-MVC-step-by-step/part1.html

Singleton Implementation with Double Checked Locking in Java

-> Singleton implementation is nothing but creating the object instance only once and reusing the same instance when ever needed, instead creating a new one each time when needed.
-> In the below code instance is of lazy loading initializing type as the instance of class is declared in static variable but which is initialized only when the method getInstacne is invoked. Eager loading will be like declaring and initializing at the same time.like shown below.
private volatile static Singleton instance = new Singleton();

Double checked locking Idiom:

-> Now lets talk about Double checked locking idiom in singleton implementation. Here object is null or not will be checked twice and then object for the class will be created.
-> Why Volatile is used?: In double checked locking idiom, suppose if thread A is entered first null condition and then second null condition, then it will create an object for the class. Now suppose if thread B is entered first null condition, at the same time for thread A object is getting created (but instance creation is not completed yet) then as the null condition fails it’ll just return the same object instance which not completely initialized (half baked object), which leads to unexpected behavior of object.
So when voltaile is used, which makes the object getting published only when it is completely initialized, which avoids above problem.
-> The real problem is that Thread A may assign a memory space for instance before it is finished constructing instance. Thread B will see that assignment and try to use it. This results in Thread B failing because it is using a partially constructed version of instance.

Code:

public class Singleton {
private volatile static Singleton instance;
private Singleton() {}
public static Singleton getInstance() {
if (instance == null) {
synchronized (Singleton.class) {
if (instance == null) {
instance = new Singleton();
}
}
}
return instance;
}
}

 

Few References:

http://javarevisited.blogspot.in/2014/05/double-checked-locking-on-singleton-in-java.html

 

 

Data Types in Java

Primitive Data types:

In Java there are eight (8) primitive data types. For all those primitive data types wrapper classes also available.

If you define the primitive data types as global variables they hold some default values which are given below.

/* Primitive data types and their default values*/
static byte by; //0
static char c; // space
static short sh; //0
static int i; //0
static long l; //0
static float f; //0.0
static double d; //0.0
static boolean b; //false

Note: If you define the primitive data types as local variables they hold nothing and you must initialize them.

Wrapper Classes (Non Primitive Data types):

If you define the wrapper class data types as global variables then they hold some default values which is null

 /* Wrapper Class data types */
static Byte by1; //null
static Character c1; //null
static Short sh1; //null
static Integer i1; //null
static Long l1; //null
static Float f1; //null
static Double d1; //null
static Boolean b1; //null

static BigDecimal bd; //null
static String s; //null

Note: If you define these wrapper class data types as local variables they hold nothing and you must initialize them.  There are few more wrapper classes like Array, List etc.

Eclipse Shortcuts:

The post discuss about keyboard shortcuts for various function in Eclipse IDE which are very useful for rapid development.

Searching a file with its name:  Ctrl + Shift + R

Search a text in all the files: Ctrl + h (File Search tab)

Run java file: [Alt + Shift + X    & J] ,    [Ctrl + F11]

Navigate to the selected text in other places of file:   Ctrl + K

Organize Imports: Ctrl + Shift + O

To Navigate to the start/end of the block:  Ctrl + Shift+ P

To see the list of opened files and to navigate to them:  Ctrl + E

Suggestion when you are typing: Ctrl + Space

To get the list of methods which you can override:  [Alt +  Shift +  S     &  V]

To get the System.out.println();   [syso & Ctrl + Space]

To clear the breakpoints: Run-> Remove all breakpoints/ skip all breakpoints [this option will be shown only when application is running in debug mode]

To open IDE views (like console, variables) : Window -> show view

To know the result of a method: Ctrl+i