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 interfaceJpaSupport.JDBCTaskThe 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 theQueryinstance for the given model class.protected javax.persistence.EntityManagergetEntityManager()Get the instance of currentEntityManager.protected voidinTransaction(Runnable task)Run the given task inside a transaction that is committed after the task is completed.protected voidjdbcTask(JpaSupport.JDBCTask task)Perform JDBC related task using theConnectionmanaged by the currentEntityManager.
-
-
-
Method Detail
-
getEntityManager
protected javax.persistence.EntityManager getEntityManager()
Get the instance of currentEntityManager.- Returns:
- the
EntityManagerinstance
-
all
protected <T extends Model> Query<T> all(Class<T> modelClass)
Get theQueryinstance 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 theConnectionmanaged by the currentEntityManager.- Parameters:
task- The task to be performed- Throws:
javax.persistence.PersistenceException- Generally indicates wrappedSQLException
-
-