Class AbstractTopiaPersistenceContext
java.lang.Object
org.nuiton.topia.persistence.internal.AbstractTopiaPersistenceContext
- All Implemented Interfaces:
Closeable,AutoCloseable,TopiaReplicationSupport,TopiaDaoSupplier,TopiaPersistenceContext,TopiaReplicationDestination,TopiaTransaction
public abstract class AbstractTopiaPersistenceContext
extends Object
implements TopiaPersistenceContext
Abstract implementation of the TopiaPersistenceContext. This class will be extended by a generated one in order to
generate getXxxDao methods.
- Since:
- 3.0
- Author:
- Arnaud Thimel (Code Lutin)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classThis subclass of TopiaHibernateSupport is made to be used only internally within this persistence context. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanFlog used to check if this persistence context is closedprotected Map<Class<? extends TopiaEntity>,TopiaDao<? extends TopiaEntity>> Already loaded DAO cache within this persistence contextprotected TopiaFiresSupportObject that handles each event propagation.This subclass of TopiaHibernateSupport is made to be used only internally within this persistence context.protected HibernateTopiaReplicationSupportprotected TopiaJpaSupportThis instance of TopiaJpaSupport is created by the persistence context itself.protected TopiaHibernateSessionRegistryThe shared instance of TopiaHibernateSessionRegistryprotected TopiaSqlSupportThis instance of TopiaSqlSupport is created by the persistence context itself.protected TopiaIdFactoryUsed to affect a new topiaId when create is called. -
Constructor Summary
ConstructorsConstructorDescriptionCreating a new TopiaPersistenceContext is equivalent to creating a new transaction -
Method Summary
Modifier and TypeMethodDescriptionprotected voidvoidclose()Closes the PersistenceContext.voidcommit()Applies all the modifications made to this context on the persistence device.voiddelete(TopiaEntity entity) Delete into this TopiaContext an entity created by another TopiaContext<E extends TopiaEntity>
voidDelete into this TopiaContext an entities created by another TopiaContext<E extends TopiaEntity>
EfindByTopiaId(String topiaId) RetrieveTopiaEntityusing its uniquetopiaId.<E extends TopiaEntity>
TopiaDao<E>Get Dao for specified class.<E extends TopiaEntity,D extends TopiaDao<E>>
DGet Dao for specified class.protected HibernateTopiaReplicationSupportGet the currently configuredTopiaFiresSupport.Get the currently configuredTopiaIdFactory.booleanisClosed()Tells if the context is closedvoidreplicate(TopiaEntity entity) Must replicate given entity in current databasevoidreplicate(TopiaReplicationDestination topiaReplicationDestination, Object... entityAndCondition) Makes a replication of some entities from this context to the given context without any entity modification.<T extends TopiaEntity>
voidreplicateEntities(TopiaReplicationDestination topiaReplicationDestination, List<T> entities) Makes a replication of some entities from this context to the given context without any entity modification.<T extends TopiaEntity>
voidreplicateEntity(TopiaReplicationDestination topiaReplicationDestination, T entity) Replicate a given entity from this context to the given context.voidrollback()Cancels all the modifications made to this context, coming back to the state when this transaction has been created (usingTopiaApplicationContext.newPersistenceContext()) or previously rollbacked (using the current method).protected voidrollback0(boolean beginAfterRollback) protected voidvoidupdate(TopiaEntity entity) Add into this TopiaContext an entity created by another TopiaContext
-
Field Details
-
daoCache
Already loaded DAO cache within this persistence context -
hibernateTopiaReplicationSupport
-
topiaIdFactory
Used to affect a new topiaId when create is called. -
sessionRegistry
The shared instance of TopiaHibernateSessionRegistry -
firesSupport
Object that handles each event propagation. Listeners are registered inside this instance. -
hibernateSupport
This subclass of TopiaHibernateSupport is made to be used only internally within this persistence context. This instance is created by the persistence context itself. -
jpaSupport
This instance of TopiaJpaSupport is created by the persistence context itself. It is actually using the TopiaHibernateSupport instance. -
sqlSupport
This instance of TopiaSqlSupport is created by the persistence context itself. It is actually using the TopiaHibernateSupport instance. -
closed
protected boolean closedFlog used to check if this persistence context is closed
-
-
Constructor Details
-
AbstractTopiaPersistenceContext
public AbstractTopiaPersistenceContext(AbstractTopiaPersistenceContextConstructorParameter parameter) Creating a new TopiaPersistenceContext is equivalent to creating a new transaction- Parameters:
parameter- everything needed (specific parameter-object)
-
-
Method Details
-
getHibernateSupport
-
getSqlSupport
-
getTopiaIdFactory
Description copied from interface:TopiaPersistenceContextGet the currently configuredTopiaIdFactory.- Specified by:
getTopiaIdFactoryin interfaceTopiaPersistenceContext- Returns:
- the
TopiaIdFactoryin use - See Also:
-
getTopiaFiresSupport
Description copied from interface:TopiaPersistenceContextGet the currently configuredTopiaFiresSupport.- Specified by:
getTopiaFiresSupportin interfaceTopiaPersistenceContext- Returns:
- the
TopiaFiresSupportin use - See Also:
-
startTransaction
- Throws:
TopiaException
-
checkNotClosed
protected void checkNotClosed() -
findByTopiaId
Description copied from interface:TopiaPersistenceContextRetrieveTopiaEntityusing its uniquetopiaId.- Specified by:
findByTopiaIdin interfaceTopiaPersistenceContext- Type Parameters:
E- type of entity- Parameters:
topiaId- unique identifier of the entity in all the application.- Returns:
- the entity found or null
-
update
Description copied from interface:TopiaPersistenceContextAdd into this TopiaContext an entity created by another TopiaContext- Specified by:
updatein interfaceTopiaPersistenceContext- Parameters:
entity- the entity to add
-
delete
Description copied from interface:TopiaPersistenceContextDelete into this TopiaContext an entity created by another TopiaContext- Specified by:
deletein interfaceTopiaPersistenceContext- Parameters:
entity- the entity to delete
-
deleteAll
Description copied from interface:TopiaPersistenceContextDelete into this TopiaContext an entities created by another TopiaContext- Specified by:
deleteAllin interfaceTopiaPersistenceContext- Type Parameters:
E- type of entity- Parameters:
entities- the entities to delete
-
getDao
Description copied from interface:TopiaDaoSupplierGet Dao for specified class. If the specialized Dao exists then it is returned otherwise a TopiaException will be thrown.- Specified by:
getDaoin interfaceTopiaDaoSupplier- Type Parameters:
E- type of entity- Parameters:
entityClass- type of entity- Returns:
- the expected dao
-
getDao
public <E extends TopiaEntity,D extends TopiaDao<E>> D getDao(Class<E> entityClass, Class<D> daoClass) Description copied from interface:TopiaDaoSupplierGet Dao for specified class. If the specialized Dao exists then it is returned otherwise a TopiaException will be thrown.- Specified by:
getDaoin interfaceTopiaDaoSupplier- Type Parameters:
E- type of entityD- type of dao- Parameters:
entityClass- type of entitydaoClass- the concrete dao class to use- Returns:
- the expected dao
-
commit
public void commit()Description copied from interface:TopiaTransactionApplies all the modifications made to this context on the persistence device. Once commit is done, a new internal transaction is started, but you do not have to get a new instance ofTopiaTransaction.- Specified by:
commitin interfaceTopiaTransaction
-
rollback
public void rollback()Description copied from interface:TopiaTransactionCancels all the modifications made to this context, coming back to the state when this transaction has been created (usingTopiaApplicationContext.newPersistenceContext()) or previously rollbacked (using the current method). Once rollback is done, a new internal transaction is started, but you do not have to get a new instance ofTopiaTransaction.- Specified by:
rollbackin interfaceTopiaTransaction
-
rollback0
protected void rollback0(boolean beginAfterRollback) -
isClosed
public boolean isClosed()Description copied from interface:TopiaPersistenceContextTells if the context is closed- Specified by:
isClosedin interfaceTopiaPersistenceContext- Returns:
trueif the context is closed,falseotherwise
-
close
public void close()Description copied from interface:TopiaPersistenceContextCloses the PersistenceContext. After calling close, it's impossible to make any operation on the database.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceTopiaPersistenceContext
-
getHibernateTopiaReplicationSupport
-
replicate
Description copied from interface:TopiaReplicationDestinationMust replicate given entity in current database- Specified by:
replicatein interfaceTopiaReplicationDestination- Parameters:
entity- the remote entity to replicate
-
replicateEntities
public <T extends TopiaEntity> void replicateEntities(TopiaReplicationDestination topiaReplicationDestination, List<T> entities) throws IllegalArgumentException Description copied from interface:TopiaReplicationSupportMakes a replication of some entities from this context to the given context without any entity modification.- Specified by:
replicateEntitiesin interfaceTopiaReplicationSupport- Type Parameters:
T- type of entity- Parameters:
topiaReplicationDestination- the destination contextentities- the list of entities instance to replicate- Throws:
IllegalArgumentException- if one of the context is closed or if trying to replicate within the same database
-
replicateEntity
public <T extends TopiaEntity> void replicateEntity(TopiaReplicationDestination topiaReplicationDestination, T entity) throws IllegalArgumentException Description copied from interface:TopiaReplicationSupportReplicate a given entity from this context to the given context.- Specified by:
replicateEntityin interfaceTopiaReplicationSupport- Type Parameters:
T- type of entity- Parameters:
topiaReplicationDestination- the destination contextentity- the entity instance to replicate- Throws:
IllegalArgumentException- if one of the context is closed or if trying to replicate within the same database
-
replicate
public void replicate(TopiaReplicationDestination topiaReplicationDestination, Object... entityAndCondition) throws IllegalArgumentException Description copied from interface:TopiaReplicationSupportMakes a replication of some entities from this context to the given context without any entity modification. Note: If theentityAndConditionparameter is empty, all the database will be replicated Note 2: The simple replication may not be sufficent. You may want to replicate only a part of some entities : use the methodTopiaReplicationSupport.replicateEntities(TopiaReplicationDestination, java.util.List).- Specified by:
replicatein interfaceTopiaReplicationSupport- Parameters:
topiaReplicationDestination- the destination contextentityAndCondition- [key;value;...] parameter which key is the entity class to replicate, and value the "where" condition to use when querying entities- Throws:
IllegalArgumentException- if one of the context is closed or if trying to replicate within the same database
-