Wednesday, January 20, 2016

Hibernate ORM

ORM stands for Object-Relational mapping. The objects in a Java class which is mapped in to the tables of a relational database using the metadata that describes the mapping between the objects and the database. It works by transforming the data from one representation to another.

Hibernate is a open source object-relational mapping and query service. In hibernate we can write HQL instead of SQL which save developers to spend more time on writing the native SQL. Hibernate has more powerful association, inheritance, polymorphism, composition, and collections. It is a beautiful approach for persisting into database using the java objects. Hibernate also allows you to express queries using java-based criteria .

Advantages of Hibernate
  • Hibernate is portable i mean database independent, Vendor independence.
  • Standard ORM also supports JPA
  • Mapping of Domain object to relational database.
  • Hibernate is better then plain JDBC.
  • JPA provider in JPA based applications.
Limitations of Hibernate
  • Slower in executing the queries than queries are used directly.
  • Only query language support for composite keys.
  • No shared references to value types.

Friday, December 11, 2015

Not able to open Heap Dump?

Most of the times the size of heap dump from a production server will be averaging from 4GB to 6GB. Our default heap settings will not be enough to load those heap dump in any of the analyzer tools.

Before loading the analyzer we can set the maximum heap size to accommodate the dump file size using the jvm argument -Xmx. This one specifies the maximum size, in bytes, of the memory allocation pool and must be greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 64MB

Suppose you are using jca457.jar as analyzer tool and your heap size is very less to accommodate the heap dump, you can use "java -jar -Xmx6000M jca457.jar" to set the heap size to 6000MB (You need to have enough space in RAM to allocate the heap size) while loading the analyzer.

In case of eclipse plugin or memory analyzer tool from IBM you can set these values in the ini file associated with the executable.

Friday, November 27, 2015

Associate a map property to user input field using converter

How to associate a map property to user input field while using formhandler?

HTML forms can set values to formhandler components using bean attribute of dsp:input tags. However if you want to associate user input values to a map attribute it can be done as follows,

<dsp:input bean="FormHandler.map-property" converter="map"  value="key=value" />

Suppose I have a map called primaryAddress in a custom formhandler MyFromHandler and addressLine1, addressLine2, city, state are attributes that needs to be captured from user. In this case we can set 4 input fields and can associated to map attributes directly.

<dsp:input bean="MyFromHandler.primaryAddress" converter="map" value="addressLine1=" />
<dsp:input bean="MyFromHandler.primaryAddress" converter="map" value="addressLine2=" />
<dsp:input bean="MyFromHandler.primaryAddress" converter="map" value="city=" />
<dsp:input bean="MyFromHandler.primaryAddress" converter="map" value="state=" />

Map property association can be done for multiple values loaded for a hidden variable as well.

<dsp:input bean="MyFromHandler.primaryAddress" converter="map" type="hidden" value="addressLine1=${loadedAddress.addressLine1}, addressLine2=${loadedAddress.addressLine2}, city=${loadedAddress.city}, state=${loadedAddress.state}">
</dsp:input> 


Wednesday, November 18, 2015

Weak Cache Hashtable

Weak cache hash table stores the items that have been removed from the cache, that have not yet been run through the garbage collection process. Entries in this table have been tagged as weak, indicating that they will be passed through the garbage collection process as soon as no further references are found for them. All items will be having weak references.

Scenario 

If the system maintains a reference to an item that has been removed from the cache, it would continue to used the item. When a new item with the same ID is created later, the repository can no longer synchronize all of the changes made. To prevent this, whenever an item is removed from the cache, it is added to a weak reference Hashtable. When an item is not found in the cache, the repository references this Hashtable. If the item it found, it is added back to the cache.

Friday, June 13, 2014

Life cycle phases of JSP

JSP is a servlet written in HTML format. Basically JSP can have java code in HTML and servlet can have HTML code in Java. The JSP engine does under go through different phases before disposing it. There are essentially 7 phases.
  • Page translation : Page is parsed, and a java file which is a servlet is created.
  • Page compilation : Page is compiled into a class file
  • Page loading : This class file is loaded.
  • Create an instance : Instance of servlet is created
  • Initialization : jspInit() method is called
  • Servicing : _jspService is called to handle service calls
  • Destroy : _jspDestroy is called to destroy it when the servlet is not required.

ATG CSC | Customize and configure return shipping address page

Following are the steps to configure the shipping address for returns,
  • Create a new jsp file that contains your return shipping address
Ship return items to:
My Company
Attn:Returns
100 Main Street
My City, My State
My Zip
  • Open ReturnShippingAddressRenderer.properties file from the location atg/commerce/custsvc/ui/renderers/ and provide the location of the new JSP file and the contextRoot variable.

  • Save ReturnShippingAddressRenderer.properties

Method types in Java

  • Re-entrant : A Java method in stack is re-entrant means that is allowing multiple concurrent invocations that do not interfere with each other. 
  • Recursive : A function is recursive if it calls itself. Given enough stack space, recursive method calls are perfectly valid in Java though it is tough to debug. Recursive functions are useful in removing iterations from many sorts of algorithms. All recursive functions are re-entrant but not all re-entrant functions are recursive. 
  • Idempotent : Idempotent methods are methods, which are written in such a way that repeated calls to the same method with the same arguments yield same results. For example clustered EJBs, which are written with idempotent methods, can automatically recover from a server failure as long as it can reach another server.