Hibernate Caching

I found some useful information on internet about hibernate caching.I thought of sharing with everyone.
High-volume database traffic is a frequent cause of performance problems in Web applications. Hibernate is a high-performance, object/relational persistence and query service. In many cases, second-level caching can be just what Hibernate needs to realize its full performance-handling potential.

What is caching – Anything you can do to minimize traffic between a database and an application server is probably a good thing. In theory, an application ought to be able to maintain a cache containing data already loaded from the database, and only hit the database when information has to be updated. When the database is hit, the changes may invalidate the cache.

There are two different cache used in hibernate-
1. First Level cache – This is associated with session. This is default implemented in hibernate on a per-transaction basis. Hibernate uses this cache mainly to reduce the number of SQL queries it needs to generate within a given transaction. For example, if an object is modified several times within the same transaction, Hibernate will generate only one SQL UPDATE statement at the end of the transaction, containing all the modifications
2. Second level cache – This is associated with Session Factory object. It will survive Sessions and can be reused in new Session by same SessionFactory (which usually is one per application). By default the 2nd level cache is not enabled. This ‘second-level’ cache exists as long as the session factory is alive. The second-level cache holds on to the ‘data’ for all properties and associations for individual entities that are marked to be cached. The second level cache is responsible for caching objects across sessions.

Cache Type
EHCache (Easy Hibernate Cache) — http://ehcache.sourceforge.net/
OSCache (Open Symphony) — http://www.opensymphony.com/oscache/
SwarmCache — http://swarmcache.sourceforge.net/
JBoss TreeCache — http://jboss.org/wiki/Wiki.jsp?page=JBossCache

EHCache -s an open source widely used java distributed cache for general purpose caching, Java EE and light-weight containers. It features memory and disk stores, replicate by copy and invalidate, listeners, cache loaders, cache extensions, cache exception handlers, a gzip caching servlet filter, RESTful and SOAP APIs and much more. Ehcache is available under an Apache open source license and is actively developed, maintained and supported.It support read only, Non strict Read/write,Read/write caching.It does not support transactional caching architecture.
OSCache – is “a Java framework” developed by OpenSymphony that makes it easy to cache content in Web applications.It is a caching solution that includes a JSP tag library and set of classes to perform fine grained dynamic caching of JSP content, servlet responses or arbitrary objects.It provides both in memory and persistent on disk caches.They can allow your site to have graceful error tolerance .It support read only, Non strict Read/write,Read/write caching.It does not support transactional schema caching architecture.
SwarmCache is a simple cluster-based caching solution based on JavaGroups. It supports read-only or nonstrict read/write caching. This type of cache is appropriate for applications that typically have many more read operations than write operations.It support read only, Non strict Read/write caching.It does not support ,Read/write and transactional caching architecture.It is is a cluster-based caching.
JBoss TreeCache – is a powerful replicated (synchronous or asynchronous) and transactional cache. Use this solution if you really need a true transaction-capable caching architecture.

ref- http://www.devx.com/dbzone/Article/29685/1954
– http://javaexp.blogspot.com/2007/10/level2-caching-in-hibernate.html

pimp it

Synthetic variable or method in Java

While working I found one keyword Synthetic variable or method in java. Never heard of this before.I found some information on net and thought of sharing knowledge with everyone. If you want add something in this ,it would be really great.

