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.EntityManager;
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.util.AtomicCounter;
39 private final Dao dao;
40 private final EntityManager manager;
45 openManagers.increment();
48 public <T> T saveObject(T obj) {
50 obj = manager.merge(obj);
51 }
catch (Exception ex) {
52 Logger.getLogger(
DaoManager.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
61 }
catch (Exception ex) {
66 public <T> T find(Class<T> javaClass, Object arg) {
67 return manager.find(javaClass, arg);
70 public void remove(Object obj) {
74 public <T> Query createQuery(CriteriaQuery<T> query) {
75 return manager.createQuery(query);
78 public <T> Query createQuery(String clause, Class<T> javaClass) {
79 return manager.createQuery(clause, javaClass);
83 return manager.createQuery(clause);
87 return manager.createQuery(
delete);
91 return manager.createQuery(update);
95 return manager.createNativeQuery(clause, resultClass);
99 return manager.createNativeQuery(clause);
103 for (Map.Entry<String, Object> e : parameters.entrySet()) {
104 q.setParameter(e.getKey(), e.getValue());
123 openManagers.decrement();
127 return !manager.isOpen();
132 private static final AtomicCounter openManagers =
new AtomicCounter();
static String logMsg(String msg)
Query createNativeQuery(String clause)
Query createNativeQuery(String clause, Class resultClass)
static AtomicCounter getCounter()
void setNamedParameters(Query q, Map< String, Object > parameters)
Query createQuery(CriteriaDelete delete)
EntityManager getManager()
Query createQuery(String clause)
Query createQuery(CriteriaUpdate update)
abstract EntityManager createEntityManager()