Author: athimel Date: 2013-08-03 03:14:27 +0200 (Sat, 03 Aug 2013) New Revision: 2787 Url: http://nuiton.org/projects/topia/repository/revisions/2787 Log: refs #1146 Prepare migrate site page refs #552 Improve APIs Javadoc refs #2748 Minimal documentation on newly created contracts Added: trunk/src/site/resources/ trunk/src/site/resources/mandatory.png trunk/src/site/resources/recommended.png trunk/src/site/rst/changelog_3.0.rst trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernateSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenableSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java Removed: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransactionSupport.java Modified: trunk/src/site/rst/migrate_to_3.0.rst trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNotFoundException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaVetoException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DefaultTopiaIdFactory.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaIdFactory.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntities.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactory.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/EntityCsvModel.java Added: trunk/src/site/resources/mandatory.png =================================================================== (Binary files differ) Property changes on: trunk/src/site/resources/mandatory.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/src/site/resources/recommended.png =================================================================== (Binary files differ) Property changes on: trunk/src/site/resources/recommended.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/src/site/rst/changelog_3.0.rst =================================================================== --- trunk/src/site/rst/changelog_3.0.rst (rev 0) +++ trunk/src/site/rst/changelog_3.0.rst 2013-08-03 01:14:27 UTC (rev 2787) @@ -0,0 +1,48 @@ +.. - +.. * #%L +.. * ToPIA +.. * $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% +.. - + +Les nouveautés de ToPIA 3.0 +=========================== + + +Modularisation de la génération des TopiaId +------------------------------------------- + +La forme des topiaIds générés à changé. Si vous souhaitez conserver l'ancienne forme parce que vous +souhaitez conserver l'uniformité avec une base de données existante ou si vous utilisez +topia-service-security, vous devez explicitement le spécifier à Topia 3.0 via la configuration : + + ``topia.persistence.topiaIdFactoryClassName=org.nuiton.topia.persistence.LegacyTopiaIdFactory`` + +Le classe **TopiaID** est dépréciée, elle sera supprimée dans les prochaines versions. + +:: + + FIXME tchemit : je ne suis pas convaincu par ça, le module security pour moi doit aussi être déprécié, donc la dernière phrase est caduc. + + +TopiaEntities enrichi +--------------------- + +TODO Property changes on: trunk/src/site/rst/changelog_3.0.rst ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/src/site/rst/migrate_to_3.0.rst =================================================================== --- trunk/src/site/rst/migrate_to_3.0.rst 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/src/site/rst/migrate_to_3.0.rst 2013-08-03 01:14:27 UTC (rev 2787) @@ -22,71 +22,110 @@ .. * #L% .. - +================================ Migrer depuis ToPIA 2.x vers 3.0 ================================ -:: - FIXME tchemit : dans ce guide je ne vois pas ce qui est obligatoire de faire ? - Y'a des choses qui restent compatibles ? Il faudrait explicitement dire ce - qu'il faut faire (ce document dans sa forme actuelle est plus un changelog - qu'un guide de migration...). - On devrait plutôt avoir une section *choses incompatibles* ou *à faire*. - Gestion des dépendances ------------------------ +======================= - * ToPIA utilise au minimum Eugene 2.6.4. - * ToPIA utilise au minimum Hibernate 4.2.1.Final. +|MANDATORY| -Renommage de variables ----------------------- +ToPIA nécessite des versions minimum de Eugene et Hibernate. Vous devez utiliser les version suivantes : - * Les constantes de TopiaEntity ont été renommé avec le prefix PROPERTY_ + * Eugene >= 2.6.4 + * Hibernate >= 4.2.1.Final -Gestion des exceptions ----------------------- - * TopiaRuntimeException est dépréciée. Il faut désormais déclarer TopiaException dans la clause catch ; - * TopiaException devient Runtime. Il n'est plus nécessaire de la gérer. +Code déprécié +============= -Modularisation de la génération des TopiaID -------------------------------------------- -La forme des topiaIds générés à changé. Si vous souhaitez conserver l'ancienne forme parce que vous -souhaitez conserver l'uniformité avec une base de données existante ou si vous utilisez -topia-service-security, vous devez explicitement le spécifier à Topia 3.0 via la configuration : +La migration vers ToPIA 3.0 voit un certain nombre de classes et attributs dépréciés. - topia.persistence.topiaIdFactoryClassName=org.nuiton.topia.persistence.LegacyTopiaIdFactory +Gérer les impacts n'est pas *nécessaire* pour passer à ToPIA 3.0, mais c'est fortement recommandé. En effet, ce code +deviendra incompatible avec ToPIA 3.1, gérer les impacts au plus tôt permettra une migration en douceur. -Le classe TopiaID est dépréciée, elle sera déplacée dans topia-service-security. Utilisez plutôt une -référence vers une instance de TopiaIdFactory (disponible dans le TopiaContextImplementor et donc dans les DAOs). -:: +Propriétés TOPIA_* +------------------ - FIXME tchemit : je ne suis pas convaincu par ça, le module security pour moi doit aussi être déprécié, donc la dernière phrase est caduc. +|RECOMMENDED| +Les constantes suivantes sont à remplacer par leurs homologues avec le prefix *PROPERTY_* : + + * ``TopiaEntity#TOPIA_ID`` devient ``TopiaEntity#PROPERTY_TOPIA_ID`` + * ``TopiaEntity#TOPIA_CREATE_DATE`` devient ``TopiaEntity#PROPERTY_TOPIA_CREATE_DATE`` + * ``TopiaEntity#TOPIA_VERSION`` devient ``TopiaEntity#PROPERTY_TOPIA_VERSION`` + * ``TopiaEntityContextable#TOPIA_CONTEXT`` devient ``TopiaEntityContextable#PROPERTY_TOPIA_CONTEXT`` + + +TopiaId +------- + +|RECOMMENDED| + +La classe sera supprimée. Pour manipuler les topiaId, il faut utiliser le **TopiaIdFactory**. + + +TopiaEntities#getTopiaIdFunction() +---------------------------------- + +|RECOMMENDED| + +La méthode est dépréciée, il faut maintenant utiliser ``TopiaEntities#GET_TOPIA_ID``. + + +TopiaContextImplementor est déprécié +------------------------------------ + +Cette classe joue un rôle central dans ToPIA 2. Si nous avons essayé de limiter les impacts pour la version 3, il est +tout de même nécessaire d'appliquer quelques modifications. + +TopiaService#[preInit|postInit](...) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +|MANDATORY| + +Les services implémentant **TopiaService** doivent changer leur code. +Les méthodes ``preInit(TopiaContextImplementor)`` et ``postInit(TopiaContextImplementor)`` doivent être remplacées par +``preInit(TopiaContext)`` et ``postInit(TopiaContext)`` + + +Gestion des exceptions +---------------------- + +|RECOMMENDED| + +**TopiaRuntimeException** est dépréciée. Il faut désormais déclarer **TopiaException** dans la clause catch. +**TopiaException** devient Runtime. Il n'est plus nécessaire de l'intercepter. + Généricité ---------- -Les methodes +|RECOMMENDED| - * TopiaContext#find(...) - * TopiaContext#findAll(...) - * TopiaContext#findUnique(...) +Les methodes suivantes sont désormais génériques : -sont devenu génériques. + * ``TopiaContext#find(...)`` + * ``TopiaContext#findAll(...)`` + * ``TopiaContext#findUnique(...)`` -Si le code précédent réalisait un cast, il faut le supprimer car cela peut -causer maintenant une erreur de compilation. +Si le code précédent réalisait un cast, il faut le supprimer car cela peut causer maintenant une erreur de compilation. TopiaContextListener -------------------- -L'API TopiaContextListener contenant des opérations de manipulation du schéma de base de données a été déprécié. -L'interface est remplacée par TopiaSchemaListener. Les méthodes présentes sur le TopiaContext qui servaient à ajouter/ -supprimer un TopiaContextListener sont elles aussi dépréciées au profit de méthodes manipulant des TopiaSchemaListener. +|RECOMMENDED| +L'API **TopiaContextListener** contenant des opérations de manipulation du schéma de base de données a été déprécié. +L'interface est remplacée par **TopiaSchemaListener**. Les méthodes présentes sur le **TopiaContext** qui servaient à +ajouter/supprimer un **TopiaContextListener** sont elles aussi dépréciées au profit de méthodes manipulant des +**TopiaSchemaListener**. + +.. |RECOMMENDED| image:: recommended.png +.. |MANDATORY| image:: mandatory.png Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -33,7 +33,6 @@ 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; @@ -54,8 +53,8 @@ * @author athimel <thimel@codelutin.com> * @version $Id$ */ -public interface TopiaContext extends TopiaTransactionSupport, TopiaListenable, TopiaSqlSupport, TopiaJpaSupport, - TopiaPersistenceContext, TopiaServiceSupport, TopiaReplicationSupport, TopiaHibernate { +public interface TopiaContext extends TopiaTransaction, TopiaListenableSupport, TopiaSqlSupport, TopiaJpaSupport, + TopiaPersistenceContext, TopiaServiceSupport, TopiaReplicationSupport, TopiaHibernateSupport { /* -------------------- TRANSACTION MANAGEMENT --------------------------*/ @@ -64,7 +63,7 @@ * * @return new context with transaction * @throws TopiaException if any exception - * @deprecated use method from {@link TopiaTransactionSupport} + * @deprecated use method from {@link TopiaTransaction} */ @Deprecated TopiaContext beginTransaction() throws TopiaException; @@ -74,7 +73,7 @@ * device. Once commit is done, a new transaction is started. * * @throws TopiaException if any exception - * @deprecated use method from {@link TopiaTransactionSupport} + * @deprecated use method from {@link TopiaTransaction} */ @Deprecated void commitTransaction() throws TopiaException; @@ -85,7 +84,7 @@ * transaction is started. * * @throws TopiaException if any exception - * @deprecated use method from {@link TopiaTransactionSupport} + * @deprecated use method from {@link TopiaTransaction} */ @Deprecated void rollbackTransaction() throws TopiaException; @@ -95,7 +94,7 @@ * time. * * @throws TopiaException if any exception - * @deprecated use method from {@link TopiaTransactionSupport} + * @deprecated use method from {@link TopiaTransaction} */ @Deprecated void closeContext() throws TopiaException; @@ -104,7 +103,7 @@ * Tells if the context is closed * * @return {@code true} if the context is closed, {@code false} otherwise - * @deprecated use method from {@link TopiaTransactionSupport} + * @deprecated use method from {@link TopiaTransaction} */ @Deprecated boolean isClosed(); @@ -119,7 +118,7 @@ * the entity. * * @param listener the listener instance to register - * @deprecated use method from {@link TopiaListenable} + * @deprecated use method from {@link TopiaListenableSupport} */ @Deprecated void addTopiaEntityListener(TopiaEntityListener listener); @@ -131,7 +130,7 @@ * * @param entityClass the TopiaEntity's class to listen * @param listener the listener instance to register - * @deprecated use method from {@link TopiaListenable} + * @deprecated use method from {@link TopiaListenableSupport} */ @Deprecated void addTopiaEntityListener(Class<? extends TopiaEntity> entityClass, @@ -142,7 +141,7 @@ * context * * @param listener the listener instance to unregister - * @deprecated use method from {@link TopiaListenable} + * @deprecated use method from {@link TopiaListenableSupport} */ @Deprecated void removeTopiaEntityListener(TopiaEntityListener listener); @@ -153,7 +152,7 @@ * * @param entityClass the listened TopiaEntity's class * @param listener the listener instance to unregister - * @deprecated use method from {@link TopiaListenable} + * @deprecated use method from {@link TopiaListenableSupport} */ @Deprecated void removeTopiaEntityListener(Class<? extends TopiaEntity> entityClass, @@ -168,7 +167,7 @@ * the entity. * * @param vetoable the vetoable instance to register - * @deprecated use method from {@link TopiaListenable} + * @deprecated use method from {@link TopiaListenableSupport} */ @Deprecated void addTopiaEntityVetoable(TopiaEntityVetoable vetoable); @@ -180,7 +179,7 @@ * * @param entityClass the TopiaEntity's class to listen * @param vetoable the vetoable instance to register - * @deprecated use method from {@link TopiaListenable} + * @deprecated use method from {@link TopiaListenableSupport} */ @Deprecated void addTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, @@ -191,7 +190,7 @@ * context * * @param vetoable the vetoable instance to unregister - * @deprecated use method from {@link TopiaListenable} + * @deprecated use method from {@link TopiaListenableSupport} */ @Deprecated void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable); @@ -202,7 +201,7 @@ * * @param entityClass the listened TopiaEntity's class * @param vetoable the vetoable instance to unregister - * @deprecated use method from {@link TopiaListenable} + * @deprecated use method from {@link TopiaListenableSupport} */ @Deprecated void removeTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, @@ -216,7 +215,7 @@ * <code>vetoable</code> instance will be notified BEFORE any entity load * * @param vetoable the vetoable instance to register - * @deprecated use method from {@link TopiaListenable} + * @deprecated use method from {@link TopiaListenableSupport} */ @Deprecated void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable); @@ -226,7 +225,7 @@ * context * * @param vetoable the vetoable instance to unregister - * @deprecated use method from {@link TopiaListenable} + * @deprecated use method from {@link TopiaListenableSupport} */ @Deprecated void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable); @@ -240,7 +239,7 @@ * the transaction. * * @param listener the listener instance to register - * @deprecated use method from {@link TopiaListenable} + * @deprecated use method from {@link TopiaListenableSupport} */ @Deprecated void addTopiaTransactionListener(TopiaTransactionListener listener); @@ -250,7 +249,7 @@ * the context * * @param listener the listener instance to unregister - * @deprecated use method from {@link TopiaListenable} + * @deprecated use method from {@link TopiaListenableSupport} */ @Deprecated void removeTopiaTransactionListener(TopiaTransactionListener listener); @@ -264,7 +263,7 @@ * the transaction. * * @param vetoable the vetoable instance to register - * @deprecated use method from {@link TopiaListenable} + * @deprecated use method from {@link TopiaListenableSupport} */ @Deprecated void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable); @@ -274,7 +273,7 @@ * the context * * @param vetoable the vetoable instance to unregister - * @deprecated use method from {@link TopiaListenable} + * @deprecated use method from {@link TopiaListenableSupport} */ @Deprecated void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable); @@ -288,7 +287,7 @@ * any change on the entity's property * * @param listener the listener instance to register - * @deprecated use method from {@link TopiaListenable} + * @deprecated use method from {@link TopiaListenableSupport} */ @Deprecated void addPropertyChangeListener(PropertyChangeListener listener); @@ -298,36 +297,12 @@ * property change from the context * * @param listener the listener instance to unregister - * @deprecated use method from {@link TopiaListenable} + * @deprecated use method from {@link TopiaListenableSupport} */ @Deprecated void removePropertyChangeListener(PropertyChangeListener listener); - /* TopiaSchemaListener */ - - /** - * 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 - * - * @param listener the listener instance to register - * @deprecated use method from {@link TopiaListenable} - */ - @Deprecated - void addTopiaSchemaListener(TopiaSchemaListener listener); - - /** - * Unregister the given TopiaSchemaListener about any schema modification - * from the context - * - * @param listener the listener instance to unregister - * @deprecated use method from {@link TopiaListenable} - */ - @Deprecated - void removeTopiaSchemaListener(TopiaSchemaListener listener); - - /* TopiaContextListener */ /** @@ -378,7 +353,7 @@ * Clear persistence implementation cache. * * @since 2.6.13 - * @deprecated use {@link TopiaHibernate#getHibernateSession().clear()} + * @deprecated use {@link TopiaHibernateSupport#getHibernateSession().clear()} */ @Deprecated void clearCache() throws TopiaException; @@ -468,16 +443,8 @@ @Deprecated 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 ? - /** * Triggers database schema creation * Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaException.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaException.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaException.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -26,8 +26,8 @@ package org.nuiton.topia; /** - * Main exception for Topia errors on hibernate manipulations. - * + * Main exception for any Topia error + * <p/> * Created: 23 déc. 2005 23:03:36 * * @author poussin <poussin@codelutin.com> @@ -39,7 +39,7 @@ private static final long serialVersionUID = -1251439453383121393L; /** - * Default constructor. + * Default constructor. */ public TopiaException() { } @@ -58,7 +58,7 @@ * with a {@code message}. * * @param message exception message - * @param cause exception cause + * @param cause exception cause */ public TopiaException(String message, Throwable cause) { super(message, cause); Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -1,55 +0,0 @@ -package org.nuiton.topia; - -/* - * #%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 org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.cfg.Configuration; - -/** - * @author Arnaud Thimel <thimel@codelutin.com> - */ -public interface TopiaHibernate { - - /** - * @return Returns the hibernate's Session. - * @throws TopiaException si aucune transaction n'est ouverte - */ - Session getHibernateSession() throws TopiaException; - - /** - * @return Returns the hibernateFactory. - * @throws TopiaNotFoundException - */ - SessionFactory getHibernateFactory() throws TopiaNotFoundException; - - /** - * @return Returns the hibernate configuration - * @throws TopiaNotFoundException - */ - Configuration getHibernateConfiguration() - throws TopiaNotFoundException; - -} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernateSupport.java (from rev 2786, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernateSupport.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernateSupport.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -0,0 +1,54 @@ +package org.nuiton.topia; + +/* + * #%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 org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.cfg.Configuration; + +/** + * This API provides methods to interact with Hibernate + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public interface TopiaHibernateSupport { + + /** + * @return Returns the Hibernate's Session. + */ + Session getHibernateSession(); + + /** + * @return Returns the HibernateFactory. + */ + SessionFactory getHibernateFactory(); + + /** + * @return Returns the Hibernate configuration + */ + Configuration getHibernateConfiguration(); + +} Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -27,12 +27,16 @@ import java.util.List; /** + * This API provides methods to use persistence using JPA queries + * * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 */ +// TODO AThimel 02/08/13 I think we need another name public interface TopiaJpaSupport { /** - * Allow to do some HQL query + * Allow to do some JPA-QL query * <p/> * WARNING : Depending on the registered service, this method may not * support something else than queries on TopiaEntity @@ -41,10 +45,9 @@ * @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 */ <T> List<T> findAll(String jpaql, - Object... propertyNamesAndValues) throws TopiaException; + Object... propertyNamesAndValues); /** * Allow to do some JPA-QL query using the given bounds. @@ -61,15 +64,14 @@ * @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 */ <T> List<T> find(String jpaql, int startIndex, int endIndex, - Object... propertyNamesAndValues) throws TopiaException; + Object... propertyNamesAndValues); /** - * Allow to do some HQL query and return an unique result. If nothing if + * Allow to do some JPA-QL query and return an unique result. If nothing if * found by the query, will return null. If more than one result is found, * will throw an exception. * <p/> @@ -80,22 +82,20 @@ * @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. */ + // TODO AThimel 02/08/13 Throw another exception if more than 1 result is found <T> T findUnique(String jpaql, - Object... propertyNamesAndValues) throws TopiaException; + Object... propertyNamesAndValues); /** - * Execute HQL operation on data (Update, Delete). + * Execute JPA-QL operation on data (Update, Delete). * * @param jpaql the JPA-QL 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 jpaql, - Object... propertyNamesAndValues) throws TopiaException; + Object... propertyNamesAndValues); } Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -1,223 +0,0 @@ -package org.nuiton.topia; - -/* - * #%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.beans.PropertyChangeListener; - -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.TopiaEntity; - -/** - * @author Arnaud Thimel <thimel@codelutin.com> - */ -public interface TopiaListenable { - - /* TopiaEntityListener */ - - /** - * 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); - - /** - * 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); - - /** - * Unregister the given TopiaEntityListener about any TopiaEntity from the - * context - * - * @param listener the listener instance to unregister - */ - void removeTopiaEntityListener(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); - - /** - * 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); - - - /* TopiaEntitiesVetoable */ - - /** - * 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); - - /** - * Unregister the given TopiaEntitiesVetoable about any TopiaEntity from the - * context - * - * @param vetoable the vetoable instance to unregister - */ - void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable); - - - /* TopiaTransactionListener */ - - /** - * Register to the context a TopiaTransactionListener about the transaction. - * <code>listener</code> instance will be notified AFTER any operation on - * the transaction. - * - * @param listener the listener instance to register - */ - void addTopiaTransactionListener(TopiaTransactionListener listener); - - /** - * Unregister the given TopiaTransactionListener about the transaction from - * the context - * - * @param listener the listener instance to unregister - */ - void removeTopiaTransactionListener(TopiaTransactionListener listener); - - - /* TopiaTransactionVetoable */ - - /** - * Register to the context a TopiaTransactionVetoable about the transaction. - * <code>vetoable</code> instance will be notified BEFORE any operation on - * the transaction. - * - * @param vetoable the vetoable instance to register - */ - void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable); - - /** - * Unregister the given TopiaTransactionVetoable about the transaction from - * the context - * - * @param vetoable the vetoable instance to unregister - */ - void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable); - - - /* PropertyChangeListener */ - - /** - * 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 - * - * @param listener the listener instance to register - */ - void addPropertyChangeListener(PropertyChangeListener listener); - - /** - * Unregister the given PropertyChangeListener about some entity's - * property change from the context - * - * @param listener the listener instance to unregister - */ - void removePropertyChangeListener(PropertyChangeListener listener); - - - /* TopiaSchemaListener */ - - /** - * 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 - * - * @param listener the listener instance to register - */ - void addTopiaSchemaListener(TopiaSchemaListener listener); - - /** - * Unregister the given TopiaSchemaListener about any schema modification - * from the context - * - * @param listener the listener instance to unregister - */ - void removeTopiaSchemaListener(TopiaSchemaListener listener); - - -} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenableSupport.java (from rev 2786, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenableSupport.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenableSupport.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -0,0 +1,227 @@ +package org.nuiton.topia; + +/* + * #%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.beans.PropertyChangeListener; + +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.TopiaEntity; + +/** + * This API provides methods to add/remove any kind of listener + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public interface TopiaListenableSupport { + + /* TopiaEntityListener */ + + /** + * 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); + + /** + * 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); + + /** + * Unregister the given TopiaEntityListener about any TopiaEntity from the + * context + * + * @param listener the listener instance to unregister + */ + void removeTopiaEntityListener(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); + + /** + * 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); + + + /* TopiaEntitiesVetoable */ + + /** + * 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); + + /** + * Unregister the given TopiaEntitiesVetoable about any TopiaEntity from the + * context + * + * @param vetoable the vetoable instance to unregister + */ + void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable); + + + /* TopiaTransactionListener */ + + /** + * Register to the context a TopiaTransactionListener about the transaction. + * <code>listener</code> instance will be notified AFTER any operation on + * the transaction. + * + * @param listener the listener instance to register + */ + void addTopiaTransactionListener(TopiaTransactionListener listener); + + /** + * Unregister the given TopiaTransactionListener about the transaction from + * the context + * + * @param listener the listener instance to unregister + */ + void removeTopiaTransactionListener(TopiaTransactionListener listener); + + + /* TopiaTransactionVetoable */ + + /** + * Register to the context a TopiaTransactionVetoable about the transaction. + * <code>vetoable</code> instance will be notified BEFORE any operation on + * the transaction. + * + * @param vetoable the vetoable instance to register + */ + void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable); + + /** + * Unregister the given TopiaTransactionVetoable about the transaction from + * the context + * + * @param vetoable the vetoable instance to unregister + */ + void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable); + + + /* PropertyChangeListener */ + + /** + * 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 + * + * @param listener the listener instance to register + */ + void addPropertyChangeListener(PropertyChangeListener listener); + + /** + * Unregister the given PropertyChangeListener about some entity's + * property change from the context + * + * @param listener the listener instance to unregister + */ + void removePropertyChangeListener(PropertyChangeListener listener); + + + /* TopiaSchemaListener */ + + /** + * 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 + * + * @param listener the listener instance to register + * @since 3.0 + */ + void addTopiaSchemaListener(TopiaSchemaListener listener); + + /** + * Unregister the given TopiaSchemaListener about any schema modification + * from the context + * + * @param listener the listener instance to unregister + * @since 3.0 + */ + void removeTopiaSchemaListener(TopiaSchemaListener listener); + +} Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNotFoundException.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNotFoundException.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNotFoundException.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -26,7 +26,7 @@ package org.nuiton.topia; /** - * TODO-FD20100507 : Need javadoc. + * Exception thrown if one of the entry from the configuration is missing at runtime * * Created: 23 déc. 2005 23:04:28 * Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -32,69 +32,53 @@ import org.nuiton.topia.persistence.TopiaIdFactory; /** + * This API provides all methods related to persistence : + * <ul> + * <li>Generic entity find</li> + * <li>Persistence customization</li> + * <li>DAO factory</li> + * <li>Schema management</li> + * </ul> + * * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 */ public interface TopiaPersistenceContext { /** - * Retrieve {@link org.nuiton.topia.persistence.TopiaEntity} using its unique {@code id}. + * Retrieve {@link org.nuiton.topia.persistence.TopiaEntity} using its unique {@code topiaId}. * * @param topiaId unique identifier of the entity in all the application. * @return the entity found or null - * @throws TopiaException for errors on retrieving the entity */ - <E extends TopiaEntity> E findByTopiaId(String topiaId) throws TopiaException; + <E extends TopiaEntity> E findByTopiaId(String topiaId); /** * Add into this TopiaContext an entity created by another TopiaContext * - * @param e the entity to add - * @throws TopiaException if any exception + * @param entity the entity to add */ - void update(TopiaEntity e) throws TopiaException; + void update(TopiaEntity entity); /** - * Triggers database schema creation + * Get the currently configured {@link TopiaIdFactory}. * - * @throws TopiaException if any exception - */ - void createSchema() throws TopiaException; - - /** - * Displays the SQL queries that would be used for a schema creation - * - * @throws TopiaException if any exception - */ - void showCreateSchema() throws TopiaException; - - /** - * Triggers database schema update - * - * @throws TopiaException if any exception - */ - void updateSchema() throws TopiaException; - - /** - * Triggers database schema drop - * - * @throws TopiaException if any exception + * @return the {@link TopiaIdFactory} in use + * @see {@link TopiaIdFactory} * @since 3.0 */ - void dropSchema() throws TopiaException; + TopiaIdFactory getTopiaIdFactory(); /** - * @return Returns the config. + * @return the list of classes managed by this TopiaPersistenceContext */ - Properties getConfig(); // TODO AThimel 02/08/13 Change type ? + List<Class<?>> getPersistenceClasses(); - // TODO AThimel 02/08/13 Javadoc - TopiaIdFactory getTopiaIdFactory(); - /** * Tells to the context if it has to use a flush mode before each query. - * + * <p/> * By default, we use a flush mode, but in some case it costs to much doing - * this, that's why you can desactivate it setting the value to {@code false}. + * this, that's why you can disable it setting the value to {@code false}. * * @param useFlushMode the new value to set * @since 2.5 @@ -102,40 +86,74 @@ void setUseFlushMode(boolean useFlushMode); /** - * Detect if the table is created on storage for a given persistant class. - * - * @param clazz the researched class - * @return Returns the hibernate. - * @throws TopiaException si aucune transaction n'est ouverte + * @return Returns the config. */ - boolean isSchemaExist(Class<?> clazz) throws TopiaException; + Properties getConfig(); // TODO AThimel 02/08/13 Change type ? /** * Get DAO for specified class. If Specialized DAO exists then it returned * otherwize TopiaDAO<entityClass> is returned * - * @param <E> type of entity * @param entityClass type of entity - * @return the required dao - * @throws TopiaException if any error + * @return the expected dao */ - <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass) - throws TopiaException; + <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass); /** * Get DAO for specified class. If Specialized DAO exists then it returned * otherwize TopiaDAO<entityClass> is returned * - * @param <E> type of entity * @param entityClass type of entity - * @param daoClass the concrete dao class to use - * @return the required dao - * @throws TopiaException if any error + * @param daoClass the concrete dao class to use + * @return the expected dao */ - <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass,Class<D> daoClass) - throws TopiaException; + <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass, Class<D> daoClass); - // TODO AThimel 02/08/13 Javadoc - List<Class<?>> getPersistenceClasses(); + /** + * Detects if the db associated to the current context contains at least one + * entity table. + * + * @return {@code true} if there is no schema for any of the dealed entities, + * {@code false} otherwise. + * @since 3.0 + */ + boolean isSchemaEmpty(); + /** + * Detects if the table is created on storage for a given persistent class. + * + * @param clazz the researched class + * @return true if the table exists on storage + * @since 3.0 + */ + boolean isTableExists(Class<?> clazz); + + /** + * @return the current schema name + * @since 3.0 + */ + String getSchemaName(); + + /** + * Triggers database schema creation + */ + void createSchema(); + + /** + * Displays the SQL queries that would be used for a schema creation + */ + void showCreateSchema(); + + /** + * Triggers database schema update + */ + void updateSchema(); + + /** + * Triggers database schema drop + * + * @since 3.0 + */ + void dropSchema(); + } Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -29,11 +29,13 @@ import org.nuiton.topia.persistence.TopiaEntity; /** + * This API provides methods about entities replication + * * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 */ public interface TopiaReplicationSupport { - /** * Makes a replication of some entities from this context to the given * context without any entity modification. @@ -49,27 +51,24 @@ * @param entityAndCondition [key;value;...] parameter which key is the * entity class to replicate, and value the * "where" condition to use when querying entities - * @throws TopiaException if any problem occurred during replicate * @throws IllegalArgumentException if one of the context is closed or if * trying to replicate within the same * database */ void replicate(TopiaContext destinationContext, - Object... entityAndCondition) throws TopiaException, IllegalArgumentException; + Object... entityAndCondition) throws IllegalArgumentException; /** * Replicate a given entity from this context to the given context. * * @param destinationContext the destination context * @param entity the entity instance to replicate - * @param <T> type of the entity to replicate - * @throws TopiaException if any problem occurred during replicate * @throws IllegalArgumentException if one of the context is closed or if * trying to replicate within the same * database */ <T extends TopiaEntity> void replicateEntity(TopiaContext destinationContext, - T entity) throws TopiaException, IllegalArgumentException; + T entity) throws IllegalArgumentException; /** * Makes a replication of some entities from this context to the given @@ -77,13 +76,11 @@ * * @param destinationContext the destination context * @param entities the list of entities instance to replicate - * @param <T> type of the entities to replicate - * @throws TopiaException if any problem occurred during replicate * @throws IllegalArgumentException if one of the context is closed or if * trying to replicate within the same * database */ <T extends TopiaEntity> void replicateEntities(TopiaContext destinationContext, - List<T> entities) throws TopiaException, IllegalArgumentException; + List<T> entities) throws IllegalArgumentException; } Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -29,14 +29,16 @@ import org.nuiton.topia.framework.TopiaService; /** + * This API provides methods to manipulate services + * * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 */ public interface TopiaServiceSupport { /** * Return true if specific service is available. * - * @param <E> type of service * @param interfaceService fqn of the service * @return the service */ @@ -46,13 +48,17 @@ * 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; + /** + * The list of registered services. The map key is the service name, and the value is the service instance. + * + * @return a map with {serviceName, serviceInstance} values + */ Map<String, TopiaService> getServices(); } Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -25,7 +25,10 @@ */ /** + * This API provides methods to run SQL queries + * * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 */ public interface TopiaSqlSupport { @@ -33,8 +36,9 @@ * Execute a given sql code inside this transaction. * * @param sqlScript the sql script to execute - * @throws TopiaException if any problem occurred while executing the sql script. */ - void executeSQL(String sqlScript) throws TopiaException; + void executeSQL(String sqlScript); + // TODO AThimel 20/07/13 Copy "void doSQLWork(TopiaSQLWork sqlWork);" from topia-3.0-jpa + } Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java (from rev 2786, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransactionSupport.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -0,0 +1,73 @@ +package org.nuiton.topia; + +/* + * #%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% + */ + +/** + * This API provides methods to manipulate transaction + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public interface TopiaTransaction { + + /** + * Returns a new context containing its own transaction. + * + * @return new context with transaction + * @deprecated Sub contexts are not supported anymore, it is not possible to get a transaction FROM a transaction + */ + @Deprecated + TopiaContext beginTransaction(); + + // TODO AThimel 03/08/13 We need another API to obtain a TopiaTransaction + // TODO AThimel 03/08/13 This new method has to be located somewhere else (TopiaTransactionSupplier ? TopiaTransactionSupport ? or just TopiaPersistenceContext ?) + + /** + * Applies all the modifications made to this context on the persistence + * device. Once commit is done, a new transaction is started. + */ + void commitTransaction(); + + /** + * 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. + */ + void rollbackTransaction(); + + /** + * Closes the context. All the children contexts will be closed in the same + * time. + */ + void closeContext(); + + /** + * Tells if the context is closed + * + * @return {@code true} if the context is closed, {@code false} otherwise + */ + boolean isClosed(); + +} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransactionSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransactionSupport.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransactionSupport.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -1,72 +0,0 @@ -package org.nuiton.topia; - -/* - * #%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% - */ - -/** - * @author Arnaud Thimel <thimel@codelutin.com> - */ -public interface TopiaTransactionSupport { - - /** - * Returns a new context containing its own transaction. - * - * @return new context with transaction - * @throws TopiaException if any exception - */ - TopiaContext beginTransaction() throws TopiaException; - - /** - * 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; - - /** - * 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; - - /** - * Closes the context. All the children contexts will be closed in the same - * time. - * - * @throws TopiaException if any exception - */ - void closeContext() throws TopiaException; - - /** - * Tells if the context is closed - * - * @return {@code true} if the context is closed, {@code false} otherwise - */ - boolean isClosed(); - -} Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaVetoException.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaVetoException.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaVetoException.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -26,13 +26,14 @@ package org.nuiton.topia; /** - * TODO-FD20100507 : Need javadoc. - * + * Exception thrown when something went wrong during event firing + * <p/> * Created: 5 janv. 2006 00:47:51 * * @author poussin <poussin@codelutin.com> * @version $Id$ */ +// TODO AThimel 03/08/13 Extends TopiaException ? public class TopiaVetoException extends RuntimeException { /** Version UID */ @@ -58,7 +59,7 @@ * with a {@code message}. * * @param message exception message - * @param cause exception cause + * @param cause exception cause */ public TopiaVetoException(String message, Throwable cause) { super(message, cause); Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -114,8 +114,7 @@ */ //TODO-fdesbois-20100507 : Need translation of javadoc. // TODO AThimel 02/08/13 must be abstract -public class AbstractTopiaContext implements TopiaContext - , TopiaContextImplementor { +public class AbstractTopiaContext implements TopiaContext, TopiaContextImplementor { /** * to use log facility, just put in your code: log.info(\"...\"); @@ -563,7 +562,7 @@ } @Override - public SessionFactory getHibernateFactory() throws TopiaNotFoundException { + public SessionFactory getHibernateFactory() { if (hibernateFactory == null) { if (getParentContext() != null) { hibernateFactory = getParentContext().getHibernateFactory(); @@ -597,8 +596,7 @@ } @Override - public Configuration getHibernateConfiguration() - throws TopiaNotFoundException { + public Configuration getHibernateConfiguration() { if (hibernateConfiguration == null) { if (getParentContext() != null) { hibernateConfiguration = getParentContext().getHibernateConfiguration(); @@ -644,7 +642,7 @@ log.debug("Load persistent class : " + classname); } - // XXX echatellier 20111007 ce cqui est dommage ici, c'est + // XXX echatellier 20111007 ce qui est dommage ici, c'est // la definition de cette classe ne sert a rien (apart security) // car pour hibernate hibernateConfiguration.addClass(persistanceClass) // il ne se sert pas de la classe en fait et fait seulement @@ -967,7 +965,7 @@ @Override public <E extends TopiaEntity> E findByTopiaId(String id) throws TopiaException { checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'", - "findById")); + "findByTopiaId")); Class<E> entityClass = getTopiaIdFactory().getClassName(id); TopiaDAO<E> dao = getDAO(entityClass); @@ -1291,12 +1289,29 @@ @Override public boolean isSchemaExist(Class<?> clazz) throws TopiaException { + return isTableExists(clazz); + } + + @Override + public boolean isSchemaEmpty() { + // TODO AThimel 02/08/13 Implement + throw new UnsupportedOperationException("Not yet implemented"); + } + + @Override + public boolean isTableExists(Class<?> clazz) { checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'", "replicateEntity")); boolean result = TopiaUtil.isSchemaExist(this, clazz.getName()); return result; } + @Override + public String getSchemaName() { + // TODO AThimel 02/08/13 I absolutely don't know if it works + return getConfig().getProperty(TopiaContextFactory.CONFIG_DEFAULT_SCHEMA); + } + /* Listeners adders */ @Override @@ -1528,14 +1543,14 @@ } @Override - public void update(TopiaEntity e) throws TopiaException { + public void update(TopiaEntity entity) throws TopiaException { checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'", "add")); - String id = e.getTopiaId(); + String id = entity.getTopiaId(); Class<TopiaEntity> entityClass = getTopiaIdFactory().getClassName(id); TopiaDAO<TopiaEntity> dao = getDAO(entityClass); - dao.update(e); + dao.update(entity); } } //AbstractTopiaContext Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -30,11 +30,9 @@ import org.hibernate.cfg.Configuration; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaHibernate; import org.nuiton.topia.TopiaNotFoundException; import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.TopiaIdFactory; import java.util.List; import java.util.Map; @@ -91,7 +89,7 @@ /** * @return Returns the hibernate. * @throws TopiaException si aucune transaction n'est ouverte - * @deprecated use method from {@link TopiaHibernate} + * @deprecated use method from {@link org.nuiton.topia.TopiaHibernateSupport} */ @Deprecated Session getHibernate() throws TopiaException; @@ -99,7 +97,7 @@ /** * @return Returns the hibernateFactory. * @throws TopiaNotFoundException - * @deprecated use method from {@link TopiaHibernate} + * @deprecated use method from {@link org.nuiton.topia.TopiaHibernateSupport} */ @Deprecated SessionFactory getHibernateFactory() throws TopiaNotFoundException; @@ -107,7 +105,7 @@ /** * @return Returns the hibernate configuration * @throws TopiaNotFoundException - * @deprecated use method from {@link TopiaHibernate} + * @deprecated use method from {@link org.nuiton.topia.TopiaHibernateSupport} */ @Deprecated Configuration getHibernateConfiguration() Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DefaultTopiaIdFactory.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DefaultTopiaIdFactory.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DefaultTopiaIdFactory.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -24,25 +24,30 @@ * #L% */ +import java.util.UUID; + +import org.nuiton.topia.TopiaException; + import com.google.common.base.Splitter; import com.google.common.collect.Iterables; -import org.nuiton.topia.TopiaException; -import java.util.UUID; - /** * Default implementation of {@link TopiaIdFactory}. Generates an FQN followed * by an random UUID. + * + * @author Brendan Le Ny <leny@codelutin.com> + * @since 3.0 */ public class DefaultTopiaIdFactory implements TopiaIdFactory { @Override public <E extends TopiaEntity> String newTopiaId(Class<E> entityClass, TopiaEntity topiaEntity) { - if ( ! entityClass.isInterface()) { + if (!entityClass.isInterface()) { throw new IllegalArgumentException( "Only interface is permit to create id: " + entityClass); } - return entityClass.getName() + '_' + UUID.randomUUID().toString(); + String result = entityClass.getName() + '_' + UUID.randomUUID().toString(); + return result; } @Override Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaIdFactory.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaIdFactory.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaIdFactory.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -56,7 +56,7 @@ * @throws org.nuiton.topia.TopiaNotFoundException */ @Override - public Class getClassName(String topiaId) throws TopiaNotFoundException { + public <E extends TopiaEntity> Class<E> getClassName(String topiaId) { String className = ""; int i = topiaId.indexOf('#'); if (i > 0) { Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -663,7 +663,7 @@ * * @return Returns the context. */ - // TODO AThimel 02/08/13 Use only TopiaPersistenceContext and TopiaHibernate + // TODO AThimel 02/08/13 Use only TopiaPersistenceContext and TopiaHibernateSupport TopiaContext getTopiaContext(); /** 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-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntities.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -25,10 +25,14 @@ */ import com.google.common.base.Function; +import com.google.common.base.Optional; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import com.google.common.collect.Iterables; public class TopiaEntities { - protected static final Function<TopiaEntity, String> GET_TOPIA_ID = new Function<TopiaEntity, String>() { + public static final Function<TopiaEntity, String> GET_TOPIA_ID = new Function<TopiaEntity, String>() { @Override public String apply(TopiaEntity input) { @@ -36,12 +40,28 @@ } }; + public static Predicate<TopiaEntity> entityHasId(String id) { + return Predicates.compose(Predicates.equalTo(id), GET_TOPIA_ID); + } + + public static <E extends TopiaEntity> E findByTopiaId(Iterable<E> entities, String id) { + E result; + if (entities == null) { + result = null; + } else { + Optional<E> eOptional = Iterables.tryFind(entities, entityHasId(id)); + result = eOptional.orNull(); + } + return result; + } + /** * Function to obtain {@link TopiaEntity#getTopiaId()} from any entity. * * @since 2.6.12 + * @deprecated use directly {@link #GET_TOPIA_ID} function */ - // TODO AThimel 20/07/13 Why is this function useful ? Why not use directly the GET_TOPIA_ID Function ? + @Deprecated public static Function<TopiaEntity, String> getTopiaIdFunction() { return GET_TOPIA_ID; } Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -57,7 +57,7 @@ * @author tchemit <tchemit@codelutin.com> * @author chatellier <chatellier@codelutin.com> * @version $Id$ - * @deprecated since 3.0 depends on implementation of TopiaIdFactory. WILL BE moved to topia-service-security + * @deprecated since 3.0 depends on implementation of TopiaIdFactory. Will be removed in next versions */ @Deprecated public class TopiaId implements Serializable { // TopiaId @@ -69,10 +69,10 @@ * Function to obtain {@link TopiaEntity#getTopiaId()} from any entity. * * @since 2.6.12 - * @deprecated since 3.0 use {@link org.nuiton.topia.persistence.TopiaEntities#getTopiaIdFunction()} + * @deprecated since 3.0 use {@link org.nuiton.topia.persistence.TopiaEntities#GET_TOPIA_ID} */ @Deprecated - public static final Function<TopiaEntity, String> GET_TOPIA_ID = TopiaEntities.getTopiaIdFunction(); + public static final Function<TopiaEntity, String> GET_TOPIA_ID = TopiaEntities.GET_TOPIA_ID; public String topiaId; Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactory.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactory.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactory.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -25,10 +25,10 @@ */ /** - * Contract representing a strategy of id generation. + * This API represents an ID generation strategy * + * @author bleny * @since 3.0 - * @author bleny */ public interface TopiaIdFactory { Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/EntityCsvModel.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/EntityCsvModel.java 2013-08-02 17:26:06 UTC (rev 2786) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/EntityCsvModel.java 2013-08-03 01:14:27 UTC (rev 2787) @@ -131,7 +131,7 @@ Collection<E> entities) { Map<String, E> universe = Maps.uniqueIndex(entities, - TopiaEntities.getTopiaIdFunction()); + TopiaEntities.GET_TOPIA_ID); newMandatoryColumn(propertyName, TopiaCsvCommons.newForeignKeyValue(entityType,