Thursday, September 26, 2013

Encrypted JDBC connection with Oracle Database

To protect sensitive data encryption is the standard way. Its highly recommended if you are dealing with sensitive data, the application database connection also need to be encrypted. In this article we will go through how to establish a secure JDBC connection to Oracle database.

 1) We need to turn on encryption in oracle server. We can do that by starting Oracle Net Manger. There we have to select Oracle Advance Security and in Encryption tab there is option to turn on Encryption for server.

2) Once the encryption for server is turned on. Next is how to establish a secure connection from Java.
JDBC driver has the capability to establish a encrypted connection. we have to pass necessary information as part of properties to do so. Here is documentation for that.

In this way we can establish encrypted connection. To test whether its working or not, we have to install some network sniffer tools. By that we can verify the exchanged data is encrypted or not. Another way is by turning on the tracing in Oracle Net Manger for network communication. And to check those trace for network traffic data is encrypted or not. 

Saturday, August 3, 2013

Internationalization Of af:query

I found ADF af:query is very useful. It provide out of box search and reporting capability. Typically we define some search criteria in View Object, and we use that criteria as af:query component.
All the labels we see in the page can be internationalized by using resource bundle in normal way.
For some labels we can use the below properties of af:query
                              ·         headerText
                              ·         resetButtonText
                              ·         saveButtonText
                              ·         searchButtonText
“Advanced” and “Saved Search” automatically take care. In fact all these labels are automatically translated as per locale. Only to support the language for which translation is not available or you want to have your customize label you can use above properties.
And rest of the labels can be customized or internationalized by using resource bundle configured for application module. To do so we need to modify the attribute of view object, In Control Hints section, Label Text filed can be modified to point right message key from the bundle.


Saturday, July 6, 2013

ADF Tree Table javax.faces.model.NoRowAvailableException

Usually this issue appears with Tree Table, when we modify the model associated with the tree. The UI state (disclosure and section information) is captured corresponding UI component object. When the model is updated those state become invalid. And when the tree try to restore the old state with new set of data then there could be a situation where this NoRowAvailableException can occur.

To avoid this better to clear the selection when model is updated. And then immediately partial refresh the tree .

I had used something like this to clear.

 if (treeTable != null && treeTable .getDisclosedRowKeys()!=null ){
        treeTable .getDisclosedRowKeys().clear();
    }

JBO-26001: NoXMLFileException

This exception comes in ADF BC projects. In my case <project>.jpx file was not part of deployment.
Run time BC needs the .jpx, As it is not able to find it throw JBO-26001: NoXMLFileException exception.
To make sure .jpx is part of deployment. Right click on project under deployment section check whether its included or not. If its not included add it.
Hope it solve the issue.

Saturday, April 13, 2013

Hashcode and Equals Method


It’s a common topic In  java interviews. And these two methods are always common to any class you write in Java. So let’s know them in and out.
boolean equals(Object  obj) and int hashCode() are two methods implemented in Object class with several other methods.  In Java every class implicitly inherit Object class so every class has these methods.  Equals method check the reference is holding same object or not.
MyClass obj1 = new MyClass();
MyClass obj2 = 0bj1;
Then obj1.equals(obj2) returns true.
MyClass obj3 = new MyClass();
In this case obj1.equals(obj3) will return false.
It means original equals method check whether two reference contain same object or not. If two object are logically similar, for ex like wrapper class Integer, Boolean etc we need to override equals method.
Boolean b1 = true;
Boolean b2 = true;
b1.equals(b2)  will return true. 
To overload equals method programmer may chose to compare field by filed.
Public class Employee
{
Integer employeeId;
String name;
public  boolean equals(Object obj)
{
 if (obj != null && obj instanceof Employee)
{
 Employee obj2 = (Employee) obj;
 return (obj2.getEmployeeId() == null ? this.employeeID == null : 
 obj2.getEmployeeId().equals(this.employeeID))
&& (obj2.getEmployeeName() == null ? this.employeeName == null : 
 obj2.getEmployeeName().equals(this.employeeName));  
}
return false;
}

Hascode method always return integer. Any two object equals return true always return same hashcode.  But its not necessary if two object produce same hashcode need to be equal.
Now here is the million dollar question if we override equals method do we need to override hashcode method. The answer is yes. We need to override hashcode method. It should satisfy two condition every distinct object produce different hashcode consistently and equals object will produce same hashcode.
Hashcode is important when we use HashTable, HashSet or HashMap in collections api. If we don’t construct the object in the above way, these collections may not work properly, performance can deteriorate.
So bottom line is always override hashcode when you override equals. J