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_FILEprotected 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 TopiaServiceinterfaceService - 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 TopiaContextImplementorpublic <E extends TopiaService> E getService(Class<E> interfaceService) throws TopiaNotFoundException
getService in interface TopiaContextE - type of the service that extends TopiaServiceinterfaceService - class of the serviceTopiaNotFoundException - if an error appears or service not found.getServiceName(Class)public <E extends TopiaService> boolean serviceEnabled(Class<E> interfaceService)
TopiaContextserviceEnabled in interface TopiaContextE - type of serviceinterfaceService - fqn of the servicepublic Collection<TopiaService> getAllServices()
getAllServices in interface TopiaContextImplementorTopiaServicepublic Set<TopiaContextImplementor> getChildContext()
TopiaContextImplementorgetChildContext in interface TopiaContextImplementorprotected void addChildContext(TopiaContextImplementor child)
public void removeChildContext(TopiaContextImplementor child)
removeChildContext in interface TopiaContextImplementorpublic TopiaContextImplementor getParentContext()
getParentContext in interface TopiaContextImplementorpublic TopiaContextImplementor getRootContext()
getRootContext in interface TopiaContextImplementorpublic Properties getConfig()
getConfig in interface TopiaContextImplementorpublic void setUseFlushMode(boolean useFlushMode)
useFlushMode.setUseFlushMode in interface TopiaContextImplementoruseFlushMode - the new value to setuseFlushModepublic void createSchema()
throws TopiaException
TopiaContextcreateSchema in interface TopiaContextTopiaException - if any exceptionpublic void updateSchema()
throws TopiaException
TopiaContextupdateSchema in interface TopiaContextTopiaException - if any exceptionpublic void showCreateSchema()
throws TopiaException
TopiaContextshowCreateSchema in interface TopiaContextTopiaException - if any exceptionpublic org.hibernate.Session getHibernate()
throws TopiaException
getHibernate in interface TopiaContextImplementorTopiaException - si aucune transaction n'est ouvertepublic org.hibernate.SessionFactory getHibernateFactory()
throws TopiaNotFoundException
getHibernateFactory in interface TopiaContextImplementorTopiaNotFoundExceptionpublic org.hibernate.boot.Metadata getMetadata()
TopiaContextImplementorgetMetadata in interface TopiaContextImplementorpublic org.hibernate.service.ServiceRegistry getServiceRegistry()
TopiaContextImplementorgetServiceRegistry in interface TopiaContextImplementorpublic <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass) throws TopiaException
TopiaContextImplementorgetDAO in interface TopiaContextImplementorE - 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
TopiaContextImplementorgetDAO in interface TopiaContextImplementorE - type of entityentityClass - type of entitydaoClass - the concrete dao class to useTopiaException - if any errorpublic TopiaContext beginTransaction() throws TopiaException
TopiaContextbeginTransaction in interface TopiaContextTopiaException - if any exceptionpublic void commitTransaction()
throws TopiaException
TopiaContextcommitTransaction in interface TopiaContextTopiaException - if any exceptionpublic void rollbackTransaction()
throws TopiaException
TopiaContextrollbackTransaction in interface TopiaContextTopiaException - if any exceptionpublic void closeContext()
throws TopiaException
TopiaContextcloseContext in interface TopiaContextTopiaException - if any exceptionprotected void finalize()
throws Throwable
public boolean isClosed()
TopiaContextisClosed in interface TopiaContexttrue si le context est ferme, false autrementpublic void executeSQL(String sqlScript) throws TopiaException
TopiaContextexecuteSQL in interface TopiaContextsqlScript - the sql script to executeTopiaException - if any problem occurs while executing the sql script.protected void checkClosed(String message) throws TopiaException
TopiaExceptionpublic TopiaEntity findByTopiaId(String id) throws TopiaException
TopiaContextTopiaEntity using its unique id.findByTopiaId in interface TopiaContextid - unique identifier of the entity in all the application.TopiaException - for errors on retrieving the entitypublic List<?> findByQuery(TopiaQuery query) throws TopiaException
TopiaContextquery. Generally this method
is used for complex query where output type is specific (more than one
element in the SELECT).findByQuery in interface TopiaContextquery - TopiaQuery to executeTopiaExceptionpublic TopiaQuery createQuery(Class<?> entityClass, String alias)
TopiaContextcreateQuery in interface TopiaContextentityClass - main entity class for the Queryalias - alias of the entity in the QueryTopiaQuerypublic List<?> findAll(String hql, Object... args) throws TopiaException
TopiaContextfindAll in interface TopiaContexthql - 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
TopiaContextstartIndex et endIndex.find in interface TopiaContexthql - 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
TopiaContextfindUnique in interface TopiaContexthql - 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 TopiaContexthql - HQL queryargs - arguments for queryTopiaExceptionpublic void add(TopiaEntity e) throws TopiaException
TopiaContextadd in interface TopiaContexte - l'entity a ajouterTopiaException - if any exceptionpublic void replicate(TopiaContext dstCtxt, Object... entityAndCondition) throws TopiaException, IllegalArgumentException
TopiaContextentityAndCondition 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 TopiaContextdstCtxt - 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
TopiaContextreplicateEntity in interface TopiaContextT - 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
TopiaContextreplicateEntities in interface TopiaContextT - 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 TopiaContextImplementorpublic void backup(File file, boolean compress) throws TopiaException
backup in interface TopiaContextfile - 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 TopiaContextfile - 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 TopiaContextdropDatabase - 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 TopiaContextTopiaExceptionpublic List<Class<?>> getPersistenceClasses()
getPersistenceClasses in interface TopiaContextImplementorpublic boolean isSchemaExist(Class<?> clazz) throws TopiaException
TopiaContextImplementorisSchemaExist in interface TopiaContextImplementorclazz - the researched classTopiaException - si aucune transaction n'est ouvertepublic void addTopiaEntityListener(TopiaEntityListener listener)
addTopiaEntityListener in interface TopiaContextpublic void addTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener)
addTopiaEntityListener in interface TopiaContextpublic void addTopiaEntityVetoable(TopiaEntityVetoable vetoable)
addTopiaEntityVetoable in interface TopiaContextpublic void addTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable)
addTopiaEntityVetoable in interface TopiaContextpublic void addTopiaTransactionListener(TopiaTransactionListener listener)
addTopiaTransactionListener in interface TopiaContextpublic void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable)
addTopiaTransactionVetoable in interface TopiaContextpublic void addPropertyChangeListener(PropertyChangeListener listener)
addPropertyChangeListener in interface TopiaContextpublic void addTopiaContextListener(TopiaContextListener listener)
addTopiaContextListener in interface TopiaContextpublic void removeTopiaEntityListener(TopiaEntityListener listener)
removeTopiaEntityListener in interface TopiaContextpublic void removeTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener)
removeTopiaEntityListener in interface TopiaContextpublic void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable)
removeTopiaEntityVetoable in interface TopiaContextpublic void removeTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable)
removeTopiaEntityVetoable in interface TopiaContextpublic void removeTopiaTransactionListener(TopiaTransactionListener listener)
removeTopiaTransactionListener in interface TopiaContextpublic void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable)
removeTopiaTransactionVetoable in interface TopiaContextpublic void removePropertyChangeListener(PropertyChangeListener listener)
removePropertyChangeListener in interface TopiaContextpublic void removeTopiaContextListener(TopiaContextListener listener)
removeTopiaContextListener in interface TopiaContextpublic void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable)
addTopiaEntitiesVetoable in interface TopiaContextpublic void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable)
removeTopiaEntitiesVetoable in interface TopiaContextprotected 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
TopiaExceptionCopyright © 2004–2022 Code Lutin. All rights reserved.