“Synthetic” attribute means a variable introduced by the compiler that doesn’t appear in the actual code. It is a compiler-created field that links a local inner class to a block’s local variable or reference type parameter. Synthetic members are only meant to be accessed by trusted code generated by the compiler. Compiler synthesizes certain hidden fields and methods in order to implement the scoping of names. Any constructs introduced by the compiler that do not have a corresponding construct in the source code must be marked as synthetic, except for default constructors and the class initialization method.[1]
it means when there is a field or method introduced into a class file by the compiler and we can not find the primary declaration in the source file, it will marked as synthetic
A synthetic field pointing to the outermost enclosing instance is named this$0. The next-outermost enclosing instance is this$1, and so forth. All these synthetic fields are initialized by constructor parameters, which have the same names as the fields they initialize. If one of the parameters is the innermost enclosing instance, it is the first. All such constructor parameters are deemed to be synthetic. If the compiler determines that the synthetic field’s value is used only in the code of the constructor, it may omit the field itself, and use only the parameter to implement variable references. A non-private final synthetic method which grants access to a private member or constructor has a name of the form access$N, where N is a decimal numeral.
when an inner class has access to an instance of an outer class, this is implemented by creating a synthetic field in the inner class, generally named this$0, which holds a reference to the outer class instance.
According to Java 6 spec – Any constructs introduced by the compiler that do not have a corresponding construct in the source code must be marked as synthetic, except for default constructors and the class initialization method.

Nested classes are sometimes implemented using synthetic fields and synthetic contructors, e.g. an inner class may use a synthetic field to save a reference to its outer class instance, and it may generate a synthetic constructor to set that field correctly.
Synthetic members are how the compiler deals with the fact that nested classes are actually compiled into top-level classes
if a static member type uses a private member of its containing type (or vice versa), the compiler generates synthetic non-private access methods and converts the expressions that access the private methods into expressions that invoke these specially generated methods. These methods are given the default package access which is sufficient, as the member class and its containing class are guaranteed to be in the same package.

Synthetic class is derived from Attribute and declares this class as `synthetic’, i.e., it needs special handling. It is instantiated from the Attribute.readAttribute() method.
According to the JVM Spec: “A class member that does not appear in the source code must be marked using a Synthetic attribute.” Also, “The Synthetic attribute was introduced in JDK release 1.1 to support nested classes and interfaces.
We can check using isSynthetic() method whether variable is synthetic variable or not.
Examples include a static variable to hold a Class object if you’ve used the “Integer.class” notation, and the member variable in a non-static inner class that holds a reference to the enclosing class. Besides the fact that they are inserted by the compiler

See the java doc on – http://bcel.sourceforge.net/docs/de/fub/bytecode/classfile/Synthetic.html

pimp it

Introduction of DOJO

Dojo is the Open Source JavaScript Toolkit. It is tool for constructing dynamic web
user interfaces. Dojo offers various widgets, utilities, higher IO (AJAX) abstraction etc.It is based on HTML and javascript. Dojo ups abstraction layer in a higher level. Dojo is sometimes advertised as AJAX
framework. It is able to make AJAX requests with Dojo But the technique of binding is under
the abstraction layer that Dojo has. Even if Dojo is nice, beautiful etc, it is quite heavy

We can one use Dojo by :-
1. Include package
2. use widget/utility/…

Package System
• Dojo consists of JavaScript files
• Package system takes care that only needed
files are included
• Each JavaScript file can be named as
package
dojo.provide(dojo.string);
• By that name the package can be taken in
use
dojo.require(dojo.string);
One has not to remember any file or
directory names
• Only dojo.js has to be included into HTML
document
• That file takes care of initialization of Dojo
• There is a couple of pre packaged builds that
consist of different kinds of packages
e.g. Widget, event or IO builds.

DOJO have following Language Libraries
• dojo.lang.*
• Wrappers for common idioms
• Functional programming APIs
• For Example
– dojo.lang.forEach
– dojo.lang.map
– dojo.lang.assert

Widget toolkit-

• Widget toolkit is also a very noticeable part of
Dojo toolkit
• Widget is a user interface object that has a
layout and some properties
• In Dojo widgets are HTML+CSS bound by
JavaScript
• Dojo has lots of useful widgets
e.g. Tabs, sorting table, dialogs

<script>
dojo.require(”dojo.widget.Editor2”);
</script>
<!-- ... -->
<textarea dojoType=”Editor2”>
...
</textarea>

For more info – www.dojotoolkit.org

pimp it

Thumbs Up