BrightSide Workbench Full Report + Source Code
org.turro.jpa.Dao Class Referenceabstract
Inheritance diagram for org.turro.jpa.Dao:
Collaboration diagram for org.turro.jpa.Dao:

Public Member Functions

 Dao ()
 
Query createQuery (String query)
 
Query createNamedQuery (String name)
 
void close ()
 
Dao clear ()
 
void persistObject (Object obj)
 
void saveEntities (Collection<? extends IDaoEntity > entities)
 
void saveCollection (Collection objs)
 
void saveCollection (Collection objs, DaoCallback callback)
 
void deleteObject (Object obj)
 
void deleteEntity (IDaoEntity entity)
 
void deleteCollection (Collection objs)
 
void deleteCollection (Collection objs, DaoCallback callback)
 
void deleteEntities (Collection< IDaoEntity > entities)
 
EntityManager getEntityManager ()
 
EntityManager getCachedEntityManager ()
 
boolean isLoaded (Object o, String attribute)
 
boolean isNotLoaded (Object o, String attribute)
 
boolean isLoaded (Object o)
 
boolean isNotLoaded (Object o)
 
List getResultList (WhereClause wc)
 
List getResultList (WhereClause wc, int max)
 
List getResultList (WhereClause wc, int start, int max)
 
List getResultList (SqlClause sc)
 
List getResultList (SqlClause sc, int max)
 
List getResultList (SqlClause sc, int start, int max)
 
List getResultList (String query)
 
List getResultList (String query, int max)
 
List getResultList (String query, Object[] pars)
 
List getResultList (String query, Object[] pars, int max)
 
Object getSingleResult (WhereClause wc)
 
Object getSingleResult (SqlClause sc)
 
Object getSingleResult (String query)
 
Object getSingleResult (String query, Object[] pars)
 
Object getSingleResultOrNull (SqlClause sc)
 
Object getSingleResultOrNull (WhereClause wc)
 
Object getSingleResultOrNull (String query)
 
Object getSingleResultOrNull (String query, Object[] pars)
 
Object getSingleNativeResult (String query)
 
Object getSingleNativeResult (String query, Object[] pars)
 
int executeUpdate (String query)
 
int executeUpdate (String query, Object[] pars)
 
int executeDelete (JpaCriteriaDelete jpaCriteriaDelete)
 
int executeDelete (Collection< JpaCriteriaDelete > jpaCriteriaDeletes)
 
int executeUpdate (JpaCriteriaUpdate jpaCriteriaUpdate)
 
int executeUpdate (Collection< JpaCriteriaUpdate > jpaCriteriaUpdates)
 
int executeUpdate (WhereClause wc)
 
int executeUpdate (SqlClause sc)
 
int executeNativeUpdate (SqlClause sc, Object... pars)
 
int executeNativeUpdate (String query, Object... pars)
 
abstract String getPath (Object object)
 
void poolObject (Object obj, int poolSize)
 
void finishPool ()
 

Static Public Member Functions

static String toJpaPositional (String query)
 
static Dao getDaoByPU (String pu)
 

Protected Member Functions

abstract EntityManagerFactory getFactory ()
 
abstract EntityManager createEntityManager ()
 
abstract EntityManager createCachedEntityManager ()
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 52 of file Dao.java.

Constructor & Destructor Documentation

◆ Dao()

org.turro.jpa.Dao.Dao ( )

Definition at line 56 of file Dao.java.

56  {
57  //em = createEntityManager();
58  }

Member Function Documentation

◆ clear()

Dao org.turro.jpa.Dao.clear ( )

Definition at line 78 of file Dao.java.

78  {
79 // if(em != null) {
80 // em.clear();
81 // }
82  return this;
83  }

◆ close()

void org.turro.jpa.Dao.close ( )

Definition at line 71 of file Dao.java.

71  {
72 // if(em != null && em.isOpen()) {
73 // em.close();
74 // }
75  }
Here is the caller graph for this function:

◆ createCachedEntityManager()

◆ createEntityManager()

◆ createNamedQuery()

Query org.turro.jpa.Dao.createNamedQuery ( String  name)

