org.nuiton.topia.framework
Class TopiaContextImpl

java.lang.Object
  extended by org.nuiton.topia.framework.TopiaContextImpl
All Implemented Interfaces:
TopiaContextImplementor, TopiaContext

public class TopiaContextImpl
extends Object
implements TopiaContextImplementor

Le TopiaContextImpl est le point d'entre pour acceder aux donnees. Il est configurer par un fichier de propriete

List des proprietes disponible

topia.persistence.properties.file
le fichier de propriété a utiliser pour configurer hibernate

topia.persistence.directories
la liste des repertoires contenant les mappings hibernates (.hbm.xml) la liste de repertoire est separer par des virgules ','

topia.persistence.classes
la liste des classes que doit géré hibernate. On peut tres bien utiliser topia.persistence.directories pour un ensemble d'entié du meme repertoire et topia.persistence.classes pour d'autres classes

TopiaContextImpl.java

Created: 23 déc. 2005 16:58:50

Version:
$Id: TopiaContextImpl.java 2196 2011-02-02 15:04:48Z tchemit $
Author:
poussin , tchemit , fdesbois

Field Summary
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.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  List<Class<?>> persistenceClasses
          Liste des classes perssitance
protected  Map<String,TopiaService> services
          key: service name; value: service instance
static String TOPIA_PERSISTENCE_CLASSES
           
static String TOPIA_PERSISTENCE_DIRECTORIES
           
static String TOPIA_PERSISTENCE_PROPERTIES_FILE
           
protected  boolean useFlushMode
          This flag permits to use (or not) the flush mode when doing queries.
 
