19 package org.turro.jpa;
21 import java.io.Closeable;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import javax.persistence.EntityTransaction;
26 import javax.persistence.Query;
27 import javax.persistence.criteria.CriteriaDelete;
28 import javax.persistence.criteria.CriteriaQuery;
29 import javax.persistence.criteria.CriteriaUpdate;
30 import org.turro.elephant.context.ElephantContext;
31 import org.turro.elephant.exception.ElephantException;
32 import org.turro.util.AtomicCounter;
41 private final EntityTransaction transaction;
45 this.transaction = manager.
getManager().getTransaction();
51 public <T> T saveObject(T obj) {
52 return manager.saveObject(obj);
59 public <T> T find(Class<T> javaClass, Object arg) {
60 return manager.find(javaClass, arg);
63 public void remove(Object obj) {
64 manager.
remove(saveObject(obj));
67 public <T> Query createQuery(CriteriaQuery<T> query) {
68 return manager.createQuery(query);
71 public <T> Query createQuery(String clause, Class<T> javaClass) {
72 return manager.createQuery(clause, javaClass);
76 return manager.createQuery(clause);
80 return manager.createQuery(
delete);
84 return manager.createQuery(update);
107 if(transaction !=
null && transaction.isActive()) {
109 transaction.commit();
110 }
catch (Exception ex) {
113 transaction.rollback();
114 }
catch (Exception e) {
119 openTransactions.decrement();
126 private void startTransaction() {
127 if(transaction !=
null && !transaction.isActive()) {
129 openTransactions.increment();
135 private static final AtomicCounter openTransactions =
new AtomicCounter();
138 return openTransactions;
static String logMsg(String msg)
Query createNativeQuery(String clause, Class resultClass)
void setNamedParameters(Query q, Map< String, Object > parameters)
EntityManager getManager()
Query createQuery(String clause)
void setNamedParameters(Query q, Map< String, Object > parameters)
Query createNativeQuery(String clause)
Query createQuery(CriteriaDelete delete)
Query createNativeQuery(String clause, Class resultClass)
static AtomicCounter getCounter()
Query createQuery(CriteriaUpdate update)