public class TopiaContextImpl extends Object implements TopiaContextImplementor
Modifier and Type | Class and Description |
---|---|
static class |
TopiaContextImpl.SQLWork |
Modifier and Type | Field and Description |
---|---|
protected Set<TopiaContextImplementor> |
childContext
Set of child context created with
beginTransaction() . |
protected boolean |
closed
Indique si le contexte a ete ferme
|
protected Properties |
config
Propriete de configuration
|
protected Map<Class<? extends TopiaEntity>,TopiaDAO<? extends TopiaEntity>> |
daoCache
cache des DAO deja chargé pour ce context
|
protected TopiaFiresSupport |
firesSupport |
protected org.hibernate.Session |
hibernate
La session utilisé par le TopiaContextImpl
|
protected org.hibernate.SessionFactory |
hibernateFactory
la factory permettant de recuperer la session hibernate.
|
protected org.hibernate.boot.Metadata |
metadata
Proprietes de mapping de la base de données.
|
protected TopiaContextImplementor |
parentContext
Le pere de ce context, les contexts initaux n'ont pas de context pere
|
protected List<Class<?>> |
persistenceClasses
Liste des classes perssitance
|
protected org.hibernate.service.ServiceRegistry |
serviceRegistry
Service registry bootstrap.
|
protected Map<String,TopiaService> |
services
key: service name; value: service instance
|
static String |
TOPIA_PERSISTENCE_CLASSES
Deprecated.
since 2.5.4 use directly
TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES |
static String |
TOPIA_PERSISTENCE_DIRECTORIES
Deprecated.
since 2.5.4 use directly
TopiaContextFactory.CONFIG_PERSISTENCE_DIRECTORIES |
static String |
TOPIA_PERSISTENCE_PROPERTIES_FILE
Deprecated.
since 2.5.4 use directly
TopiaContextFactory.CONFIG_PERSISTENCE_PROPERTIES_FILE |
protected boolean |
useFlushMode
This flag permits to use (or not) the flush mode when doing queries.
|
Modifier | Constructor and Description |
---|---|
protected |
TopiaContextImpl()
Default constructor, useful for tests.
|
|
TopiaContextImpl(Properties config)
Constructor used by
TopiaContextFactory to initialize rootContext
using config . |
protected |
TopiaContextImpl(TopiaContextImplementor parentContext)
Constructor used by
beginTransaction() to instantiate child from
parentContext . |
Modifier and Type | Method and Description |
---|---|
void |
add(TopiaEntity e)
Permet d'ajouter dans le TopiaContext une TopiaEntity créé par un autre
context.
|
protected void |
addChildContext(TopiaContextImplementor child) |
void |
addPropertyChangeListener(PropertyChangeListener listener) |
void |
addTopiaContextListener(TopiaContextListener listener) |
void |
addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) |
void |
addTopiaEntityListener(Class<? extends TopiaEntity> entityClass,
TopiaEntityListener listener) |
void |
addTopiaEntityListener(TopiaEntityListener listener) |
void |
addTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass,
TopiaEntityVetoable vetoable) |
void |
addTopiaEntityVetoable(TopiaEntityVetoable vetoable) |
void |
addTopiaTransactionListener(TopiaTransactionListener listener) |
void |
addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable) |
void |
backup(File file,
boolean compress)
Backup database in gzip compressed file.
|
TopiaContext |
beginTransaction()
Return a new context containing his own transaction.
|
protected String[] |
buildQueries(Object... entityAndCondition)
Build the list of queries from the given parameter
entityAndCondition . |
protected void |
checkClosed(String message) |
void |
clear(boolean dropDatabase)
Only h2 supported for now
|
void |
clearCache()
Clear hibernate cache to free memory.
|
void |
closeContext()
Ferme le contexte.
|
void |
commitTransaction()
applique les modifications apporté a ce context sur la base de données.
|
TopiaQuery |
createQuery(Class<?> entityClass,
String alias)
Instantiate a new TopiaQuery.
|
void |
createSchema()
Permet de créer le schema de la base de données.
|
int |
execute(String hql,
Object... args)
Execute HQL operation on data (Update, Delete)
|
void |
executeSQL(String sqlScript)
Execute a given sql code inside this transaction.
|
protected void |
finalize()
Pour le context root on ferme tous les fils, et la factory hibernate.
|
List<?> |
find(String hql,
int startIndex,
int endIndex,
Object... args)
Permet de faire une requete HQL hibernate directement sur la base en
precisant la fenetre des elements a remonter avec les parametres
startIndex et endIndex . |
List<?> |
findAll(String hql,
Object... args)
Permet de faire une requete HQL hibernate directement sur la base.
|
List<?> |
findByQuery(TopiaQuery query)
Retrieve results executing a simple
query . |
TopiaEntity |
findByTopiaId(String id)
Retrieve
TopiaEntity using its unique id . |
Object |
findUnique(String hql,
Object... paramNamesAndValues)
Allow to do some HQL query and return an unique result.
|
Collection<TopiaService> |
getAllServices() |
Set<TopiaContextImplementor> |
getChildContext()
Retrieve a thread-safe copy of children context set.
|
Properties |
getConfig() |
<E extends TopiaEntity> |
getDAO(Class<E> entityClass)
Get DAO for specified class.
|
<E extends TopiaEntity,D extends TopiaDAO<E>> |
getDAO(Class<E> entityClass,
Class<D> daoClass)
Get DAO for specified class.
|
TopiaFiresSupport |
getFiresSupport() |
org.hibernate.Session |
getHibernate() |
org.hibernate.SessionFactory |
getHibernateFactory() |
org.hibernate.boot.Metadata |
getMetadata()
Proprietes de mapping de la base de données.
|
TopiaContextImplementor |
getParentContext() |
List<Class<?>> |
getPersistenceClasses() |
protected String |
getProperExceptionMessage(Throwable eee) |
TopiaContextImplementor |
getRootContext() |
<E extends TopiaService> |
getService(Class<E> interfaceService)
Take one service, this service must be valid service interface with
public static final SERVICE_NAME declaration.
|
protected TopiaService |
getService(String name) |
protected <E extends TopiaService> |
getServiceName(Class<E> interfaceService)
Retrieve service name using SERVICE_NAME static field on service
interface.
|
org.hibernate.service.ServiceRegistry |
getServiceRegistry()
Service registry bootstrap.
|
Map<String,TopiaService> |
getServices() |
boolean |
isClosed()
Indique si le contexte a ete ferme.
|
boolean |
isSchemaExist(Class<?> clazz)
Detect if the table is created on storage for a given persistant class.
|
protected Map<String,TopiaService> |
loadServices(Properties config) |
protected void |
postInitServices(Map<String,TopiaService> services) |
protected void |
preInitServices(Map<String,TopiaService> services) |
void |
removeChildContext(TopiaContextImplementor child) |
void |
removePropertyChangeListener(PropertyChangeListener listener) |
void |
removeTopiaContextListener(TopiaContextListener listener) |
void |
removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) |
void |
removeTopiaEntityListener(Class<? extends TopiaEntity> entityClass,
TopiaEntityListener listener) |
void |
removeTopiaEntityListener(TopiaEntityListener listener) |
void |
removeTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass,
TopiaEntityVetoable vetoable) |
void |
removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) |
void |
removeTopiaTransactionListener(TopiaTransactionListener listener) |
void |
removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable) |
void |
replicate(TopiaContext dstCtxt,
Object... entityAndCondition)
Permet de dupliquer de ce context vers un context d'une autre base des
données sans modification des entites.
|
protected void |
replicate0(TopiaContextImpl dstContextImpl,
Object... entities) |
<T extends TopiaEntity> |
replicateEntities(TopiaContext dstCtxt,
List<T> entities)
Permet de dupliquer les entités du type donné vers un autre context.
|
<T extends TopiaEntity> |
replicateEntity(TopiaContext dstCtxt,
T entity)
Permet de dupliquer une entité du type donné vers un autre context.
|
void |
restore(File file)
Read database from gzip compressed file
Only work for h2 database
|
void |
rollbackTransaction()
annule les modifications apporté a ce context.
|
<E extends TopiaService> |
serviceEnabled(Class<E> interfaceService)
Return true if specific service is available.
|
protected boolean |
serviceEnabled(String name) |
void |
setUseFlushMode(boolean useFlushMode)
Change the value of flag
useFlushMode . |
void |
showCreateSchema()
Permet d'afficher les requetes SQL de creation de base.
|
void |
updateSchema()
Permet de mettre à jour le schema de la base de données.
|
@Deprecated public static final String TOPIA_PERSISTENCE_DIRECTORIES
TopiaContextFactory.CONFIG_PERSISTENCE_DIRECTORIES
@Deprecated public static final String TOPIA_PERSISTENCE_CLASSES
TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES
@Deprecated public static final String TOPIA_PERSISTENCE_PROPERTIES_FILE
TopiaContextFactory.CONFIG_PERSISTENCE_PROPERTIES_FILE
protected TopiaContextImplementor parentContext
protected org.hibernate.service.ServiceRegistry serviceRegistry
protected org.hibernate.boot.Metadata metadata
protected org.hibernate.SessionFactory hibernateFactory
protected org.hibernate.Session hibernate
protected boolean closed
protected boolean useFlushMode
true
), in that case whebn doing queries (says in method
findAll(String, Object...)
or find(String, int, int, Object...)
)
it will use the flush mode FlushMode.AUTO
).
But sometimes, when doing a lot of queries (for some imports for example),
we do NOT want the session to be flushed each time we do a find, then you
can set this flag to false
using the method setUseFlushMode(boolean)
protected Properties config
protected Map<Class<? extends TopiaEntity>,TopiaDAO<? extends TopiaEntity>> daoCache
protected final Set<TopiaContextImplementor> childContext
beginTransaction()
. We are
listener on these context. A WeakHashMap is used to remove old context
automically when it's not used anymore. The finalize()
method will
be executed when Garbage collector is called when reference is removed.
The set is synchronized in case of using multi-threading.protected Map<String,TopiaService> services
protected TopiaFiresSupport firesSupport
protected TopiaContextImpl()
public TopiaContextImpl(Properties config) throws TopiaNotFoundException
TopiaContextFactory
to initialize rootContext
using config
.config
- for the new root contextTopiaNotFoundException
- if one of persistent class from
configuration is not foundprotected TopiaContextImpl(TopiaContextImplementor parentContext)
beginTransaction()
to instantiate child from
parentContext
.parentContext
- context parent of the new TopiaContext childprotected Map<String,TopiaService> loadServices(Properties config)
protected void preInitServices(Map<String,TopiaService> services)
protected void postInitServices(Map<String,TopiaService> services)
protected TopiaService getService(String name)
protected boolean serviceEnabled(String name)
protected <E extends TopiaService> String getServiceName(Class<E> interfaceService) throws IllegalAccessException, NoSuchFieldException
E
- type of the service that extends TopiaService
interfaceService
- class of the serviceIllegalAccessException
- if field SERVICE_NAME can't be accessedNoSuchFieldException
- if no field SERVICE_NAME is definedpublic Map<String,TopiaService> getServices()
getServices
in interface TopiaContextImplementor
public <E extends TopiaService> E getService(Class<E> interfaceService) throws TopiaNotFoundException
getService
in interface TopiaContext
E
- type of the service that extends TopiaService
interfaceService
- class of the serviceTopiaNotFoundException
- if an error appears or service not found.getServiceName(Class)
public <E extends TopiaService> boolean serviceEnabled(Class<E> interfaceService)
TopiaContext
serviceEnabled
in interface TopiaContext
E
- type of serviceinterfaceService
- fqn of the servicepublic Collection<TopiaService> getAllServices()
getAllServices
in interface TopiaContextImplementor
TopiaService
public Set<TopiaContextImplementor> getChildContext()
TopiaContextImplementor
getChildContext
in interface TopiaContextImplementor
protected void addChildContext(TopiaContextImplementor child)
public void removeChildContext(TopiaContextImplementor child)
removeChildContext
in interface TopiaContextImplementor
public TopiaContextImplementor getParentContext()
getParentContext
in interface TopiaContextImplementor
public TopiaContextImplementor getRootContext()
getRootContext
in interface TopiaContextImplementor
public Properties getConfig()
getConfig
in interface TopiaContextImplementor
public void setUseFlushMode(boolean useFlushMode)
useFlushMode
.setUseFlushMode
in interface TopiaContextImplementor
useFlushMode
- the new value to setuseFlushMode
public void createSchema() throws TopiaException
TopiaContext
createSchema
in interface TopiaContext
TopiaException
- if any exceptionpublic void updateSchema() throws TopiaException
TopiaContext
updateSchema
in interface TopiaContext
TopiaException
- if any exceptionpublic void showCreateSchema() throws TopiaException
TopiaContext
showCreateSchema
in interface TopiaContext
TopiaException
- if any exceptionpublic org.hibernate.Session getHibernate() throws TopiaException
getHibernate
in interface TopiaContextImplementor
TopiaException
- si aucune transaction n'est ouvertepublic org.hibernate.SessionFactory getHibernateFactory() throws TopiaNotFoundException
getHibernateFactory
in interface TopiaContextImplementor
TopiaNotFoundException
public org.hibernate.boot.Metadata getMetadata()
TopiaContextImplementor
getMetadata
in interface TopiaContextImplementor
public org.hibernate.service.ServiceRegistry getServiceRegistry()
TopiaContextImplementor
getServiceRegistry
in interface TopiaContextImplementor
public <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass) throws TopiaException
TopiaContextImplementor
getDAO
in interface TopiaContextImplementor
E
- type of entityentityClass
- type of entityTopiaException
- if any errorpublic <E extends TopiaEntity,D extends TopiaDAO<E>> D getDAO(Class<E> entityClass, Class<D> daoClass) throws TopiaException
TopiaContextImplementor
getDAO
in interface TopiaContextImplementor
E
- type of entityentityClass
- type of entitydaoClass
- the concrete dao class to useTopiaException
- if any errorpublic TopiaContext beginTransaction() throws TopiaException
TopiaContext
beginTransaction
in interface TopiaContext
TopiaException
- if any exceptionpublic void commitTransaction() throws TopiaException
TopiaContext
commitTransaction
in interface TopiaContext
TopiaException
- if any exceptionpublic void rollbackTransaction() throws TopiaException
TopiaContext
rollbackTransaction
in interface TopiaContext
TopiaException
- if any exceptionpublic void closeContext() throws TopiaException
TopiaContext
closeContext
in interface TopiaContext
TopiaException
- if any exceptionprotected void finalize() throws Throwable
public boolean isClosed()
TopiaContext
isClosed
in interface TopiaContext
true
si le context est ferme, false
autrementpublic void executeSQL(String sqlScript) throws TopiaException
TopiaContext
executeSQL
in interface TopiaContext
sqlScript
- the sql script to executeTopiaException
- if any problem occurs while executing the sql script.protected void checkClosed(String message) throws TopiaException
TopiaException
public TopiaEntity findByTopiaId(String id) throws TopiaException
TopiaContext
TopiaEntity
using its unique id
.findByTopiaId
in interface TopiaContext
id
- unique identifier of the entity in all the application.TopiaException
- for errors on retrieving the entitypublic List<?> findByQuery(TopiaQuery query) throws TopiaException
TopiaContext
query
. Generally this method
is used for complex query where output type is specific (more than one
element in the SELECT).findByQuery
in interface TopiaContext
query
- TopiaQuery to executeTopiaException
public TopiaQuery createQuery(Class<?> entityClass, String alias)
TopiaContext
createQuery
in interface TopiaContext
entityClass
- main entity class for the Queryalias
- alias of the entity in the QueryTopiaQuery
public List<?> findAll(String hql, Object... args) throws TopiaException
TopiaContext
findAll
in interface TopiaContext
hql
- la requete a faireargs
- les arguments de la requeteTopiaException
- si une erreur survient durant la requetepublic List<?> find(String hql, int startIndex, int endIndex, Object... args) throws TopiaException
TopiaContext
startIndex
et endIndex
.find
in interface TopiaContext
hql
- la requete a fairestartIndex
- la position du premier element a remonterendIndex
- la position du dernier element a remonterargs
- les arguments de la requeteTopiaException
- si une erreur survient durant la requetepublic Object findUnique(String hql, Object... paramNamesAndValues) throws TopiaException
TopiaContext
findUnique
in interface TopiaContext
hql
- the JPA-QL query to executeparamNamesAndValues
- an array of query parameters based on
[key,value,key,value,...]TopiaException
- for any error during querying or if the the query
returns more than one result.public int execute(String hql, Object... args) throws TopiaException
execute
in interface TopiaContext
hql
- HQL queryargs
- arguments for queryTopiaException
public void add(TopiaEntity e) throws TopiaException
TopiaContext
add
in interface TopiaContext
e
- l'entity a ajouterTopiaException
- if any exceptionpublic void replicate(TopiaContext dstCtxt, Object... entityAndCondition) throws TopiaException, IllegalArgumentException
TopiaContext
entityAndCondition
est vide,
alors on duplique toutes les entités de la base.
Note 2: Il se peut que la replication simple ne soit pas
suffisante (par example si l'on veut repliquer q'une partie d'une
entité), on utilisera donc la seconde méthode TopiaContext.replicateEntities(TopiaContext, List)
.replicate
in interface TopiaContext
dstCtxt
- le context de la base destinationentityAndCondition
- paramètre qui vont par deux, qui represente la
classe de l'entity a exporter et la condition
where que doit respecter l'objet pour etre
exporter (entityClass, condition)TopiaException
- si une erreur pendant la duplicationIllegalArgumentException
- si l'un des context n'est pas ouvert, ou
si on essaye de dupliquer dans la même
base.public <T extends TopiaEntity> void replicateEntity(TopiaContext dstCtxt, T entity) throws TopiaException, IllegalArgumentException
TopiaContext
replicateEntity
in interface TopiaContext
T
- le type des entités à répliquerdstCtxt
- le context de la base destinationentity
- l'entité à répliquerTopiaException
- si une erreur pendant la duplicationIllegalArgumentException
- si l'un des context n'est pas ouvert, ou
si on essaye de dupliquer dans la même
base.public <T extends TopiaEntity> void replicateEntities(TopiaContext dstCtxt, List<T> entities) throws TopiaException, IllegalArgumentException
TopiaContext
replicateEntities
in interface TopiaContext
T
- le type des entités à répliquerdstCtxt
- le context de la base destinationentities
- les entités à répliquerTopiaException
- si une erreur pendant la duplicationIllegalArgumentException
- si l'un des context n'est pas ouvert, ou
si on essaye de dupliquer dans la même
base.public TopiaFiresSupport getFiresSupport()
getFiresSupport
in interface TopiaContextImplementor
public void backup(File file, boolean compress) throws TopiaException
backup
in interface TopiaContext
file
- file to write backupcompress
- if true then use gzip to compress fileTopiaException
- if any exceptionTopiaContext.backup(File,boolean)
public void restore(File file) throws TopiaException
restore
in interface TopiaContext
file
- le fichier ou prendre les informations, il peut-etre
compressé avec gzip ou non.TopiaException
- if any exceptionTopiaContext.restore(File)
public void clear(boolean dropDatabase) throws TopiaException
clear
in interface TopiaContext
dropDatabase
- si vrai alors supprime aussi la base de données si la
base utilise des fichiers les fichiers seront
supprimé (ex: h2) ou sera fait sur la base
(postgresql)TopiaException
- if any exceptionTopiaContext.clear(boolean)
public void clearCache() throws TopiaException
clearCache
in interface TopiaContext
TopiaException
public List<Class<?>> getPersistenceClasses()
getPersistenceClasses
in interface TopiaContextImplementor
public boolean isSchemaExist(Class<?> clazz) throws TopiaException
TopiaContextImplementor
isSchemaExist
in interface TopiaContextImplementor
clazz
- the researched classTopiaException
- si aucune transaction n'est ouvertepublic void addTopiaEntityListener(TopiaEntityListener listener)
addTopiaEntityListener
in interface TopiaContext
public void addTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener)
addTopiaEntityListener
in interface TopiaContext
public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable)
addTopiaEntityVetoable
in interface TopiaContext
public void addTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable)
addTopiaEntityVetoable
in interface TopiaContext
public void addTopiaTransactionListener(TopiaTransactionListener listener)
addTopiaTransactionListener
in interface TopiaContext
public void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable)
addTopiaTransactionVetoable
in interface TopiaContext
public void addPropertyChangeListener(PropertyChangeListener listener)
addPropertyChangeListener
in interface TopiaContext
public void addTopiaContextListener(TopiaContextListener listener)
addTopiaContextListener
in interface TopiaContext
public void removeTopiaEntityListener(TopiaEntityListener listener)
removeTopiaEntityListener
in interface TopiaContext
public void removeTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener)
removeTopiaEntityListener
in interface TopiaContext
public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable)
removeTopiaEntityVetoable
in interface TopiaContext
public void removeTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable)
removeTopiaEntityVetoable
in interface TopiaContext
public void removeTopiaTransactionListener(TopiaTransactionListener listener)
removeTopiaTransactionListener
in interface TopiaContext
public void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable)
removeTopiaTransactionVetoable
in interface TopiaContext
public void removePropertyChangeListener(PropertyChangeListener listener)
removePropertyChangeListener
in interface TopiaContext
public void removeTopiaContextListener(TopiaContextListener listener)
removeTopiaContextListener
in interface TopiaContext
public void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable)
addTopiaEntitiesVetoable
in interface TopiaContext
public void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable)
removeTopiaEntitiesVetoable
in interface TopiaContext
protected String[] buildQueries(Object... entityAndCondition) throws TopiaException, IllegalArgumentException
entityAndCondition
.
If no parameter is given, then build the queries for all entities is db,
with no condition.entityAndCondition
- the list of tuples (Class,String)TopiaException
- if any pb of db while getting entities
classes.IllegalArgumentException
- if any pb with the given parameter
(mainly ClassCastException).protected void replicate0(TopiaContextImpl dstContextImpl, Object... entities) throws TopiaException
TopiaException
Copyright © 2004–2022 Code Lutin. All rights reserved.