Definition at line 66 of file Dao.java.

66  {
67  return getEntityManager().createNamedQuery(name);
68  }
EntityManager getEntityManager()
Definition: Dao.java:202
Here is the call graph for this function:

◆ createQuery()

Query org.turro.jpa.Dao.createQuery ( String  query)

Definition at line 61 of file Dao.java.

61  {
62  return getEntityManager().createQuery(query);
63  }
Here is the call graph for this function:

◆ deleteCollection() [1/2]

void org.turro.jpa.Dao.deleteCollection ( Collection  objs)

Definition at line 175 of file Dao.java.

175  {
176  deleteCollection(objs, null);
177  }
void deleteCollection(Collection objs)
Definition: Dao.java:175
Here is the caller graph for this function:

◆ deleteCollection() [2/2]

void org.turro.jpa.Dao.deleteCollection ( Collection  objs,
DaoCallback  callback 
)

Definition at line 179 of file Dao.java.

179  {
180  try(DaoTransaction transaction = new DaoTransaction(this)) {
181  for(Object obj : objs) {
182  if(callback != null) {
183  callback.before(obj);
184  }
185  transaction.remove(transaction.saveObject(obj));
186  if(callback != null) {
187  callback.after(obj, null);
188  }
189  }
190  }
191  }
Here is the call graph for this function:

◆ deleteEntities()

void org.turro.jpa.Dao.deleteEntities ( Collection< IDaoEntity entities)

Definition at line 193 of file Dao.java.

193  {
194  try(DaoTransaction transaction = new DaoTransaction(this)) {
195  for(IDaoEntity entity : entities) {
196  entity.prepareDelete();
197  transaction.remove(transaction.saveObject(entity));
198  }
199  }
200  }

◆ deleteEntity()

void org.turro.jpa.Dao.deleteEntity ( IDaoEntity  entity)

Definition at line 168 of file Dao.java.

