Package com.axelor.db
Class JpaSupport
- java.lang.Object
-
- com.axelor.db.JpaSupport
-
- Direct Known Subclasses:
MailController
,ResponseInterceptor
,TaskController
public abstract class JpaSupport extends Object
This class provides some useful methods in JPA context, can be used as a base class for services to make it more convenient.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
JpaSupport.JDBCTask
The jdbc task interface.
-
Constructor Summary
Constructors Constructor Description JpaSupport()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T extends Model>
Query<T>all(Class<T> modelClass)
Get theQuery
instance for the given model class.protected javax.persistence.EntityManager
getEntityManager()
Get the instance of currentEntityManager
.protected void
inTransaction(Runnable task)
Run the given task inside a transaction that is committed after the task is completed.protected void
jdbcTask(JpaSupport.JDBCTask task)
Perform JDBC related task using theConnection
managed by the currentEntityManager
.
-
-
-
Method Detail
-
getEntityManager
protected javax.persistence.EntityManager getEntityManager()
Get the instance of currentEntityManager
.- Returns:
- the
EntityManager
instance
-
all
protected <T extends Model> Query<T> all(Class<T> modelClass)
Get theQuery
instance for the given model class.- Type Parameters:
T
- the type of the model- Parameters:
modelClass
- the model class- Returns:
- an instance of
Query
-
inTransaction
protected void inTransaction(Runnable task)
Run the given task inside a transaction that is committed after the task is completed.- Parameters:
task
- the task to run
-
jdbcTask
protected void jdbcTask(JpaSupport.JDBCTask task)
Perform JDBC related task using theConnection
managed by the currentEntityManager
.- Parameters:
task
- The task to be performed- Throws:
javax.persistence.PersistenceException
- Generally indicates wrappedSQLException
-
-