Author: athimel Date: 2013-08-02 18:21:12 +0200 (Fri, 02 Aug 2013) New Revision: 2785 Url: http://nuiton.org/projects/topia/repository/revisions/2785 Log: refs #2748 Split TopiaContext in several smaller contracts Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.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/TopiaTransaction.java Modified: trunk/pom.xml trunk/topia-persistence/pom.xml trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java trunk/topia-service-migration/pom.xml trunk/topia-service-replication/pom.xml trunk/topia-service-security/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2013-07-25 17:03:03 UTC (rev 2784) +++ trunk/pom.xml 2013-08-02 16:21:12 UTC (rev 2785) @@ -37,7 +37,7 @@ </parent> <artifactId>topia</artifactId> - <version>3.0-alpha-2-SNAPSHOT</version> + <version>3.0-SNAPSHOT</version> <modules> <module>topia-persistence</module> Modified: trunk/topia-persistence/pom.xml =================================================================== --- trunk/topia-persistence/pom.xml 2013-07-25 17:03:03 UTC (rev 2784) +++ trunk/topia-persistence/pom.xml 2013-08-02 16:21:12 UTC (rev 2785) @@ -35,7 +35,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>topia</artifactId> - <version>3.0-alpha-2-SNAPSHOT</version> + <version>3.0-SNAPSHOT</version> </parent> <groupId>org.nuiton.topia</groupId> 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-25 17:03:03 UTC (rev 2784) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-08-02 16:21:12 UTC (rev 2785) @@ -25,6 +25,10 @@ package org.nuiton.topia; +import java.beans.PropertyChangeListener; +import java.io.File; +import java.util.List; + import org.nuiton.topia.event.TopiaContextListener; import org.nuiton.topia.event.TopiaEntitiesVetoable; import org.nuiton.topia.event.TopiaEntityListener; @@ -35,10 +39,6 @@ import org.nuiton.topia.framework.TopiaService; import org.nuiton.topia.persistence.TopiaEntity; -import java.beans.PropertyChangeListener; -import java.io.File; -import java.util.List; - /** * The TopiaContext is the most important class of ToPIA. It contains all the * methods to manipulate data : transaction management, entities querying, event @@ -53,8 +53,11 @@ * @author tchemit <tchemit@codelutin.com> * @author athimel <thimel@codelutin.com> * @version $Id$ + * @deprecated Since 3.0, TopiaContext is splitted in multiple contracts */ -public interface TopiaContext { +@Deprecated +public interface TopiaContext extends TopiaTransaction, TopiaListenable, TopiaSqlSupport, TopiaJpaSupport, + TopiaPersistenceContext, TopiaServiceSupport, TopiaReplicationSupport { /* -------------------- TRANSACTION MANAGEMENT --------------------------*/ @@ -63,7 +66,9 @@ * * @return new context with transaction * @throws TopiaException if any exception + * @deprecated use method from {@link TopiaTransaction} */ + @Deprecated TopiaContext beginTransaction() throws TopiaException; /** @@ -71,7 +76,9 @@ * device. Once commit is done, a new transaction is started. * * @throws TopiaException if any exception + * @deprecated use method from {@link TopiaTransaction} */ + @Deprecated void commitTransaction() throws TopiaException; /** @@ -80,7 +87,9 @@ * transaction is started. * * @throws TopiaException if any exception + * @deprecated use method from {@link TopiaTransaction} */ + @Deprecated void rollbackTransaction() throws TopiaException; /** @@ -88,14 +97,18 @@ * time. * * @throws TopiaException if any exception + * @deprecated use method from {@link TopiaTransaction} */ + @Deprecated void closeContext() throws TopiaException; /** * Tells if the context is closed * * @return {@code true} if the context is closed, {@code false} otherwise + * @deprecated use method from {@link TopiaTransaction} */ + @Deprecated boolean isClosed(); /* ------------------------ EVENT FIRING --------------------------*/ @@ -108,7 +121,9 @@ * the entity. * * @param listener the listener instance to register + * @deprecated use method from {@link TopiaListenable} */ + @Deprecated void addTopiaEntityListener(TopiaEntityListener listener); /** @@ -118,7 +133,9 @@ * * @param entityClass the TopiaEntity's class to listen * @param listener the listener instance to register + * @deprecated use method from {@link TopiaListenable} */ + @Deprecated void addTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener); @@ -127,7 +144,9 @@ * context * * @param listener the listener instance to unregister + * @deprecated use method from {@link TopiaListenable} */ + @Deprecated void removeTopiaEntityListener(TopiaEntityListener listener); /** @@ -136,7 +155,9 @@ * * @param entityClass the listened TopiaEntity's class * @param listener the listener instance to unregister + * @deprecated use method from {@link TopiaListenable} */ + @Deprecated void removeTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener); @@ -149,7 +170,9 @@ * the entity. * * @param vetoable the vetoable instance to register + * @deprecated use method from {@link TopiaListenable} */ + @Deprecated void addTopiaEntityVetoable(TopiaEntityVetoable vetoable); /** @@ -159,7 +182,9 @@ * * @param entityClass the TopiaEntity's class to listen * @param vetoable the vetoable instance to register + * @deprecated use method from {@link TopiaListenable} */ + @Deprecated void addTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable); @@ -168,7 +193,9 @@ * context * * @param vetoable the vetoable instance to unregister + * @deprecated use method from {@link TopiaListenable} */ + @Deprecated void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable); /** @@ -177,7 +204,9 @@ * * @param entityClass the listened TopiaEntity's class * @param vetoable the vetoable instance to unregister + * @deprecated use method from {@link TopiaListenable} */ + @Deprecated void removeTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable); @@ -189,7 +218,9 @@ * <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 void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable); /** @@ -197,7 +228,9 @@ * context * * @param vetoable the vetoable instance to unregister + * @deprecated use method from {@link TopiaListenable} */ + @Deprecated void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable); @@ -209,7 +242,9 @@ * the transaction. * * @param listener the listener instance to register + * @deprecated use method from {@link TopiaListenable} */ + @Deprecated void addTopiaTransactionListener(TopiaTransactionListener listener); /** @@ -217,7 +252,9 @@ * the context * * @param listener the listener instance to unregister + * @deprecated use method from {@link TopiaListenable} */ + @Deprecated void removeTopiaTransactionListener(TopiaTransactionListener listener); @@ -229,7 +266,9 @@ * the transaction. * * @param vetoable the vetoable instance to register + * @deprecated use method from {@link TopiaListenable} */ + @Deprecated void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable); /** @@ -237,7 +276,9 @@ * the context * * @param vetoable the vetoable instance to unregister + * @deprecated use method from {@link TopiaListenable} */ + @Deprecated void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable); @@ -249,7 +290,9 @@ * any change on the entity's property * * @param listener the listener instance to register + * @deprecated use method from {@link TopiaListenable} */ + @Deprecated void addPropertyChangeListener(PropertyChangeListener listener); /** @@ -257,7 +300,9 @@ * property change from the context * * @param listener the listener instance to unregister + * @deprecated use method from {@link TopiaListenable} */ + @Deprecated void removePropertyChangeListener(PropertyChangeListener listener); @@ -269,7 +314,9 @@ * AFTER any change on the schema * * @param listener the listener instance to register + * @deprecated use method from {@link TopiaListenable} */ + @Deprecated void addTopiaSchemaListener(TopiaSchemaListener listener); /** @@ -277,7 +324,9 @@ * from the context * * @param listener the listener instance to unregister + * @deprecated use method from {@link TopiaListenable} */ + @Deprecated void removeTopiaSchemaListener(TopiaSchemaListener listener); @@ -312,10 +361,31 @@ * @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 + * @deprecated use {@link TopiaPersistenceContext#findByTopiaId(String)} */ + @Deprecated <E extends TopiaEntity> E findByTopiaId(String topiaId) throws TopiaException; /** + * Add into this TopiaContext an entity created by another TopiaContext + * + * @param e the entity to add + * @throws TopiaException if any exception + * @deprecated use {@link TopiaPersistenceContext#update(org.nuiton.topia.persistence.TopiaEntity)} + */ + @Deprecated + void add(TopiaEntity e) throws TopiaException; + + /** + * Clear persistence implementation cache. + * + * @since 2.6.13 + * @deprecated use {@link TopiaHibernate#getHibernateSession().clear()} + */ + @Deprecated + void clearCache() throws TopiaException; + + /** * Allow to do some HQL query * <p/> * WARNING : Depending on the registered service, this method may not @@ -326,7 +396,9 @@ * [propertyName;value;propertyName;value;...] * @return The result list * @throws TopiaException for any error during querying + * @deprecated use method from {@link TopiaJpaSupport} */ + @Deprecated <E> List<E> findAll(String hql, Object... propertyNamesAndValues) throws TopiaException; @@ -346,7 +418,9 @@ * [propertyName;value;propertyName;value;...] * @return The result list * @throws TopiaException for any error during querying + * @deprecated use method from {@link TopiaJpaSupport} */ + @Deprecated <E> List<E> find(String hql, int startIndex, int endIndex, @@ -366,36 +440,13 @@ * @return The result instance or null * @throws TopiaException for any error during querying or if the the query * returns more than one result. + * @deprecated use method from {@link TopiaJpaSupport} */ + @Deprecated <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; - - /** - * Detaches the given entity from the session - * - * @param e the entity to detach - * @throws TopiaException if any exception - * - * @since 3.0 - */ - void evict(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 the HQL query @@ -403,7 +454,9 @@ * [propertyName;value;propertyName;value;...] * @return The number of entities updated or deleted. * @throws TopiaException if any exception + * @deprecated use method from {@link TopiaJpaSupport} */ + @Deprecated int execute(String hql, Object... propertyNamesAndValues) throws TopiaException; @@ -412,7 +465,9 @@ * * @param sqlScript the sql script to execute * @throws TopiaException if any problem occurred while executing the sql script. + * @deprecated use method from {@link TopiaSqlSupport} */ + @Deprecated void executeSQL(String sqlScript) throws TopiaException; // TODO AThimel 20/07/13 Copy "void doSQLWork(TopiaSQLWork sqlWork);" from topia-3.0-jpa ? @@ -429,31 +484,29 @@ * Triggers database schema creation * * @throws TopiaException if any exception + * @deprecated use methods from {@link TopiaPersistenceContext} */ + @Deprecated void createSchema() throws TopiaException; /** * Displays the SQL queries that would be used for a schema creation * * @throws TopiaException if any exception + * @deprecated use methods from {@link TopiaPersistenceContext} */ + @Deprecated void showCreateSchema() throws TopiaException; /** * Triggers database schema update * * @throws TopiaException if any exception + * @deprecated use methods from {@link TopiaPersistenceContext} */ + @Deprecated void updateSchema() throws TopiaException; - /** - * Triggers database schema drop - * - * @throws TopiaException if any exception - * @since 3.0 - */ - void dropSchema() throws TopiaException; - /* -------------------- SERVICES MANAGMENT -------------------------------*/ /** @@ -462,7 +515,9 @@ * @param <E> type of service * @param interfaceService fqn of the service * @return the service + * @deprecated use methods from {@link TopiaServiceSupport} */ + @Deprecated <E extends TopiaService> boolean serviceEnabled(Class<E> interfaceService); /** @@ -473,7 +528,9 @@ * @param interfaceService class of the service * @return the service * @throws TopiaNotFoundException if service can't be retrieved + * @deprecated use methods from {@link TopiaServiceSupport} */ + @Deprecated <E extends TopiaService> E getService(Class<E> interfaceService) throws TopiaNotFoundException; /* ------------------ IMPORT / EXPORT / REPLICATION ---------------------*/ @@ -497,7 +554,9 @@ * @throws IllegalArgumentException if one of the context is closed or if * trying to replicate within the same * database + * @deprecated use methods from {@link TopiaReplicationSupport} */ + @Deprecated void replicate(TopiaContext destinationContext, Object... entityAndCondition) throws TopiaException, IllegalArgumentException; @@ -511,7 +570,9 @@ * @throws IllegalArgumentException if one of the context is closed or if * trying to replicate within the same * database + * @deprecated use methods from {@link TopiaReplicationSupport} */ + @Deprecated <T extends TopiaEntity> void replicateEntity(TopiaContext destinationContext, T entity) throws TopiaException, IllegalArgumentException; @@ -526,7 +587,9 @@ * @throws IllegalArgumentException if one of the context is closed or if * trying to replicate within the same * database + * @deprecated use methods from {@link TopiaReplicationSupport} */ + @Deprecated <T extends TopiaEntity> void replicateEntities(TopiaContext destinationContext, List<T> entities) throws TopiaException, IllegalArgumentException; @@ -548,7 +611,7 @@ boolean compress) throws TopiaException; /** - * l'inverse de la methode {@link #backup(File,boolean)}. + * 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. Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java 2013-08-02 16:21:12 UTC (rev 2785) @@ -0,0 +1,55 @@ +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; + +} Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java 2013-08-02 16:21:12 UTC (rev 2785) @@ -0,0 +1,101 @@ +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.util.List; + +/** + * @author Arnaud Thimel <thimel@codelutin.com> + */ +public interface TopiaJpaSupport { + + /** + * 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 jpaql the JPA-QL 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 + */ + <T> List<T> findAll(String jpaql, + Object... propertyNamesAndValues) throws TopiaException; + + /** + * 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 jpaql the JPA-QL 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 + */ + <T> List<T> find(String jpaql, + int startIndex, + int endIndex, + Object... propertyNamesAndValues) throws TopiaException; + + /** + * Allow to do some HQL 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/> + * WARNING : Depending on the registered service, this method may not + * support something else than queries on TopiaEntity + * + * @param jpaql the JPA-QL 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. + */ + <T> T findUnique(String jpaql, + Object... propertyNamesAndValues) throws TopiaException; + + /** + * Execute HQL 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; + +} Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.java 2013-08-02 16:21:12 UTC (rev 2785) @@ -0,0 +1,223 @@ +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); + + +} Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-08-02 16:21:12 UTC (rev 2785) @@ -0,0 +1,141 @@ +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.util.List; +import java.util.Properties; + +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaIdFactory; + +/** + * @author Arnaud Thimel <thimel@codelutin.com> + */ +public interface TopiaPersistenceContext { + + /** + * Retrieve {@link org.nuiton.topia.persistence.TopiaEntity} using its unique {@code id}. + * + * @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; + + /** + * Add into this TopiaContext an entity created by another TopiaContext + * + * @param e the entity to add + * @throws TopiaException if any exception + */ + void update(TopiaEntity e) throws TopiaException; + + /** + * Triggers database schema creation + * + * @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 + * @since 3.0 + */ + void dropSchema() throws TopiaException; + + /** + * @return Returns the config. + */ + Properties getConfig(); // TODO AThimel 02/08/13 Change type ? + + // TODO AThimel 02/08/13 Javadoc + TopiaIdFactory getTopiaIdFactory(); + + /** + * Tells to the context if it has to use a flush mode before each query. + * + * 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}. + * + * @param useFlushMode the new value to set + * @since 2.5 + */ + 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 + */ + boolean isSchemaExist(Class<?> clazz) throws TopiaException; + + /** + * 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 + */ + <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass) + throws TopiaException; + + /** + * 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 + */ + <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass,Class<D> daoClass) + throws TopiaException; + + // TODO AThimel 02/08/13 Javadoc + List<Class<?>> getPersistenceClasses(); + +} Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java 2013-08-02 16:21:12 UTC (rev 2785) @@ -0,0 +1,89 @@ +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.util.List; + +import org.nuiton.topia.persistence.TopiaEntity; + +/** + * @author Arnaud Thimel <thimel@codelutin.com> + */ +public interface TopiaReplicationSupport { + + + /** + * Makes a replication of some entities from this context to the given + * context without any entity modification. + * <p/> + * <b>Note:</b> If the <code>entityAndCondition</code> parameter is empty, + * all the database will be replicated + * <p/> + * <b>Note 2:</b> The simple replication may not be sufficent. You may want + * to replicate only a part of some entities : use the method {@link + * #replicateEntities(TopiaContext, java.util.List)}. + * + * @param destinationContext the destination context + * @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; + + /** + * 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; + + /** + * Makes a replication of some entities from this context to the given + * context without any entity modification. + * + * @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; + +} Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java 2013-08-02 16:21:12 UTC (rev 2785) @@ -0,0 +1,58 @@ +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.util.Map; + +import org.nuiton.topia.framework.TopiaService; + +/** + * @author Arnaud Thimel <thimel@codelutin.com> + */ +public interface TopiaServiceSupport { + + /** + * 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; + + Map<String, TopiaService> getServices(); + +} Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java 2013-08-02 16:21:12 UTC (rev 2785) @@ -0,0 +1,40 @@ +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 TopiaSqlSupport { + + /** + * 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; + +} Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.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-02 16:21:12 UTC (rev 2785) @@ -0,0 +1,72 @@ +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 TopiaTransaction { + + /** + * 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(); + +} Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.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-25 17:03:03 UTC (rev 2784) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2013-08-02 16:21:12 UTC (rev 2785) @@ -25,6 +25,29 @@ package org.nuiton.topia.framework; +import java.beans.PropertyChangeListener; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.WeakHashMap; +import java.util.zip.GZIPInputStream; + import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -64,29 +87,6 @@ import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaIdFactory; -import java.beans.PropertyChangeListener; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.lang.reflect.Field; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.WeakHashMap; -import java.util.zip.GZIPInputStream; - /** * Le TopiaContextImpl est le point d'entre pour acceder aux donnees. Il est * configurer par un fichier de propriete @@ -115,13 +115,19 @@ //TODO-fdesbois-20100507 : Need translation of javadoc. public class TopiaContextImpl implements TopiaContextImplementor { - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** + * to use log facility, just put in your code: log.info(\"...\"); + */ private static final Log log = LogFactory.getLog(TopiaContextImpl.class); - /** Le pere de ce context, les contexts initaux n'ont pas de context pere */ + /** + * Le pere de ce context, les contexts initaux n'ont pas de context pere + */ protected TopiaContextImplementor parentContext; - /** L'objet configuration utilisé pour la creation de la factory hibernate */ + /** + * L'objet configuration utilisé pour la creation de la factory hibernate + */ protected Configuration hibernateConfiguration; /** @@ -130,28 +136,35 @@ */ protected SessionFactory hibernateFactory; - /** La session utilisé par le TopiaContextImpl */ + /** + * La session utilisé par le TopiaContextImpl + */ protected Session hibernate; - /** Indique si le contexte a ete ferme */ + /** + * Indique si le contexte a ete ferme + */ protected boolean closed; /** * This flag permits to use (or not) the flush mode when doing queries. - * + * <p/> * The normal usage is to says yes (that's why the default value is * {@code true}), in that case whebn doing queries (says in method * {@link #findAll(String, Object...)} or {@link #find(String, int, int, Object...)}) * it will use the flush mode {@link FlushMode#AUTO}). - * + * <p/> * But sometimes, when doing a lot of queries (for some imports for example), * we do NOT want the session to be flushed each time we do a find, then you * can set this flag to {@code false} using the method {@link #setUseFlushMode(boolean)} + * * @since 2.5 */ protected boolean useFlushMode = true; - /** Propriete de configuration */ + /** + * Propriete de configuration + */ protected Properties config; /** @@ -161,7 +174,9 @@ */ protected TopiaIdFactory topiaIdFactory; - /** cache des DAO deja chargé pour ce context */ + /** + * cache des DAO deja chargé pour ce context + */ protected Map<Class<? extends TopiaEntity>, TopiaDAO<? extends TopiaEntity>> daoCache = new HashMap<Class<? extends TopiaEntity>, @@ -182,15 +197,21 @@ Collections.newSetFromMap( new WeakHashMap<TopiaContextImplementor, Boolean>())); - /** key: service name; value: service instance */ + /** + * key: service name; value: service instance + */ protected Map<String, TopiaService> services; protected TopiaFiresSupport firesSupport = new TopiaFiresSupport(); - /** Liste des classes perssitance */ + /** + * Liste des classes perssitance + */ protected List<Class<?>> persistenceClasses = new ArrayList<Class<?>>(); - /** Default constructor, useful for tests. */ + /** + * Default constructor, useful for tests. + */ protected TopiaContextImpl() { } @@ -248,7 +269,7 @@ protected Map<String, TopiaService> loadServices(Properties config) { Map<String, TopiaService> result = new HashMap<String, TopiaService>(); // recherche des services present dans la config - for (Enumeration<?> e = config.propertyNames(); e.hasMoreElements();) { + for (Enumeration<?> e = config.propertyNames(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); if (key.matches("^topia\\.service\\.\\w+$")) { String classService = config.getProperty(key); @@ -455,7 +476,7 @@ /** * Change the value of flag {@link #useFlushMode}. - * + * * @param useFlushMode the new value to set * @see #useFlushMode * @since 2.5 @@ -520,22 +541,20 @@ if (log.isDebugEnabled()) { showSchema = true; } - getFiresSupport().firePreCreateSchema(this); + getFiresSupport().firePreDropSchema(this); new SchemaExport(getHibernateConfiguration()).execute(showSchema, true, true, false); - getFiresSupport().firePostCreateSchema(this); + getFiresSupport().firePostDropSchema(this); } catch (HibernateException eee) { throw new TopiaException( String.format("Could not drop schema for reason: %s", - eee.getMessage()), eee); + eee.getMessage()), eee); } } @Override public Session getHibernate() throws TopiaException { - if (hibernate == null) { - throw new TopiaException("No hibernate session"); - } - return hibernate; + Session result = getHibernateSession(); + return result; } @Override @@ -546,9 +565,9 @@ } else { // init service registry - ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings( + ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings( getHibernateConfiguration().getProperties()).buildServiceRegistry(); - + hibernateFactory = getHibernateConfiguration().buildSessionFactory(serviceRegistry); // we can't reuse original serviceRegistry instance @@ -564,7 +583,7 @@ eventListenerRegistry.appendListeners(EventType.POST_LOAD, listener); eventListenerRegistry.appendListeners(EventType.POST_UPDATE, listener); eventListenerRegistry.appendListeners(EventType.POST_DELETE, listener); - + // following listeners must be called before hibernate eventListenerRegistry.prependListeners(EventType.SAVE_UPDATE, listener); } @@ -619,7 +638,7 @@ if (log.isDebugEnabled()) { log.debug("Load persistent class : " + classname); } - + // XXX echatellier 20111007 ce cqui est dommage ici, c'est // la definition de cette classe ne sert a rien (apart security) // car pour hibernate hibernateConfiguration.addClass(persistanceClass) @@ -636,7 +655,7 @@ } throw new TopiaNotFoundException( String.format("Persistence class %1$s not found", - classname)); + classname)); } persistenceClasses.add(clazz); @@ -751,7 +770,7 @@ // on ne synchronise jamais les données avec la base tant que // l'utilisateur n'a pas fait de commit du context result.hibernate.setFlushMode(FlushMode.MANUAL); - + // tchemit 2010-12-06 propagates the value of the flag result.useFlushMode = useFlushMode; @@ -776,7 +795,7 @@ throw new TopiaException( String.format("An error occurs while asking a new transaction: %1$s", - eee.getMessage()), + eee.getMessage()), eee); } @@ -953,12 +972,12 @@ } @Override - public <E> List<E> findAll(String hql, Object... propertyNamesAndValues) throws TopiaException { + public <E> List<E> findAll(String jpaql, 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); + Query query = getHibernate().createQuery(jpaql); for (int j = 0; j < propertyNamesAndValues.length; j += 2) { String name = (String) propertyNamesAndValues[j]; Object value = propertyNamesAndValues[j + 1]; @@ -979,18 +998,18 @@ return result; } catch (HibernateException eee) { throw new TopiaException(String.format("An error occurs while query operation: %1$s : %2$s", - hql, eee.getMessage()), eee); + jpaql, eee.getMessage()), eee); } } @Override - public <E> List<E> find(String hql, int startIndex, int endIndex, Object... propertyNamesAndValues) + public <E> List<E> find(String jpaql, 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); + Query query = getHibernate().createQuery(jpaql); for (int j = 0; j < propertyNamesAndValues.length; j += 2) { String name = (String) propertyNamesAndValues[j]; Object value = propertyNamesAndValues[j + 1]; @@ -1013,22 +1032,22 @@ return result; } catch (HibernateException eee) { throw new TopiaException(String.format("An error occurs while query operation: %1$s : %2$s", - hql, eee.getMessage()), eee); + jpaql, eee.getMessage()), eee); } } @Override - public <E> E findUnique(String hql, Object... propertyNamesAndValues) + public <E> E findUnique(String jpaql, 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, propertyNamesAndValues); + List<E> results = find(jpaql, 0, 1, propertyNamesAndValues); // If there is more than 1 result, throw an exception if (results.size() > 1) { String message = String.format( - "Query '%s' returns more than 1 unique result", hql); + "Query '%s' returns more than 1 unique result", jpaql); throw new TopiaException(message); } @@ -1043,18 +1062,18 @@ /** * Execute HQL operation on data (Update, Delete) * - * @param hql HQL query + * @param jpaql HQL query * @param propertyNamesAndValues arguments for query * @return The number of entities updated or deleted. * @throws TopiaException */ @Override - public int execute(String hql, Object... propertyNamesAndValues) throws TopiaException { + public int execute(String jpaql, 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); + Query query = getHibernate().createQuery(jpaql); for (int j = 0; j < propertyNamesAndValues.length; j += 2) { query.setParameter((String) propertyNamesAndValues[j], propertyNamesAndValues[j + 1]); } @@ -1062,27 +1081,16 @@ return result; } catch (HibernateException eee) { throw new TopiaException(String.format("An error occurs while query operation: %1$s : %2$s", - hql, eee.getMessage()), eee); + jpaql, eee.getMessage()), eee); } } @Override public void add(TopiaEntity e) throws TopiaException { - checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'", - "add")); - - String id = e.getTopiaId(); - Class<TopiaEntity> entityClass = getTopiaIdFactory().getClassName(id); - TopiaDAO<TopiaEntity> dao = getDAO(entityClass); - dao.update(e); + update(e); } @Override - public void evict(TopiaEntity e) throws TopiaException { - getHibernate().evict(e); - } - - @Override public void replicate(TopiaContext dstCtxt, Object... entityAndCondition) throws TopiaException, IllegalArgumentException { checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'", @@ -1158,12 +1166,12 @@ /** * Backup database in gzip compressed file. - * + * <p/> * <b>Note: </b> Only works for h2 database. * * @param file file to write backup * @param compress if true then use gzip to compress file - * @see TopiaContext#backup(File,boolean) + * @see TopiaContext#backup(File, boolean) */ @Override public void backup(File file, boolean compress) throws TopiaException { @@ -1206,7 +1214,7 @@ // decompresse file in temporary file InputStream in = new BufferedInputStream(new FileInputStream(file)); try { - in.mark(2); + in.mark(2); // read header to see if is compressed file int b = in.read(); @@ -1224,7 +1232,7 @@ SQLQuery query = getHibernate().createSQLQuery( "RUNSCRIPT FROM '" + file.getAbsolutePath() + "'" + options); - + query.executeUpdate(); // send event AFTER restore @@ -1232,7 +1240,7 @@ } catch (Exception eee) { throw new TopiaException(String.format( String.format("An error occurs while restore operation: %1$s : %2$s", - sql, eee.getMessage())), eee); + sql, eee.getMessage())), eee); } } @@ -1263,7 +1271,7 @@ /** * Clear hibernate cache to free memory. - * + * <p/> * see http://docs.jboss.org/hibernate/orm/3.5/reference/en-US/html/transactions.ht... */ @Override @@ -1425,7 +1433,7 @@ // si entityAndcondition est vide alors il faut le remplir // avec toutes les entités du mapping (class, null) if (entityAndCondition.length == 0) { - Map<?,?> classMetadata = getHibernateFactory().getAllClassMetadata(); + Map<?, ?> classMetadata = getHibernateFactory().getAllClassMetadata(); entityAndCondition = new Object[classMetadata.size() * 2]; int i = 0; for (Object className : classMetadata.keySet()) { @@ -1447,7 +1455,7 @@ "entityAndCondition must be a couple of (Class, String)"); } String queries[] = new String[entityAndCondition.length / 2]; - for (int i = 0; i < entityAndCondition.length;) { + for (int i = 0; i < entityAndCondition.length; ) { try { entityClass = (Class<?>) entityAndCondition[i++]; condition = (String) entityAndCondition[i++]; @@ -1506,5 +1514,25 @@ } } } + + @Override + public Session getHibernateSession() throws TopiaException { + if (hibernate == null) { + throw new TopiaException("No hibernate session"); + } + return hibernate; + } + + @Override + public void update(TopiaEntity e) throws TopiaException { + checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'", + "add")); + + String id = e.getTopiaId(); + Class<TopiaEntity> entityClass = getTopiaIdFactory().getClassName(id); + TopiaDAO<TopiaEntity> dao = getDAO(entityClass); + dao.update(e); + } + } //TopiaContextImpl 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-07-25 17:03:03 UTC (rev 2784) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2013-08-02 16:21:12 UTC (rev 2785) @@ -30,6 +30,7 @@ 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; @@ -50,42 +51,65 @@ * @version $Id$ */ //TODO-fdesbois-20100507 : Need more javadoc. -public interface TopiaContextImplementor extends TopiaContext { +@Deprecated +public interface TopiaContextImplementor extends TopiaContext, TopiaHibernate { /** * Retrieve a thread-safe copy of children context set. * * @return Returns the childContext. + * @deprecated Hierarchical context are not supported anymore */ + @Deprecated Set<TopiaContextImplementor> getChildContext(); - /** @return Returns the parentContext. */ + /** + * @return Returns the parentContext. + * @deprecated Hierarchical context are not supported anymore + */ + @Deprecated TopiaContextImplementor getParentContext(); + /** + * @deprecated Hierarchical context are not supported anymore + */ + @Deprecated TopiaContextImplementor getRootContext(); - /** @return Returns the config. */ + /** + * @deprecated Hierarchical context are not supported anymore + */ + @Deprecated + void removeChildContext(TopiaContextImplementor child); + + /** @return Returns the config. + * @deprecated use method from {@link org.nuiton.topia.TopiaPersistenceContext} + */ + @Deprecated Properties getConfig(); - // TODO brendan 05/07/13 expose it in TopiaContext ? - TopiaIdFactory getTopiaIdFactory(); - /** * @return Returns the hibernate. * @throws TopiaException si aucune transaction n'est ouverte + * @deprecated use method from {@link TopiaHibernate} */ + @Deprecated Session getHibernate() throws TopiaException; /** * @return Returns the hibernateFactory. * @throws TopiaNotFoundException + * @deprecated use method from {@link TopiaHibernate} */ + @Deprecated SessionFactory getHibernateFactory() throws TopiaNotFoundException; /** * @return Returns the hibernate configuration * @throws TopiaNotFoundException + * @deprecated use method from {@link TopiaHibernate} */ + @Deprecated Configuration getHibernateConfiguration() throws TopiaNotFoundException; @@ -97,15 +121,20 @@ * * @param useFlushMode the new value to set * @since 2.5 + * @deprecated use method from {@link org.nuiton.topia.TopiaPersistenceContext} */ + @Deprecated 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 + * @deprecated use method from {@link org.nuiton.topia.TopiaPersistenceContext} */ + @Deprecated boolean isSchemaExist(Class<?> clazz) throws TopiaException; /** @@ -116,7 +145,9 @@ * @param entityClass type of entity * @return the required dao * @throws TopiaException if any error + * @deprecated use method from {@link org.nuiton.topia.TopiaPersistenceContext} */ + @Deprecated <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass) throws TopiaException; @@ -129,16 +160,29 @@ * @param daoClass the concrete dao class to use * @return the required dao * @throws TopiaException if any error + * @deprecated use method from {@link org.nuiton.topia.TopiaPersistenceContext} */ + @Deprecated <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass,Class<D> daoClass) throws TopiaException; + /** + * @deprecated internal usage + */ + @Deprecated TopiaFiresSupport getFiresSupport(); - void removeChildContext(TopiaContextImplementor child); - + /** + * @deprecated use methods from {@link org.nuiton.topia.TopiaServiceSupport} + */ + @Deprecated Map<String, TopiaService> getServices(); + /** + * @deprecated use method from {@link org.nuiton.topia.TopiaPersistenceContext} + */ + @Deprecated List<Class<?>> getPersistenceClasses(); + } //TopiaContextImplementor Modified: trunk/topia-service-migration/pom.xml =================================================================== --- trunk/topia-service-migration/pom.xml 2013-07-25 17:03:03 UTC (rev 2784) +++ trunk/topia-service-migration/pom.xml 2013-08-02 16:21:12 UTC (rev 2785) @@ -35,7 +35,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>topia</artifactId> - <version>3.0-alpha-2-SNAPSHOT</version> + <version>3.0-SNAPSHOT</version> </parent> <groupId>org.nuiton.topia</groupId> Modified: trunk/topia-service-replication/pom.xml =================================================================== --- trunk/topia-service-replication/pom.xml 2013-07-25 17:03:03 UTC (rev 2784) +++ trunk/topia-service-replication/pom.xml 2013-08-02 16:21:12 UTC (rev 2785) @@ -35,7 +35,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>topia</artifactId> - <version>3.0-alpha-2-SNAPSHOT</version> + <version>3.0-SNAPSHOT</version> </parent> <groupId>org.nuiton.topia</groupId> Modified: trunk/topia-service-security/pom.xml =================================================================== --- trunk/topia-service-security/pom.xml 2013-07-25 17:03:03 UTC (rev 2784) +++ trunk/topia-service-security/pom.xml 2013-08-02 16:21:12 UTC (rev 2785) @@ -35,7 +35,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>topia</artifactId> - <version>3.0-alpha-2-SNAPSHOT</version> + <version>3.0-SNAPSHOT</version> </parent> <groupId>org.nuiton.topia</groupId>