Constructor Summary
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.
 
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(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>/code>.
protected  void checkClosed(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(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 exportXML(Writer xml, 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.
 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 find(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.
 Collection<TopiaService> getAllServices()
           
 Set<TopiaContextImplementor> getChildContext()
          Retrieve a thread-safe copy of children context set.
 Properties getConfig()
           
<E extends TopiaEntity>
TopiaDAO<E>
getDAO(Class<E> entityClass)
          Get DAO for specified class.
<E extends TopiaEntity,D extends TopiaDAO<E>>
D
getDAO(Class<E> entityClass, 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()
           
 List<Class<?>> getPersistenceClasses()
           
protected  String getProperExceptionMessage(Throwable eee)
           
 TopiaContextImplementor getRootContext()
           
<E extends TopiaService>
E
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>
String
getServiceName(Class<E> interfaceService)
          Retrieve service name using SERVICE_NAME static field on service interface.
 Map<String,TopiaService> getServices()
           
 void importXML(Reader xml)
          Permet d'importer des données en XML.
 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>
void
replicateEntities(TopiaContext dstCtxt, List<T> entities)
          Permet de dupliquer les entités du type donné vers un autre context.
<T extends TopiaEntity>
void
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>
boolean
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.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOPIA_PERSISTENCE_DIRECTORIES

public static final String TOPIA_PERSISTENCE_DIRECTORIES
See Also:
Constant Field Values

TOPIA_PERSISTENCE_CLASSES

public static final String TOPIA_PERSISTENCE_CLASSES
See Also:
Constant Field Values

TOPIA_PERSISTENCE_PROPERTIES_FILE

public static final String TOPIA_PERSISTENCE_PROPERTIES_FILE
See Also:
Constant Field Values

parentContext

protected TopiaContextImplementor parentContext
Le pere de ce context, les contexts initaux n'ont pas de context pere


hibernateConfiguration

protected org.hibernate.cfg.Configuration hibernateConfiguration
L'objet configuration utilisé pour la creation de la factory hibernate


hibernateFactory

protected org.hibernate.SessionFactory hibernateFactory
la factory permettant de recuperer la session hibernate. Seul les TopiaContextImpl initiaux contiennent un hibernateFactory


hibernate

protected org.hibernate.Session hibernate
La session utilisé par le TopiaContextImpl


closed

protected boolean closed
Indique si le contexte a ete ferme


useFlushMode

protected boolean useFlushMode
This flag permits to use (or not) the flush mode when doing queries. The normal usage is to says yes (that's why the default value is true), in that case whebn doing queries (says in method find(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)

Since:
2.5

config

protected Properties config
Propriete de configuration


daoCache

protected Map<Class<? extends TopiaEntity>,TopiaDAO<? extends TopiaEntity>> daoCache
cache des DAO deja chargé pour ce context


childContext

protected final Set<TopiaContextImplementor> childContext
Set of child context created with 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.

See Also:
Collections.synchronizedSet(Set), Collections.newSetFromMap(Map)

services

protected Map<String,TopiaService> services
key: service name; value: service instance


firesSupport

protected TopiaFiresSupport firesSupport

persistenceClasses

protected List<Class<?>> persistenceClasses
Liste des classes perssitance

Constructor Detail

TopiaContextImpl

protected TopiaContextImpl()
Default constructor, useful for tests.


TopiaContextImpl

public TopiaContextImpl(Properties config)
                 throws TopiaNotFoundException
Constructor used by TopiaContextFactory to initialize rootContext using config.

Parameters:
config - for the new root context
Throws:
TopiaNotFoundException - if one of persistent class from configuration is not found

TopiaContextImpl

protected TopiaContextImpl(TopiaContextImplementor parentContext)
Constructor used by beginTransaction() to instantiate child from parentContext.

Parameters:
parentContext - context parent of the new TopiaContext child
Method Detail

getProperExceptionMessage

protected String getProperExceptionMessage(Throwable eee)

loadServices

protected Map<String,TopiaService> loadServices(Properties config)

preInitServices

protected void preInitServices(Map<String,TopiaService> services)

postInitServices

protected void postInitServices(Map<String,TopiaService> services)

getService

protected TopiaService getService(String name)

serviceEnabled

protected boolean serviceEnabled(String name)

getServiceName

protected <E extends TopiaService> String getServiceName(Class<E> interfaceService)
                         throws IllegalAccessException,
                                NoSuchFieldException
Retrieve service name using SERVICE_NAME static field on service interface.

Type Parameters:
E - type of the service that extends TopiaService
Parameters:
interfaceService - class of the service
Returns:
the service name
Throws:
IllegalAccessException - if field SERVICE_NAME can't be accessed
NoSuchFieldException - if no field SERVICE_NAME is defined

getServices

public Map<String,TopiaService> getServices()
Specified by:
getServices in interface TopiaContextImplementor

getService

public <E extends TopiaService> E getService(Class<E> interfaceService)
                                  throws TopiaNotFoundException
Take one service, this service must be valid service interface with public static final SERVICE_NAME declaration.

Specified by:
getService in interface TopiaContext
Type Parameters:
E - type of the service that extends TopiaService
Parameters:
interfaceService - class of the service
Returns:
the service
Throws:
TopiaNotFoundException - if an error appears or service not found.
See Also:
getServiceName(Class)

serviceEnabled

public <E extends TopiaService> boolean serviceEnabled(Class<E> interfaceService)
Description copied from interface: TopiaContext
Return true if specific service is available.

Specified by:
serviceEnabled in interface TopiaContext
Type Parameters:
E - type of service
Parameters:
interfaceService - fqn of the service
Returns:
the service

getAllServices

public Collection<TopiaService> getAllServices()
Specified by:
getAllServices in interface TopiaContextImplementor
Returns:
a collection of TopiaService

getChildContext

public Set<TopiaContextImplementor> getChildContext()
Description copied from interface: TopiaContextImplementor
Retrieve a thread-safe copy of children context set.

Specified by:
getChildContext in interface TopiaContextImplementor
Returns:
Returns the childContext.

addChildContext

protected void addChildContext(TopiaContextImplementor child)

removeChildContext

public void removeChildContext(TopiaContextImplementor child)
Specified by:
removeChildContext in interface TopiaContextImplementor

getParentContext

public TopiaContextImplementor getParentContext()
Specified by:
getParentContext in interface TopiaContextImplementor
Returns:
Returns the parentContext.

getRootContext

public TopiaContextImplementor getRootContext()
Specified by:
getRootContext in interface TopiaContextImplementor

getConfig

public Properties getConfig()
Specified by:
getConfig in interface TopiaContextImplementor
Returns:
Returns the config.

setUseFlushMode

public void setUseFlushMode(boolean useFlushMode)
Change the value of flag useFlushMode.

Specified by:
setUseFlushMode in interface TopiaContextImplementor
Parameters:
useFlushMode - the new value to set
Since:
2.5
See Also:
useFlushMode

createSchema

public void createSchema()
                  throws TopiaException
Description copied from interface: TopiaContext
Permet de créer le schema de la base de données.

Specified by:
createSchema in interface TopiaContext
Throws:
TopiaException - if any exception

showCreateSchema

public void showCreateSchema()
                      throws TopiaException
Description copied from interface: TopiaContext
Permet d'afficher les requetes SQL de creation de base.

Specified by:
showCreateSchema in interface TopiaContext
Throws:
TopiaException - if any exception

updateSchema

public void updateSchema()
                  throws TopiaException
Description copied from interface: TopiaContext
Permet de mettre à jour le schema de la base de données.

Specified by:
updateSchema in interface TopiaContext
Throws:
TopiaException - if any exception

getHibernate

public org.hibernate.Session getHibernate()
                                   throws TopiaException
Specified by:
getHibernate in interface TopiaContextImplementor
Returns:
Returns the hibernate.
Throws:
TopiaException - si aucune transaction n'est ouverte

getHibernateFactory

public org.hibernate.SessionFactory getHibernateFactory()
                                                 throws TopiaNotFoundException
Specified by:
getHibernateFactory in interface TopiaContextImplementor
Returns:
Returns the hibernateFactory.
Throws:
TopiaNotFoundException

getHibernateConfiguration

public org.hibernate.cfg.Configuration getHibernateConfiguration()
                                                          throws TopiaNotFoundException
Specified by:
getHibernateConfiguration in interface TopiaContextImplementor
Returns:
Returns the hibernate configuration
Throws:
TopiaNotFoundException

getDAO

public <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass)
                                       throws TopiaException
Description copied from interface: TopiaContextImplementor
Get DAO for specified class. If Specialized DAO exists then it returned otherwize TopiaDAO<entityClass> is returned

Specified by:
getDAO in interface TopiaContextImplementor
Type Parameters:
E - type of entity
Parameters:
entityClass - type of entity
Returns:
the required dao
Throws:
TopiaException - if any error

getDAO

public <E extends TopiaEntity,D extends TopiaDAO<E>> D getDAO(Class<E> entityClass,
                                                              Class<D> daoClass)
                             throws TopiaException
Description copied from interface: TopiaContextImplementor
Get DAO for specified class. If Specialized DAO exists then it returned otherwize TopiaDAO<entityClass> is returned

Specified by:
getDAO in interface TopiaContextImplementor
Type Parameters:
E - type of entity
Parameters:
entityClass - type of entity
daoClass - the concrete dao class to use
Returns:
the required dao
Throws:
TopiaException - if any error

beginTransaction

public TopiaContext beginTransaction()
                              throws TopiaException
Description copied from interface: TopiaContext
Return a new context containing his own transaction.

Specified by:
beginTransaction in interface TopiaContext
Returns:
new context with transaction
Throws:
TopiaException - if any exception

commitTransaction

public void commitTransaction()
                       throws TopiaException
Description copied from interface: TopiaContext
applique les modifications apporté a ce context sur la base de données.

Specified by:
commitTransaction in interface TopiaContext
Throws:
TopiaException - if any exception

rollbackTransaction

public void rollbackTransaction()
                         throws TopiaException
Description copied from interface: TopiaContext
annule les modifications apporté a ce context.

Specified by:
rollbackTransaction in interface TopiaContext
Throws:
TopiaException - if any exception

closeContext

public void closeContext()
                  throws TopiaException
Description copied from interface: TopiaContext
Ferme le contexte.

Specified by:
closeContext in interface TopiaContext
Throws:
TopiaException - if any exception

finalize

protected void finalize()
                 throws Throwable
Pour le context root on ferme tous les fils, et la factory hibernate.

Overrides:
finalize in class Object
Throws:
Throwable

isClosed

public boolean isClosed()
Description copied from interface: TopiaContext
Indique si le contexte a ete ferme.

Specified by:
isClosed in interface TopiaContext
Returns:
true si le context est ferme, false autrement

checkClosed

protected void checkClosed(String message)
                    throws TopiaException
Throws:
TopiaException

findByTopiaId

public TopiaEntity findByTopiaId(String id)
                          throws TopiaException
Description copied from interface: TopiaContext
Retrieve TopiaEntity using its unique id.

Specified by:
findByTopiaId in interface TopiaContext
Parameters:
id - unique identifier of the entity in all the application.
Returns:
the entity found or null if not
Throws:
TopiaException - for errors on retrieving the entity

findByQuery

public List findByQuery(TopiaQuery query)
                 throws TopiaException
Description copied from interface: TopiaContext
Retrieve results executing a simple query. Generally this method is used for complex query where output type is specific (more than one element in the SELECT).

Specified by:
findByQuery in interface TopiaContext
Parameters:
query - TopiaQuery to execute
Returns:
a List of results as hibernate give us
Throws:
TopiaException

createQuery

public TopiaQuery createQuery(Class<?> entityClass,
                              String alias)
Description copied from interface: TopiaContext
Instantiate a new TopiaQuery.

Specified by:
createQuery in interface TopiaContext
Parameters:
entityClass - main entity class for the Query
alias - alias of the entity in the Query
Returns:
a new TopiaQuery
See Also:
TopiaQuery

find

public List find(String hql,
                 Object... args)
          throws TopiaException
Description copied from interface: TopiaContext
Permet de faire une requete HQL hibernate directement sur la base.

Specified by:
find in interface TopiaContext
Parameters:
hql - la requete a faire
args - les arguments de la requete
Returns:
La liste des resultats
Throws:
TopiaException - si une erreur survient durant la requete

find

public List<?> find(String hql,
                    int startIndex,
                    int endIndex,
                    Object... args)
             throws TopiaException
Description copied from interface: TopiaContext
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.

Specified by:
find in interface TopiaContext
Parameters:
hql - la requete a faire
startIndex - la position du premier element a remonter
endIndex - la position du dernier element a remonter
args - les arguments de la requete
Returns:
La liste des resultats
Throws:
TopiaException - si une erreur survient durant la requete

execute

public int execute(String hql,
                   Object... args)
            throws TopiaException
Execute HQL operation on data (Update, Delete)

Specified by:
execute in interface TopiaContext
Parameters:
hql - HQL query
args - arguments for query
Returns:
The number of entities updated or deleted.
Throws:
TopiaException

add

public void add(TopiaEntity e)
         throws TopiaException
Description copied from interface: TopiaContext
Permet d'ajouter dans le TopiaContext une TopiaEntity créé par un autre context.

Specified by:
add in interface TopiaContext
Parameters:
e - l'entity a ajouter
Throws:
TopiaException - if any exception

importXML

public void importXML(Reader xml)
               throws TopiaException
Description copied from interface: TopiaContext
Permet d'importer des données en XML.

Specified by:
importXML in interface TopiaContext
Parameters:
xml - le flux XML
Throws:
TopiaException - si une erreur survient durant l'import

exportXML

public void exportXML(Writer xml,
                      Object... entityAndcondition)
               throws TopiaException
Description copied from interface: TopiaContext
Permet d'exporter certaines données en XML.

Note: Si le parametre entityAndCondition est vide, alors on duplique toutes les entités de la base.

Specified by:
exportXML in interface TopiaContext
Parameters:
xml - le flux XML dans lequel il faut ecrire
entityAndcondition - 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)
Throws:
TopiaException - si une erreur survient durant l'export

replicate

public void replicate(TopiaContext dstCtxt,
                      Object... entityAndCondition)
               throws TopiaException,
                      IllegalArgumentException
Description copied from interface: TopiaContext
Permet de dupliquer de ce context vers un context d'une autre base des données sans modification des entites.

Note: Si le parametre 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).

Specified by:
replicate in interface TopiaContext
Parameters:
dstCtxt - le context de la base destination
entityAndCondition - 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)
Throws:
TopiaException - si une erreur pendant la duplication
IllegalArgumentException - si l'un des context n'est pas ouvert, ou si on essaye de dupliquer dans la même base.

replicateEntity

public <T extends TopiaEntity> void replicateEntity(TopiaContext dstCtxt,
                                                    T entity)
                     throws TopiaException,
                            IllegalArgumentException
Description copied from interface: TopiaContext
Permet de dupliquer une entité du type donné vers un autre context.

Specified by:
replicateEntity in interface TopiaContext
Type Parameters:
T - le type des entités à répliquer
Parameters:
dstCtxt - le context de la base destination
entity - l'entité à répliquer
Throws:
TopiaException - si une erreur pendant la duplication
IllegalArgumentException - si l'un des context n'est pas ouvert, ou si on essaye de dupliquer dans la même base.

replicateEntities

public <T extends TopiaEntity> void replicateEntities(TopiaContext dstCtxt,
                                                      List<T> entities)
                       throws TopiaException,
                              IllegalArgumentException
Description copied from interface: TopiaContext
Permet de dupliquer les entités du type donné vers un autre context.

Specified by:
replicateEntities in interface TopiaContext
Type Parameters:
T - le type des entités à répliquer
Parameters:
dstCtxt - le context de la base destination
entities - les entités à répliquer
Throws:
TopiaException - si une erreur pendant la duplication
IllegalArgumentException - si l'un des context n'est pas ouvert, ou si on essaye de dupliquer dans la même base.

getFiresSupport

public TopiaFiresSupport getFiresSupport()
Specified by:
getFiresSupport in interface TopiaContextImplementor

backup

public void backup(File file,
                   boolean compress)
            throws TopiaException
Backup database in gzip compressed file. Note: Only works for h2 database.

Specified by:
backup in interface TopiaContext
Parameters:
file - file to write backup
compress - if true then use gzip to compress file
Throws:
TopiaException - if any exception
See Also:
TopiaContext.backup(File,boolean)

restore

public void restore(File file)
             throws TopiaException
Read database from gzip compressed file

Only work for h2 database

Specified by:
restore in interface TopiaContext
Parameters:
file - le fichier ou prendre les informations, il peut-etre compressé avec gzip ou non.
Throws:
TopiaException - if any exception
See Also:
TopiaContext.restore(File)

clear

public void clear(boolean dropDatabase)
           throws TopiaException
Only h2 supported for now

Specified by:
clear in interface TopiaContext
Parameters:
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)
Throws:
TopiaException - if any exception
See Also:
TopiaContext.clear(boolean)

getPersistenceClasses

public List<Class<?>> getPersistenceClasses()
Specified by:
getPersistenceClasses in interface TopiaContextImplementor

isSchemaExist

public boolean isSchemaExist(Class<?> clazz)
                      throws TopiaException
Description copied from interface: TopiaContextImplementor
Detect if the table is created on storage for a given persistant class.

Specified by:
isSchemaExist in interface TopiaContextImplementor
Parameters:
clazz - the researched class
Returns:
Returns the hibernate.
Throws:
TopiaException - si aucune transaction n'est ouverte

addTopiaEntityListener

public void addTopiaEntityListener(TopiaEntityListener listener)
Specified by:
addTopiaEntityListener in interface TopiaContext

addTopiaEntityListener

public void addTopiaEntityListener(Class<? extends TopiaEntity> entityClass,
                                   TopiaEntityListener listener)
Specified by:
addTopiaEntityListener in interface TopiaContext

addTopiaEntityVetoable

public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable)
Specified by:
addTopiaEntityVetoable in interface TopiaContext

addTopiaEntityVetoable

public void addTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass,
                                   TopiaEntityVetoable vetoable)
