Posts

Spring Transaction in JTA With Atomikos 2

We are going to implement JTA IN Spring to support Distributed(XA) Transactions in our Module. The underlying JTA implementation that we will be using is Atomikos. It is Open Source. Let's first traverse through the configuration part for implementing JTA in Spring. The required list of jars are: 1) hibernate-core-3.6.0.Final.jar 2) transactions-jta-3.6.4.jar 3) atomikos-util-3.6.4.jar 4) transactions-3.6.4.jar 5) transactions-api-3.6.4.jar 6) transactions-hibernate3-3.6.4.jar 7) transactions-jdbc-3.6.4.jar 8) concurrent-1.3.4.jar 9) cglib-nodep-2.2.3.jar -------------------------------------------- Config Changes of Application Context.xml -------------------------------------------- &ltcontext:component-scan base-package="com.springRest.controllers"&gt&lt/context:component-scan&gt &ltcontext:annotation-config&gt&lt/context:annotation-config&gt &lttx:annotation-driven transaction-manager="transactionManager"/...

Spring Data JPA & Spring 3 Transactions Through JTA and Atomikos

In this article I will discuss about Spring Transactions with JTA. The underlying JTA implementation with Atomikos. The server platform is jBoss7. The XA-DataSource configured in jBoss AS7 is of the type Oracle 10g. The Underlyimg Persistence Provider in Hibernate 4. I have used the Hibernate Module already available with jBoass AS7, but during Startup of my application I faced some issues for which i have to Externally plug in the jar "hibernate-core-3.6.0.Final.jar", Tried to find out the reason behind but remain undone. Now before going into the discussion, I will first try note down the jars that I have used, as this portion has Given me Immense pain due to lack of proper Documentation. jar List --------------------------------- 1) hibernate-core-3.6.0.Final.jar 2) transactions-jta-3.6.4.jar 3) atomikos-util-3.6.4.jar 4) transactions-3.6.4.jar 5) transactions-api-3.6.4.jar 6) transactions-hibernate3-3.6.4.jar 7) transactions-jdbc-3.6.4...

Memento Pattern with AspectJ

Hello Friends, This time i have implemented Memento Pattern with AspectJ. In Memento Pattern, there are two roles: 1) Originator & 2)Memento Originator is the Object or the Entity that we are working with. Memento is the artifact where we are going to save the state of the Originator, so that when required we can roll back the current state of the Originator with the state saved in the Memento. Here I have saved only the state of the Originator during Initialization. Multiple states of Originator as required can be saved in Memento and can be restored when required based on the requirement. Intersting Huh!!!! We are going to implement this feature with AspectJ public abstract aspect MyNewAspectMementoPattern { public interface Originator { public void setMemento(Memento memento); //public Originator getObject(); public Originator restoreState(); } public interface Memento { public void setState(Originator originator); public Originator getSt...

State Pattern with Aspect

Today I am going discuss Implementation of State Pattern throgh AspectJ In state Pattern there are two roles to watch out for, The Context and the state. The Context Role contains state. Now when an operation is required to be carried out on context then the state is checked Now based on the state, the operation on the state is undertaken and if required the new state is set in context. The mentioned operation is carried out through the AspectJ. public abstract aspect MyNewAspectStatePattern { public interface Context { public void setState(State state); public State getState(); } public interface State { public void perform(); } public abstract pointcut interceptInitialState(Context context/*,com.aspectj.target.State state*/); } In the above aspect there are two states as mentioned, the Context and the State. The context has the state within itself and the State role has the perform method for performing operations. public aspect MyNewAspe...

Aspect's Paradigm With Design Patterns (Proxy Pattern)

Implementation of Design patterns with AspectJ is another intersting episode of AspectJ. After I have implemented a few such Design patterns, I came to realize the power of AspectJ and How beautiful it is. So,I will share my expereince with this dimension of AspectJ Proxy Pattren First, I have created some Utility classes which will be assigned some role using Aspects Dynamically. package com.aspectj.target; import java.io.IOException; import javax.naming.OperationNotSupportedException; public class PureSubject { public String write() { System.out.println(" @@@ In PureSubject.write() @@@ "); return "### PureSubject.write() completed ###"; } public String read() throws OperationNotSupportedException { throw new OperationNotSupportedException("This Operation is not Supported in this version"); } public String update() throws OperationNotSupportedException { throw new OperationNotSupportedException("This Operatio...

Aspects of AspectJ

Image
This time I will share my experience with AspectJ. Aspects evolve for the separation of cross cutting concerns from the business logic. The cross cutting concerns evolve Logging,Transaction Management,Security Concerns etc. i.e. anything that is not inherently related with Business Logic. For implementing aspects we need to know about AspectJ programming syntax, which are not exact replica of java files but almost similar and follows all oops concepts. The source files are with extension .aj and the source files are compiled to .class files(in exact bytecode format like normal java class files) by the AspectJ compiler so that any JVM can execute the compiled aspects. Whenever we talk about aspects one term always comes to our mind that is WEAVING . Aspects are woven into the source code at 1) Compile time (Compile Time Weaving) 2) Load Time (Load Time Weaving) 3) Run Time (Th...

Stax Parsing

Image
Here, I will provide STAX parsing Outline. STAX is streaming parsing API. Now the question arises, that why should we use STAX, instead of DOM,SAX,JAXP (well known tools for working with the XML infosets) and other XML parsing API's, what extra benefit does STAX provides us, so here it is: 1) StAX is a streaming PULL-PUSH parsing java API for reading and writing XMLs. 2) StAX API is a set of interfaces providing a framework for bi-directional parser. It provides two sets of APIs, cursor and iterator based. 3) Unlike DOM it doesn't load the entire Document tree in the memory(i.e. In Memory Objects), but it uses the Streaming Architecture just like File Streaming and thus reducing memory footprint. 4) Like JDBC StAX is a standard, and there are different implementations confirming to those standards like stax.codehaus, sjsxp,woodstox etc. 5) The Streaming API provides us with advantage of reading and writing large XML documents sequentially, performing operat...