Author: athimel Date: 2013-07-20 02:48:20 +0200 (Sat, 20 Jul 2013) New Revision: 2777 Url: http://nuiton.org/projects/topia/repository/revisions/2777 Log: refs #552 Clean TopiaContext API fixes #2781 Rename TopiaContextListener to TopiaSchemaListener Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaSchemaListener.java Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextListener.java trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntities.java Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-07-20 00:12:27 UTC (rev 2776) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-07-20 00:48:20 UTC (rev 2777) @@ -29,6 +29,7 @@ import org.nuiton.topia.event.TopiaEntitiesVetoable; import org.nuiton.topia.event.TopiaEntityListener; import org.nuiton.topia.event.TopiaEntityVetoable; +import org.nuiton.topia.event.TopiaSchemaListener; import org.nuiton.topia.event.TopiaTransactionListener; import org.nuiton.topia.event.TopiaTransactionVetoable; import org.nuiton.topia.framework.TopiaService; @@ -39,170 +40,317 @@ import java.util.List; /** - * TODO-FD20100507 : Need javadoc + translate the one on methods. + * The TopiaContext is the most important class of ToPIA. It contains all the + * methods to manipulate data : transaction management, entities querying, event + * firing, schema management, services management, ... * <p/> + * To get an instance of TopiaContext, see {@link TopiaContextFactory#getContext(java.util.Properties)} + * <p/> + * <p/> * Created: 3 janv. 2006 21:18:34 * * @author poussin <poussin@codelutin.com> * @author tchemit <tchemit@codelutin.com> + * @author athimel <thimel@codelutin.com> * @version $Id$ */ public interface TopiaContext { - /* Adders */ + /* -------------------- TRANSACTION MANAGEMENT --------------------------*/ - void addTopiaEntityListener(TopiaEntityListener listener); + /** + * Returns a new context containing its own transaction. + * + * @return new context with transaction + * @throws TopiaException if any exception + */ + TopiaContext beginTransaction() throws TopiaException; - void addTopiaEntityListener( - Class<? extends TopiaEntity> entityClass, - TopiaEntityListener listener); + /** + * Applies all the modifications made to this context on the persistence + * device. Once commit is done, a new transaction is started. + * + * @throws TopiaException if any exception + */ + void commitTransaction() throws TopiaException; - void addTopiaEntityVetoable(TopiaEntityVetoable vetoable); + /** + * Cancels all the modifications made to this context, coming back to the + * state on the last beginTransaction. Once rollback is done, a new + * transaction is started. + * + * @throws TopiaException if any exception + */ + void rollbackTransaction() throws TopiaException; - void addTopiaEntityVetoable( - Class<? extends TopiaEntity> entityClass, - TopiaEntityVetoable vetoable); + /** + * Closes the context. All the children contexts will be closed in the same + * time. + * + * @throws TopiaException if any exception + */ + void closeContext() throws TopiaException; - void addTopiaTransactionListener(TopiaTransactionListener listener); + /** + * Tells if the context is closed + * + * @return {@code true} if the context is closed, {@code false} otherwise + */ + boolean isClosed(); - void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable); + /* ------------------------ EVENT FIRING --------------------------*/ - void addPropertyChangeListener(PropertyChangeListener listener); + /* TopiaEntityListener */ - void addTopiaContextListener(TopiaContextListener listener); + /** + * Register to the context a TopiaEntityListener about any TopiaEntity. + * <code>listener</code> instance will be notified AFTER any operation on + * the entity. + * + * @param listener the listener instance to register + */ + void addTopiaEntityListener(TopiaEntityListener listener); - void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable); + /** + * Register to the context a TopiaEntityListener about the given entity + * class. <code>listener</code> instance will be notified AFTER any + * operation on the entity. + * + * @param entityClass the TopiaEntity's class to listen + * @param listener the listener instance to register + */ + void addTopiaEntityListener(Class<? extends TopiaEntity> entityClass, + TopiaEntityListener listener); - /* Removers */ - + /** + * Unregister the given TopiaEntityListener about any TopiaEntity from the + * context + * + * @param listener the listener instance to unregister + */ void removeTopiaEntityListener(TopiaEntityListener listener); - void removeTopiaEntityListener( - Class<? extends TopiaEntity> entityClass, - TopiaEntityListener listener); + /** + * Unregister the given TopiaEntityListener about the given entity class + * from the context + * + * @param entityClass the listened TopiaEntity's class + * @param listener the listener instance to unregister + */ + void removeTopiaEntityListener(Class<? extends TopiaEntity> entityClass, + TopiaEntityListener listener); + + /* TopiaEntityVetoable */ + + /** + * Register to the context a TopiaEntityVetoable about any TopiaEntity. + * <code>vetoable</code> instance will be notified BEFORE any operation on + * the entity. + * + * @param vetoable the vetoable instance to register + */ + void addTopiaEntityVetoable(TopiaEntityVetoable vetoable); + + /** + * Register to the context a TopiaEntityVetoable about the given entity + * class. <code>vetoable</code> instance will be notified BEFORE any + * operation on the entity. + * + * @param entityClass the TopiaEntity's class to listen + * @param vetoable the vetoable instance to register + */ + void addTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, + TopiaEntityVetoable vetoable); + + /** + * Unregister the given TopiaEntityVetoable about any TopiaEntity from the + * context + * + * @param vetoable the vetoable instance to unregister + */ void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable); - void removeTopiaEntityVetoable( - Class<? extends TopiaEntity> entityClass, - TopiaEntityVetoable vetoable); + /** + * Unregister the given TopiaEntityVetoable about the given entity class + * from the context + * + * @param entityClass the listened TopiaEntity's class + * @param vetoable the vetoable instance to unregister + */ + void removeTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, + TopiaEntityVetoable vetoable); - void removeTopiaTransactionListener(TopiaTransactionListener listener); - void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable); + /* TopiaEntitiesVetoable */ - void removePropertyChangeListener(PropertyChangeListener listener); + /** + * Register to the context a TopiaEntitiesVetoable about any TopiaEntity. + * <code>vetoable</code> instance will be notified BEFORE any entity load + * + * @param vetoable the vetoable instance to register + */ + void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable); - void removeTopiaContextListener(TopiaContextListener listener); - + /** + * Unregister the given TopiaEntitiesVetoable about any TopiaEntity from the + * context + * + * @param vetoable the vetoable instance to unregister + */ void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable); + + /* TopiaTransactionListener */ + /** - * Return true if specific service is available. + * Register to the context a TopiaTransactionListener about the transaction. + * <code>listener</code> instance will be notified AFTER any operation on + * the transaction. * - * @param <E> type of service - * @param interfaceService fqn of the service - * @return the service + * @param listener the listener instance to register */ - <E extends TopiaService> boolean serviceEnabled( - Class<E> interfaceService); + void addTopiaTransactionListener(TopiaTransactionListener listener); /** - * Return the service. This service must be valid with public static final - * SERVICE_NAME property. + * Unregister the given TopiaTransactionListener about the transaction from + * the context * - * @param <E> type of service - * @param interfaceService class of the service - * @return the service - * @throws TopiaNotFoundException if service can't be retrieved + * @param listener the listener instance to unregister */ - <E extends TopiaService> E getService(Class<E> interfaceService) - throws TopiaNotFoundException; + void removeTopiaTransactionListener(TopiaTransactionListener listener); + + /* TopiaTransactionVetoable */ + /** - * Permet de créer le schema de la base de données. + * Register to the context a TopiaTransactionVetoable about the transaction. + * <code>vetoable</code> instance will be notified BEFORE any operation on + * the transaction. * - * @throws TopiaException if any exception + * @param vetoable the vetoable instance to register */ - void createSchema() throws TopiaException; + void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable); /** - * Permet d'afficher les requetes SQL de creation de base. + * Unregister the given TopiaTransactionVetoable about the transaction from + * the context * - * @throws TopiaException if any exception + * @param vetoable the vetoable instance to unregister */ - void showCreateSchema() throws TopiaException; + void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable); + + /* PropertyChangeListener */ + /** - * Permet de mettre à jour le schema de la base de données. + * Register to the context a PropertyChangeListener about some entity's + * property change. <code>listener</code> instance will be notified AFTER + * any change on the entity's property * - * @throws TopiaException if any exception + * @param listener the listener instance to register */ - void updateSchema() throws TopiaException; + void addPropertyChangeListener(PropertyChangeListener listener); /** - * Permet de supprimer le schema de la base de données. + * Unregister the given PropertyChangeListener about some entity's + * property change from the context * - * @throws TopiaException if any exception - * @since 3.0 + * @param listener the listener instance to unregister */ - void dropSchema() throws TopiaException; + void removePropertyChangeListener(PropertyChangeListener listener); + + /* TopiaSchemaListener */ + /** - * Return a new context containing his own transaction. + * Register to the context a TopiaSchemaListener about any schema + * modification. <code>listener</code> instance will be notified BEFORE and + * AFTER any change on the schema * - * @return new context with transaction - * @throws TopiaException if any exception + * @param listener the listener instance to register */ - TopiaContext beginTransaction() throws TopiaException; + void addTopiaSchemaListener(TopiaSchemaListener listener); /** - * applique les modifications apporté a ce context sur la base de données. + * Unregister the given TopiaSchemaListener about any schema modification + * from the context * - * @throws TopiaException if any exception + * @param listener the listener instance to unregister */ - void commitTransaction() throws TopiaException; + void removeTopiaSchemaListener(TopiaSchemaListener listener); + + /* TopiaContextListener */ + /** - * annule les modifications apporté a ce context. + * Register to the context a TopiaContextListener about any schema + * modification. <code>listener</code> instance will be notified BEFORE and + * AFTER any change on the schema * - * @throws TopiaException if any exception + * @param listener the listener instance to register + * @deprecated Use addTopiaSchemaListener */ - void rollbackTransaction() throws TopiaException; + @Deprecated + void addTopiaContextListener(TopiaContextListener listener); /** + * Unregister the given TopiaContextListener about any schema modification + * from the context + * + * @param listener the listener instance to unregister + * @deprecated Use removeTopiaSchemaListener + */ + @Deprecated + void removeTopiaContextListener(TopiaContextListener listener); + + /* -------------------- GLOBAL OPERATIONS ON ENTITIES --------------------*/ + + /** * Retrieve {@link TopiaEntity} using its unique {@code id}. * * @param topiaId unique identifier of the entity in all the application. - * @return the entity found or null if not + * @return the entity found or null * @throws TopiaException for errors on retrieving the entity */ <E extends TopiaEntity> E findByTopiaId(String topiaId) throws TopiaException; /** - * Permet de faire une requete HQL hibernate directement sur la base. + * Allow to do some HQL query + * <p/> + * WARNING : Depending on the registered service, this method may not + * support something else than queries on TopiaEntity * - * @param hql la requete a faire - * @param args les arguments de la requete - * @return La liste des resultats - * @throws TopiaException si une erreur survient durant la requete + * @param hql the HQL query + * @param propertyNamesAndValues the query parameters. Arguments are key-value paired : + * [propertyName;value;propertyName;value;...] + * @return The result list + * @throws TopiaException for any error during querying */ - <E> List<E> findAll(String hql, Object... args) throws TopiaException; + <E> List<E> findAll(String hql, + Object... propertyNamesAndValues) throws TopiaException; /** - * Permet de faire une requete HQL hibernate directement sur la base en - * precisant la fenetre des elements a remonter avec les parametres {@code - * startIndex} et {@code endIndex}. + * Allow to do some JPA-QL query using the given bounds. + * <p/> + * No lower bound : <code>startIndex</code> = 0.<br/> + * No upper bound : <code>endIndex</code> = -1. + * <p/> + * WARNING : Depending on the registered service, this method may not + * support something else than queries on TopiaEntity * - * @param hql la requete a faire - * @param startIndex la position du premier element a remonter - * @param endIndex la position du dernier element a remonter - * @param args les arguments de la requete - * @return La liste des resultats - * @throws TopiaException si une erreur survient durant la requete + * @param hql the HQL query + * @param startIndex first index of entity to return + * @param endIndex last index of entity to return + * @param propertyNamesAndValues the query parameters. Arguments are key-value paired : + * [propertyName;value;propertyName;value;...] + * @return The result list + * @throws TopiaException for any error during querying */ - <E> List<E> find(String hql, int startIndex, int endIndex, Object... args) - throws TopiaException; + <E> List<E> find(String hql, + int startIndex, + int endIndex, + Object... propertyNamesAndValues) throws TopiaException; /** * Allow to do some HQL query and return an unique result. If nothing if @@ -212,36 +360,115 @@ * WARNING : Depending on the registered service, this method may not * support something else than queries on TopiaEntity * - * @param jpaql the JPA-QL query to execute - * @param paramNamesAndValues an array of query parameters based on - * [key,value,key,value,...] + * @param hql the HQL query + * @param propertyNamesAndValues the query parameters. Arguments are key-value paired : + * [propertyName;value;propertyName;value;...] * @return The result instance or null * @throws TopiaException for any error during querying or if the the query * returns more than one result. */ - <E> E findUnique(String jpaql, Object... paramNamesAndValues) - throws TopiaException; + <E> E findUnique(String hql, + Object... propertyNamesAndValues) throws TopiaException; /** + * Add into this TopiaContext an entity created by another TopiaContext + * + * @param e the entity to add + * @throws TopiaException if any exception + */ + void add(TopiaEntity e) throws TopiaException; + + /** + * Clear persistence implementation cache. + * + * @since 2.6.13 + */ + void clearCache() throws TopiaException; + + /** * Execute HQL operation on data (Update, Delete). * - * @param hql la requete a faire - * @param args les arguments de la requete + * @param hql the HQL query + * @param propertyNamesAndValues the query parameters. Arguments are key-value paired : + * [propertyName;value;propertyName;value;...] * @return The number of entities updated or deleted. * @throws TopiaException if any exception */ - int execute(String hql, Object... args) throws TopiaException; + int execute(String hql, + Object... propertyNamesAndValues) throws TopiaException; /** - * Permet d'ajouter dans le TopiaContext une TopiaEntity créé par un autre - * context. + * Execute a given sql code inside this transaction. * - * @param e l'entity a ajouter + * @param sqlScript the sql script to execute + * @throws TopiaException if any problem occurred while executing the sql script. + */ + void executeSQL(String sqlScript) throws TopiaException; + + // TODO AThimel 20/07/13 Copy "void doSQLWork(TopiaSQLWork sqlWork);" from topia-3.0-jpa ? + + /* -------------------- SCHEMA MANAGMENT -----------------------------*/ + + // TODO AThimel 20/07/13 Copy "boolean isSchemaEmpty();" from topia-3.0-jpa ? + + // TODO AThimel 20/07/13 Copy "boolean isTableExists(Class<?> clazz);" from topia-3.0-jpa ? + + // TODO AThimel 20/07/13 Copy "String getSchemaName();" from topia-3.0-jpa ? + + /** + * Permet de créer le schema de la base de données. + * * @throws TopiaException if any exception */ - void add(TopiaEntity e) throws TopiaException; + void createSchema() throws TopiaException; /** + * Permet d'afficher les requetes SQL de creation de base. + * + * @throws TopiaException if any exception + */ + void showCreateSchema() throws TopiaException; + + /** + * Permet de mettre à jour le schema de la base de données. + * + * @throws TopiaException if any exception + */ + void updateSchema() throws TopiaException; + + /** + * Permet de supprimer le schema de la base de données. + * + * @throws TopiaException if any exception + * @since 3.0 + */ + void dropSchema() throws TopiaException; + + /* -------------------- SERVICES MANAGMENT -------------------------------*/ + + /** + * Return true if specific service is available. + * + * @param <E> type of service + * @param interfaceService fqn of the service + * @return the service + */ + <E extends TopiaService> boolean serviceEnabled(Class<E> interfaceService); + + /** + * Return the service. This service must be valid with public static final + * SERVICE_NAME property. + * + * @param <E> type of service + * @param interfaceService class of the service + * @return the service + * @throws TopiaNotFoundException if service can't be retrieved + */ + <E extends TopiaService> E getService(Class<E> interfaceService) throws TopiaNotFoundException; + + /* ------------------ IMPORT / EXPORT / REPLICATION ---------------------*/ + + /** * Permet de dupliquer de ce context vers un context d'une autre base des * données sans modification des entites. * <p/> @@ -263,8 +490,8 @@ * si on essaye de dupliquer dans la même * base. */ - void replicate(TopiaContext dstCtxt, Object... entityAndCondition) - throws TopiaException, IllegalArgumentException; + void replicate(TopiaContext dstCtxt, + Object... entityAndCondition) throws TopiaException, IllegalArgumentException; /** * Permet de dupliquer une entité du type donné vers un autre context. @@ -277,8 +504,8 @@ * si on essaye de dupliquer dans la même * base. */ - <T extends TopiaEntity> void replicateEntity(TopiaContext dstCtxt, T entity) - throws TopiaException, IllegalArgumentException; + <T extends TopiaEntity> void replicateEntity(TopiaContext dstCtxt, + T entity) throws TopiaException, IllegalArgumentException; /** * Permet de dupliquer les entités du type donné vers un autre context. @@ -292,9 +519,10 @@ * base. */ <T extends TopiaEntity> void replicateEntities(TopiaContext dstCtxt, - List<T> entities) - throws TopiaException, IllegalArgumentException; + List<T> entities) throws TopiaException, IllegalArgumentException; + /* ------------------ H2 specific methods ---------------------*/ + /** * Sauve la base de données dans un format natif a la base, la * representation n'est pas portable d'une base a l'autre. Cette methode ne @@ -304,56 +532,35 @@ * @param file le nom du fichier ou stocker les informations * @param compress si vrai compress le fichier avec gzip * @throws TopiaException if any exception + * @deprecated Only H2 compatible : remove it, or move to another class */ - void backup(File file, boolean compress) throws TopiaException; + @Deprecated + void backup(File file, + boolean compress) throws TopiaException; /** - * Supprime toutes les tables et autres elements de la database. - * - * @param 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 - */ - void clear(boolean dropDatabase) throws TopiaException; - - /** - * Clear persistence implementation cache. - * - * @since 2.6.13 - */ - void clearCache() throws TopiaException; - - /** * l'inverse de la methode {@link #backup(File,boolean)}. * * @param file le fichier ou prendre les informations, il peut-etre * compressé avec gzip ou non. * @throws TopiaException if any exception + * @deprecated Only H2 compatible : remove it, or move to another class */ + @Deprecated void restore(File file) throws TopiaException; + /** - * Ferme le contexte. + * Supprime toutes les tables et autres elements de la database. * + * @param 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 + * @deprecated Only H2 compatible : remove it, or move to another class */ - void closeContext() throws TopiaException; + @Deprecated + void clear(boolean dropDatabase) throws TopiaException; - /** - * Indique si le contexte a ete ferme. - * - * @return {@code true} si le context est ferme, {@code false} autrement - */ - boolean isClosed(); - - /** - * Execute a given sql code inside this transaction. - * - * @param sqlScript the sql script to execute - * @throws TopiaException if any problem occurs while executing the sql script. - */ - void executeSQL(String sqlScript) throws TopiaException; - } //TopiaContext Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextListener.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextListener.java 2013-07-20 00:12:27 UTC (rev 2776) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextListener.java 2013-07-20 00:48:20 UTC (rev 2777) @@ -25,8 +25,6 @@ package org.nuiton.topia.event; -import java.util.EventListener; - /** * Listener for TopiaContext actions. * <p/> @@ -40,63 +38,43 @@ * @author chatellier <chatellier@codelutin.com> * @version $Id$ */ -public interface TopiaContextListener extends EventListener { +@Deprecated +public interface TopiaContextListener extends TopiaSchemaListener { /** - * Called before dropSchema call - * - * @param event event - * @since 3.0 + * @deprecated Use {@link TopiaSchemaListener#preCreateSchema(TopiaContextEvent)} */ - void preDropSchema(TopiaContextEvent event); - - /** - * Called after dropSchema call - * - * @param event event - * @since 3.0 - */ - void postDropSchema(TopiaContextEvent event); - - /** - * Called before createSchema call - * - * @param event event - */ + @Deprecated void preCreateSchema(TopiaContextEvent event); /** - * Called after createSchema call - * - * @param event event + * @deprecated Use {@link TopiaSchemaListener#postCreateSchema(TopiaContextEvent)} */ + @Deprecated void postCreateSchema(TopiaContextEvent event); /** - * Called before updateSchema call - * - * @param event event + * @deprecated Use {@link TopiaSchemaListener#preUpdateSchema(TopiaContextEvent)} */ + @Deprecated void preUpdateSchema(TopiaContextEvent event); /** - * Called after updateSchema call - * - * @param event event + * @deprecated Use {@link TopiaSchemaListener#postUpdateSchema(TopiaContextEvent)} */ + @Deprecated void postUpdateSchema(TopiaContextEvent event); /** - * Called before restoreSchema call - * - * @param event event + * @deprecated Use {@link TopiaSchemaListener#preRestoreSchema(TopiaContextEvent)} */ + @Deprecated void preRestoreSchema(TopiaContextEvent event); /** - * Called after restoreSchema call - * - * @param event event + * @deprecated Use {@link TopiaSchemaListener#postRestoreSchema(TopiaContextEvent)} */ + @Deprecated void postRestoreSchema(TopiaContextEvent event); + } Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaSchemaListener.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaSchemaListener.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaSchemaListener.java 2013-07-20 00:48:20 UTC (rev 2777) @@ -0,0 +1,102 @@ +package org.nuiton.topia.event; + +/* + * #%L + * ToPIA :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import java.util.EventListener; + +/** + * Listener for TopiaContext actions. + * <p/> + * Listener are notified for action such as : + * <ul> + * <li>createSchema</li> + * <li>updateSchema</li> + * <li>...</li> + * </ul> + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public interface TopiaSchemaListener extends EventListener { + + /** + * Called before createSchema call + * + * @param event event + */ + void preCreateSchema(TopiaContextEvent event); + + /** + * Called after createSchema call + * + * @param event event + */ + void postCreateSchema(TopiaContextEvent event); + + /** + * Called before updateSchema call + * + * @param event event + */ + void preUpdateSchema(TopiaContextEvent event); + + /** + * Called after updateSchema call + * + * @param event event + */ + void postUpdateSchema(TopiaContextEvent event); + + /** + * Called after updateSchema call + * + * @param event event + */ + void preRestoreSchema(TopiaContextEvent event); + + /** + * Called after updateSchema call + * + * @param event event + */ + void postRestoreSchema(TopiaContextEvent event); + + /** + * Called before dropSchema call + * + * @param event event + * @since 3.0 + */ + void preDropSchema(TopiaContextEvent event); + + /** + * Called after dropSchema call + * + * @param event event + * @since 3.0 + */ + void postDropSchema(TopiaContextEvent event); + +} Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaSchemaListener.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2013-07-20 00:12:27 UTC (rev 2776) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2013-07-20 00:48:20 UTC (rev 2777) @@ -55,6 +55,7 @@ import org.nuiton.topia.event.TopiaEntitiesVetoable; import org.nuiton.topia.event.TopiaEntityListener; import org.nuiton.topia.event.TopiaEntityVetoable; +import org.nuiton.topia.event.TopiaSchemaListener; import org.nuiton.topia.event.TopiaTransactionListener; import org.nuiton.topia.event.TopiaTransactionVetoable; import org.nuiton.topia.persistence.DefaultTopiaIdFactory; @@ -950,15 +951,15 @@ } @Override - public <E> List<E> findAll(String hql, Object... args) throws TopiaException { + public <E> List<E> findAll(String hql, Object... propertyNamesAndValues) throws TopiaException { checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'", "findAll")); try { Query query = getHibernate().createQuery(hql); - for (int j = 0; j < args.length; j += 2) { - String name = (String) args[j]; - Object value = args[j + 1]; + for (int j = 0; j < propertyNamesAndValues.length; j += 2) { + String name = (String) propertyNamesAndValues[j]; + Object value = propertyNamesAndValues[j + 1]; if (value.getClass().isArray()) { query.setParameterList(name, (Object[]) value); } else if (value instanceof Collection<?>) { @@ -981,16 +982,16 @@ } @Override - public <E> List<E> find(String hql, int startIndex, int endIndex, Object... args) + public <E> List<E> find(String hql, int startIndex, int endIndex, Object... propertyNamesAndValues) throws TopiaException { checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'", "find")); try { Query query = getHibernate().createQuery(hql); - for (int j = 0; j < args.length; j += 2) { - String name = (String) args[j]; - Object value = args[j + 1]; + for (int j = 0; j < propertyNamesAndValues.length; j += 2) { + String name = (String) propertyNamesAndValues[j]; + Object value = propertyNamesAndValues[j + 1]; if (value.getClass().isArray()) { query.setParameterList(name, (Object[]) value); } else if (value instanceof Collection<?>) { @@ -1015,12 +1016,12 @@ } @Override - public <E> E findUnique(String hql, Object... paramNamesAndValues) + public <E> E findUnique(String hql, Object... propertyNamesAndValues) throws TopiaException { checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'", "findUnique")); - List<E> results = find(hql, 0, 1, paramNamesAndValues); + List<E> results = find(hql, 0, 1, propertyNamesAndValues); // If there is more than 1 result, throw an exception if (results.size() > 1) { @@ -1041,19 +1042,19 @@ * Execute HQL operation on data (Update, Delete) * * @param hql HQL query - * @param args arguments for query + * @param propertyNamesAndValues arguments for query * @return The number of entities updated or deleted. * @throws TopiaException */ @Override - public int execute(String hql, Object... args) throws TopiaException { + public int execute(String hql, Object... propertyNamesAndValues) throws TopiaException { checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'", "find")); try { Query query = getHibernate().createQuery(hql); - for (int j = 0; j < args.length; j += 2) { - query.setParameter((String) args[j], args[j + 1]); + for (int j = 0; j < propertyNamesAndValues.length; j += 2) { + query.setParameter((String) propertyNamesAndValues[j], propertyNamesAndValues[j + 1]); } int result = query.executeUpdate(); return result; @@ -1319,10 +1320,16 @@ } @Override + @Deprecated public void addTopiaContextListener(TopiaContextListener listener) { getFiresSupport().addTopiaContextListener(listener); } + @Override + public void addTopiaSchemaListener(TopiaSchemaListener listener) { + getFiresSupport().addTopiaSchemaListener(listener); + } + /* Listeners removers */ @Override @@ -1369,11 +1376,17 @@ } @Override + @Deprecated public void removeTopiaContextListener(TopiaContextListener listener) { getFiresSupport().removeTopiaContextListener(listener); } @Override + public void removeTopiaSchemaListener(TopiaSchemaListener listener) { + getFiresSupport().removeTopiaSchemaListener(listener); + } + + @Override public void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) { getFiresSupport().addTopiaEntitiesVetoable(vetoable); } Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java 2013-07-20 00:12:27 UTC (rev 2776) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java 2013-07-20 00:48:20 UTC (rev 2777) @@ -65,6 +65,7 @@ import org.nuiton.topia.event.TopiaEntityEvent; import org.nuiton.topia.event.TopiaEntityListener; import org.nuiton.topia.event.TopiaEntityVetoable; +import org.nuiton.topia.event.TopiaSchemaListener; import org.nuiton.topia.event.TopiaTransactionEvent; import org.nuiton.topia.event.TopiaTransactionListener; import org.nuiton.topia.event.TopiaTransactionVetoable; @@ -119,8 +120,8 @@ /* Pour les actions du topia context */ - protected ListenerSet<TopiaContextListener> topiaContextListeners = - new ListenerSet<TopiaContextListener>(); + protected ListenerSet<TopiaSchemaListener> topiaSchemaListeners = + new ListenerSet<TopiaSchemaListener>(); /** * used to register objects loaded during transaction. @@ -733,9 +734,9 @@ log.debug("firePreCreateSchema"); } TopiaContextEvent event = new TopiaContextEvent(context); - for (TopiaContextListener topiaContextListener : topiaContextListeners) { + for (TopiaSchemaListener topiaSchemaListener : topiaSchemaListeners) { try { - topiaContextListener.preCreateSchema(event); + topiaSchemaListener.preCreateSchema(event); } catch (Exception eee) { throw new TopiaVetoException(eee); } @@ -752,9 +753,9 @@ log.debug("firePostCreateSchema"); } TopiaContextEvent event = new TopiaContextEvent(context); - for (TopiaContextListener topiaContextListener : topiaContextListeners) { + for (TopiaSchemaListener topiaSchemaListener : topiaSchemaListeners) { try { - topiaContextListener.postCreateSchema(event); + topiaSchemaListener.postCreateSchema(event); } catch (Exception eee) { throw new TopiaVetoException(eee); } @@ -771,9 +772,9 @@ log.debug("firePostCreateSchema"); } TopiaContextEvent event = new TopiaContextEvent(context); - for (TopiaContextListener topiaContextListener : topiaContextListeners) { + for (TopiaSchemaListener topiaSchemaListener : topiaSchemaListeners) { try { - topiaContextListener.preUpdateSchema(event); + topiaSchemaListener.preUpdateSchema(event); } catch (Exception eee) { throw new TopiaVetoException(eee); } @@ -790,9 +791,9 @@ log.debug("firePostCreateSchema"); } TopiaContextEvent event = new TopiaContextEvent(context); - for (TopiaContextListener topiaContextListener : topiaContextListeners) { + for (TopiaSchemaListener topiaSchemaListener : topiaSchemaListeners) { try { - topiaContextListener.postUpdateSchema(event); + topiaSchemaListener.postUpdateSchema(event); } catch (Exception eee) { throw new TopiaVetoException(eee); } @@ -809,9 +810,9 @@ log.debug("firePreRestoreSchema"); } TopiaContextEvent event = new TopiaContextEvent(context); - for (TopiaContextListener topiaContextListener : topiaContextListeners) { + for (TopiaSchemaListener topiaSchemaListener : topiaSchemaListeners) { try { - topiaContextListener.preRestoreSchema(event); + topiaSchemaListener.preRestoreSchema(event); } catch (Exception eee) { throw new TopiaVetoException(eee); } @@ -828,9 +829,9 @@ log.debug("firePostRestoreSchema"); } TopiaContextEvent event = new TopiaContextEvent(context); - for (TopiaContextListener topiaContextListener : topiaContextListeners) { + for (TopiaSchemaListener topiaSchemaListener : topiaSchemaListeners) { try { - topiaContextListener.postRestoreSchema(event); + topiaSchemaListener.postRestoreSchema(event); } catch (Exception eee) { throw new TopiaVetoException(eee); } @@ -848,9 +849,9 @@ log.debug("firePreDropSchema"); } TopiaContextEvent event = new TopiaContextEvent(context); - for (TopiaContextListener topiaContextListener : topiaContextListeners) { + for (TopiaSchemaListener topiaSchemaListener : topiaSchemaListeners) { try { - topiaContextListener.preDropSchema(event); + topiaSchemaListener.preDropSchema(event); } catch (Exception eee) { throw new TopiaVetoException(eee); } @@ -868,9 +869,9 @@ log.debug("firePostDropSchema"); } TopiaContextEvent event = new TopiaContextEvent(context); - for (TopiaContextListener topiaContextListener : topiaContextListeners) { + for (TopiaSchemaListener topiaSchemaListener : topiaSchemaListeners) { try { - topiaContextListener.postDropSchema(event); + topiaSchemaListener.postDropSchema(event); } catch (Exception eee) { throw new TopiaVetoException(eee); } @@ -923,10 +924,21 @@ return transactionVetoables; } + @Deprecated public ListenerSet<TopiaContextListener> getTopiaContextListeners() { - return topiaContextListeners; + ListenerSet<TopiaContextListener> copy = new ListenerSet<TopiaContextListener>(); + for (TopiaSchemaListener topiaSchemaListener : topiaSchemaListeners) { + if (topiaSchemaListener instanceof TopiaContextListener) { + copy.add((TopiaContextListener)topiaSchemaListener); + } + } + return copy; } + public ListenerSet<TopiaSchemaListener> getTopiaSchemaListeners() { + return topiaSchemaListeners; + } + public ListenerSet<TopiaEntitiesVetoable> getTopiaEntitiesVetoable() { return entitiesVetoables; } @@ -980,13 +992,21 @@ propertyChangeListeners.add(listener); } + @Deprecated public void addTopiaContextListener(TopiaContextListener listener) { if (listener == null) { throw new NullPointerException("listener can not be null."); } - topiaContextListeners.add(listener); + topiaSchemaListeners.add(listener); } + public void addTopiaSchemaListener(TopiaSchemaListener listener) { + if (listener == null) { + throw new NullPointerException("listener can not be null."); + } + topiaSchemaListeners.add(listener); + } + public void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) { if (vetoable == null) { throw new NullPointerException("listener can not be null."); @@ -1047,9 +1067,16 @@ if (listener == null) { throw new NullPointerException("listener can not be null."); } - topiaContextListeners.remove(listener); + topiaSchemaListeners.remove(listener); } + public void removeTopiaSchemaListener(TopiaSchemaListener listener) { + if (listener == null) { + throw new NullPointerException("listener can not be null."); + } + topiaSchemaListeners.remove(listener); + } + public void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) { if (vetoable == null) { throw new NullPointerException("listener can not be null."); Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntities.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntities.java 2013-07-20 00:12:27 UTC (rev 2776) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntities.java 2013-07-20 00:48:20 UTC (rev 2777) @@ -41,6 +41,7 @@ * * @since 2.6.12 */ + // TODO AThimel 20/07/13 Why is this function useful ? Why not use directly the GET_TOPIA_ID Function ? public static Function<TopiaEntity, String> getTopiaIdFunction() { return GET_TOPIA_ID; }