Integration Using Spring
The aim of this document is to explain how to integrate EclipseLink and Oracle Coherence using Spring Framework. These white paper target audiences are developers/technical architects/technical managers. This white paper assumes the reader has the knowledge of the following: -
Spring framework is collections of smaller frameworks and act as glue, which tie together different layers of enterprise application and provide consistent and simple programming model based on best practices. Some of the key features of the spring framework are: -
· Provides IOC container (Inversion of control/Dependency Injection)
· Provides AOP (Aspect Oriented Programming) framework.
· Provides Data Access framework
· Provides declarative Transaction management framework.
· Provides testing framework which enables use to develop code using TDD approach (Test Driven Development)
3. Eclipse Link
Eclipse Link is a comprehensive open source persistence solution with around 12 years of commercial usage. Some of the key features of Eclipse Link are: -
· Fully JPA compliant
· Enables simplified configuration of the target application server
· Enable integration with JTA transaction manager
· Very flexible framework, which allows customizations like SessionCustomizer & DescriptorCustomizer, which allows customizations of eclipse link session.
· Provide support for concurrency protection – locking
· EclipseLink cache. It has two types of caches i.e. L1 cache (EntityManager) and L2 cache (EntityManagerFactory)
· Provides advance query facilitity like object graph loading optimization using Join and Batch Fetch.
Oracle Coherence is a JCache-compliant in memory distributed data grid solution for clustered applications and application servers. Some of the key features of Oracle Coherence are: -
· Container – less clustering of java processing (pojo – pliain old java objects)
· Real-time event observation (Listener pattern)
· Parallel queries and aggregation (Purely object based queries)
· Clustered JMX
Eclipse link grid – spring aware cache store/loader
Coherence supports pluggable CacheLoader and CacheStore implementations. As result the entity classes annotated with JPA specifications can directly interact with Coherence API (get, put, etc)
SpringAwareEntityCacheLoader is class which supports reading the JPA entities from the database by implementing load/loadAll methods. SpringAwareEntityCacheStore extendsSpringAwareEntityCacheLoader and also support write, update and delete operations to the database. This class also implements CacheStore and implements the methods store, storeAll, erase, eraseAll.
The figure shows a typical Oracle Coherence and Eclipse Link integration viaSpringAwareEntityCacheStore.CACHE FACTORY SPRING INTEGRATION
The entry point to access caches or any other services is CacheFactory through the use of its static methods (getCache etc). Coherence provides flexibility to override its default behavior via use of cache configuration file (coherence-cache-config.xml). Hence its possible to provide custom implementations of Coherence interfaces CacheStore & CacheLoader. These interfaces can be configured via a class-scheme. Class schemes provide a mechanism for instantiating an arbitrary Java object. The class-scheme may be configured to either instantiate objects directly via their class-name (using new operator), or indirectly via a class-factory-name and method-name. The class-scheme must be configured with either a class-name or class-factory-name and method-name.
It is possible to tell Coherence to retrieve objects (cache store) configured in a class-scheme from a Spring BeanFactory instead of creating its own instance.
SpringAwareCacheStoreFactory is spring aware class, which extends DefaultConfigurableCacheFactory, and provides the ability to delegate class-scheme bean instantiations responsibility to spring’s BeanFactory class.
Key features of SpringAwareCacheStoreFactory
1. Application Context Aware class: - Since this class implements spring ApplicationContextAware interface, as result at the time bean post processing, this class will be handed over the current ApplicationContext. Hence it will be useful for the cache servers that require beans from the spring container.
2. Bean Factory Ware class: - This class also implements spring BeanFactoryAware interface, as result at the time of bean post processing current BeanFactory will be handed over to it. As a result a BeanFactory can be provided at the runtime by an application or provided directly by the spring container. This is useful for Coherence applications running in a container that already has an existing BeanFactory.
Note: - Implementation of spring’s InitializingBean interface will make sure BeanFatory is set before making call to DefaultConfigurableFactory class instantiateAny method is called. This is the key method, which creates object (cache store)-using class-scheme. Typically the object will be configured as spring-bean: myCaheStore in the class-scheme tag in the coherence config file.
3. Ability to set the path of coherence configuration file and hence clean approach to manage coherence configuration files.
Using Spring as a glue framework to integrate Eclipse Link and Oracle Coherence provides following key benefits: -
1. Ability to inject separate data source to be used by SpringAwareCacheStore to perform the database operations. The data source can be setup in spring configuration file
2. Ability to provide pool of data sources. Again these data sources pools can be configured in spring configuration file.
3. Provide seprate EntityManager for the SpringAwareEntityCacheStore as result application’s transaction will never be interfered.
4. Make it possible to use spring’s JpaDaoSupport and hence spring declarative transaction management and also spring programming model (best practices)
1 comment:
Great man. Better than oracle wiki.
how will you define the spring bean with "myCacheStore"
i tried defining it to my domain object as follows
bean id="myCacheStore"
class="com. xx.Contract"
scope="prototype"
property name="sessionFactory" ref="sessionFactory"
Not sure if this is correct but i am getting following exception . I am using Coherence 3.5.2
class-scheme java.lang.ClassNotFoundException: spring-bean:entityCacheStore
at com.tangosol.util.Base.ensureRuntimeException(Base.java:293)
Caused by: java.lang.ClassNotFoundException: spring-bean:entityCacheStore
at java.lang.Class.forName0(Native Method)
Post a Comment