168  {
169  try(DaoTransaction transaction = new DaoTransaction(this)) {
170  entity.prepareDelete();
171  transaction.remove(transaction.saveObject(entity));
172  }
173  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ deleteObject()

void org.turro.jpa.Dao.deleteObject ( Object  obj)

Definition at line 162 of file Dao.java.

162  {
163  try(DaoTransaction transaction = new DaoTransaction(this)) {
164  transaction.remove(transaction.saveObject(obj));
165  }
166  }
Here is the caller graph for this function:

◆ executeDelete() [1/2]

int org.turro.jpa.Dao.executeDelete ( Collection< JpaCriteriaDelete jpaCriteriaDeletes)

Definition at line 486 of file Dao.java.

486  {
487  if(jpaCriteriaDeletes == null || jpaCriteriaDeletes.isEmpty()) return 0;
488  try(DaoTransaction transaction = new DaoTransaction(this)) {
489  int res = 0;
490  for(JpaCriteriaDelete jpaCriteriaDelete : jpaCriteriaDeletes) {
491  Query q = transaction.createQuery(jpaCriteriaDelete.delete());
492  res += q.executeUpdate();
493  }
494  return res;
495  }
496  }

◆ executeDelete() [2/2]

int org.turro.jpa.Dao.executeDelete ( JpaCriteriaDelete  jpaCriteriaDelete)

Definition at line 480 of file Dao.java.

480  {
481  List<JpaCriteriaDelete> list = new ArrayList<>();
482  list.add(jpaCriteriaDelete);
483  return executeDelete(list);
484  }
int executeDelete(JpaCriteriaDelete jpaCriteriaDelete)
Definition: Dao.java:480

◆ executeNativeUpdate() [1/2]

int org.turro.jpa.Dao.executeNativeUpdate ( SqlClause  sc,
Object...  pars 
)

Definition at line 536 of file Dao.java.

536  {
537  return executeNativeUpdate(sc.clause(), pars);
538  }
int executeNativeUpdate(SqlClause sc, Object... pars)
Definition: Dao.java:536
Here is the caller graph for this function:

◆ executeNativeUpdate() [2/2]

int org.turro.jpa.Dao.executeNativeUpdate ( String  query,
Object...  pars 
)

Definition at line 540 of file Dao.java.

540  {
541  try(DaoTransaction transaction = new DaoTransaction(this)) {
542  Query q = transaction.createNativeQuery(toJpaPositional(query));
543  if(pars != null) {
544  for(int i = 0; i < pars.length; i++) {
545  q.setParameter(i + 1, pars[i]);
546  }
547  }
548  int res = q.executeUpdate();
549  return res;
550  }
551  }
static String toJpaPositional(String query)
Definition: Dao.java:567
Here is the call graph for this function:

◆ executeUpdate() [1/6]

int org.turro.jpa.Dao.executeUpdate ( Collection< JpaCriteriaUpdate jpaCriteriaUpdates)

Definition at line 504 of file Dao.java.

504  {
505  if(jpaCriteriaUpdates == null || jpaCriteriaUpdates.isEmpty()) return 0;
506  try(DaoTransaction transaction = new DaoTransaction(this)) {
507  int res = 0;
508  for(JpaCriteriaUpdate jpaCriteriaUpdate : jpaCriteriaUpdates) {
509  Query q = transaction.createQuery(jpaCriteriaUpdate.update());
510  res += q.executeUpdate();
511  }
512  return res;
513  }
514  }

◆ executeUpdate() [2/6]

int org.turro.jpa.Dao.executeUpdate ( JpaCriteriaUpdate  jpaCriteriaUpdate)

Definition at line 498 of file Dao.java.

498  {
499  List<JpaCriteriaUpdate> list = new ArrayList<>();
500  list.add(jpaCriteriaUpdate);
501  return executeUpdate(list);
502  }
int executeUpdate(String query)
Definition: Dao.java:463
Here is the call graph for this function:

◆ executeUpdate() [3/6]

int org.turro.jpa.Dao.executeUpdate ( SqlClause  sc)

Definition at line 526 of file Dao.java.

526  {
527  try(DaoTransaction transaction = new DaoTransaction(this)) {
528  Query q = transaction.createQuery(sc.clause());
529  transaction.setNamedParameters(q, sc.getNamedValues());
530  int res = q.executeUpdate();
531  return res;
532  }
533  }

◆ executeUpdate() [4/6]

int org.turro.jpa.Dao.executeUpdate ( String  query)

Definition at line 463 of file Dao.java.

463  {
464  return executeUpdate(query, null);
465  }
Here is the caller graph for this function:

◆ executeUpdate() [5/6]

int org.turro.jpa.Dao.executeUpdate ( String  query,
Object[]  pars 
)

Definition at line 467 of file Dao.java.

467  {
468  try(DaoTransaction transaction = new DaoTransaction(this)) {
469  Query q = transaction.createQuery(toJpaPositional(query));
470  if(pars != null) {
471  for(int i = 0; i < pars.length; i++) {
472  q.setParameter(i + 1, pars[i]);
473  }
474  }
475  int res = q.executeUpdate();
476  return res;
477  }
478  }
Here is the call graph for this function:

◆ executeUpdate() [6/6]

int org.turro.jpa.Dao.executeUpdate ( WhereClause  wc)

Definition at line 516 of file Dao.java.

516  {
517  try(DaoTransaction transaction = new DaoTransaction(this)) {
518  Query q = transaction.createQuery(wc.getClause());
519  wc.setNamedParameters(q);
520  int res = q.executeUpdate();
521  return res;
522  }
523  }
Here is the call graph for this function:

◆ finishPool()

void org.turro.jpa.Dao.finishPool ( )

Definition at line 592 of file Dao.java.

592  {
593  if(pool != null && pool.size() > 0) {
594  saveCollection(pool);
595  }
596  pool = null;
597  }
void saveCollection(Collection objs)
Definition: Dao.java:144
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCachedEntityManager()

EntityManager org.turro.jpa.Dao.getCachedEntityManager ( )

Definition at line 207 of file Dao.java.

207  {
208  return createCachedEntityManager();
209  }
abstract EntityManager createCachedEntityManager()
Here is the call graph for this function:

◆ getDaoByPU()

static Dao org.turro.jpa.Dao.getDaoByPU ( String  pu)
static

Definition at line 654 of file Dao.java.

654  {
655  for(String className : ClassNames.cached().byAnnotation(ElephantDao.class.getName())) {
656  Class javaClass = Reflections.of(className).is(Dao.class).returnClass();
657  if(javaClass != null) {
658  if(((ElephantDao) javaClass.getAnnotation(ElephantDao.class)).pu().equals(pu)) {
659  return (Dao) Reflections.of(javaClass).instance();
660  }
661  }
662  }
663  return null;
664  }
Here is the caller graph for this function:

◆ getEntityManager()

EntityManager org.turro.jpa.Dao.getEntityManager ( )

Definition at line 202 of file Dao.java.

202  {
203  return null;
204  }
Here is the caller graph for this function:

◆ getFactory()

◆ getPath()

◆ getResultList() [1/10]

List org.turro.jpa.Dao.getResultList ( SqlClause  sc)

Definition at line 332 of file Dao.java.

332  {
333  return getResultList(sc, -1, -1);
334  }

◆ getResultList() [2/10]

List org.turro.jpa.Dao.getResultList ( SqlClause  sc,
int  max 
)

Definition at line 337 of file Dao.java.

337  {
338  return getResultList(sc, -1, max);
339  }

◆ getResultList() [3/10]

List org.turro.jpa.Dao.getResultList ( SqlClause  sc,
int  start,
int  max 
)

Definition at line 342 of file Dao.java.

342  {
343  if(sc == null) return Collections.EMPTY_LIST;
344  try(DaoManager manager = new DaoManager(this)) {
345  Query q = manager.createQuery(sc.clause());
346  q.setLockMode(LockModeType.NONE);
347  manager.setNamedParameters(q, sc.getNamedValues());
348  if(start > 0) q.setFirstResult(start);
349  if(max > 0) q.setMaxResults(max);
350  return q.getResultList();
351  }
352  }

◆ getResultList() [4/10]

List org.turro.jpa.Dao.getResultList ( String  query)

Definition at line 354 of file Dao.java.

354  {
355  return getResultList(query, null);
356  }

◆ getResultList() [5/10]

List org.turro.jpa.Dao.getResultList ( String  query,
int  max 
)

Definition at line 358 of file Dao.java.

358  {
359  return getResultList(query, null, max);
360  }

◆ getResultList() [6/10]

List org.turro.jpa.Dao.getResultList ( String  query,
Object[]  pars 
)

Definition at line 362 of file Dao.java.

362  {
363  return getResultList(query, pars, -1);
364  }

◆ getResultList() [7/10]

List org.turro.jpa.Dao.getResultList ( String  query,
Object[]  pars,
int  max 
)

Definition at line 366 of file Dao.java.

366  {
367  try(DaoManager manager = new DaoManager(this)) {
368  Query q = manager.createQuery(toJpaPositional(query));
369  q.setLockMode(LockModeType.NONE);
370  if(max > 0) q.setMaxResults(max);
371  if(pars != null) {
372  for(int i = 0; i < pars.length; i++) {
373  q.setParameter(i + 1, pars[i]);
374  }
375  }
376  return q.getResultList();
377  }
378  }
Here is the call graph for this function:

◆ getResultList() [8/10]

List org.turro.jpa.Dao.getResultList ( WhereClause  wc)

Definition at line 309 of file Dao.java.

309  {
310  return getResultList(wc, -1, -1);
311  }

◆ getResultList() [9/10]

List org.turro.jpa.Dao.getResultList ( WhereClause  wc,
int  max 
)

Definition at line 313 of file Dao.java.

313  {
314  return getResultList(wc, -1, max);
315  }

◆ getResultList() [10/10]

List org.turro.jpa.Dao.getResultList ( WhereClause  wc,
int  start,
int  max 
)

Definition at line 317 of file Dao.java.

317  {
318  if(wc == null) return Collections.EMPTY_LIST;
319  try(DaoManager manager = new DaoManager(this)) {
320  Query q = wc.isUseNative() ?
321  manager.createNativeQuery(wc.getClause(), wc.getResultClass()) :
322  manager.createQuery(wc.getClause());
323  if(!wc.isUseNative()) q.setLockMode(LockModeType.NONE);
324  wc.setNamedParameters(q);
325  if(start > 0) q.setFirstResult(start);
326  if(max > 0) q.setMaxResults(max);
327  return q.getResultList();
328  }
329  }
Here is the call graph for this function:

◆ getSingleNativeResult() [1/2]

Object org.turro.jpa.Dao.getSingleNativeResult ( String  query)

Definition at line 447 of file Dao.java.

447  {
448  return getSingleNativeResult(query, null);
449  }
Object getSingleNativeResult(String query)
Definition: Dao.java:447
Here is the caller graph for this function:

◆ getSingleNativeResult() [2/2]

Object org.turro.jpa.Dao.getSingleNativeResult ( String  query,
Object[]  pars 
)

Definition at line 451 of file Dao.java.

451  {
452  try(DaoManager manager = new DaoManager(this)) {
453  Query q = manager.createNativeQuery(toJpaPositional(query));
454  if(pars != null) {
455  for(int i = 0; i < pars.length; i++) {
456  q.setParameter(i + 1, pars[i]);
457  }
458  }
459  return q.getSingleResult();
460  }
461  }
Here is the call graph for this function:

◆ getSingleResult() [1/4]

Object org.turro.jpa.Dao.getSingleResult ( SqlClause  sc)

Definition at line 392 of file Dao.java.

392  {
393  try(DaoManager manager = new DaoManager(this)) {
394  Query q = manager.createQuery(sc.clause());
395  q.setLockMode(LockModeType.NONE);
396  manager.setNamedParameters(q, sc.getNamedValues());
397  return q.getSingleResult();
398  }
399  }

◆ getSingleResult() [2/4]

Object org.turro.jpa.Dao.getSingleResult ( String  query)

Definition at line 401 of file Dao.java.

401  {
402  return getSingleResult(query, null);
403  }
Object getSingleResult(WhereClause wc)
Definition: Dao.java:380
Here is the call graph for this function:

◆ getSingleResult() [3/4]

Object org.turro.jpa.Dao.getSingleResult ( String  query,
Object[]  pars 
)

Definition at line 405 of file Dao.java.

405  {
406  try(DaoManager manager = new DaoManager(this)) {
407  Query q = manager.createQuery(toJpaPositional(query));
408  q.setLockMode(LockModeType.NONE);
409  if(pars != null) {
410  for(int i = 0; i < pars.length; i++) {
411  q.setParameter(i + 1, pars[i]);
412  }
413  }
414  return q.getSingleResult();
415  }
416  }
Here is the call graph for this function:

◆ getSingleResult() [4/4]

Object org.turro.jpa.Dao.getSingleResult ( WhereClause  wc)

Definition at line 380 of file Dao.java.

380  {
381  try(DaoManager manager = new DaoManager(this)) {
382  Query q = wc.isUseNative() ?
383  manager.createNativeQuery(wc.getClause()) :
384  manager.createQuery(wc.getClause());
385  if(!wc.isUseNative()) q.setLockMode(LockModeType.NONE);
386  wc.setNamedParameters(q);
387  return q.getSingleResult();
388  }
389  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSingleResultOrNull() [1/4]

Object org.turro.jpa.Dao.getSingleResultOrNull ( SqlClause  sc)

Definition at line 419 of file Dao.java.

419  {
420  try {
421  return getSingleResult(sc);
422  } catch(NoResultException ex) {
423  return null;
424  }
425  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSingleResultOrNull() [2/4]

Object org.turro.jpa.Dao.getSingleResultOrNull ( String  query)

Definition at line 435 of file Dao.java.

435  {
436  return getSingleResultOrNull(query, null);
437  }
Object getSingleResultOrNull(SqlClause sc)
Definition: Dao.java:419
Here is the call graph for this function:

◆ getSingleResultOrNull() [3/4]

Object org.turro.jpa.Dao.getSingleResultOrNull ( String  query,
Object[]  pars 
)

Definition at line 439 of file Dao.java.

439  {
440  try {
441  return getSingleResult(query, pars);
442  } catch(NoResultException ex) {
443  return null;
444  }
445  }
Here is the call graph for this function:

◆ getSingleResultOrNull() [4/4]

Object org.turro.jpa.Dao.getSingleResultOrNull ( WhereClause  wc)

Definition at line 427 of file Dao.java.

427  {
428  try {
429  return getSingleResult(wc);
430  } catch(NoResultException ex) {
431  return null;
432  }
433  }
Here is the call graph for this function:

◆ isLoaded() [1/2]

boolean org.turro.jpa.Dao.isLoaded ( Object  o)

Definition at line 220 of file Dao.java.

220  {
221  PersistenceUnitUtil puu = getFactory().getPersistenceUnitUtil();
222  return puu.isLoaded(o);
223  }
abstract EntityManagerFactory getFactory()
Here is the call graph for this function:

◆ isLoaded() [2/2]

boolean org.turro.jpa.Dao.isLoaded ( Object  o,
String  attribute 
)

Definition at line 211 of file Dao.java.

211  {
212  PersistenceUnitUtil puu = getFactory().getPersistenceUnitUtil();
213  return puu.isLoaded(o, attribute);
214  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isNotLoaded() [1/2]

boolean org.turro.jpa.Dao.isNotLoaded ( Object  o)

Definition at line 225 of file Dao.java.

225  {
226  return !isLoaded(o);
227  }
boolean isLoaded(Object o, String attribute)
Definition: Dao.java:211
Here is the call graph for this function:

◆ isNotLoaded() [2/2]

boolean org.turro.jpa.Dao.isNotLoaded ( Object  o,
String  attribute 
)

Definition at line 216 of file Dao.java.

216  {
217  return !isLoaded(o, attribute);
218  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ persistObject()

void org.turro.jpa.Dao.persistObject ( Object  obj)

Definition at line 127 of file Dao.java.

127  {
128  try(DaoTransaction transaction = new DaoTransaction(this)) {
129  transaction.persist(obj);
130  }
131  }
Here is the caller graph for this function:

◆ poolObject()

void org.turro.jpa.Dao.poolObject ( Object  obj,
int  poolSize 
)

Definition at line 581 of file Dao.java.

581  {
582  if(pool == null) {
583  pool = new ArrayList();
584  }
585  pool.add(obj);
586  if(pool.size() >= poolSize) {
587  saveCollection(pool);
588  pool.clear();
589  }
590  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveCollection() [1/2]

void org.turro.jpa.Dao.saveCollection ( Collection  objs)

Definition at line 144 of file Dao.java.

144  {
145  saveCollection(objs, null);
146  }
Here is the caller graph for this function:

◆ saveCollection() [2/2]

void org.turro.jpa.Dao.saveCollection ( Collection  objs,
DaoCallback  callback 
)

Definition at line 148 of file Dao.java.

148  {
149  try(DaoTransaction transaction = new DaoTransaction(this)) {
150  for(Object obj : objs) {
151  if(callback != null) {
152  callback.before(obj);
153  }
154  Object newObj = transaction.saveObject(obj);
155  if(callback != null) {
156  callback.after(obj, newObj);
157  }
158  }
159  }
160  }
Here is the call graph for this function:

◆ saveEntities()

void org.turro.jpa.Dao.saveEntities ( Collection<? extends IDaoEntity entities)

Definition at line 133 of file Dao.java.

133  {
134  try(DaoTransaction transaction = new DaoTransaction(this)) {
135  for(IDaoEntity entity : entities) {
136  if(!entity.isEmpty()) {
137  entity.prepareSave();
138  transaction.saveObject(entity);
139  }
140  }
141  }
142  }
Here is the caller graph for this function:

◆ toJpaPositional()

static String org.turro.jpa.Dao.toJpaPositional ( String  query)
static

Definition at line 567 of file Dao.java.

567  {
568  MatchReplacer replacer = new MatchReplacer(Pattern.compile("\\?")) {
569  int i = 1;
570  @Override public String replacement(MatchResult m) {
571  return "$0" + i++;
572  }
573  };
574  return replacer.replace(query);
575  }
Here is the caller graph for this function:

The documentation for this class was generated from the following file: