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
ConstructorDescriptionPersistenceServiceImpl
(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 TypeMethodDescriptionvoid
beginTransaction
(boolean rollbackOnly) Start a new transaction.compileQuery
(String query) <T> T
createCountQueryBuilder
(Class<? extends Entity> entityClass) Create a newCountQueryBuilder
which executes count queries.createCountQueryBuilder
(Class<? extends Entity> entityClass, Map<String, ?> hints) Create a newCountQueryBuilder
which executes count queries.createCountQueryBuilder
(String modelName) Create a newCountQueryBuilder
which executes count queries.createCountQueryBuilder
(String modelName, Map<String, ?> hints) Create a newCountQueryBuilder
which 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 newPrimaryKeyQueryBuilder
which executes queries forPrimaryKey
instances.createPrimaryKeyQueryBuilder
(Class<? extends Entity> entityClass, Map<String, ?> hints) Create a newPrimaryKeyQueryBuilder
which executes queries forPrimaryKey
instances.createPrimaryKeyQueryBuilder
(String modelName) Create a newPrimaryKeyQueryBuilder
which executes queries forPrimaryKey
instances.createPrimaryKeyQueryBuilder
(String modelName, Map<String, ?> hints) Create a newPrimaryKeyQueryBuilder
which executes queries forPrimaryKey
instances.<T> SinglePathQueryBuilder
<T> createQueryBuilder
(Class<? extends Entity> entityClass, Class<T> resultType) Create a newSinglePathQueryBuilder
that returns a single path of the root entity.<T> SinglePathQueryBuilder
<T> Create a newSinglePathQueryBuilder
that returns a single path of the root entity.<T extends Entity>
EntityQueryBuilder<T> createQueryBuilder
(Class<T> entityClass) Create a newEntityQueryBuilder
that returnsEntity
instances of the given type.<T extends Entity>
EntityQueryBuilder<T> createQueryBuilder
(Class<T> entityClass, Map<String, ?> hints) Create a newEntityQueryBuilder
that returnsEntity
instances of the given type.createQueryBuilder
(String modelName) Create a newEntityQueryBuilder
that returnsEntity
instances of the given type.<T> SinglePathQueryBuilder
<T> createQueryBuilder
(String modelName, Class<T> returnType) Create a newSinglePathQueryBuilder
that returns a single path of the root entity.<T> SinglePathQueryBuilder
<T> createQueryBuilder
(String modelName, Class<T> returnType, Map<String, ?> hints) Create a newSinglePathQueryBuilder
that returns a single path of the root entity.createQueryBuilder
(String modelName, Map<String, ?> hints) Create a newEntityQueryBuilder
that returnsEntity
instances of the given type.<T> PathQueryBuilder
<T> createQueryBuilderForPaths
(Class<? extends Entity> entityClass, Class<T> targetClass) Create a newPathQueryBuilder
that 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 newPathQueryBuilder
that returns anObject
[] containing multiple paths of the root entity.<T> PathQueryBuilder
<T> createQueryBuilderForPaths
(String modelName, Class<T> targetClass) Create a newPathQueryBuilder
that returns anObject
[] containing multiple paths of the root entity.<T> PathQueryBuilder
<T> createQueryBuilderForPaths
(String modelName, Class<T> targetClass, Map<String, ?> hints) Create a newPathQueryBuilder
that returns anObject
[] containing multiple paths of the root entity.void
doInNewSession
(Runnable runnable) Same as returnFromNewSession but without a return typevoid
doInTransaction
(CheckedConsumer<TransactionControl> consumer) <T> T
doWithConnection
(org.hibernate.jdbc.ReturningWork<T> work) Execute an instance ofReturningWork
using 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 TransactionControl
getIfPresent
(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> T
returnFromNewSession
(Supplier<T> supplier) Run the given supplier with a new session<T> T
returnFromTransaction
(CheckedFunction<TransactionControl, T> function) Run the given function function inside a transaction.void
setArgumentFactories
(List<ArgumentFactoryContribution> contributions) void
setCommitInvokerContributions
(List<CommitInvokerContribution> commitInvokerContributions) void
setJdbcFunctions
(List<JdbcFunction> jdbcFunctions) void
setPrimaryKeyLoaders
(List<PrimaryKeyLoader> primaryKeyLoaders) void
setQueryBuilderInterceptors
(List<QueryBuilderInterceptor> queryBuilderInterceptors) void
setRowMapperFactories
(List<ResultRowMapperFactory> rowMapperFactories) protected boolean
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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:
create
in interfacePersistenceService
- Returns:
- an instance of the given entity interface
-
create
- Specified by:
create
in interfacePersistenceService
- Returns:
- an instance of the given entity model
-
queryAll
- Specified by:
queryAll
in interfacePersistenceService
- Returns:
- all entities of the given class
-
queryAll
- Specified by:
queryAll
in interfacePersistenceService
- Returns:
- all entities of the given class
-
get
- Specified by:
get
in interfacePersistenceService
- Returns:
- the entity with the given identifier
-
get
- Specified by:
get
in interfacePersistenceService
- Returns:
- the entity with the given identifier
-
get
- Specified by:
get
in interfacePersistenceService
- Parameters:
identifier
- the unique_id or string key of an entity- Returns:
- the entity with the given identifier
-
get
- Specified by:
get
in interfacePersistenceService
- Parameters:
identifier
- the unique_id or string key of an entity- Returns:
- the entity with the given identifier
-
getIfPresent
- Specified by:
getIfPresent
in interfacePersistenceService
- Returns:
- the entity with the given identifier or an empty optional if it does not exist
-
getIfPresent
- Specified by:
getIfPresent
in interfacePersistenceService
- Returns:
- the entity with the given identifier or an empty optional if it does not exist
-
getIfPresent
- Specified by:
getIfPresent
in 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:
getIfPresent
in 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:PersistenceService
Start 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:
beginTransaction
in interfacePersistenceService
- Parameters:
rollbackOnly
- if the transaction should be rolled back at the end of the transaction- Returns:
- the
TransactionControl
for the newly created transaction - See Also:
-
getCurrentTransaction
- Specified by:
getCurrentTransaction
in interfacePersistenceService
- Returns:
- a
TransactionControl
for the currently running transaction (or null)
-
returnFromTransaction
Description copied from interface:PersistenceService
Run 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:
returnFromTransaction
in interfacePersistenceService
- Type Parameters:
T
- the return type- Parameters:
function
- the function to run- Returns:
- the result of the function
-
doInTransaction
Description copied from interface:PersistenceService
The same as returnFromTransaction, but accepts aConsumer
instead of aFunction
and has therefore no return type.- Specified by:
doInTransaction
in interfacePersistenceService
- Parameters:
consumer
- the function to run
-
transactionInProgress
-
getCurrentSession
- Specified by:
getCurrentSession
in interfacePersistenceService
- Returns:
- the currently active session - this may open a new thread-bound session.
-
returnFromNewSession
Description copied from interface:PersistenceService
Run the given supplier with a new session- Specified by:
returnFromNewSession
in interfacePersistenceService
- Type Parameters:
T
- the return type- Parameters:
supplier
- the supplier to run- Returns:
- the result of the supplier
-
doInNewSession
Description copied from interface:PersistenceService
Same as returnFromNewSession but without a return type- Specified by:
doInNewSession
in interfacePersistenceService
- Parameters:
runnable
- to run in a new session
-
doWithConnection
public <T> T doWithConnection(org.hibernate.jdbc.ReturningWork<T> work) Description copied from interface:PersistenceService
Execute an instance ofReturningWork
using the connection (transaction) of the current session.- Specified by:
doWithConnection
in interfacePersistenceService
-
txInvoker
- Specified by:
txInvoker
in interfacePersistenceService
-
createDeleteBuilder
Description copied from interface:PersistenceService
Create a new delete builder for the currentSession
.- Specified by:
createDeleteBuilder
in interfacePersistenceService
- Parameters:
entityClass
- the root entity (which is also the return type)
-
createDeleteBuilder
Description copied from interface:PersistenceService
Create a new delete builder for the currentSession
.- Specified by:
createDeleteBuilder
in interfacePersistenceService
- Parameters:
modelName
- the model name of the root entity
-
compileQuery
- Specified by:
compileQuery
in interfacePersistenceService
-
createQueryBuilder
Description copied from interface:PersistenceService
Create a newEntityQueryBuilder
that returnsEntity
instances of the given type.- Specified by:
createQueryBuilder
in 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:PersistenceService
Create a newEntityQueryBuilder
that returnsEntity
instances of the given type.- Specified by:
createQueryBuilder
in interfacePersistenceService
- Parameters:
entityClass
- the root entity (which is also the return type)hints
- optional hints about the query (seeQueryHints
for available hints)
-
createQueryBuilder
Description copied from interface:PersistenceService
Create a newEntityQueryBuilder
that returnsEntity
instances of the given type.- Specified by:
createQueryBuilder
in interfacePersistenceService
- Parameters:
modelName
- the model name of the root entity
-
createQueryBuilder
Description copied from interface:PersistenceService
Create a newEntityQueryBuilder
that returnsEntity
instances of the given type.- Specified by:
createQueryBuilder
in interfacePersistenceService
- Parameters:
modelName
- the model name of the root entityhints
- optional hints about the query (seeQueryHints
for available hints)
-
createQueryBuilder
public <T> SinglePathQueryBuilder<T> createQueryBuilder(Class<? extends Entity> entityClass, Class<T> resultType) Description copied from interface:PersistenceService
Create a newSinglePathQueryBuilder
that returns a single path of the root entity.- Specified by:
createQueryBuilder
in 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:PersistenceService
Create a newSinglePathQueryBuilder
that returns a single path of the root entity.- Specified by:
createQueryBuilder
in interfacePersistenceService
- Parameters:
entityClass
- the root entityresultType
- the type of the path to be returnedhints
- optional hints about the query (seeQueryHints
for available hints)
-
createQueryBuilder
Description copied from interface:PersistenceService
Create a newSinglePathQueryBuilder
that returns a single path of the root entity.- Specified by:
createQueryBuilder
in 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:PersistenceService
Create a newSinglePathQueryBuilder
that returns a single path of the root entity.- Specified by:
createQueryBuilder
in interfacePersistenceService
- Parameters:
modelName
- the model name of the root entityreturnType
- the type of the path to be returnedhints
- optional hints about the query (seeQueryHints
for available hints)
-
createQueryBuilderForPaths
public <T> PathQueryBuilder<T> createQueryBuilderForPaths(Class<? extends Entity> entityClass, Class<T> targetClass) Description copied from interface:PersistenceService
Create a newPathQueryBuilder
that returns anObject
[] containing multiple paths of the root entity.- Specified by:
createQueryBuilderForPaths
in interfacePersistenceService
- Parameters:
entityClass
- the root entitytargetClass
- the return type of the query builder (for exampleMap
orObject
[]
-
createQueryBuilderForPaths
Description copied from interface:PersistenceService
Create a newPathQueryBuilder
that returns anObject
[] containing multiple paths of the root entity.- Specified by:
createQueryBuilderForPaths
in interfacePersistenceService
- Parameters:
modelName
- the model name of the root entitytargetClass
- the return type of the query builder (for exampleMap
orObject
[]
-
createQueryBuilderForPaths
public <T> PathQueryBuilder<T> createQueryBuilderForPaths(Class<? extends Entity> entityClass, Class<T> targetClass, Map<String, ?> hints) Description copied from interface:PersistenceService
Create a newPathQueryBuilder
that returns anObject
[] containing multiple paths of the root entity.- Specified by:
createQueryBuilderForPaths
in interfacePersistenceService
- Parameters:
entityClass
- the root entitytargetClass
- the return type of the query builder (for exampleMap
orObject
[]hints
- optional hints about the query (seeQueryHints
for available hints)
-
createQueryBuilderForPaths
public <T> PathQueryBuilder<T> createQueryBuilderForPaths(String modelName, Class<T> targetClass, Map<String, ?> hints) Description copied from interface:PersistenceService
Create a newPathQueryBuilder
that returns anObject
[] containing multiple paths of the root entity.- Specified by:
createQueryBuilderForPaths
in interfacePersistenceService
- Parameters:
modelName
- the model name of the root entitytargetClass
- the return type of the query builder (for exampleMap
orObject
[]hints
- optional hints about the query (seeQueryHints
for available hints)
-
createCountQueryBuilder
Description copied from interface:PersistenceService
Create a newCountQueryBuilder
which executes count queries.- Specified by:
createCountQueryBuilder
in interfacePersistenceService
- Parameters:
entityClass
- the root entity
-
createCountQueryBuilder
Description copied from interface:PersistenceService
Create a newCountQueryBuilder
which executes count queries.- Specified by:
createCountQueryBuilder
in 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:PersistenceService
Create a newCountQueryBuilder
which executes count queries.- Specified by:
createCountQueryBuilder
in interfacePersistenceService
- Parameters:
entityClass
- the root entityhints
- optional hints about the query (seeQueryHints
for available hints)
-
createCountQueryBuilder
Description copied from interface:PersistenceService
Create a newCountQueryBuilder
which executes count queries.- Specified by:
createCountQueryBuilder
in interfacePersistenceService
- Parameters:
modelName
- the model name of the root entityhints
- optional hints about the query (seeQueryHints
for available hints)
-
createPrimaryKeyQueryBuilder
Description copied from interface:PersistenceService
Create a newPrimaryKeyQueryBuilder
which executes queries forPrimaryKey
instances.- Specified by:
createPrimaryKeyQueryBuilder
in interfacePersistenceService
- Parameters:
modelName
- the model name of the root entity
-
createPrimaryKeyQueryBuilder
Description copied from interface:PersistenceService
Create a newPrimaryKeyQueryBuilder
which executes queries forPrimaryKey
instances.- Specified by:
createPrimaryKeyQueryBuilder
in interfacePersistenceService
- Parameters:
entityClass
- the root entity
-
createPrimaryKeyQueryBuilder
Description copied from interface:PersistenceService
Create a newPrimaryKeyQueryBuilder
which executes queries forPrimaryKey
instances.- Specified by:
createPrimaryKeyQueryBuilder
in interfacePersistenceService
- Parameters:
modelName
- the model name of the root entityhints
- optional hints about the query (seeQueryHints
for available hints)
-
createPrimaryKeyQueryBuilder
public PrimaryKeyQueryBuilder createPrimaryKeyQueryBuilder(Class<? extends Entity> entityClass, Map<String, ?> hints) Description copied from interface:PersistenceService
Create a newPrimaryKeyQueryBuilder
which executes queries forPrimaryKey
instances.- Specified by:
createPrimaryKeyQueryBuilder
in interfacePersistenceService
- Parameters:
entityClass
- the root entityhints
- optional hints about the query (seeQueryHints
for available hints)
-
loadEntityClassByName
Description copied from interface:PersistenceService
Utility method to load the dynamically generated entity class by entity name.- Specified by:
loadEntityClassByName
in 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:
addSessionListener
in interfacePersistenceService
-
removeSessionListener
- Specified by:
removeSessionListener
in interfacePersistenceService
-