-
Notifications
You must be signed in to change notification settings - Fork 233
Transaction Management
Transaction handling in NoSQL is challenging. Most of them don't provide a way to ensure atomicity and concurrency and it's programmer's responsibility to ensure those cases where things may go wrong. It gets complicated when more than one data-stores are involved (cross-datastore persistence).
Kundera, being a JPA provider supports Transaction Management. There are two ways you can achieve this:
javax.persistence.EntityTransaction interface provides following methods for defining transaction boundaries and managing transactions on operations.
public abstract void begin();
public abstract void commit();
public abstract void rollback();
public abstract void setRollbackOnly();
public abstract boolean getRollbackOnly();
public abstract boolean isActive();
EntityManagerImpl class in Kundera implements both javax.persistence.EntityManager and javax.persistence.EntityTransaction. This means they are available to you for use, just the way you use them in enterprise java application in relational world.
Here is an example:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("cassandra_pu");
EntityManager em = emf.createEntityManager();
em.setFlushMode(FlushModeType.COMMIT); //Necessary for flusing on transaction commit, AUTO option flushes automatically
em.getTransaction().begin();
Person p1 = new Person("1", "Amresh");
Person p2 = new Person("2", "Vivek");
Person p3 = new Person("3", "Kuldeep");
em.persist(p1);
em.persist(p2);
em.persist(p3);
em.getTransaction().commit(); //Will write p1, p2, p3 to database
Person pp1 = em.find(Person.class, "1"); //Not null
Person pp2 = em.find(Person.class, "2"); //Not null
Person pp3 = em.find(Person.class, "3"); //Not null
em.getTransaction().begin(); //begin new transaction
p2.setPersonName("Junk value");
em.merge(p2);
em.getTransaction().rollback();
pp2 = em.find(Person.class, "2"); //Not null, and person name still "Vivek"
Refer to test case EntityTransactionTest for more on this.
JTA is de-facto industry standard for transaction management (especially in container-managed environment). Kundera supports JTA and it works seamlessly with Spring too.
javax.transaction.UserTransaction interface provides following methods for defining transaction boundaries and managing transactions on operations.
public abstract void begin() throws NotSupportedException, SystemException;
public abstract void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException;
public abstract void rollback() throws IllegalStateException, SecurityException, SystemException;
public abstract void setRollbackOnly() throws IllegalStateException, SystemException;
public abstract int getStatus() throws SystemException;
public abstract void setTransactionTimeout(int paramInt) throws SystemException;
KunderaJTAUserTransaction class in Kundera implements this interface. This makes it possible for container to call UserTransaction methods for transaction management.
We have built a web application called twitample (available on Github here). It runs in tomcat and uses JTA on all data-store operations. Feel free to run this and see code to get a feel of it.
-
Datastores Supported
- Releases
-
Architecture
-
Concepts
-
Getting Started in 5 minutes
-
Features
- Object Mapper
- Polyglot Persistence
- Queries Support
- JPQL (JPA Query Language)
- Native Queries
- Batch insert update
- Schema Generation
- Primary Key Auto generation
- Transaction Management
- REST Based Access
- Geospatial Persistence and Queries
- Graph Database Support
-
Composite Keys
-
No hard annotation for schema
-
Support for Mapped superclass
-
Object to NoSQL Data Mapping
-
Cassandra's User Defined Types and Indexes on Collections
-
Support for aggregation
- Scalar Queries over Cassandra
- Connection pooling using Kundera Cassandra
- Configuration
-
Kundera with Couchdb
-
Kundera with Elasticsearch
-
Kundera with HBase
-
Kundera with Kudu
-
Kundera with RethinkDB
-
Kundera with MongoDB
-
Kundera with OracleNoSQL
-
Kundera with Redis
-
Kundera with Spark
-
Extend Kundera
- Sample Codes and Examples
-
Blogs and Articles
-
Tutorials
* Kundera with Openshift
* Kundera with Play Framework
* Kundera with GWT
* Kundera with JBoss
* Kundera with Spring
-
Performance
-
Troubleshooting
-
FAQ
- Production deployments
- Feedback