|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.nuiton.topia.framework.TopiaContextImpl
public class TopiaContextImpl
TODO-fdesbois-20100507 : Need translation of javadoc.
Le TopiaContextImpl est le point d'entre pour acceder aux donnees. Il est configurer par un fichier de propriete List des proprietes disponible
| Field Summary | |
|---|---|
protected java.util.Set<TopiaContextImplementor> |
childContext
Set of child context created with beginTransaction(). |
protected boolean |
closed
Indique si le contexte a ete ferme |
protected java.util.Properties |
config
Propriete de configuration |
protected java.util.Map<java.lang.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.cfg.Configuration |
hibernateConfiguration
L'objet configuration utilisé pour la creation de la factory hibernate |
protected org.hibernate.SessionFactory |
hibernateFactory
la factory permettant de recuperer la session hibernate. |
protected TopiaContextImplementor |
parentContext
Le pere de ce context, les contexts initaux n'ont pas de context pere |
protected java.util.List<java.lang.Class<?>> |
persistenceClasses
Liste des classes perssitance |
protected java.util.Map<java.lang.String,TopiaService> |
services
key: service name; value: service instance |
static java.lang.String |
TOPIA_PERSISTENCE_CLASSES
|
static java.lang.String |
TOPIA_PERSISTENCE_DIRECTORIES
|
static java.lang.String |
TOPIA_PERSISTENCE_PROPERTIES_FILE
|
| Constructor Summary | |
|---|---|
protected |
TopiaContextImpl()
Default constructor, useful for tests. |
|
TopiaContextImpl(java.util.Properties config)
Constructor used by TopiaContextFactory to initialize rootContext
using config. |
protected |
TopiaContextImpl(TopiaContextImplementor parentContext)
Constructor used by beginTransaction() to instantiate child from
parentContext. |
| Method Summary | ||
|---|---|---|
void |
add(TopiaEntity e)
Permet d'ajouter dans le TopiaContext une TopiaEntity créé par un autre context. |
|
protected void |
addChildContext(TopiaContextImplementor child)
|
|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
|
|
void |
addTopiaContextListener(TopiaContextListener listener)
|
|
void |
addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable)
|
|
void |
addTopiaEntityListener(java.lang.Class<? extends TopiaEntity> entityClass,
TopiaEntityListener listener)
|
|
void |
addTopiaEntityListener(TopiaEntityListener listener)
|
|
void |
addTopiaEntityVetoable(java.lang.Class<? extends TopiaEntity> entityClass,
TopiaEntityVetoable vetoable)
|
|
void |
addTopiaEntityVetoable(TopiaEntityVetoable vetoable)
|
|
void |
addTopiaTransactionListener(TopiaTransactionListener listener)
|
|
void |
addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable)
|
|
void |
backup(java.io.File file,
boolean compress)
Backup database in gzip compressed file Only work for h2 database |
|
TopiaContext |
beginTransaction()
Return a new context containing his own transaction. |
|
protected java.lang.String[] |
buildQueries(java.lang.Object... entityAndCondition)
Build the list of queries from the given parameter entityAndCondition>/code>. |
|
protected void |
checkClosed(java.lang.String message)
|
|
void |
clear(boolean dropDatabase)
Only h2 supported for now |
|
void |
closeContext()
Ferme le contexte. |
|
void |
commitTransaction()
applique les modifications apporté a ce context sur la base de données. |
|
TopiaQuery |
createQuery(java.lang.Class<?> entityClass,
java.lang.String alias)
Instantiate a new TopiaQuery. |
|
void |
createSchema()
Permet de créer le schema de la base de données. |
|
int |
execute(java.lang.String hql,
java.lang.Object... args)
Execute HQL operation on data (Update, Delete) |
|
void |
exportXML(java.io.Writer xml,
java.lang.Object... entityAndcondition)
Permet d'exporter certaines données en XML. |
|
protected void |
finalize()
Pour le context root on ferme tous les fils, et la factory hibernate |
|
java.util.List<?> |
find(java.lang.String hql,
int startIndex,
int endIndex,
java.lang.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. |
|
java.util.List |
find(java.lang.String hql,
java.lang.Object... args)
Permet de faire une requete HQL hibernate directement sur la base. |
|
java.util.List |
findByQuery(TopiaQuery query)
Retrieve results executing a simple query. |
|
TopiaEntity |
findByTopiaId(java.lang.String id)
Retrieve TopiaEntity using its unique id. |
|
java.util.Collection<TopiaService> |
getAllServices()
|
|
java.util.Set<TopiaContextImplementor> |
getChildContext()
Retrieve a thread-safe copy of children context set. |
|
java.util.Properties |
getConfig()
|
|
|
getDAO(java.lang.Class<E> entityClass)
Get DAO for specified class. |
|
|
getDAO(java.lang.Class<E> entityClass,
java.lang.Class<D> daoClass)
Get DAO for specified class. |
|
TopiaFiresSupport |
getFiresSupport()
|
|
org.hibernate.Session |
getHibernate()
|
|
org.hibernate.cfg.Configuration |
getHibernateConfiguration()
|
|
org.hibernate.SessionFactory |
getHibernateFactory()
|
|
TopiaContextImplementor |
getParentContext()
|
|
java.util.List<java.lang.Class<?>> |
getPersistenceClasses()
|
|
protected java.lang.String |
getProperExceptionMessage(java.lang.Throwable eee)
|
|
TopiaContextImplementor |
getRootContext()
|
|
|
getService(java.lang.Class<E> interfaceService)
Take one service, this service must be valid service interface with public static final SERVICE_NAME declaration. |
|
protected TopiaService |
getService(java.lang.String name)
|
|
protected
|
getServiceName(java.lang.Class<E> interfaceService)
Retrieve service name using SERVICE_NAME static field on service interface. |
|
java.util.Map<java.lang.String,TopiaService> |
getServices()
|
|
void |
importXML(java.io.Reader xml)
Permet d'importer des données en XML. |
|
boolean |
isClosed()
Indique si le contexte a ete ferme. |
|
boolean |
isSchemaExist(java.lang.Class<?> clazz)
Detect if the table is created on storage for a given persistant class. |
|
protected java.util.Map<java.lang.String,TopiaService> |
loadServices(java.util.Properties config)
|
|
protected void |
postInitServices(java.util.Map<java.lang.String,TopiaService> services)
|
|
protected void |
preInitServices(java.util.Map<java.lang.String,TopiaService> services)
|
|
void |
removeChildContext(TopiaContextImplementor child)
|
|
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
|
|
void |
removeTopiaContextListener(TopiaContextListener listener)
|
|
void |
removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable)
|
|
void |
removeTopiaEntityListener(java.lang.Class<? extends TopiaEntity> entityClass,
TopiaEntityListener listener)
|
|
void |
removeTopiaEntityListener(TopiaEntityListener listener)
|
|
void |
removeTopiaEntityVetoable(java.lang.Class<? extends TopiaEntity> entityClass,
TopiaEntityVetoable vetoable)
|
|
void |
removeTopiaEntityVetoable(TopiaEntityVetoable vetoable)
|
|
void |
removeTopiaTransactionListener(TopiaTransactionListener listener)
|
|
void |
removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable)
|
|
void |
replicate(TopiaContext dstCtxt,
java.lang.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,
java.lang.Object... entities)
|
|
|
replicateEntities(TopiaContext dstCtxt,
java.util.List<T> entities)
Permet de dupliquer les entités du type donné vers un autre context. |
|
|
replicateEntity(TopiaContext dstCtxt,
T entity)
Permet de dupliquer une entité du type donné vers un autre context. |
|
void |
restore(java.io.File file)
Read database from gzip compressed file Only work for h2 database |
|
void |
rollbackTransaction()
annule les modifications apporté a ce context. |
|
|
serviceEnabled(java.lang.Class<E> interfaceService)
Return true if specific service is available. |
|
protected boolean |
serviceEnabled(java.lang.String name)
|
|
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. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String TOPIA_PERSISTENCE_DIRECTORIES
public static final java.lang.String TOPIA_PERSISTENCE_CLASSES
public static final java.lang.String TOPIA_PERSISTENCE_PROPERTIES_FILE
protected TopiaContextImplementor parentContext
protected org.hibernate.cfg.Configuration hibernateConfiguration
protected org.hibernate.SessionFactory hibernateFactory
protected org.hibernate.Session hibernate
protected boolean closed
protected java.util.Properties config
protected java.util.Map<java.lang.Class<? extends TopiaEntity>,TopiaDAO<? extends TopiaEntity>> daoCache
protected final java.util.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.
Collections.synchronizedSet(Set),
Collections.newSetFromMap(Map)protected java.util.Map<java.lang.String,TopiaService> services
protected TopiaFiresSupport firesSupport
protected java.util.List<java.lang.Class<?>> persistenceClasses
| Constructor Detail |
|---|
protected TopiaContextImpl()
public TopiaContextImpl(java.util.Properties config)
throws TopiaNotFoundException
TopiaContextFactory to initialize rootContext
using config.
config - for the new root context
TopiaNotFoundException - 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 child| Method Detail |
|---|
protected java.lang.String getProperExceptionMessage(java.lang.Throwable eee)
protected java.util.Map<java.lang.String,TopiaService> loadServices(java.util.Properties config)
protected void preInitServices(java.util.Map<java.lang.String,TopiaService> services)
protected void postInitServices(java.util.Map<java.lang.String,TopiaService> services)
protected TopiaService getService(java.lang.String name)
protected boolean serviceEnabled(java.lang.String name)
protected <E extends TopiaService> java.lang.String getServiceName(java.lang.Class<E> interfaceService)
throws java.lang.IllegalAccessException,
java.lang.NoSuchFieldException
E - type of the service that extends TopiaServiceinterfaceService - class of the service
java.lang.IllegalAccessException - if field SERVICE_NAME can't be accessed
java.lang.NoSuchFieldException - if no field SERVICE_NAME is definedpublic java.util.Map<java.lang.String,TopiaService> getServices()
getServices in interface TopiaContextImplementor
public <E extends TopiaService> E getService(java.lang.Class<E> interfaceService)
throws TopiaNotFoundException
getService in interface TopiaContextE - type of the service that extends TopiaServiceinterfaceService - class of the service
TopiaNotFoundException - if an error appears or service not found.getServiceName(Class)public <E extends TopiaService> boolean serviceEnabled(java.lang.Class<E> interfaceService)
TopiaContext
serviceEnabled in interface TopiaContextE - type of serviceinterfaceService - fqn of the service
public java.util.Collection<TopiaService> getAllServices()
getAllServices in interface TopiaContextImplementorTopiaServicepublic java.util.Set<TopiaContextImplementor> getChildContext()
TopiaContextImplementor
getChildContext 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 java.util.Properties getConfig()
getConfig in interface TopiaContextImplementor
public void createSchema()
throws TopiaException
TopiaContext
createSchema in interface TopiaContextTopiaException - if any exception
public void showCreateSchema()
throws TopiaException
TopiaContext
showCreateSchema in interface TopiaContextTopiaException - if any exception
public void updateSchema()
throws TopiaException
TopiaContext
updateSchema in interface TopiaContextTopiaException - if any exception
public org.hibernate.Session getHibernate()
throws TopiaException
getHibernate in interface TopiaContextImplementorTopiaException - si aucune transaction n'est ouverte
public org.hibernate.SessionFactory getHibernateFactory()
throws TopiaNotFoundException
getHibernateFactory in interface TopiaContextImplementorTopiaNotFoundException
public org.hibernate.cfg.Configuration getHibernateConfiguration()
throws TopiaNotFoundException
getHibernateConfiguration in interface TopiaContextImplementorTopiaNotFoundException
public <E extends TopiaEntity> TopiaDAO<E> getDAO(java.lang.Class<E> entityClass)
throws TopiaException
TopiaContextImplementor
getDAO in interface TopiaContextImplementorTopiaException
public <E extends TopiaEntity,D extends TopiaDAO<E>> D getDAO(java.lang.Class<E> entityClass,
java.lang.Class<D> daoClass)
throws TopiaException
TopiaContextImplementor
getDAO in interface TopiaContextImplementorTopiaException
public TopiaContext beginTransaction()
throws TopiaException
TopiaContext
beginTransaction in interface TopiaContextTopiaException - if any exception
public void commitTransaction()
throws TopiaException
TopiaContext
commitTransaction in interface TopiaContextTopiaException - if any exception
public void rollbackTransaction()
throws TopiaException
TopiaContext
rollbackTransaction in interface TopiaContextTopiaException - if any exception
public void closeContext()
throws TopiaException
TopiaContext
closeContext in interface TopiaContextTopiaException - if any exception
protected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.ThrowableObject.finalize()public boolean isClosed()
TopiaContext
isClosed in interface TopiaContexttrue si le context est ferme, false autrement
protected void checkClosed(java.lang.String message)
throws TopiaException
TopiaException
public TopiaEntity findByTopiaId(java.lang.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 entity
public java.util.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 execute
TopiaException
public TopiaQuery createQuery(java.lang.Class<?> entityClass,
java.lang.String alias)
TopiaContext
createQuery in interface TopiaContextentityClass - main entity class for the Queryalias - alias of the entity in the Query
TopiaQuery
public java.util.List find(java.lang.String hql,
java.lang.Object... args)
throws TopiaException
TopiaContext
find in interface TopiaContexthql - la requete a faireargs - les arguments de la requete
TopiaException - si une erreur survient durant la requete
public java.util.List<?> find(java.lang.String hql,
int startIndex,
int endIndex,
java.lang.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 requete
TopiaException - si une erreur survient durant la requete
public int execute(java.lang.String hql,
java.lang.Object... args)
throws TopiaException
execute in interface TopiaContexthql - HQL queryargs - arguments for query
TopiaException
public void add(TopiaEntity e)
throws TopiaException
TopiaContext
add in interface TopiaContexte - l'entity a ajouter
TopiaException - if any exception
public void importXML(java.io.Reader xml)
throws TopiaException
TopiaContext
importXML in interface TopiaContextxml - le flux XML
TopiaException - si une erreur survient durant l'import
public void exportXML(java.io.Writer xml,
java.lang.Object... entityAndcondition)
throws TopiaException
TopiaContextentityAndCondition est vide,
alors on duplique toutes les entités de la base.
exportXML in interface TopiaContextxml - le flux XML dans lequel il faut ecrireentityAndcondition - 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 survient durant l'export
public void replicate(TopiaContext dstCtxt,
java.lang.Object... entityAndCondition)
throws TopiaException,
java.lang.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 duplication
java.lang.IllegalArgumentException - 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,
java.lang.IllegalArgumentException
TopiaContext
replicateEntity in interface TopiaContextT - le type des entités à répliquerdstCtxt - le context de la base destinationentity - l'entité à répliquer
TopiaException - si une erreur pendant la duplication
java.lang.IllegalArgumentException - 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,
java.util.List<T> entities)
throws TopiaException,
java.lang.IllegalArgumentException
TopiaContext
replicateEntities in interface TopiaContextT - le type des entités à répliquerdstCtxt - le context de la base destinationentities - les entités à répliquer
TopiaException - si une erreur pendant la duplication
java.lang.IllegalArgumentException - 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(java.io.File file,
boolean compress)
throws TopiaException
backup in interface TopiaContextfile - file to write backupcompress - if true then use gzip to compress file
TopiaException - if any exceptionTopiaContext.backup(java.io.File,boolean)
public void restore(java.io.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(java.io.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 java.util.List<java.lang.Class<?>> getPersistenceClasses()
getPersistenceClasses in interface TopiaContextImplementor
public boolean isSchemaExist(java.lang.Class<?> clazz)
throws TopiaException
TopiaContextImplementor
isSchemaExist in interface TopiaContextImplementorclazz - the researched class
TopiaException - si aucune transaction n'est ouvertepublic void addTopiaEntityListener(TopiaEntityListener listener)
addTopiaEntityListener in interface TopiaContext
public void addTopiaEntityListener(java.lang.Class<? extends TopiaEntity> entityClass,
TopiaEntityListener listener)
addTopiaEntityListener in interface TopiaContextpublic void addTopiaEntityVetoable(TopiaEntityVetoable vetoable)
addTopiaEntityVetoable in interface TopiaContext
public void addTopiaEntityVetoable(java.lang.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(java.beans.PropertyChangeListener listener)
addPropertyChangeListener in interface TopiaContextpublic void addTopiaContextListener(TopiaContextListener listener)
addTopiaContextListener in interface TopiaContextpublic void removeTopiaEntityListener(TopiaEntityListener listener)
removeTopiaEntityListener in interface TopiaContext
public void removeTopiaEntityListener(java.lang.Class<? extends TopiaEntity> entityClass,
TopiaEntityListener listener)
removeTopiaEntityListener in interface TopiaContextpublic void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable)
removeTopiaEntityVetoable in interface TopiaContext
public void removeTopiaEntityVetoable(java.lang.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(java.beans.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 TopiaContext
protected java.lang.String[] buildQueries(java.lang.Object... entityAndCondition)
throws TopiaException,
java.lang.IllegalArgumentException
entityAndCondition>/code>.
If no parameter is given, then build the queries for all entities is db,
with no condition.
- Parameters:
entityAndCondition - the list of tuples (Class,String)
- Returns:
- the list of queries.
- Throws:
TopiaException - if any pb of db while getting entities
classes.
java.lang.IllegalArgumentException - if any pb with the given parameter
(mainly ClassCastException).
protected void replicate0(TopiaContextImpl dstContextImpl,
java.lang.Object... entities)
throws TopiaException
TopiaException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||