Specified by:
addTopiaEntityVetoable in interface TopiaContext

addTopiaTransactionListener

public void addTopiaTransactionListener(TopiaTransactionListener listener)
Specified by:
addTopiaTransactionListener in interface TopiaContext

addTopiaTransactionVetoable

public void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable)
Specified by:
addTopiaTransactionVetoable in interface TopiaContext

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Specified by:
addPropertyChangeListener in interface TopiaContext

addTopiaContextListener

public void addTopiaContextListener(TopiaContextListener listener)
Specified by:
addTopiaContextListener in interface TopiaContext

removeTopiaEntityListener

public void removeTopiaEntityListener(TopiaEntityListener listener)
Specified by:
removeTopiaEntityListener in interface TopiaContext

removeTopiaEntityListener

public void removeTopiaEntityListener(Class<? extends TopiaEntity> entityClass,
                                      TopiaEntityListener listener)
Specified by:
removeTopiaEntityListener in interface TopiaContext

removeTopiaEntityVetoable

public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable)
Specified by:
removeTopiaEntityVetoable in interface TopiaContext

removeTopiaEntityVetoable

public void removeTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass,
                                      TopiaEntityVetoable vetoable)
Specified by:
removeTopiaEntityVetoable in interface TopiaContext

removeTopiaTransactionListener

public void removeTopiaTransactionListener(TopiaTransactionListener listener)
Specified by:
removeTopiaTransactionListener in interface TopiaContext

removeTopiaTransactionVetoable

public void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable)
Specified by:
removeTopiaTransactionVetoable in interface TopiaContext

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Specified by:
removePropertyChangeListener in interface TopiaContext

removeTopiaContextListener

public void removeTopiaContextListener(TopiaContextListener listener)
Specified by:
removeTopiaContextListener in interface TopiaContext

addTopiaEntitiesVetoable

public void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable)
Specified by:
addTopiaEntitiesVetoable in interface TopiaContext

removeTopiaEntitiesVetoable

public void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable)
Specified by:
removeTopiaEntitiesVetoable in interface TopiaContext

buildQueries

protected String[] buildQueries(Object... entityAndCondition)
                         throws TopiaException,
                                IllegalArgumentException
Build the list of queries from the given parameter 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.
IllegalArgumentException - if any pb with the given parameter (mainly ClassCastException).

replicate0

protected void replicate0(TopiaContextImpl dstContextImpl,
                          Object... entities)
                   throws TopiaException
Throws:
TopiaException


Copyright © 2004-2011 CodeLutin. All Rights Reserved.