Class PersistenceServiceImpl
java.lang.Object
ch.tocco.nice2.persist.core.impl.hibernate.pojo.PersistenceServiceImpl
- All Implemented Interfaces:
PersistenceService
-
Nested Class Summary
Nested classes/interfaces inherited from interface ch.tocco.nice2.persist.core.api.hibernate.PersistenceService
PersistenceService.CompiledQuery -
Constructor Summary
ConstructorsConstructorDescriptionPersistenceServiceImpl(SessionFactoryManager sessionFactoryManager, TypeManager typeManager, FieldResolver fieldResolver, EntityFactory entityFactory, EntityTransactionContext entityTransactionContext, EntityFacadeListenerManager entityFacadeListenerManager, DataModel dataModel, BinaryDataAccessor binaryDataAccessor, ConditionFactory conditionFactory, QueryCompiler queryCompiler, ContextService contextService, InsecureOrderPathsRegistry insecureOrderPathsRegistry) -
Method Summary
Modifier and TypeMethodDescriptionvoidbeginTransaction(boolean rollbackOnly) Start a new transaction.compileQuery(String query) <T> TcreateCountQueryBuilder(Class<? extends Entity> entityClass) Create a newCountQueryBuilderwhich executes count queries.createCountQueryBuilder(Class<? extends Entity> entityClass, Map<String, ?> hints) Create a newCountQueryBuilderwhich executes count queries.createCountQueryBuilder(String modelName) Create a newCountQueryBuilderwhich executes count queries.createCountQueryBuilder(String modelName, Map<String, ?> hints) Create a newCountQueryBuilderwhich executes count queries.createDeleteBuilder(Class<? extends Entity> entityClass) Create a new delete builder for the currentSession.createDeleteBuilder(String modelName) Create a new delete builder for the currentSession.createPrimaryKeyQueryBuilder(Class<? extends Entity> entityClass) Create a newPrimaryKeyQueryBuilderwhich executes queries forPrimaryKeyinstances.createPrimaryKeyQueryBuilder(Class<? extends Entity> entityClass, Map<String, ?> hints) Create a newPrimaryKeyQueryBuilderwhich executes queries forPrimaryKeyinstances.createPrimaryKeyQueryBuilder(String modelName) Create a newPrimaryKeyQueryBuilderwhich executes queries forPrimaryKeyinstances.createPrimaryKeyQueryBuilder(String modelName, Map<String, ?> hints) Create a newPrimaryKeyQueryBuilderwhich executes queries forPrimaryKeyinstances.<T> SinglePathQueryBuilder<T> createQueryBuilder(Class<? extends Entity> entityClass, Class<T> resultType) Create a newSinglePathQueryBuilderthat returns a single path of the root entity.<T> SinglePathQueryBuilder<T> Create a newSinglePathQueryBuilderthat returns a single path of the root entity.<T extends Entity>
EntityQueryBuilder<T> createQueryBuilder(Class<T> entityClass) Create a newEntityQueryBuilderthat returnsEntityinstances of the given type.<T extends Entity>
EntityQueryBuilder<T> createQueryBuilder(Class<T> entityClass, Map<String, ?> hints) Create a newEntityQueryBuilderthat returnsEntityinstances of the given type.createQueryBuilder(String modelName) Create a newEntityQueryBuilderthat returnsEntityinstances of the given type.<T> SinglePathQueryBuilder<T> createQueryBuilder(String modelName, Class<T> returnType) Create a newSinglePathQueryBuilderthat returns a single path of the root entity.<T> SinglePathQueryBuilder<T> createQueryBuilder(String modelName, Class<T> returnType, Map<String, ?> hints) Create a newSinglePathQueryBuilderthat returns a single path of the root entity.createQueryBuilder(String modelName, Map<String, ?> hints) Create a newEntityQueryBuilderthat returnsEntityinstances of the given type.<T> PathQueryBuilder<T> createQueryBuilderForPaths(Class<? extends Entity> entityClass, Class<T> targetClass) Create a newPathQueryBuilderthat returns anObject[] containing multiple paths of the root entity.<T> PathQueryBuilder<T> createQueryBuilderForPaths(Class<? extends Entity> entityClass, Class<T> targetClass, Map<String, ?> hints) Create a newPathQueryBuilderthat returns anObject[] containing multiple paths of the root entity.<T> PathQueryBuilder<T> createQueryBuilderForPaths(String modelName, Class<T> targetClass) Create a newPathQueryBuilderthat returns anObject[] containing multiple paths of the root entity.<T> PathQueryBuilder<T> createQueryBuilderForPaths(String modelName, Class<T> targetClass, Map<String, ?> hints) Create a newPathQueryBuilderthat returns anObject[] containing multiple paths of the root entity.voiddoInNewSession(Runnable runnable) Same as returnFromNewSession but without a return typevoiddoInTransaction(CheckedConsumer<TransactionControl> consumer) <T> TdoWithConnection(org.hibernate.jdbc.ReturningWork<T> work) Execute an instance ofReturningWorkusing the connection (transaction) of the current session.<T extends Entity>
Tget(Class<T> entityClass, Serializable pk) <T extends Entity>
Tget(String modelName, Serializable id) @Nullable TransactionControlgetIfPresent(Class<T> entityClass, Serializable pk) getIfPresent(Class<T> entityClass, String identifier) getIfPresent(String modelName, Serializable id) getIfPresent(String modelName, String identifier) loadEntityClassByName(String entityName) Utility method to load the dynamically generated entity class by entity name.void<T> TreturnFromNewSession(Supplier<T> supplier) Run the given supplier with a new session<T> TreturnFromTransaction(CheckedFunction<TransactionControl, T> function) Run the given function function inside a transaction.voidsetArgumentFactories(List<ArgumentFactoryContribution> contributions) voidsetCommitInvokerContributions(List<CommitInvokerContribution> commitInvokerContributions) voidsetJdbcFunctions(List<JdbcFunction> jdbcFunctions) voidsetPrimaryKeyLoaders(List<PrimaryKeyLoader> primaryKeyLoaders) voidsetQueryBuilderInterceptors(List<QueryBuilderInterceptor> queryBuilderInterceptors) voidsetRowMapperFactories(List<ResultRowMapperFactory> rowMapperFactories) protected booleanMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ch.tocco.nice2.persist.core.api.hibernate.PersistenceService
beginTransaction
-
Constructor Details
-
PersistenceServiceImpl
public PersistenceServiceImpl(@Lazy SessionFactoryManager sessionFactoryManager, TypeManager typeManager, FieldResolver fieldResolver, @Lazy EntityFactory entityFactory, @Lazy EntityTransactionContext entityTransactionContext, @Lazy EntityFacadeListenerManager entityFacadeListenerManager, @Lazy DataModel dataModel, @Lazy BinaryDataAccessor binaryDataAccessor, ConditionFactory conditionFactory, @Lazy QueryCompiler queryCompiler, ContextService contextService, InsecureOrderPathsRegistry insecureOrderPathsRegistry)
-
-
Method Details
-
setQueryBuilderInterceptors
@Autowired public void setQueryBuilderInterceptors(List<QueryBuilderInterceptor> queryBuilderInterceptors) -
setPrimaryKeyLoaders
-
setRowMapperFactories
-
setCommitInvokerContributions
@Autowired public void setCommitInvokerContributions(List<CommitInvokerContribution> commitInvokerContributions) -
setJdbcFunctions
-
setArgumentFactories
-
create
- Specified by:
createin interfacePersistenceService- Returns:
- an instance of the given entity interface
-
create
- Specified by:
createin interfacePersistenceService- Returns:
- an instance of the given entity model
-
queryAll
- Specified by:
queryAllin interfacePersistenceService- Returns:
- all entities of the given class
-
queryAll
- Specified by:
queryAllin interfacePersistenceService- Returns:
- all entities of the given class
-
get
- Specified by:
getin interfacePersistenceService- Returns:
- the entity with the given identifier
-
get
- Specified by:
getin interfacePersistenceService- Returns:
- the entity with the given identifier
-
get
- Specified by:
getin interfacePersistenceService- Parameters:
identifier- the unique_id or string key of an entity- Returns:
- the entity with the given identifier
-
get
- Specified by:
getin interfacePersistenceService- Parameters:
identifier- the unique_id or string key of an entity- Returns:
- the entity with the given identifier
-
getIfPresent
- Specified by:
getIfPresentin interfacePersistenceService- Returns:
- the entity with the given identifier or an empty optional if it does not exist
-
getIfPresent
- Specified by:
getIfPresentin interfacePersistenceService- Returns:
- the entity with the given identifier or an empty optional if it does not exist
-
getIfPresent
- Specified by:
getIfPresentin interfacePersistenceService- Parameters:
identifier- the unique_id or string key of an entity- Returns:
- the entity with the given identifier or an empty optional if it does not exist
-
getIfPresent
- Specified by:
getIfPresentin interfacePersistenceService- Parameters:
identifier- the unique_id or string key of an entity- Returns:
- the entity with the given identifier or an empty optional if it does not exist
-
beginTransaction
Description copied from interface:PersistenceServiceStart a new transaction. PreferablyPersistenceService.doInTransaction(CheckedConsumer)andPersistenceService.returnFromTransaction(CheckedFunction)should be used. The transaction handling (commit/rollback) must be handled by the user of this method.- Specified by:
beginTransactionin interfacePersistenceService- Parameters:
rollbackOnly- if the transaction should be rolled back at the end of the transaction- Returns:
- the
TransactionControlfor the newly created transaction - See Also:
-
getCurrentTransaction
- Specified by:
getCurrentTransactionin interfacePersistenceService- Returns:
- a
TransactionControlfor the currently running transaction (or null)
-
returnFromTransaction
Description copied from interface:PersistenceServiceRun the given function function inside a transaction. If a transaction is already running, the existing transaction is used. Newly created entities will automatically be inserted before committing.- Specified by:
returnFromTransactionin interfacePersistenceService- Type Parameters:
T- the return type- Parameters:
function- the function to run- Returns:
- the result of the function
-
doInTransaction
Description copied from interface:PersistenceServiceThe same as returnFromTransaction, but accepts aConsumerinstead of aFunctionand has therefore no return type.- Specified by:
doInTransactionin interfacePersistenceService- Parameters:
consumer- the function to run
-
transactionInProgress
-
getCurrentSession
- Specified by:
getCurrentSessionin interfacePersistenceService- Returns:
- the currently active session - this may open a new thread-bound session.
-
returnFromNewSession
Description copied from interface:PersistenceServiceRun the given supplier with a new session- Specified by:
returnFromNewSessionin interfacePersistenceService- Type Parameters:
T- the return type- Parameters:
supplier- the supplier to run- Returns:
- the result of the supplier
-
doInNewSession
Description copied from interface:PersistenceServiceSame as returnFromNewSession but without a return type- Specified by:
doInNewSessionin interfacePersistenceService- Parameters:
runnable- to run in a new session
-
doWithConnection
public <T> T doWithConnection(org.hibernate.jdbc.ReturningWork<T> work) Description copied from interface:PersistenceServiceExecute an instance ofReturningWorkusing the connection (transaction) of the current session.- Specified by:
doWithConnectionin interfacePersistenceService
-
txInvoker
- Specified by:
txInvokerin interfacePersistenceService
-
createDeleteBuilder
Description copied from interface:PersistenceServiceCreate a new delete builder for the currentSession.- Specified by:
createDeleteBuilderin interfacePersistenceService- Parameters:
entityClass- the root entity (which is also the return type)
-
createDeleteBuilder
Description copied from interface:PersistenceServiceCreate a new delete builder for the currentSession.- Specified by:
createDeleteBuilderin interfacePersistenceService- Parameters:
modelName- the model name of the root entity
-
compileQuery
- Specified by:
compileQueryin interfacePersistenceService
-
createQueryBuilder
Description copied from interface:PersistenceServiceCreate a newEntityQueryBuilderthat returnsEntityinstances of the given type.- Specified by:
createQueryBuilderin interfacePersistenceService- Parameters:
entityClass- the root entity (which is also the return type)
-
createQueryBuilder
public <T extends Entity> EntityQueryBuilder<T> createQueryBuilder(Class<T> entityClass, Map<String, ?> hints) Description copied from interface:PersistenceServiceCreate a newEntityQueryBuilderthat returnsEntityinstances of the given type.- Specified by:
createQueryBuilderin interfacePersistenceService- Parameters:
entityClass- the root entity (which is also the return type)hints- optional hints about the query (seeQueryHintsfor available hints)
-
createQueryBuilder
Description copied from interface:PersistenceServiceCreate a newEntityQueryBuilderthat returnsEntityinstances of the given type.- Specified by:
createQueryBuilderin interfacePersistenceService- Parameters:
modelName- the model name of the root entity
-
createQueryBuilder
Description copied from interface:PersistenceServiceCreate a newEntityQueryBuilderthat returnsEntityinstances of the given type.- Specified by:
createQueryBuilderin interfacePersistenceService- Parameters:
modelName- the model name of the root entityhints- optional hints about the query (seeQueryHintsfor available hints)
-
createQueryBuilder
public <T> SinglePathQueryBuilder<T> createQueryBuilder(Class<? extends Entity> entityClass, Class<T> resultType) Description copied from interface:PersistenceServiceCreate a newSinglePathQueryBuilderthat returns a single path of the root entity.- Specified by:
createQueryBuilderin interfacePersistenceService- Parameters:
entityClass- the root entityresultType- the type of the path to be returned
-
createQueryBuilder
public <T> SinglePathQueryBuilder<T> createQueryBuilder(Class<? extends Entity> entityClass, Class<T> resultType, Map<String, ?> hints) Description copied from interface:PersistenceServiceCreate a newSinglePathQueryBuilderthat returns a single path of the root entity.- Specified by:
createQueryBuilderin interfacePersistenceService- Parameters:
entityClass- the root entityresultType- the type of the path to be returnedhints- optional hints about the query (seeQueryHintsfor available hints)
-
createQueryBuilder
Description copied from interface:PersistenceServiceCreate a newSinglePathQueryBuilderthat returns a single path of the root entity.- Specified by:
createQueryBuilderin interfacePersistenceService- Parameters:
modelName- the model name of the root entityreturnType- the type of the path to be returned
-
createQueryBuilder
public <T> SinglePathQueryBuilder<T> createQueryBuilder(String modelName, Class<T> returnType, Map<String, ?> hints) Description copied from interface:PersistenceServiceCreate a newSinglePathQueryBuilderthat returns a single path of the root entity.- Specified by:
createQueryBuilderin interfacePersistenceService- Parameters:
modelName- the model name of the root entityreturnType- the type of the path to be returnedhints- optional hints about the query (seeQueryHintsfor available hints)
-
createQueryBuilderForPaths
public <T> PathQueryBuilder<T> createQueryBuilderForPaths(Class<? extends Entity> entityClass, Class<T> targetClass) Description copied from interface:PersistenceServiceCreate a newPathQueryBuilderthat returns anObject[] containing multiple paths of the root entity.- Specified by:
createQueryBuilderForPathsin interfacePersistenceService- Parameters:
entityClass- the root entitytargetClass- the return type of the query builder (for exampleMaporObject[]
-
createQueryBuilderForPaths
Description copied from interface:PersistenceServiceCreate a newPathQueryBuilderthat returns anObject[] containing multiple paths of the root entity.- Specified by:
createQueryBuilderForPathsin interfacePersistenceService- Parameters:
modelName- the model name of the root entitytargetClass- the return type of the query builder (for exampleMaporObject[]
-
createQueryBuilderForPaths
public <T> PathQueryBuilder<T> createQueryBuilderForPaths(Class<? extends Entity> entityClass, Class<T> targetClass, Map<String, ?> hints) Description copied from interface:PersistenceServiceCreate a newPathQueryBuilderthat returns anObject[] containing multiple paths of the root entity.- Specified by:
createQueryBuilderForPathsin interfacePersistenceService- Parameters:
entityClass- the root entitytargetClass- the return type of the query builder (for exampleMaporObject[]hints- optional hints about the query (seeQueryHintsfor available hints)
-
createQueryBuilderForPaths
public <T> PathQueryBuilder<T> createQueryBuilderForPaths(String modelName, Class<T> targetClass, Map<String, ?> hints) Description copied from interface:PersistenceServiceCreate a newPathQueryBuilderthat returns anObject[] containing multiple paths of the root entity.- Specified by:
createQueryBuilderForPathsin interfacePersistenceService- Parameters:
modelName- the model name of the root entitytargetClass- the return type of the query builder (for exampleMaporObject[]hints- optional hints about the query (seeQueryHintsfor available hints)
-
createCountQueryBuilder
Description copied from interface:PersistenceServiceCreate a newCountQueryBuilderwhich executes count queries.- Specified by:
createCountQueryBuilderin interfacePersistenceService- Parameters:
entityClass- the root entity
-
createCountQueryBuilder
Description copied from interface:PersistenceServiceCreate a newCountQueryBuilderwhich executes count queries.- Specified by:
createCountQueryBuilderin interfacePersistenceService- Parameters:
modelName- the model name of the root entity
-
createCountQueryBuilder
public CountQueryBuilder createCountQueryBuilder(Class<? extends Entity> entityClass, Map<String, ?> hints) Description copied from interface:PersistenceServiceCreate a newCountQueryBuilderwhich executes count queries.- Specified by:
createCountQueryBuilderin interfacePersistenceService- Parameters:
entityClass- the root entityhints- optional hints about the query (seeQueryHintsfor available hints)
-
createCountQueryBuilder
Description copied from interface:PersistenceServiceCreate a newCountQueryBuilderwhich executes count queries.- Specified by:
createCountQueryBuilderin interfacePersistenceService- Parameters:
modelName- the model name of the root entityhints- optional hints about the query (seeQueryHintsfor available hints)
-
createPrimaryKeyQueryBuilder
Description copied from interface:PersistenceServiceCreate a newPrimaryKeyQueryBuilderwhich executes queries forPrimaryKeyinstances.- Specified by:
createPrimaryKeyQueryBuilderin interfacePersistenceService- Parameters:
modelName- the model name of the root entity
-
createPrimaryKeyQueryBuilder
Description copied from interface:PersistenceServiceCreate a newPrimaryKeyQueryBuilderwhich executes queries forPrimaryKeyinstances.- Specified by:
createPrimaryKeyQueryBuilderin interfacePersistenceService- Parameters:
entityClass- the root entity
-
createPrimaryKeyQueryBuilder
Description copied from interface:PersistenceServiceCreate a newPrimaryKeyQueryBuilderwhich executes queries forPrimaryKeyinstances.- Specified by:
createPrimaryKeyQueryBuilderin interfacePersistenceService- Parameters:
modelName- the model name of the root entityhints- optional hints about the query (seeQueryHintsfor available hints)
-
createPrimaryKeyQueryBuilder
public PrimaryKeyQueryBuilder createPrimaryKeyQueryBuilder(Class<? extends Entity> entityClass, Map<String, ?> hints) Description copied from interface:PersistenceServiceCreate a newPrimaryKeyQueryBuilderwhich executes queries forPrimaryKeyinstances.- Specified by:
createPrimaryKeyQueryBuilderin interfacePersistenceService- Parameters:
entityClass- the root entityhints- optional hints about the query (seeQueryHintsfor available hints)
-
loadEntityClassByName
Description copied from interface:PersistenceServiceUtility method to load the dynamically generated entity class by entity name.- Specified by:
loadEntityClassByNamein interfacePersistenceService- Parameters:
entityName- name of the entity to load. Can be the fully qualified class name or just the entity name- Returns:
- the entity class instance
-
addSessionListener
- Specified by:
addSessionListenerin interfacePersistenceService
-
removeSessionListener
- Specified by:
removeSessionListenerin interfacePersistenceService
-