Author: tchemit Date: 2013-12-20 15:59:42 +0100 (Fri, 20 Dec 2013) New Revision: 2949 Url: http://nuiton.org/projects/topia/repository/revisions/2949 Log: refs #2893: Refactor packages (first pass) Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/QueryMissingOrderException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaApplicationContext.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaApplicationContextCache.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaContextFactory.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDaoSupplier.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaNoResultException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaNonUniqueResultException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaNotFoundException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaPersistenceContext.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaReplicationDestination.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaService.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaTransaction.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaTransactionAware.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaVetoException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/EntityState.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaContextAdapter.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaContextEvent.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntitiesEvent.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntitiesVetoable.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntityEvent.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntityListener.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntityVetoable.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaSchemaListener.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaTransactionEvent.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaTransactionListener.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaTransactionVetoable.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/package-info.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaApplicationContext.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaPersistenceContext.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/TopiaConnectionProvider.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/TopiaHibernateSessionRegistry.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/HibernateTopiaJpaSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/HibernateTopiaReplicationSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/HibernateTopiaSqlSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaFiresSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaHibernateEventListener.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaServiceSupportImpl.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/Collector.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/DBMapping.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/EntityListUpdator.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/ListUpdator.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/Loador.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaHibernateSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaJpaSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaListenableSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaReplicationSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaServiceSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaSqlQuery.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaSqlSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaSqlWork.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaUtil.java Removed: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaReplicationSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaSqlSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/QueryMissingOrderException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaApplicationContextCache.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDaoSupplier.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernateSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenableSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNoResultException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNonUniqueResultException.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/TopiaQueryException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationDestination.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/TopiaServiceSupportImpl.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlQuery.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlWork.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaVetoException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/event/ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaHibernateSessionRegistry.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Collector.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityListUpdator.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/ListUpdator.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java Modified: trunk/topia-it/src/main/java/org/nuiton/topia/it/TopiaConfigurationHelper.java trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/AbstractTopiaTestApplicationContext.java trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/AbstractTopiaTestPersistenceContext.java trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/GeneratedPersonneTopiaDao.java trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/topiatest/AbstractExtraDAOEntityTopiaDao.java trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/topiatest/deletetest/AbstractContact2TopiaDao.java trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/topiatest/persistence/Entity1Abstract.java trunk/topia-it/src/main/resources/TopiaContextImpl.properties trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TestHelper.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaApplicationContextCacheTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaJpaSupportTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/EntityStateTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaConnectionProviderTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaContextReplicateTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaUtilTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/generator/TopiaTestCase.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/EntityVisitorExportXmlTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/NaturalIdTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/util/CollectorTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/util/TopiaEntityHelperTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/util/TopiaEntityRefTester.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/CascadeSaveTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/EnumTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/deletetest/DeleteEntityTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/service/FakeService.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/service/TestService.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/service/package-info.java trunk/topia-it/src/test/java/org/nuiton/topia/persistence/TopiaDaoTest.java trunk/topia-junit/src/main/java/org/nuiton/topia/junit/AbstractDatabaseResource.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DefaultTopiaIdFactory.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DepthEntityVisitor.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HibernateProvider.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HorizontalEntityVisitor.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/TopiaEntity.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityContextable.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/TopiaCsvCommons.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/ImportStrategy.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/ExportEntityVisitor.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/TopiaCsvExports.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/AssociationMeta.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TableMeta.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaH2Util.java trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByClass.java trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByClassNG.java trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByMethod.java trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationService.java trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersionDAO.java trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationContext.java trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationModelBuilder.java trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationOperation.java trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationOperationUndoable.java trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationService.java trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationServiceImpl.java trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/model/ReplicationModel.java trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachLink.java trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/DettachAssociation.java trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/Duplicate.java trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/LoadLink.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/FakeOperation.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UncreatableOperation.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UnregistredOperation.java trunk/topia-templates/src/main/java/org/nuiton/topia/templates/ApplicationContextTransformer.java trunk/topia-templates/src/main/java/org/nuiton/topia/templates/DAOHelperTransformer.java trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityDaoTransformer.java trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityEnumTransformer.java trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityTransformer.java trunk/topia-templates/src/main/java/org/nuiton/topia/templates/PersistenceContextTransformer.java trunk/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaTagValues.java Modified: trunk/topia-it/src/main/java/org/nuiton/topia/it/TopiaConfigurationHelper.java =================================================================== --- trunk/topia-it/src/main/java/org/nuiton/topia/it/TopiaConfigurationHelper.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/main/java/org/nuiton/topia/it/TopiaConfigurationHelper.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -27,7 +27,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.cfg.Environment; -import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.persistence.TopiaContextFactory; import org.nuiton.topia.it.legacy.TopiaTestEntityEnum; import org.nuiton.topia.junit.ConfigurationHelper; Modified: trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/AbstractTopiaTestApplicationContext.java =================================================================== --- trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/AbstractTopiaTestApplicationContext.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/AbstractTopiaTestApplicationContext.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -24,7 +24,7 @@ * #L% */ -import org.nuiton.topia.AbstractTopiaApplicationContext; +import org.nuiton.topia.persistence.internal.AbstractTopiaApplicationContext; import java.util.Map; import java.util.Properties; Modified: trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/AbstractTopiaTestPersistenceContext.java =================================================================== --- trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/AbstractTopiaTestPersistenceContext.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/AbstractTopiaTestPersistenceContext.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -24,10 +24,10 @@ * #L% */ -import org.nuiton.topia.AbstractTopiaPersistenceContext; -import org.nuiton.topia.TopiaListenableSupport; +import org.nuiton.topia.persistence.internal.AbstractTopiaPersistenceContext; +import org.nuiton.topia.persistence.support.TopiaListenableSupport; import org.nuiton.topia.persistence.HibernateProvider; -import org.nuiton.topia.persistence.TopiaHibernateSessionRegistry; +import org.nuiton.topia.persistence.internal.TopiaHibernateSessionRegistry; import org.nuiton.topia.persistence.TopiaIdFactory; /** Modified: trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/GeneratedPersonneTopiaDao.java =================================================================== --- trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/GeneratedPersonneTopiaDao.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/GeneratedPersonneTopiaDao.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -27,7 +27,7 @@ import java.util.List; import java.util.Map; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.AbstractTopiaDao; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityEnum; Modified: trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/topiatest/AbstractExtraDAOEntityTopiaDao.java =================================================================== --- trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/topiatest/AbstractExtraDAOEntityTopiaDao.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/topiatest/AbstractExtraDAOEntityTopiaDao.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -24,7 +24,7 @@ */ package org.nuiton.topia.it.legacy.topiatest; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; /** * Created: 26 mai 2010 Modified: trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/topiatest/deletetest/AbstractContact2TopiaDao.java =================================================================== --- trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/topiatest/deletetest/AbstractContact2TopiaDao.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/topiatest/deletetest/AbstractContact2TopiaDao.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -26,7 +26,7 @@ package org.nuiton.topia.it.legacy.topiatest.deletetest; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.it.legacy.topiatest.Company; import org.nuiton.topia.it.legacy.topiatest.Employe; Modified: trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/topiatest/persistence/Entity1Abstract.java =================================================================== --- trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/topiatest/persistence/Entity1Abstract.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/main/java/org/nuiton/topia/it/legacy/topiatest/persistence/Entity1Abstract.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -24,7 +24,7 @@ */ package org.nuiton.topia.it.legacy.topiatest.persistence; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.EntityVisitor; import org.nuiton.topia.persistence.TopiaEntityAbstract; Modified: trunk/topia-it/src/main/resources/TopiaContextImpl.properties =================================================================== --- trunk/topia-it/src/main/resources/TopiaContextImpl.properties 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/main/resources/TopiaContextImpl.properties 2013-12-20 14:59:42 UTC (rev 2949) @@ -34,4 +34,4 @@ #hibernate.connection.url=jdbc:h2:file:target/surefire-workdir/h2data # AThimel 16/12/2013 : Uncomment the next line to tests the ToPIA connection provider -#hibernate.connection.provider_class=org.nuiton.topia.framework.TopiaConnectionProvider +#hibernate.connection.provider_class=org.nuiton.topia.persistence.internal.TopiaConnectionProvider Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TestHelper.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TestHelper.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TestHelper.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -29,10 +29,10 @@ import org.apache.commons.logging.LogFactory; import org.hibernate.cfg.Environment; import org.junit.Ignore; -import org.nuiton.topia.AbstractTopiaApplicationContext; -import org.nuiton.topia.TopiaApplicationContextCache; -import org.nuiton.topia.TopiaContextFactory; -import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaApplicationContextCache; +import org.nuiton.topia.persistence.TopiaContextFactory; +import org.nuiton.topia.persistence.TopiaNotFoundException; import org.nuiton.util.FileUtil; import java.io.File; @@ -89,19 +89,19 @@ return result; } - protected static final Function<Properties,AbstractTopiaApplicationContext> CREATE_TOPIA_TEST_CONTEXT = new Function<Properties, AbstractTopiaApplicationContext>() { + protected static final Function<Properties,TopiaApplicationContext> CREATE_TOPIA_TEST_CONTEXT = new Function<Properties, TopiaApplicationContext>() { @Override - public AbstractTopiaApplicationContext apply(Properties input) { + public TopiaApplicationContext apply(Properties input) { return new TopiaTestTopiaApplicationContext(input); } }; - public static AbstractTopiaApplicationContext initTopiaContext(File testDirectory, + public static TopiaApplicationContext initTopiaContext(File testDirectory, String dbname) throws IOException, TopiaNotFoundException { - AbstractTopiaApplicationContext topiaContext = initTopiaContext( + TopiaApplicationContext topiaContext = initTopiaContext( testDirectory, DEFAULT_CONFIGURATION_LOCATION, dbname @@ -109,7 +109,7 @@ return topiaContext; } - public static AbstractTopiaApplicationContext initTopiaContext(File testDirectory, + public static TopiaApplicationContext initTopiaContext(File testDirectory, String dbPropertiesPath, String dbname) throws IOException, TopiaNotFoundException { Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaApplicationContextCacheTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaApplicationContextCacheTest.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaApplicationContextCacheTest.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -31,8 +31,8 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.nuiton.topia.AbstractTopiaApplicationContext; -import org.nuiton.topia.TopiaApplicationContextCache; +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaApplicationContextCache; import org.nuiton.topia.junit.ConfigurationHelper; import java.io.File; @@ -55,14 +55,14 @@ private static final Log log = LogFactory.getLog(TopiaApplicationContextCacheTest.class); - protected static final Function<Properties,AbstractTopiaApplicationContext> CREATE_TOPIA_TEST_CONTEXT = new Function<Properties, AbstractTopiaApplicationContext>() { + protected static final Function<Properties,TopiaApplicationContext> CREATE_TOPIA_TEST_CONTEXT = new Function<Properties, TopiaApplicationContext>() { @Override - public AbstractTopiaApplicationContext apply(Properties input) { + public TopiaApplicationContext apply(Properties input) { return new TopiaTestTopiaApplicationContext(input); } }; - protected static Map<Properties, AbstractTopiaApplicationContext> contextCache; + protected static Map<Properties, TopiaApplicationContext> contextCache; protected static File testBasedir; @@ -73,7 +73,7 @@ testBasedir = ConfigurationHelper.getTestSpecificDirectory(TopiaApplicationContextCacheTest.class, "dummy"); Field field = FieldUtils.getField(TopiaApplicationContextCache.class, "contextCache", true); - contextCache = (Map<Properties, AbstractTopiaApplicationContext>) field.get(null); + contextCache = (Map<Properties, TopiaApplicationContext>) field.get(null); } @Before @@ -146,19 +146,19 @@ log.info("test 1 : add new properties, will instantiate a new" + " TopiaContext"); - AbstractTopiaApplicationContext test1 = TopiaApplicationContextCache.getContext(propertiesParent, CREATE_TOPIA_TEST_CONTEXT); + TopiaApplicationContext test1 = TopiaApplicationContextCache.getContext(propertiesParent, CREATE_TOPIA_TEST_CONTEXT); Assert.assertNotNull(test1); Assert.assertEquals(1, contextCache.size()); log.info("test 2 : with same properties, will retrieve existing" + " TopiaContext"); - AbstractTopiaApplicationContext test2 = TopiaApplicationContextCache.getContext(propertiesParent, CREATE_TOPIA_TEST_CONTEXT); + TopiaApplicationContext test2 = TopiaApplicationContextCache.getContext(propertiesParent, CREATE_TOPIA_TEST_CONTEXT); Assert.assertEquals(test1, test2); Assert.assertEquals(1, contextCache.size()); log.info("test 3 : use other properties, will instantiate a different" + "TopiaContext"); - AbstractTopiaApplicationContext test3 = TopiaApplicationContextCache.getContext(properties, CREATE_TOPIA_TEST_CONTEXT); + TopiaApplicationContext test3 = TopiaApplicationContextCache.getContext(properties, CREATE_TOPIA_TEST_CONTEXT); log.debug("cache size : " + contextCache.size()); log.debug("result : " + test1); log.debug("result3 : " + test3); @@ -168,7 +168,7 @@ log.info("test 4 : use other properties but equivalent to existing " + "TopiaContext"); // Test flating of properties - AbstractTopiaApplicationContext test4 = TopiaApplicationContextCache.getContext(propertiesAll, CREATE_TOPIA_TEST_CONTEXT); + TopiaApplicationContext test4 = TopiaApplicationContextCache.getContext(propertiesAll, CREATE_TOPIA_TEST_CONTEXT); Assert.assertEquals(test1, test4); Assert.assertEquals(2, contextCache.size()); @@ -190,7 +190,7 @@ "jdbc:h2:file:" + f.getAbsolutePath()); - AbstractTopiaApplicationContext test5 = TopiaApplicationContextCache.getContext(properties, CREATE_TOPIA_TEST_CONTEXT); + TopiaApplicationContext test5 = TopiaApplicationContextCache.getContext(properties, CREATE_TOPIA_TEST_CONTEXT); Assert.assertNotSame(test1, test5); Assert.assertEquals(3, contextCache.size()); @@ -198,7 +198,7 @@ test5.newPersistenceContext(); test5.closeContext(); - AbstractTopiaApplicationContext test5b = TopiaApplicationContextCache.getContext(properties, CREATE_TOPIA_TEST_CONTEXT); + TopiaApplicationContext test5b = TopiaApplicationContextCache.getContext(properties, CREATE_TOPIA_TEST_CONTEXT); Assert.assertNotSame(test5, test5b); Assert.assertEquals(3, contextCache.size()); } Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaJpaSupportTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaJpaSupportTest.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaJpaSupportTest.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -28,9 +28,9 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.AbstractTopiaPersistenceContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaJpaSupport; +import org.nuiton.topia.persistence.internal.AbstractTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.support.TopiaJpaSupport; import org.nuiton.topia.it.legacy.topiatest.Address; import org.nuiton.topia.it.legacy.topiatest.AddressTopiaDao; import org.nuiton.topia.it.legacy.topiatest.Gender; Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/EntityStateTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/EntityStateTest.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/EntityStateTest.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -27,7 +27,7 @@ import org.junit.Assert; import org.junit.Test; -import org.nuiton.topia.framework.EntityState; +import org.nuiton.topia.persistence.event.EntityState; /** * EntityStateTest.java Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaConnectionProviderTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaConnectionProviderTest.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaConnectionProviderTest.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -31,9 +31,9 @@ import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.TopiaContextFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaConnectionProvider; +import org.nuiton.topia.persistence.TopiaContextFactory; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.internal.TopiaConnectionProvider; import org.nuiton.topia.it.legacy.TopiaDatabase; import org.nuiton.topia.it.legacy.TopiaTestTopiaPersistenceContext; import org.nuiton.topia.it.legacy.test.entities.Person; Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaContextReplicateTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaContextReplicateTest.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaContextReplicateTest.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -30,7 +30,7 @@ import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.persistence.TopiaContextFactory; import org.nuiton.topia.it.legacy.TopiaDatabase; import org.nuiton.topia.it.legacy.TopiaTestTopiaPersistenceContext; import org.nuiton.topia.it.legacy.test.entities.Person; Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaUtilTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaUtilTest.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaUtilTest.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -32,7 +32,7 @@ import org.junit.Rule; import org.junit.Test; import org.nuiton.topia.it.legacy.TopiaDatabase; -import org.nuiton.topia.framework.TopiaUtil; +import org.nuiton.topia.persistence.util.TopiaUtil; import org.nuiton.topia.it.legacy.test.entities.PersonImpl; import org.nuiton.topia.it.legacy.topiatest.Personne; Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/generator/TopiaTestCase.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/generator/TopiaTestCase.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/generator/TopiaTestCase.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -30,7 +30,7 @@ import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.it.legacy.TopiaDatabase; import org.nuiton.topia.it.legacy.TopiaTestTopiaPersistenceContext; import org.nuiton.topia.it.legacy.topiatest.Company; Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/EntityVisitorExportXmlTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/EntityVisitorExportXmlTest.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/EntityVisitorExportXmlTest.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -31,7 +31,7 @@ import org.junit.Rule; import org.junit.Test; import org.nuiton.topia.it.legacy.TopiaDatabase; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.it.legacy.TopiaTestTopiaPersistenceContext; import org.nuiton.topia.it.legacy.topiatest.Address; import org.nuiton.topia.it.legacy.topiatest.AddressTopiaDao; Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/NaturalIdTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/NaturalIdTest.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/NaturalIdTest.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -32,7 +32,7 @@ import org.junit.Rule; import org.junit.Test; import org.nuiton.topia.it.legacy.TopiaDatabase; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.it.legacy.TopiaTestEntityEnum; import org.nuiton.topia.it.legacy.TopiaTestTopiaPersistenceContext; import org.nuiton.topia.it.legacy.topiatest.NaturalizedEntity; Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/util/CollectorTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/util/CollectorTest.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/util/CollectorTest.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -31,7 +31,7 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.it.legacy.TopiaTestEntityEnum; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityEnum; @@ -40,7 +40,7 @@ import org.nuiton.topia.it.legacy.topiatest.Department; import org.nuiton.topia.it.legacy.topiatest.DepartmentImpl; import org.nuiton.topia.it.legacy.topiatest.EmployeImpl; -import org.nuiton.topia.persistence.util.Collector; +import org.nuiton.topia.persistence.legacy.Collector; /** @author tchemit <chemit@codelutin.com> */ public class CollectorTest { Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/util/TopiaEntityHelperTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/util/TopiaEntityHelperTest.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/util/TopiaEntityHelperTest.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -29,7 +29,7 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.it.legacy.TopiaTestEntityEnum; import org.nuiton.topia.persistence.DefaultTopiaIdFactory; import org.nuiton.topia.persistence.TopiaEntity; Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/util/TopiaEntityRefTester.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/util/TopiaEntityRefTester.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/util/TopiaEntityRefTester.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -27,7 +27,7 @@ import org.junit.After; import org.junit.Assert; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityEnum; import org.nuiton.topia.persistence.util.TopiaEntityHelper; Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/CascadeSaveTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/CascadeSaveTest.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/CascadeSaveTest.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -26,7 +26,7 @@ import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.it.legacy.TopiaDatabase; import org.nuiton.topia.it.legacy.TopiaTestTopiaPersistenceContext; @@ -40,7 +40,7 @@ /** * The following test will fail if no topiaId is injected on cascade save. This will test code within this method : - * org.nuiton.topia.framework.TopiaHibernateEventListener#onSaveOrUpdate(org.hibernate.event.spi.SaveOrUpdateEvent) + * org.nuiton.topia.persistence.internal.support.TopiaHibernateEventListener#onSaveOrUpdate(org.hibernate.event.spi.SaveOrUpdateEvent) * * @throws TopiaException */ Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/EnumTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/EnumTest.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/EnumTest.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -28,7 +28,7 @@ import org.junit.Rule; import org.junit.Test; import org.nuiton.topia.it.legacy.TopiaDatabase; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.it.legacy.TopiaTestTopiaPersistenceContext; /** Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/deletetest/DeleteEntityTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/deletetest/DeleteEntityTest.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/deletetest/DeleteEntityTest.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -43,7 +43,7 @@ import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.it.legacy.TopiaDatabase; import org.nuiton.topia.it.legacy.TopiaTestTopiaPersistenceContext; import org.nuiton.topia.it.legacy.topiatest.Gender; Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/service/FakeService.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/service/FakeService.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/service/FakeService.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -24,8 +24,9 @@ */ package org.nuiton.topia.it.legacy.topiatest.service; -import org.nuiton.topia.AbstractTopiaApplicationContext; -import org.nuiton.topia.framework.TopiaService; +import org.nuiton.topia.persistence.internal.AbstractTopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaService; /** * FakeService which implements {@link TopiaService} to test existing service @@ -56,7 +57,7 @@ } @Override - public boolean postInit(AbstractTopiaApplicationContext context) { + public boolean postInit(TopiaApplicationContext context) { return true; } } Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/service/TestService.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/service/TestService.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/service/TestService.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -25,8 +25,9 @@ package org.nuiton.topia.it.legacy.topiatest.service; import org.junit.Ignore; -import org.nuiton.topia.AbstractTopiaApplicationContext; -import org.nuiton.topia.framework.TopiaService; +import org.nuiton.topia.persistence.internal.AbstractTopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaService; /** * TestService which implements {@link TopiaService} to test loading from {@link @@ -59,7 +60,7 @@ } @Override - public boolean postInit(AbstractTopiaApplicationContext context) { + public boolean postInit(TopiaApplicationContext context) { return true; } } Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/service/package-info.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/service/package-info.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/service/package-info.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -24,6 +24,6 @@ */ /** * This package contains classes which implements {@link - * org.nuiton.topia.framework.TopiaService} to test services API. + * org.nuiton.topia.persistence.TopiaService} to test services API. */ package org.nuiton.topia.it.legacy.topiatest.service; \ No newline at end of file Modified: trunk/topia-it/src/test/java/org/nuiton/topia/persistence/TopiaDaoTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/persistence/TopiaDaoTest.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-it/src/test/java/org/nuiton/topia/persistence/TopiaDaoTest.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -34,7 +34,6 @@ import org.junit.Rule; import org.junit.Test; import org.nuiton.topia.it.legacy.TopiaDatabase; -import org.nuiton.topia.TopiaException; import org.nuiton.topia.it.legacy.TopiaTestTopiaPersistenceContext; import org.nuiton.topia.it.legacy.test.entities.Person; import org.nuiton.topia.it.legacy.test.entities.PersonTopiaDao; Modified: trunk/topia-junit/src/main/java/org/nuiton/topia/junit/AbstractDatabaseResource.java =================================================================== --- trunk/topia-junit/src/main/java/org/nuiton/topia/junit/AbstractDatabaseResource.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-junit/src/main/java/org/nuiton/topia/junit/AbstractDatabaseResource.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -30,11 +30,11 @@ import org.hibernate.cfg.Configuration; import org.junit.rules.TestWatcher; import org.junit.runner.Description; -import org.nuiton.topia.AbstractTopiaApplicationContext; +import org.nuiton.topia.persistence.internal.AbstractTopiaApplicationContext; import org.nuiton.topia.persistence.HibernateProvider; -import org.nuiton.topia.TopiaContextFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaContextFactory; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; import java.io.File; import java.io.InputStream; Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,410 +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 com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.HibernateException; -import org.hibernate.cfg.Configuration; -import org.hibernate.tool.hbm2ddl.SchemaExport; -import org.hibernate.tool.hbm2ddl.SchemaUpdate; -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.TopiaFiresSupport; -import org.nuiton.topia.framework.TopiaService; -import org.nuiton.topia.framework.TopiaUtil; -import org.nuiton.topia.persistence.DefaultTopiaIdFactory; -import org.nuiton.topia.persistence.HibernateProvider; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.TopiaHibernateSessionRegistry; -import org.nuiton.topia.persistence.TopiaIdFactory; - -import java.beans.PropertyChangeListener; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.WeakHashMap; - -/** - * The application context is the main class in ToPIA usage. This class is a kind of equivalent of the RootTopiaContext. - * It contains only high level methods and new contexts creation (transaction begin, ...). This class has to be extended - * by the user, even if some default one could be automatically generated. - * - * @author Arnaud Thimel <thimel@codelutin.com> - * @since 3.0 - */ -public abstract class AbstractTopiaApplicationContext<K extends TopiaPersistenceContext> implements TopiaListenableSupport, TopiaServiceSupport { - - private static final Log log = LogFactory.getLog(AbstractTopiaApplicationContext.class); - - protected TopiaIdFactory topiaIdFactory; - - protected ImmutableMap<String, String> configuration; - - protected TopiaFiresSupport topiaFiresSupport = new TopiaFiresSupport(); - - protected TopiaServiceSupport topiaServiceSupport; - - protected HibernateProvider hibernateProvider; - - protected TopiaHibernateSessionRegistry sessionRegistry = new TopiaHibernateSessionRegistry(); - - protected boolean closed = false; - - protected Set<TopiaPersistenceContext> persistenceContexts = Collections.newSetFromMap( - new WeakHashMap<TopiaPersistenceContext, Boolean>()); - - public abstract K newPersistenceContext(); - - public AbstractTopiaApplicationContext(Properties properties) { - // TODO arnaud 11/10/13 vérifier le comportement - this((Map) ImmutableMap.copyOf(properties)); - } - - public AbstractTopiaApplicationContext(Map<String, String> configuration) { - Map<String, String> configurationCopy = Maps.newHashMap(); - configurationCopy.putAll(configuration); - if ( ! configuration.containsKey(TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES)) { - configurationCopy.put(TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES, getImplementationClassesAsString()); - } - this.configuration = ImmutableMap.copyOf(configurationCopy); - this.topiaServiceSupport = new TopiaServiceSupportImpl(this); - // FIXME AThimel 11/10/13 This is not nice, need a 2-step init because of mutual dependency with hibernateProvider - ((TopiaServiceSupportImpl)this.topiaServiceSupport).init(); - } - - protected abstract Class<? extends TopiaEntity>[] getImplementationClasses(); - - public abstract String getModelVersion() ; - - public abstract String getModelName() ; - - public abstract <T extends TopiaEntity> Class<T> getContractClass(Class<T> klass); - - public abstract <T extends TopiaEntity> Class<T> getImplementationClass(Class<T> klass); - - public abstract Class<? extends TopiaEntity>[] getContractClasses(); - - protected String getImplementationClassesAsString() { - StringBuilder buffer = new StringBuilder(); - for (Class<? extends TopiaEntity> aClass : getImplementationClasses()) { - buffer.append(',').append(aClass.getName()); - } - return buffer.substring(1); - } - - protected void registerPersistenceContext(TopiaPersistenceContext persistenceContext) { - persistenceContexts.add(persistenceContext); - } - - // FIXME AThimel 25/11/13 I don't like it to be public, but necessary for services. Review it - public HibernateProvider getHibernateProvider() { - if (hibernateProvider == null) { - hibernateProvider = new HibernateProvider(configuration, topiaServiceSupport, sessionRegistry); - } - return hibernateProvider; - } - - protected TopiaListenableSupport getTopiaListenableSupport() { - return topiaFiresSupport; - } - - public ImmutableMap<String, String> getConfiguration() { - return configuration; - } - - protected TopiaIdFactory getTopiaIdFactory() { - if (topiaIdFactory == null) { - String topiaIdFactoryClassName = - getConfiguration().get(TopiaContextFactory.CONFIG_PERSISTENCE_TOPIA_ID_FACTORY_CLASS_NAME); - if (StringUtils.isEmpty(topiaIdFactoryClassName)) { - topiaIdFactory = new DefaultTopiaIdFactory(); - } else { - try { - Class topiaIdFactoryClass = Class.forName(topiaIdFactoryClassName); - Preconditions.checkState(TopiaIdFactory.class.isAssignableFrom(topiaIdFactoryClass), - topiaIdFactoryClassName + " is not a valid class name. The class must implements " - + TopiaIdFactory.class.getSimpleName()); - - topiaIdFactory = (TopiaIdFactory) topiaIdFactoryClass.newInstance(); - } catch (ClassNotFoundException e) { - throw new TopiaException("Unable to create user specified TopiaIdFactory", e); - } catch (InstantiationException e) { - throw new TopiaException("Unable to create user specified TopiaIdFactory", e); - } catch (IllegalAccessException e) { - throw new TopiaException("Unable to create user specified TopiaIdFactory", e); - } - } - - } - return topiaIdFactory; - } - - public TopiaHibernateSessionRegistry getSessionRegistry() { - return sessionRegistry; - } - - @Override - public void addTopiaEntityListener(TopiaEntityListener listener) { - topiaFiresSupport.addTopiaEntityListener(listener); - } - - @Override - public void addTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener) { - topiaFiresSupport.addTopiaEntityListener(entityClass, listener); - } - - @Override - public void removeTopiaEntityListener(TopiaEntityListener listener) { - topiaFiresSupport.removeTopiaEntityListener(listener); - } - - @Override - public void removeTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener) { - topiaFiresSupport.removeTopiaEntityListener(entityClass, listener); - } - - @Override - public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) { - topiaFiresSupport.addTopiaEntityVetoable(vetoable); - } - - @Override - public void addTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable) { - topiaFiresSupport.addTopiaEntityVetoable(entityClass, vetoable); - } - - @Override - public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) { - topiaFiresSupport.removeTopiaEntityVetoable(vetoable); - } - - @Override - public void removeTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable) { - topiaFiresSupport.removeTopiaEntityVetoable(entityClass, vetoable); - } - - @Override - public void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) { - topiaFiresSupport.addTopiaEntitiesVetoable(vetoable); - } - - @Override - public void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) { - topiaFiresSupport.removeTopiaEntitiesVetoable(vetoable); - } - - @Override - public void addTopiaTransactionListener(TopiaTransactionListener listener) { - topiaFiresSupport.addTopiaTransactionListener(listener); - } - - @Override - public void removeTopiaTransactionListener(TopiaTransactionListener listener) { - topiaFiresSupport.removeTopiaTransactionListener(listener); - } - - @Override - public void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable) { - topiaFiresSupport.addTopiaTransactionVetoable(vetoable); - } - - @Override - public void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable) { - topiaFiresSupport.removeTopiaTransactionVetoable(vetoable); - } - - @Override - public void addPropertyChangeListener(PropertyChangeListener listener) { - topiaFiresSupport.addPropertyChangeListener(listener); - } - - @Override - public void removePropertyChangeListener(PropertyChangeListener listener) { - topiaFiresSupport.removePropertyChangeListener(listener); - } - - @Override - public void addTopiaSchemaListener(TopiaSchemaListener listener) { - topiaFiresSupport.addTopiaSchemaListener(listener); - } - - @Override - public void removeTopiaSchemaListener(TopiaSchemaListener listener) { - topiaFiresSupport.removeTopiaSchemaListener(listener); - } - - @Override - public <E extends TopiaService> boolean serviceEnabled(Class<E> interfaceService) { - return topiaServiceSupport.serviceEnabled(interfaceService); - } - - @Override - public <E extends TopiaService> E getService(Class<E> interfaceService) throws TopiaNotFoundException { - return topiaServiceSupport.getService(interfaceService); - } - - @Override - public Map<String, TopiaService> getServices() { - return topiaServiceSupport.getServices(); - } - - public List<Class<?>> getPersistenceClasses() { - return getHibernateProvider().getPersistentClasses(); - } - - public boolean isSchemaEmpty() { - Configuration configuration = getHibernateProvider().getHibernateConfiguration(); - boolean result = TopiaUtil.isSchemaEmpty(configuration); - return result; - } - - public boolean isTableExists(Class<?> clazz) { - Configuration configuration = getHibernateProvider().getHibernateConfiguration(); - boolean result = TopiaUtil.isSchemaExist(configuration, clazz.getName()); - return result; - } - - public String getSchemaName() { - // TODO AThimel 02/08/13 I absolutely don't know if it works - return getConfiguration().get(TopiaContextFactory.CONFIG_DEFAULT_SCHEMA); - } - - public void createSchema() { - try { - boolean showSchema = false; - if (log.isDebugEnabled()) { - showSchema = true; - } - // TODO brendan 11/10/13 reable event - // topiaFiresSupport.firePreCreateSchema(this); - new SchemaExport(getHibernateProvider().getHibernateConfiguration()).execute(showSchema, true, false, true); - // TODO brendan 11/10/13 reable event - // topiaFiresSupport.firePostCreateSchema(this); - } catch (HibernateException eee) { - throw new TopiaException( - String.format("Could not create schema for reason: %s", - eee.getMessage()), eee); - } - } - - public void showCreateSchema() { - try { - new SchemaExport(getHibernateProvider().getHibernateConfiguration()). - execute(true, false, false, true); - } catch (HibernateException eee) { - throw new TopiaException( - String.format("Could not show create schema for reason: %s", - eee.getMessage()), eee); - } - - } - - public void updateSchema() { - try { - boolean showSchema = false; - if (log.isDebugEnabled()) { - showSchema = true; - } - - // TODO brendan 11/10/13 reable event - // topiaFiresSupport.firePreUpdateSchema(this); - new SchemaUpdate(getHibernateProvider().getHibernateConfiguration()).execute(showSchema, - true); - // topiaFiresSupport.firePostUpdateSchema(this); - } catch (HibernateException eee) { - throw new TopiaException( - String.format("Could not update schema for reason: %s", - eee.getMessage()), eee); - } - } - - public void dropSchema() { - try { - boolean showSchema = false; - if (log.isDebugEnabled()) { - showSchema = true; - } - - // TODO brendan 11/10/13 reable event - // topiaFiresSupport.firePreDropSchema(this); - new SchemaExport(getHibernateProvider().getHibernateConfiguration()).execute(showSchema, true, true, false); -// topiaFiresSupport.firePostDropSchema(this); - } catch (HibernateException eee) { - throw new TopiaException( - String.format("Could not drop schema for reason: %s", - eee.getMessage()), eee); - } - } - - public void closeContext() throws TopiaException { - - // Throw exception if context is already closed - Preconditions.checkState(!closed, "Context was already closed"); - - // Iterate over the children PersistenceContexts and close them - for (TopiaPersistenceContext persistenceContext : persistenceContexts) { - if (persistenceContext == null) { - if (log.isWarnEnabled()) { - log.warn("null TopiaPersistenceContext found in #persistenceContexts"); - } - } else { - // Avoid to have exception from checkClosed method on child - try { - if (!persistenceContext.isClosed()) { - persistenceContext.closeContext(); - } - } catch (Exception eee) { - // Don't let any exception stop the application closing - if (log.isWarnEnabled()) { - log.warn("Unable to close TopiaPersistenceContext", eee); - } - } - } - } - - hibernateProvider.close(); - closed = true; - - if (log.isDebugEnabled()) { - log.debug("TopiaApplicationContext closed"); - } - } - - public boolean isClosed() { - return closed; - } - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,434 +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 com.google.common.base.Preconditions; -import com.google.common.collect.Maps; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.FlushMode; -import org.hibernate.HibernateException; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.Transaction; -import org.hibernate.cfg.Configuration; -import org.nuiton.topia.framework.TopiaFiresSupport; -import org.nuiton.topia.persistence.AbstractTopiaDao; -import org.nuiton.topia.persistence.HibernateProvider; -import org.nuiton.topia.persistence.TopiaDao; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.TopiaHibernateSessionRegistry; -import org.nuiton.topia.persistence.TopiaIdFactory; - -import java.lang.reflect.InvocationTargetException; -import java.util.List; -import java.util.Map; - -/** - * Abstract implementation of the TopiaPersistenceContext. This class will be extended by a generated one in order to - * generate getXxxDao methods. - * - * @author Arnaud Thimel <thimel@codelutin.com> - * @since 3.0 - */ -public abstract class AbstractTopiaPersistenceContext implements TopiaPersistenceContext { - - private static final Log log = LogFactory.getLog(AbstractTopiaPersistenceContext.class); - - /** - * Already loaded DAO cache within this persistence context - */ - protected Map<Class<? extends TopiaEntity>, TopiaDao<? extends TopiaEntity>> daoCache = Maps.newConcurrentMap(); - - protected HibernateTopiaReplicationSupport hibernateTopiaReplicationSupport; - - // TODO AThimel 27/09/13 Javadoc - protected TopiaListenableSupport listenableSupport; - - /** - * Used to affect a new topiaId when create is called. - */ - protected TopiaIdFactory topiaIdFactory; - - /** - * The shared instance of TopiaHibernateSessionRegistry - */ - protected TopiaHibernateSessionRegistry sessionRegistry; - - // TODO AThimel 27/09/13 Javadoc - protected TopiaFiresSupport firesSupport; - - /** - * This subclass of TopiaHibernateSupport is made to be used only internally within this persistence context. This - * instance is created by the persistence context itself. - */ - protected InternalTopiaHibernateSupport hibernateSupport; - - /** - * This instance of TopiaJpaSupport is created by the persistence context itself. It is actually using the - * TopiaHibernateSupport instance. - */ - protected TopiaJpaSupport jpaSupport; - - /** - * This instance of TopiaSqlSupport is created by the persistence context itself. It is actually using the - * TopiaHibernateSupport instance. - */ - protected TopiaSqlSupport sqlSupport; - - /** - * Flog used to check if this persistence context is closed - */ - protected boolean closed = false; - - /** - * Creating a new TopiaPersistenceContext is equivalent to creating a new transaction - * - * @param hibernateProvider holds the Hibernate configuration and session factory - * @param listenableSupport the listenableSupport instance to use within this persistence context - * @param topiaIdFactory the TopiaIdFactory instance created according to the application's configuration - */ - public AbstractTopiaPersistenceContext(HibernateProvider hibernateProvider, - TopiaListenableSupport listenableSupport, - TopiaIdFactory topiaIdFactory, - TopiaHibernateSessionRegistry sessionRegistry) { - - this.listenableSupport = listenableSupport; - this.topiaIdFactory = topiaIdFactory; - this.sessionRegistry = sessionRegistry; - this.firesSupport = new TopiaFiresSupport(); - - // Hibernate support can be created using the given hibernateProvider - this.hibernateSupport = new InternalTopiaHibernateSupport(hibernateProvider); - - // Now starts the transaction, as this persistenceContext IS the TopiaTransaction - startTransaction(); - - // Create the different supports that may be needed by the DAOs - this.jpaSupport = new HibernateTopiaJpaSupport(hibernateSupport, firesSupport); - this.sqlSupport = new HibernateTopiaSqlSupport(hibernateSupport); - } - - protected TopiaFiresSupport getFiresSupport() { - return firesSupport; - } - - public TopiaHibernateSupport getHibernateSupport() { - return hibernateSupport; - } - - public TopiaSqlSupport getSqlSupport() { - return sqlSupport; - } - - @Override - public TopiaIdFactory getTopiaIdFactory() { - return topiaIdFactory; - } - - @Override - public TopiaFiresSupport getTopiaFiresSupport() { - return firesSupport; - } - - /** - * This subclass of TopiaHibernateSupport is made to be used only internally within this persistence context. This - * class only acts as an information container (as a structure does). - */ - protected class InternalTopiaHibernateSupport implements TopiaHibernateSupport { - - protected HibernateProvider hibernateProvider; - protected Session hibernateSession; - - protected InternalTopiaHibernateSupport(HibernateProvider hibernateProvider) { - this.hibernateProvider = hibernateProvider; - } - - public void setHibernateSession(Session hibernateSession) { - this.hibernateSession = hibernateSession; - } - - @Override - public Session getHibernateSession() { - Preconditions.checkState(hibernateSession != null, "Session is not yet initialized"); - return hibernateSession; - } - - @Override - public SessionFactory getHibernateFactory() { - return hibernateProvider.getSessionFactory(); - } - - @Override - public Configuration getHibernateConfiguration() { - return hibernateProvider.getHibernateConfiguration(); - } - } - - protected void startTransaction() throws TopiaException { - - SessionFactory factory = hibernateSupport.getHibernateFactory(); - Session result = factory.openSession(); - hibernateSupport.setHibernateSession(result); - - // new TopiaInterceptor(result)); - // on ne synchronise jamais les données avec la base tant que - // l'utilisateur n'a pas fait de commit du context - result.setFlushMode(FlushMode.MANUAL); - - // tchemit 2010-12-06 propagates the value of the flag -// result.useFlushMode = useFlushMode; - - sessionRegistry.register(result, this); - - // 20060926 poussin ajouter pour voir si ca regle les problemes de - // deadlock h2. Conclusion, il faut bien ouvrir une transaction - // maintenant, sinon lorsque l'on fait des acces a la base, une - // transaction par defaut est utilisé mais elle n'est jamais vraiment - // fermé ce qui pose des problemes de lock sur les tables. - try { - result.beginTransaction(); - } catch (Exception eee) { - - // on a pas pu ouvrir la transaction, on faut donc tout fermer - // et declancher une exception - try { - result.close(); - sessionRegistry.unregister(result); - } catch (HibernateException e1) { - if (log.isErrorEnabled()) { - log.error("Could not close hibernate session", e1); - } - } - - String message = String.format("An error occurs while asking a new transaction: %1$s", eee.getMessage()); - throw new TopiaException(message, eee); - } - - // fire event - getFiresSupport().fireOnBeginTransaction(this); - } - - protected void checkClosed() throws TopiaException { - if (closed) { - throw new TopiaException("This context is closed, it is not possible to use it anymore"); - } - } - - @Override - public <E extends TopiaEntity> E findByTopiaId(String topiaId) { - checkClosed(); - - Class<E> entityClass = getTopiaIdFactory().getClassName(topiaId); - TopiaDao<E> dao = getDao(entityClass); - E result = dao.findByTopiaId(topiaId); - return result; - } - - @Override - public void update(TopiaEntity entity) { - checkClosed(); - - String topiaId = entity.getTopiaId(); - Class<TopiaEntity> entityClass = getTopiaIdFactory().getClassName(topiaId); - TopiaDao<TopiaEntity> dao = getDao(entityClass); - dao.update(entity); - - } - - @Override - public <E extends TopiaEntity> TopiaDao<E> getDao(Class<E> entityClass) { - Preconditions.checkArgument(entityClass != null, "The method 'getDao' requires a non null 'entityClass' parameter"); - - SessionFactory hibernateFactory = hibernateSupport.getHibernateFactory(); - if (hibernateFactory.getClassMetadata(entityClass) == null && - hibernateFactory.getClassMetadata(entityClass.getName() + "Impl") == null && - hibernateFactory.getClassMetadata(entityClass.getName() + "Abstract") == null) { - - if (log.isInfoEnabled()) { - String format = "List of supported persistence classes: %s"; - String message = String.format(format, hibernateFactory.getAllClassMetadata().keySet()); - log.info(message); - } - String format = "The following entity type %s is not managed by this context, you probably forgot to declare it."; - String message = String.format(format, entityClass.getName()); - throw new TopiaException(message); - } - - TopiaDao<E> dao = (TopiaDao<E>) daoCache.get(entityClass); - if (dao == null) { - - // Looking for specialized DAO - // This DAO is supposed to exist, as created by generation - String daoClassName = entityClass.getName() + "TopiaDao"; - try { - Class<TopiaDao<E>> daoClass = (Class<TopiaDao<E>>) Class.forName(daoClassName); - dao = daoClass.getConstructor().newInstance(); - } catch (InstantiationException e) { - log.fatal("Unable to instantiate DAO class " + daoClassName, e); - throw new TopiaException("unable to instantiate DAO class " + daoClassName, e); - } catch (IllegalAccessException e) { - log.fatal("Unable to instantiate DAO class " + daoClassName, e); - throw new TopiaException("unable to instantiate DAO class " + daoClassName, e); - } catch (InvocationTargetException e) { - log.fatal("Unable to instantiate DAO class " + daoClassName, e); - throw new TopiaException("unable to instantiate DAO class " + daoClassName, e); - } catch (NoSuchMethodException e) { - log.fatal("Unable to instantiate DAO class " + daoClassName, e); - throw new TopiaException("unable to instantiate DAO class " + daoClassName, e); - } catch (ClassNotFoundException e) { - log.fatal("Unable to find DAO class " + daoClassName, e); - throw new TopiaException("unable to find DAO class " + daoClassName, e); - } - - if (dao instanceof AbstractTopiaDao) { - AbstractTopiaDao abstractTopiaDao = (AbstractTopiaDao) dao; - abstractTopiaDao.init(jpaSupport, sqlSupport, listenableSupport, topiaIdFactory, firesSupport, this); - } - - daoCache.put(entityClass, dao); - - } - - return dao; - } - - @Override - public <E extends TopiaEntity, D extends TopiaDao<E>> D getDao(Class<E> entityClass, Class<D> daoClass) { - TopiaDao<E> dao = getDao(entityClass); - D result = (D) dao; - return result; - } - - @Override - public void commit() { - checkClosed(); - - try { - - Session hibernateSession = hibernateSupport.getHibernateSession(); - - Transaction transaction = hibernateSession.getTransaction(); - hibernateSession.flush(); - transaction.commit(); - - getFiresSupport().fireOnPostCommit(this); -// TopiaContextImplementor parent = getParentContext(); -// if (parent != null) { -// parent.getFiresSupport().fireOnPostCommit(this); -// } - - hibernateSession.beginTransaction(); - - // it's seem necessary to change session after commit - // NON, NON, NON, il ne faut surtout pas le faire, ca pose plein de - // probleme - // hibernate = getHibernateFactory().openSession(); - // hibernate.setFlushMode(FlushMode.NEVER); - } catch (Exception eee) { - String message = String.format("An error occurred during commit operation: %1$s", eee.getMessage()); - throw new TopiaException(message, eee); - } - } - - @Override - public void rollback() { - checkClosed(); - try { - Session hibernateSession = hibernateSupport.getHibernateSession(); - - Transaction transaction = hibernateSession.getTransaction(); - hibernateSession.clear(); - transaction.rollback(); - hibernateSession.close(); - - sessionRegistry.unregister(hibernateSession); - - // it's very important to change the session after rollback - // otherwise there are many error during next Entity's modification - hibernateSession = hibernateSupport.getHibernateFactory().openSession(); - hibernateSupport.setHibernateSession(hibernateSession); - hibernateSession.setFlushMode(FlushMode.MANUAL); - - sessionRegistry.register(hibernateSession, this); - - hibernateSession.beginTransaction(); - - getFiresSupport().fireOnPostRollback(this); -// TopiaContextImplementor parent = getParentContext(); -// if (parent != null) { -// parent.getFiresSupport().fireOnPostRollback(this); -// } - - } catch (HibernateException eee) { - String message = String.format("An error occurred during rollback operation: %1$s", eee.getMessage()); - throw new TopiaException(message, eee); - } - } - - @Override - public void closeContext() { - checkClosed(); - closed = true; - - // Now close the current Hibernate session - Session hibernateSession = hibernateSupport.getHibernateSession(); - hibernateSession.close(); - - sessionRegistry.unregister(hibernateSession); - } - - @Override - public boolean isClosed() { - return closed; - } - - protected HibernateTopiaReplicationSupport getHibernateTopiaReplicationSupport() { - if (hibernateTopiaReplicationSupport == null) { - hibernateTopiaReplicationSupport = new HibernateTopiaReplicationSupport(hibernateSupport); - } - return hibernateTopiaReplicationSupport; - } - - @Override - public void replicate(TopiaEntity entity) { - getHibernateTopiaReplicationSupport().replicate(entity); - } - - @Override - public <T extends TopiaEntity> void replicateEntities(TopiaReplicationDestination topiaReplicationDestination, List<T> entities) throws IllegalArgumentException { - getHibernateTopiaReplicationSupport().replicateEntities(topiaReplicationDestination, entities); - } - - @Override - public <T extends TopiaEntity> void replicateEntity(TopiaReplicationDestination topiaReplicationDestination, T entity) throws IllegalArgumentException { - getHibernateTopiaReplicationSupport().replicateEntity(topiaReplicationDestination, entity); - } - - @Override - public void replicate(TopiaReplicationDestination topiaReplicationDestination, Object... entityAndCondition) throws IllegalArgumentException { - getHibernateTopiaReplicationSupport().replicate(topiaReplicationDestination, entityAndCondition); - } -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -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.util.Collection; -import java.util.List; -import java.util.Map; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.FlushMode; -import org.hibernate.HibernateException; -import org.hibernate.Query; -import org.nuiton.topia.framework.TopiaFiresSupport; -import org.nuiton.topia.framework.TopiaUtil; - -/** - * This class is the Hibernate implementation of TopiaJpaSupport. It realizes the bridge between the JPA specification - * and the technical choice made for its implementation : Hibernate. - * - * @author Arnaud Thimel <thimel@codelutin.com> - * @since 3.0 - */ -public class HibernateTopiaJpaSupport implements TopiaJpaSupport { - - private static final Log log = LogFactory.getLog(HibernateTopiaJpaSupport.class); - - // TODO AThimel 27/09/13 Javadoc - protected TopiaHibernateSupport hibernateSupport; - - // TODO AThimel 27/09/13 Javadoc - protected TopiaFiresSupport firesSupport; - - /** - * 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, Map<String, Object>)} or {@link #find(String, int, int, Map<String, 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; - - public HibernateTopiaJpaSupport(TopiaHibernateSupport hibernateSupport, TopiaFiresSupport firesSupport) { - this.hibernateSupport = hibernateSupport; - this.firesSupport = firesSupport; - } - - public TopiaHibernateSupport getHibernateSupport() { - return hibernateSupport; - } - - @Override - public void setUseFlushMode(boolean useFlushMode) { - this.useFlushMode = useFlushMode; - } - - protected Query prepareQuery(String jpaql, Map<String, Object> parameters) { - Query query = hibernateSupport.getHibernateSession().createQuery(jpaql); - for (Map.Entry<String, Object> entry : parameters.entrySet()) { - String name = entry.getKey(); - Object value = entry.getValue(); - if (value.getClass().isArray()) { - query.setParameterList(name, (Object[]) value); - } else if (value instanceof Collection<?>) { - query.setParameterList(name, (Collection<?>) value); - } else { - query.setParameter(name, value); - } - } - // tchemit 2010-11-30 reproduce the same behaviour than before with the dao legacy - if (useFlushMode) { - query.setFlushMode(FlushMode.AUTO); - } - return query; - } - - @Override - public <T> List<T> findAll(String jpaql, Map<String, Object> parameters) { - try { - Query query = prepareQuery(jpaql, parameters); - - List result = query.list(); - result = firesSupport.fireEntitiesLoad(this, result); - return result; - } catch (HibernateException eee) { - throw new TopiaException(String.format("An error occurs during query operation: %1$s : %2$s", - jpaql, eee.getMessage()), eee); - } catch (RuntimeException e) { - if (log.isWarnEnabled()) { - log.warn("exception occurred for query \n" + jpaql + "\nwith parameters " + parameters); - } - throw e; - } - } - - @Override - public <T> T findUnique(String jpaql, Map<String, Object> parameters) { - - // Execute query, and ask for up to 2 results only - List<T> results = find(jpaql, 0, 1, parameters); - - // 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", jpaql); - throw new TopiaException(message); - } - - // otherwise return the first one, or null - T result = null; - if (!results.isEmpty()) { - result = results.get(0); - } - return result; - } - - @Override - public <T> List<T> find(String jpaql, int startIndex, int endIndex, Map<String, Object> parameters) { - try { - Query query = prepareQuery(jpaql, parameters); - - // Set bounds - query.setFirstResult(startIndex); - query.setMaxResults(endIndex - startIndex + 1); - - List result = query.list(); - result = firesSupport.fireEntitiesLoad(this, result); - return result; - } catch (HibernateException eee) { - throw new TopiaException(String.format("An error occurs during query operation: %1$s : %2$s", - jpaql, eee.getMessage()), eee); - } catch (RuntimeException e) { - if (log.isWarnEnabled()) { - log.warn("exception occurred for query \n" + jpaql + "\nwith parameters " + parameters); - } - throw e; - } - } - - @Override - public int execute(String jpaql, Map<String, Object> parameters) { - try { - Query query = prepareQuery(jpaql, parameters); - - int result = query.executeUpdate(); - return result; - } catch (HibernateException eee) { - throw new TopiaException(String.format("An error occurs during execute operation: %1$s : %2$s", - jpaql, eee.getMessage()), eee); - } catch (RuntimeException e) { - if (log.isWarnEnabled()) { - log.warn("exception occurred for query \n" + jpaql + "\nwith parameters " + parameters); - } - throw e; - } - } - - @Override - public void save(Object object) { - try { - hibernateSupport.getHibernateSession().save(object); - } catch (HibernateException eee) { - throw new TopiaException("Unable to 'save' instance", eee); - } - } - - @Override - public void update(Object object) { - try { - hibernateSupport.getHibernateSession().update(object); - } catch (HibernateException eee) { - throw new TopiaException("Unable to 'update' instance", eee); - } - } - - @Override - public void saveOrUpdate(Object object) { - try { - hibernateSupport.getHibernateSession().saveOrUpdate(object); - } catch (HibernateException eee) { - throw new TopiaException("Unable to 'saveOrUpdate' instance", eee); - } - } - - @Override - public void delete(Object object) { - try { - hibernateSupport.getHibernateSession().delete(object); - } catch (HibernateException eee) { - throw new TopiaException("Unable to 'delete' instance", eee); - } - } - -} // HibernateTopiaJpaSupport Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaReplicationSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaReplicationSupport.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaReplicationSupport.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,180 +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.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.HibernateException; -import org.hibernate.ReplicationMode; -import org.nuiton.topia.persistence.TopiaEntity; - -import java.util.List; -import java.util.Map; - -public class HibernateTopiaReplicationSupport implements TopiaReplicationSupport, TopiaReplicationDestination { - - private static final Log log = LogFactory.getLog(HibernateTopiaReplicationSupport.class); - - protected TopiaHibernateSupport topiaHibernateSupport; - - public HibernateTopiaReplicationSupport(TopiaHibernateSupport topiaHibernateSupport) { - this.topiaHibernateSupport = topiaHibernateSupport; - } - - @Override - public void replicate( - TopiaReplicationDestination topiaReplicationDestination, - Object... entityAndCondition) throws IllegalArgumentException { - - String[] queries = buildQueries(entityAndCondition); - - try { - for (String query : queries) { - if (log.isDebugEnabled()) { - log.debug("acquire entities " + query); - } - // acquire data to replicate - List<?> entities = topiaHibernateSupport.getHibernateSession().createQuery(query).list(); - replicate0(topiaReplicationDestination, entities.toArray()); - if (log.isDebugEnabled()) { - log.debug("replication of entities " + query + - " was sucessfully done."); - } - } - } catch (HibernateException eee) { - throw new TopiaException(String.format("An error occurs while a replication operation: %s", - eee.getMessage()), eee); - } - } - - @Override - public <T extends TopiaEntity> void replicateEntity( - TopiaReplicationDestination topiaReplicationDestination, - T entity) throws IllegalArgumentException { - - replicate0(topiaReplicationDestination, entity); - - } - - @Override - public <T extends TopiaEntity> void replicateEntities( - TopiaReplicationDestination topiaReplicationDestination, - List<T> entities) throws IllegalArgumentException { - - replicate0(topiaReplicationDestination, entities.toArray()); - - } - - protected void replicate0(TopiaReplicationDestination topiaReplicationDestination, - Object... entities) { - try { - for (Object entity : entities) { - // dettach entity to source session, to make possible copy of - // collection without a hibernate exception (list opened in - // two session...) - topiaHibernateSupport.getHibernateSession().evict(entity); - topiaReplicationDestination.replicate((TopiaEntity) entity); - } - - } catch (HibernateException eee) { - throw new TopiaException(String.format("An error occurs while a replication operation : %s", - eee.getMessage()), eee); - } - } - - /** - * Build the list of queries from the given parameter - * <code>entityAndCondition</code>. - * <p/> - * If no parameter is given, then build the queries for all entities is db, - * with no condition. - * - * @param entityAndCondition the list of tuples (Class,String) - * @return the list of queries. - * @throws TopiaException if any pb of db while getting entities - * classes. - * @throws IllegalArgumentException if any pb with the given parameter - * (mainly ClassCastException). - */ - protected String[] buildQueries(Object... entityAndCondition) - throws TopiaException, IllegalArgumentException { - Class<?> entityClass; - String condition; - - // si entityAndcondition est vide alors il faut le remplir - // avec toutes les entités du mapping (class, null) - if (entityAndCondition.length == 0) { - Map<?, ?> classMetadata = topiaHibernateSupport.getHibernateFactory().getAllClassMetadata(); - entityAndCondition = new Object[classMetadata.size() * 2]; - int i = 0; - for (Object className : classMetadata.keySet()) { - try { - entityAndCondition[i++] = Class.forName((String) className); - } catch (ClassNotFoundException e) { - // should never happen! - throw new TopiaException( - "class cast exception for entity " + className); - } - entityAndCondition[i++] = null; - - } - } - - // prepare queries to perform beofre opening any transaction - if (entityAndCondition.length % 2 != 0) { - throw new IllegalArgumentException( - "entityAndCondition must be a couple of (Class, String)"); - } - String queries[] = new String[entityAndCondition.length / 2]; - for (int i = 0; i < entityAndCondition.length; ) { - try { - entityClass = (Class<?>) entityAndCondition[i++]; - condition = (String) entityAndCondition[i++]; - String query = "from " + entityClass.getName(); - if (condition != null && !condition.isEmpty()) { - query += " where " + condition; - } - queries[(i - 1) / 2] = query; - } catch (ClassCastException e) { - if (i % 2 == 0) { - throw new IllegalArgumentException( - "Others arguement must be String not " + - entityAndCondition[i - 1], e); - } else { - throw new IllegalArgumentException( - "Others arguement must be Class not " + - entityAndCondition[i - 1], e); - } - } - } - return queries; - } - - @Override - public void replicate(TopiaEntity entity) { - topiaHibernateSupport.getHibernateSession().replicate(entity, ReplicationMode.EXCEPTION); - } - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaSqlSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaSqlSupport.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaSqlSupport.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,168 +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.HibernateException; -import org.hibernate.jdbc.Work; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -/** - * @author Arnaud Thimel <thimel@codelutin.com> - */ -public class HibernateTopiaSqlSupport implements TopiaSqlSupport { - - protected TopiaHibernateSupport hibernateSupport; - - public HibernateTopiaSqlSupport(TopiaHibernateSupport hibernateSupport) { - this.hibernateSupport = hibernateSupport; - } - - public static class HibernateSqlWork implements Work { - - protected final String script; - - public HibernateSqlWork(String script) { - this.script = script; - } - - @Override - public void execute(Connection connection) throws SQLException { - PreparedStatement sta = connection.prepareStatement(script); - try { - sta.execute(); - } finally { - sta.close(); - } - } - } - - public static class HibernateTopiaSqlWork implements Work { - - protected final TopiaSqlWork work; - - public HibernateTopiaSqlWork(TopiaSqlWork work) { - this.work = work; - } - - @Override - public void execute(Connection connection) throws SQLException { - work.execute(connection); - } - } - - public static class HibernateTopiaSqlQueryWork<O> implements Work { - - protected final TopiaSqlQuery<O> query; - - protected final boolean multipleResult; - - protected final List<O> result = new ArrayList<O>(); - - public HibernateTopiaSqlQueryWork(TopiaSqlQuery<O> query, boolean multipleResult) { - this.query = query; - this.multipleResult = multipleResult; - } - - @Override - public void execute(Connection connection) throws SQLException { - - PreparedStatement ps = query.prepareQuery(connection); - try { - ResultSet set = ps.executeQuery(); - - query.afterExecuteQuery(set); - - if (set.next()) { - O singleResult = query.prepareResult(set); - if (singleResult != null) { - result.add(singleResult); - } - if (multipleResult) { - while (set.next()) { - singleResult = query.prepareResult(set); - if (singleResult != null) { - result.add(singleResult); - } - } - } - } - - } catch (Exception e) { - throw new TopiaException("Could not execute query", e); - } finally { - ps.close(); - } - } - - public List<O> getResult() { - return result; - } - } - - @Override - public void executeSql(String sqlScript) { - HibernateSqlWork work = new HibernateSqlWork(sqlScript); - try { - hibernateSupport.getHibernateSession().doWork(work); - } catch (HibernateException e) { - throw new TopiaException("Could not execute sql code", e); - } - } - - @Override - public void doSqlWork(TopiaSqlWork sqlWork) { - HibernateTopiaSqlWork work = new HibernateTopiaSqlWork(sqlWork); - try { - hibernateSupport.getHibernateSession().doWork(work); - } catch (HibernateException e) { - throw new TopiaException("Could not execute sql code", e); - } - } - - @Override - public <O> O findSingleResult(final TopiaSqlQuery<O> query) throws TopiaException { - - HibernateTopiaSqlQueryWork<O> work = new HibernateTopiaSqlQueryWork<O>(query, false); - hibernateSupport.getHibernateSession().doWork(work); - final List<O> result = work.getResult(); - return result.isEmpty() ? null : result.get(0); - } - - @Override - public <O> List<O> findMultipleResult(final TopiaSqlQuery<O> query) throws TopiaException { - - HibernateTopiaSqlQueryWork<O> work = new HibernateTopiaSqlQueryWork<O>(query, true); - hibernateSupport.getHibernateSession().doWork(work); - final List<O> result = work.getResult(); - return result; - } - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/QueryMissingOrderException.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/QueryMissingOrderException.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/QueryMissingOrderException.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,50 +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.util.Map; - -/** - * If you get this exception, it means that you asked topia - * to make an operation that need a deterministic way to sort the - * result but you didn't defined such query. - * - * To fix you issue, you may use another API call (maybe user findAny instead - * of findFirst) or change your query by adding an order by clause. A quick and - * easy fix would be to just use "order by topiaId". - * - * @since 3.0 - */ -public class QueryMissingOrderException extends TopiaQueryException { - - protected static final String MESSAGE = "given query needs an order by clause since the API call you use need the results sorting to be deterministic"; - - private static final long serialVersionUID = 8154110639594660107L; - - public QueryMissingOrderException(String hql, Map<String, Object> hqlParameters) { - super(MESSAGE, hql, hqlParameters); - } - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaApplicationContextCache.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaApplicationContextCache.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaApplicationContextCache.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,133 +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.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import org.apache.commons.collections.map.AbstractReferenceMap; -import org.apache.commons.collections.map.ReferenceMap; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import com.google.common.base.Function; -import com.google.common.collect.Lists; - -/** - * This class will provide a TopiaApplicationContext cache. Its usage is not necessary, contexts can be directly created - * outside of this cache, then the cache will not contain any reference to the created ApplicationContexts. - * <p/> - * This class is 'inspired' from the TopiaContextFactory of ToPIA 2.x - * - * @author Arnaud Thimel <thimel@codelutin.com> - * @since 3.0 - */ -public class TopiaApplicationContextCache { - - private static final Log log = LogFactory.getLog(TopiaApplicationContextCache.class); - - /** - * Cache that contains all some already registered caches - */ - protected static Map<Properties, AbstractTopiaApplicationContext> contextCache = - new ReferenceMap(AbstractReferenceMap.HARD, - AbstractReferenceMap.SOFT); - - /** - * Static method that can provide an ApplicationContext. If the found context is closed, or if it does not exist, a - * new one is created using the given Function<Properties, C>. - * - * @param <C> the type of TopiaApplicationContext you expect - * @param config the configuration of the context - * @param createContextFunction the function that will be in charge of the context creation. It might not be used - * inside the method if the context is found and still opened - * @return an opened instance of XyzTopiaApplicationContext - * @throws TopiaNotFoundException if any pb - */ - public static <C extends AbstractTopiaApplicationContext> C getContext( - Properties config, Function<Properties, C> createContextFunction) - throws TopiaNotFoundException { - // Put all properties from a hierarchy in the current properties object. - // Resolve problem with hibernate which used iterator to get properties - // and so only values from the current properties object and not all - // hierarchy - Properties cloned = new Properties(); - for (String key : config.stringPropertyNames()) { - cloned.setProperty(key, config.getProperty(key)); - } - C result = (C) contextCache.get(cloned); - if (result == null || result.isClosed()) { - if (createContextFunction == null) { - throw new TopiaException( - "Function<Properties, AbstractTopiaApplicationContext> is required to create context"); - } else { - result = createContextFunction.apply(cloned); - } - if (log.isDebugEnabled()) { - log.debug("New context created : " + result); - } - contextCache.put(cloned, result); - } else if (log.isDebugEnabled()) { - log.debug("Context found : " + result); - } - return result; - } - - /** - * Method to get the list of contexts in memory (each context is identified by its URL). - * <p/> - * To be used for debugging purpose only. - * - * @return a list of contexts URLs - */ - public static List<String> getRegisteredContextUrls() { - List<String> result = Lists.newArrayList(); - for (Properties e : contextCache.keySet()) { - result.add(e.getProperty(TopiaContextFactory.CONFIG_URL)); - } - return result; - } - - /** - * Remove the given TopiaApplicationContext from the registered ones - * - * @param context the context instance to remove - */ - public static void removeContext(AbstractTopiaApplicationContext context) { - - Iterator<AbstractTopiaApplicationContext> it = contextCache.values().iterator(); - - while (it.hasNext()) { - AbstractTopiaApplicationContext curr = it.next(); - if (curr == context) { - it.remove(); - break; - } - } - } - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,109 +0,0 @@ -/* - * #%L - * ToPIA :: Persistence - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 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% - */ - -package org.nuiton.topia; - -import org.apache.commons.collections.map.AbstractReferenceMap; -import org.apache.commons.collections.map.ReferenceMap; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.cfg.Environment; -import org.nuiton.topia.framework.TopiaUtil; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import com.google.common.base.Function; -import com.google.common.base.Supplier; - -/** - * TODO-FD20100507 : Need javadoc + translate the one on methods. - * <p/> - * Created: 3 janv. 2006 21:19:37 - * - * @author poussin <poussin@codelutin.com> - * @author tchemit <tchemit@codelutin.com> - * @version $Id$ - */ -@Deprecated -public class TopiaContextFactory { - - private static final Log log = LogFactory.getLog(TopiaContextFactory.class); - - private static final String DEFAULT_CONFIG_PROPERTIES = - "TopiaContextImpl.properties"; - - public final static String CONFIG_DEFAULT_SCHEMA = Environment.DEFAULT_SCHEMA; - - public final static String CONFIG_USER = Environment.USER; - - public final static String CONFIG_PASS = Environment.PASS; - - public final static String CONFIG_DRIVER = Environment.DRIVER; - - public final static String CONFIG_DIALECT = Environment.DIALECT; - - public final static String CONFIG_CONNECTION_PROVIDER = Environment.CONNECTION_PROVIDER; - - public final static String CONFIG_BYTECODE_PROVIDER = Environment.BYTECODE_PROVIDER; - - public final static String CONFIG_CURRENT_SESSION_CONTEXT_CLASS = Environment.CURRENT_SESSION_CONTEXT_CLASS; - - public final static String CONFIG_GENERATE_STATISTICS = Environment.GENERATE_STATISTICS; - - public final static String CONFIG_FORMAT_SQL = Environment.FORMAT_SQL; - - public final static String CONFIG_HBM2DDL_AUTO = Environment.HBM2DDL_AUTO; - - public final static String CONFIG_POOL_SIZE = Environment.POOL_SIZE; - - public final static String CONFIG_SHOW_SQL = Environment.SHOW_SQL; - - public final static String CONFIG_URL = Environment.URL; - - public final static String CONFIG_PERSISTENCE_DIRECTORIES = - "topia.persistence.directories"; - - public final static String CONFIG_PERSISTENCE_CLASSES = - "topia.persistence.classes"; - - public final static String CONFIG_PERSISTENCE_PROPERTIES_FILE = - "topia.persistence.properties.file"; - - /** - * Configuration directive to change topia Ids generation strategy. - * - * Expected value is an fqn to a class which implements - * {@link org.nuiton.topia.persistence.TopiaIdFactory} - * - * @since 3.0 - */ - public final static String CONFIG_PERSISTENCE_TOPIA_ID_FACTORY_CLASS_NAME = - "topia.persistence.topiaIdFactoryClassName"; - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDaoSupplier.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDaoSupplier.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDaoSupplier.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,54 +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.nuiton.topia.persistence.TopiaDao; -import org.nuiton.topia.persistence.TopiaEntity; - -/** - * @author bleny - */ -public interface TopiaDaoSupplier { - - /** - * Get Dao for specified class. If the specialized Dao exists then it is - * returned otherwise a TopiaException will be thrown - * - * @param entityClass type of entity - * @return the expected dao - */ - <E extends TopiaEntity> TopiaDao<E> getDao(Class<E> entityClass); - - /** - * Get Dao for specified class. If the specialized Dao exists then it is - * returned otherwise a TopiaException will be thrown - * - * @param entityClass type of entity - * @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); - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaException.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaException.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaException.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,76 +0,0 @@ -/* - * #%L - * ToPIA :: Persistence - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 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% - */ - -package org.nuiton.topia; - -/** - * Main exception for any Topia error - * <p/> - * Created: 23 déc. 2005 23:03:36 - * - * @author poussin <poussin@codelutin.com> - * @version $Id$ - */ -public class TopiaException extends RuntimeException { - - /** Version UID */ - private static final long serialVersionUID = -1251439453383121393L; - - /** - * Default constructor. - */ - public TopiaException() { - } - - /** - * Constructor with {@code message}. - * - * @param message exception message - */ - public TopiaException(String message) { - super(message); - } - - /** - * Constructor for a wrapped TopiaException over a {@code cause} - * with a {@code message}. - * - * @param message exception message - * @param cause exception cause - */ - public TopiaException(String message, Throwable cause) { - super(message, cause); - } - - /** - * Constructor for a wrapped TopiaException over a {@code cause}. - * - * @param cause exception cause - */ - public TopiaException(Throwable cause) { - super(cause); - } - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernateSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernateSupport.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernateSupport.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,54 +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; - -/** - * 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(); - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,146 +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.util.List; -import java.util.Map; - -/** - * This API provides methods to use persistence using JPA queries - * - * @author Arnaud Thimel <thimel@codelutin.com> - * @since 3.0 - */ -public interface TopiaJpaSupport { - - /** - * 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 - * - * @param jpaql the JPA-QL query - * @param parameters a map which keys are the attribute names and values are the attributes expected values - * @return The result list - */ - <T> List<T> findAll(String jpaql, - Map<String, Object> parameters); - - /** - * 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 parameters a map which keys are the attribute names and values are the attributes expected values - * @return The result list - */ - <T> List<T> find(String jpaql, - int startIndex, - int endIndex, - Map<String, Object> parameters); - - /** - * 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/> - * WARNING : Depending on the registered service, this method may not - * support something else than queries on TopiaEntity - * - * @param jpaql the JPA-QL query - * @param parameters a map which keys are the attribute names and values are the attributes expected values - * @return The result instance or null - */ - <T> T findUnique(String jpaql, - Map<String, Object> parameters); - - /** - * Execute JPA-QL operation on data (Update, Delete). - * - * @param jpaql the JPA-QL query - * @param parameters a map which keys are the attribute names and values are the attributes expected values - * @return The number of entities updated or deleted. - */ - int execute(String jpaql, - Map<String, Object> parameters); - - /** - * 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 disable it setting the value to {@code false}. - * - * @param useFlushMode the new value to set - * @since 2.5 - */ - void setUseFlushMode(boolean useFlushMode); - - /** - * Persist the given transient instance, first assigning a generated identifier. This method is JPA implementation - * independent. - * <p/> - * This method is "inspired" of the Hibernate's Session#save method. - * - * @param object a transient instance of a persistent class - */ - void save(Object object); - - /** - * Update the persistent instance with the identifier of the given detached instance. - * <p/> - * This method is "inspired" of the Hibernate's Session#update method. - * - * @param object a detached instance containing updated state - */ - void update(Object object); - - /** - * Either {@link #save(Object)} or {@link #update(Object)} the given instance. - * <p/> - * This method is "inspired" of the Hibernate's Session#saveOrUpdate method. - * - * @param object a transient or detached instance containing new or updated state - * @see #save(java.lang.Object) - * @see #update(Object object) - */ - void saveOrUpdate(Object object); - - /** - * Remove a persistent instance. - * <p/> - * This method is "inspired" of the Hibernate's Session#delete method. - * - * @param object the instance to be removed - */ - void delete(Object object); - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenableSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenableSupport.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenableSupport.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,227 +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; - -/** - * 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); - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNoResultException.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNoResultException.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNoResultException.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,40 +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.util.Map; - -/** - * Exception raised when a query returned no result while at least one - * result was expected. - * - * @since 3.0 - */ -public class TopiaNoResultException extends TopiaQueryException { - - public TopiaNoResultException(String hql, Map<String, Object> hqlParameters) { - super("given query doesn't returns any result (at least one expected)", hql, hqlParameters); - } -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNonUniqueResultException.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNonUniqueResultException.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNonUniqueResultException.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,41 +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.util.Map; - -/** - * Exception raised when a query returns more than one result while it was - * expected to return only one (or no result). - * - * @since 3.0 - */ -public class TopiaNonUniqueResultException extends TopiaQueryException { - - public TopiaNonUniqueResultException(String hql, Map<String, Object> hqlParameters) { - super("given query returns more than one result", hql, hqlParameters); - } - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNotFoundException.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNotFoundException.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNotFoundException.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,75 +0,0 @@ -/* - * #%L - * ToPIA :: Persistence - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 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% - */ - -package org.nuiton.topia; - -/** - * Exception thrown if one of the entry from the configuration is missing at runtime - * - * Created: 23 déc. 2005 23:04:28 - * - * @author poussin <poussin@codelutin.com> - * @version $Id$ - */ -public class TopiaNotFoundException extends TopiaException { - - /** Version UID */ - private static final long serialVersionUID = -8206486077608923797L; - - /** - * Default constructor. - */ - public TopiaNotFoundException() { - } - - /** - * Constructor with {@code message}. - * - * @param message exception message - */ - public TopiaNotFoundException(String message) { - super(message); - } - - /** - * Constructor for a wrapped TopiaNotFoundException over a {@code cause} - * with a {@code message}. - * - * @param message exception message - * @param cause exception cause - */ - public TopiaNotFoundException(String message, Throwable cause) { - super(message, cause); - } - - /** - * Constructor for a wrapped TopiaNotFoundException over a {@code cause}. - * - * @param cause exception cause - */ - public TopiaNotFoundException(Throwable cause) { - super(cause); - } -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,91 +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.nuiton.topia.framework.TopiaFiresSupport; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.TopiaIdFactory; - -/** - * This API provides all methods related to persistence : - * <ul> - * <li>Generic entity find</li> - * <li>DAO factory</li> - * <li>Schema management</li> - * </ul> - * - * @author Arnaud Thimel <thimel@codelutin.com> - * @since 3.0 - */ -public interface TopiaPersistenceContext extends TopiaReplicationSupport, TopiaReplicationDestination, - TopiaDaoSupplier, TopiaTransaction { - - /** - * 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 - */ - <E extends TopiaEntity> E findByTopiaId(String topiaId); - - /** - * Add into this TopiaContext an entity created by another TopiaContext - * - * @param entity the entity to add - */ - void update(TopiaEntity entity); - - /** - * Get the currently configured {@link TopiaIdFactory}. - * - * @return the {@link TopiaIdFactory} in use - * @see {@link TopiaIdFactory} - * @since 3.0 - */ - TopiaIdFactory getTopiaIdFactory(); - - /** - * 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(); - - /** - * Get the currently configured {@link TopiaFiresSupport}. - * - * @return the {@link TopiaFiresSupport} in use - * @see {@link TopiaFiresSupport} - * @since 3.0 - */ - TopiaFiresSupport getTopiaFiresSupport(); - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaQueryException.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaQueryException.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaQueryException.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,78 +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.util.Map; - -/** - * Exception raised when an error occur in the context of a - * particular query. Catching this exception class allow you - * to get the buggy request and its parameters. - * - * When cathing such an exception you may ease development by - * logging all the provided information given by {@link #getHql()} - * and {@link #getHqlParameters()} but it's considered dangerous - * since parameters can contain sensible data (such as passwords) - * that should not be printed anywhere. - * - * @since 3.0 - */ -public class TopiaQueryException extends TopiaException { - - protected String hql; - - protected Map<String, Object> hqlParameters; - - public TopiaQueryException(String hql, Map<String, Object> hqlParameters) { - this.hql = hql; - this.hqlParameters = hqlParameters; - } - - public TopiaQueryException(String message, String hql, Map<String, Object> hqlParameters) { - super(message); - this.hql = hql; - this.hqlParameters = hqlParameters; - } - - public TopiaQueryException(String message, Throwable cause, String hql, Map<String, Object> hqlParameters) { - super(message, cause); - this.hql = hql; - this.hqlParameters = hqlParameters; - } - - public TopiaQueryException(Throwable cause, String hql, Map<String, Object> hqlParameters) { - super(cause); - this.hql = hql; - this.hqlParameters = hqlParameters; - } - - public String getHql() { - return hql; - } - - public Map<String, Object> getHqlParameters() { - return hqlParameters; - } -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationDestination.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationDestination.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationDestination.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,43 +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.nuiton.topia.persistence.TopiaEntity; - -/** - * Represent the destination of a replication process. The source is - * {@link TopiaReplicationSupport} - */ -public interface TopiaReplicationDestination { - - /** - * Must replicate given entity in current database - * - * @since 3.0 - * @param entity - */ - void replicate(TopiaEntity entity); - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,86 +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.nuiton.topia.persistence.TopiaEntity; - -import java.util.List; - -/** - * This API provides methods about entities replication to a destination - * - * @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. - * <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(TopiaReplicationDestination, java.util.List)}. - * - * @param topiaReplicationDestination 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 IllegalArgumentException if one of the context is closed or if - * trying to replicate within the same - * database - */ - void replicate(TopiaReplicationDestination topiaReplicationDestination, - Object... entityAndCondition) throws IllegalArgumentException; - - /** - * Replicate a given entity from this context to the given context. - * - * @param topiaReplicationDestination the destination context - * @param entity the entity instance to replicate - * @throws IllegalArgumentException if one of the context is closed or if - * trying to replicate within the same - * database - */ - <T extends TopiaEntity> void replicateEntity(TopiaReplicationDestination topiaReplicationDestination, - T entity) throws IllegalArgumentException; - - /** - * Makes a replication of some entities from this context to the given - * context without any entity modification. - * - * @param topiaReplicationDestination the destination context - * @param entities the list of entities instance to replicate - * @throws IllegalArgumentException if one of the context is closed or if - * trying to replicate within the same - * database - */ - <T extends TopiaEntity> void replicateEntities(TopiaReplicationDestination topiaReplicationDestination, - List<T> entities) throws IllegalArgumentException; - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,64 +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.util.Map; - -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 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 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(); - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupportImpl.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupportImpl.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupportImpl.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,176 +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.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.framework.TopiaService; - -import com.google.common.collect.ImmutableMap; - -/** - * FIXME AThimel 11/10/13 All this life-cycle has to be reviewed - * - * @author Arnaud Thimel <thimel@codelutin.com> - */ -public class TopiaServiceSupportImpl implements TopiaServiceSupport { - - private static final Log log = LogFactory.getLog(TopiaServiceSupportImpl.class); - - protected ImmutableMap<String, TopiaService> services; - protected AbstractTopiaApplicationContext applicationContext; - - public TopiaServiceSupportImpl(AbstractTopiaApplicationContext applicationContext) { - this.applicationContext = applicationContext; - this.services = loadServices(applicationContext.getConfiguration()); - } - - public void init() { - preInitServices(this.services); - applicationContext.getHibernateProvider().getHibernateConfiguration(); // force mapping loading - postInitServices(this.services); - } - - protected void preInitServices(Map<String, TopiaService> services) { - for (TopiaService service : services.values()) { - if (!service.preInit(applicationContext)) { - log.warn(String.format("The service named '%1$s' could not be post-initialized (service not activated)", - service.getServiceName())); - } - } - } - - protected void postInitServices(Map<String, TopiaService> services) { - for (TopiaService service : services.values()) { - if (!service.postInit(applicationContext)) { - log.warn(String.format("The service named '%1$s' could not be pre-initialized (service not activated)", - service.getServiceName())); - } - } - } - - /** - * Retrieve service name using SERVICE_NAME static field on service - * interface. - * - * @param interfaceService class of the service - * @param <E> type of the service that extends {@link - * TopiaService} - * @return the service name - * @throws IllegalAccessException if field SERVICE_NAME can't be accessed - * @throws NoSuchFieldException if no field SERVICE_NAME is defined - */ - protected <E extends TopiaService> String getServiceName( - Class<E> interfaceService) - throws IllegalAccessException, NoSuchFieldException { - Field f = interfaceService.getField("SERVICE_NAME"); - String name = (String) f.get(null); - return name; - } - - protected String getProperExceptionMessage(Throwable eee) { - return eee.getClass().getSimpleName() + " : " + eee.getMessage(); - } - - protected ImmutableMap<String, TopiaService> loadServices(ImmutableMap<String, String> configuration) { - Map<String, TopiaService> result = new HashMap<String, TopiaService>(); - // recherche des services present dans la config - for (String key : configuration.keySet()) { - if (key.matches("^topia\\.service\\.\\w+$")) { - String serviceClass = configuration.get(key); - try { - Class<?> forName = Class.forName(serviceClass); - Object newInstance = forName.getConstructor().newInstance(); - TopiaService service = (TopiaService) newInstance; - if (key.equals("topia.service." + service.getServiceName())) { - result.put(service.getServiceName(), service); - log.info(String.format("Service '%1$s' loaded (implementation %2$s)", - key, serviceClass)); - } else { - log.warn(String.format("The service with key '%1$s' has a different name '%2$s'! (service not activated)", - key, service.getServiceName())); - } - } catch (Throwable eee) { - String message = - String.format("The service %1$s of type %2$s was not found.", - key, serviceClass); - if (log.isDebugEnabled()) { - log.debug(message, eee); - } else if (log.isErrorEnabled()) { - log.error(message); - } - } - } - } - return ImmutableMap.copyOf(result); - } - - - @Override - public <E extends TopiaService> boolean serviceEnabled(Class<E> interfaceService) { - boolean result = false; - try { - String name = getServiceName(interfaceService); - result = getServices().containsKey(name); - } catch (Exception eee) { - String format = "The service named '%1$s' could not be found for following reason: %2$s"; - String message = String.format(format, interfaceService, getProperExceptionMessage(eee)); - if (log.isDebugEnabled()) { - log.debug(message, eee); - } else if (log.isWarnEnabled()) { - log.warn(message); - } - } - return result; - } - - @Override - public <E extends TopiaService> E getService(Class<E> interfaceService) throws TopiaNotFoundException { - E result; - try { - String name = getServiceName(interfaceService); - result = (E) getServices().get(name); - } catch (Exception eee) { - String format = "Could not retreave service %1$s for following reason: %2$s"; - String message = String.format(format, interfaceService, getProperExceptionMessage(eee)); - throw new TopiaNotFoundException(message, eee); - } - if (result == null) { - String message = String.format("The service %1$s was not found.", interfaceService); - throw new TopiaNotFoundException(message); - } - return result; - } - - @Override - public Map<String, TopiaService> getServices() { - return services; - } - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlQuery.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlQuery.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlQuery.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,142 +0,0 @@ -/* - * #%L - * ToPIA :: Persistence - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 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% - */ -package org.nuiton.topia; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * Wrap a Sql query some object. - * - * Implements the {@link #prepareResult(ResultSet)} to transforma result set - * row to an object. - * - * You can also do some stuff on the result set just after the query was - * executed using method {@link #afterExecuteQuery(ResultSet)}. - * - * @param <O> the type of result data - * @since 2.5 - */ -public abstract class TopiaSqlQuery<O> { - - /** - * Prepare the statement used to do the sql query. - * - * @param connection jdbc connection to use - * @return the statement containing the query to execute - * @throws SQLException if any problem - */ - protected abstract PreparedStatement prepareQuery(Connection connection) throws SQLException; - - /** - * given a result set, extract the data. - * - * @param set the result set - * @return the data extracted from the current set, or {@code null} - * @throws SQLException if any prob - */ - protected abstract O prepareResult(ResultSet set) throws SQLException; - - /** - * A hook to obtain the result set just after the query execute. - * - * @param set the result set just obtained - * @throws SQLException if any prob - * @since 2.6.4 - */ - protected void afterExecuteQuery(ResultSet set) throws SQLException { - // by default do nothing - } - - /** - * Obtain the column names of a given result set using his metadata. - * - * @param set the result set to inspect - * @return the column names of the result set - * @throws SQLException if any pb - * @since 2.6.4 - */ - protected String[] getColumnNames(ResultSet set) throws SQLException { - ResultSetMetaData metaData = set.getMetaData(); - int columnCount = metaData.getColumnCount(); - String[] result = new String[columnCount]; - for (int i = 0; i < columnCount; i++) { - result[i] = metaData.getColumnName(i + 1); - } - return result; - } - - /** - * From a given result set, let's count his number of row. - * <p/> - * <strong>Note:</strong> the result set must be scrollable to go back to - * before first row. - * - * @param set the result set to inspect - * @return the number of row of the given result set - * @throws SQLException if any pb - * @since 2.6.4 - */ - protected long getNbRows(ResultSet set) throws SQLException { - - //FIXME tchemit-2012-11-22 use set.last() - long nbRows = 0; - while (set.next()) { - nbRows++; - } - // go back before first row (be ware the resultset must be scrollable) - set.beforeFirst(); - return nbRows; - } - - /** - * Given the column names of the result set, transform the row of the - * result set to a map with column name as key. - * - * @param columnNames column names of the result set - * @param set the set to inspect - * @return the map for the given row of the result set - * @throws SQLException if any pb - * @since 2.6.4 - */ - protected Map<String, Object> getRowAsMap(String[] columnNames, - ResultSet set) throws SQLException { - - Map<String, Object> result = new LinkedHashMap<String, Object>(); - int length = columnNames.length; - for (int i = 0; i < length; i++) { - String name = columnNames[i]; - Object value = set.getObject(i + 1); - result.put(name, value); - } - return result; - } - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,69 +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.util.List; - -/** - * This API provides methods to run SQL queries - * - * @author Arnaud Thimel <thimel@codelutin.com> - * @since 3.0 - */ -public interface TopiaSqlSupport { - - /** - * Execute a given SQL code inside this transaction. - * - * @param sqlScript the sql script to execute - */ - void executeSql(String sqlScript); - - /** - * Runs the given SQL work on the current context - * - * @param sqlWork the SQL work instance to execute - */ - void doSqlWork(TopiaSqlWork sqlWork); - - /** - * Runs the given SQL query and return its first result if there is some. - * - * @param query query to play - * @return the single result or {@code null} if none found. - * @throws TopiaException for any pb - */ - <O> O findSingleResult(TopiaSqlQuery<O> query) throws TopiaException; - - /** - * Runs the given SQL query and return all his result if there is some. - * - * @param query query to play - * @return the list of results (the list is empty if query returns no result). - * @throws TopiaException for any pb - */ - <O> List<O> findMultipleResult(TopiaSqlQuery<O> query) throws TopiaException; - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlWork.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlWork.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlWork.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,49 +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.sql.Connection; -import java.sql.SQLException; - -/** - * Interface used for any native SQL batch. This interface is highly inspired - * of org.hibernate.jdbc.Work. - * - * @author Arnaud Thimel <thimel@codelutin.com> - * @since 3.0 - */ -public interface TopiaSqlWork { - - /** - * Execute the discrete work encapsulated by this work instance using the - * supplied connection. - * - * @param connection The connection on which to perform the work. - * @throws SQLException Thrown during execution of the underlying JDBC - * interaction. - */ - void execute(Connection connection) throws SQLException; - -} \ No newline at end of file Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,48 +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% - */ - -/** - * This API provides methods to manipulate transaction - * - * @author Arnaud Thimel <thimel@codelutin.com> - * @since 3.0 - */ -public interface TopiaTransaction { - - /** - * Applies all the modifications made to this context on the persistence - * device. Once commit is done, a new transaction is started. - */ - void commit(); - - /** - * 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 rollback(); - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaVetoException.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaVetoException.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaVetoException.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,75 +0,0 @@ -/* - * #%L - * ToPIA :: Persistence - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 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% - */ - -package org.nuiton.topia; - -/** - * Exception thrown when something went wrong during event firing - * <p/> - * Created: 5 janv. 2006 00:47:51 - * - * @author poussin <poussin@codelutin.com> - * @version $Id$ - */ -public class TopiaVetoException extends TopiaException { - - private static final long serialVersionUID = 6809613247516488399L; - - /** - * Default constructor. - */ - public TopiaVetoException() { - } - - /** - * Constructor with {@code message}. - * - * @param message exception message - */ - public TopiaVetoException(String message) { - super(message); - } - - /** - * Constructor for a wrapped TopiaVetoException over a {@code cause} - * with a {@code message}. - * - * @param message exception message - * @param cause exception cause - */ - public TopiaVetoException(String message, Throwable cause) { - super(message, cause); - } - - /** - * Constructor for a wrapped TopiaVetoException over a {@code cause}. - * - * @param cause exception cause - */ - public TopiaVetoException(Throwable cause) { - super(cause); - } - -} Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -45,18 +45,13 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.QueryMissingOrderException; -import org.nuiton.topia.TopiaDaoSupplier; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaJpaSupport; -import org.nuiton.topia.TopiaListenableSupport; -import org.nuiton.topia.TopiaNoResultException; -import org.nuiton.topia.TopiaNonUniqueResultException; -import org.nuiton.topia.TopiaSqlSupport; -import org.nuiton.topia.event.TopiaEntityListener; -import org.nuiton.topia.event.TopiaEntityVetoable; -import org.nuiton.topia.framework.TopiaFiresSupport; -import org.nuiton.topia.framework.TopiaUtil; +import org.nuiton.topia.persistence.support.TopiaJpaSupport; +import org.nuiton.topia.persistence.support.TopiaListenableSupport; +import org.nuiton.topia.persistence.support.TopiaSqlSupport; +import org.nuiton.topia.persistence.event.TopiaEntityListener; +import org.nuiton.topia.persistence.event.TopiaEntityVetoable; +import org.nuiton.topia.persistence.internal.support.TopiaFiresSupport; +import org.nuiton.topia.persistence.util.TopiaUtil; import org.nuiton.topia.persistence.pager.TopiaPagerBean; import org.nuiton.util.PagerBeanUtil; @@ -74,7 +69,7 @@ * <p/> * This class is directly extended by the GeneratedXyzTopiaDao which groups all the Xyz specific methods. * <p/> - * Instances are created bt the model's specific {@link org.nuiton.topia.TopiaPersistenceContext}, which implements the + * Instances are created bt the model's specific {@link TopiaPersistenceContext}, which implements the * {@link TopiaDaoSupplier} contract. * * @param <E> the managed entity type @@ -629,7 +624,7 @@ // * we don't want expose it. // * // * @return the meta-data of the entity -// * @throws org.nuiton.topia.TopiaException if any pb +// * @throws org.nuiton.topia.persistence.TopiaException if any pb // */ // protected ClassMetadata getClassMetadata() { // ClassMetadata meta = topiaHibernateSupport.getHibernateFactory().getClassMetadata(getEntityClass()); 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-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DefaultTopiaIdFactory.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -25,7 +25,6 @@ */ import org.apache.commons.lang3.StringUtils; -import org.nuiton.topia.TopiaException; import java.util.UUID; Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DepthEntityVisitor.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DepthEntityVisitor.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DepthEntityVisitor.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -27,7 +27,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaException; import java.util.ArrayList; import java.util.Collection; Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HibernateProvider.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HibernateProvider.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HibernateProvider.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -45,12 +45,10 @@ import org.hibernate.service.jdbc.connections.spi.ConnectionProvider; import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.Stoppable; -import org.nuiton.topia.TopiaContextFactory; -import org.nuiton.topia.TopiaNotFoundException; -import org.nuiton.topia.TopiaServiceSupport; -import org.nuiton.topia.framework.TopiaHibernateEventListener; -import org.nuiton.topia.framework.TopiaService; -import org.nuiton.topia.framework.TopiaUtil; +import org.nuiton.topia.persistence.internal.TopiaHibernateSessionRegistry; +import org.nuiton.topia.persistence.support.TopiaServiceSupport; +import org.nuiton.topia.persistence.internal.support.TopiaHibernateEventListener; +import org.nuiton.topia.persistence.util.TopiaUtil; import com.google.common.collect.Lists; Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HorizontalEntityVisitor.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HorizontalEntityVisitor.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HorizontalEntityVisitor.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -27,7 +27,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaException; import java.util.ArrayList; import java.util.Collection; 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-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaIdFactory.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -25,7 +25,6 @@ */ import org.apache.commons.lang3.StringUtils; -import org.nuiton.topia.TopiaNotFoundException; /** * Implements {@link TopiaIdFactory} with Topia 2.x and before ids. @@ -54,7 +53,7 @@ * * @param topiaId * @return class - * @throws org.nuiton.topia.TopiaNotFoundException + * @throws TopiaNotFoundException */ @Override public <E extends TopiaEntity> Class<E> getClassName(String topiaId) { Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/QueryMissingOrderException.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/QueryMissingOrderException.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/QueryMissingOrderException.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/QueryMissingOrderException.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,50 @@ +package org.nuiton.topia.persistence; + +/* + * #%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; + +/** + * If you get this exception, it means that you asked topia + * to make an operation that need a deterministic way to sort the + * result but you didn't defined such query. + * + * To fix you issue, you may use another API call (maybe user findAny instead + * of findFirst) or change your query by adding an order by clause. A quick and + * easy fix would be to just use "order by topiaId". + * + * @since 3.0 + */ +public class QueryMissingOrderException extends TopiaQueryException { + + protected static final String MESSAGE = "given query needs an order by clause since the API call you use need the results sorting to be deterministic"; + + private static final long serialVersionUID = 8154110639594660107L; + + public QueryMissingOrderException(String hql, Map<String, Object> hqlParameters) { + super(MESSAGE, hql, hqlParameters); + } + +} Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaApplicationContext.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaApplicationContext.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaApplicationContext.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,50 @@ +package org.nuiton.topia.persistence; + +import com.google.common.collect.ImmutableMap; +import org.nuiton.topia.persistence.support.TopiaListenableSupport; +import org.nuiton.topia.persistence.support.TopiaServiceSupport; + +import java.util.List; + +/** + * Created on 12/20/13. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 3.0 + */ +public interface TopiaApplicationContext<K extends TopiaPersistenceContext> extends TopiaListenableSupport, TopiaServiceSupport { + + K newPersistenceContext(); + + String getModelVersion(); + + String getModelName(); + + <T extends TopiaEntity> Class<T> getContractClass(Class<T> klass); + + <T extends TopiaEntity> Class<T> getImplementationClass(Class<T> klass); + + Class<? extends TopiaEntity>[] getContractClasses(); + + ImmutableMap<String, String> getConfiguration(); + + List<Class<?>> getPersistenceClasses(); + + boolean isSchemaEmpty(); + + boolean isTableExists(Class<?> clazz); + + String getSchemaName(); + + void createSchema(); + + void showCreateSchema(); + + void updateSchema(); + + void dropSchema(); + + void closeContext() throws TopiaException; + + boolean isClosed(); +} Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaApplicationContext.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaApplicationContextCache.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaApplicationContextCache.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaApplicationContextCache.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaApplicationContextCache.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,134 @@ +package org.nuiton.topia.persistence; + +/* + * #%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.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.apache.commons.collections.map.AbstractReferenceMap; +import org.apache.commons.collections.map.ReferenceMap; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.google.common.base.Function; +import com.google.common.collect.Lists; +import org.nuiton.topia.persistence.internal.AbstractTopiaApplicationContext; + +/** + * This class will provide a TopiaApplicationContext cache. Its usage is not necessary, contexts can be directly created + * outside of this cache, then the cache will not contain any reference to the created ApplicationContexts. + * <p/> + * This class is 'inspired' from the TopiaContextFactory of ToPIA 2.x + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public class TopiaApplicationContextCache { + + private static final Log log = LogFactory.getLog(TopiaApplicationContextCache.class); + + /** + * Cache that contains all some already registered caches + */ + protected static Map<Properties, TopiaApplicationContext> contextCache = + new ReferenceMap(AbstractReferenceMap.HARD, + AbstractReferenceMap.SOFT); + + /** + * Static method that can provide an ApplicationContext. If the found context is closed, or if it does not exist, a + * new one is created using the given Function<Properties, C>. + * + * @param <C> the type of TopiaApplicationContext you expect + * @param config the configuration of the context + * @param createContextFunction the function that will be in charge of the context creation. It might not be used + * inside the method if the context is found and still opened + * @return an opened instance of XyzTopiaApplicationContext + * @throws TopiaNotFoundException if any pb + */ + public static <C extends AbstractTopiaApplicationContext> C getContext( + Properties config, Function<Properties, C> createContextFunction) + throws TopiaNotFoundException { + // Put all properties from a hierarchy in the current properties object. + // Resolve problem with hibernate which used iterator to get properties + // and so only values from the current properties object and not all + // hierarchy + Properties cloned = new Properties(); + for (String key : config.stringPropertyNames()) { + cloned.setProperty(key, config.getProperty(key)); + } + C result = (C) contextCache.get(cloned); + if (result == null || result.isClosed()) { + if (createContextFunction == null) { + throw new TopiaException( + "Function<Properties, AbstractTopiaApplicationContext> is required to create context"); + } else { + result = createContextFunction.apply(cloned); + } + if (log.isDebugEnabled()) { + log.debug("New context created : " + result); + } + contextCache.put(cloned, result); + } else if (log.isDebugEnabled()) { + log.debug("Context found : " + result); + } + return result; + } + + /** + * Method to get the list of contexts in memory (each context is identified by its URL). + * <p/> + * To be used for debugging purpose only. + * + * @return a list of contexts URLs + */ + public static List<String> getRegisteredContextUrls() { + List<String> result = Lists.newArrayList(); + for (Properties e : contextCache.keySet()) { + result.add(e.getProperty(TopiaContextFactory.CONFIG_URL)); + } + return result; + } + + /** + * Remove the given TopiaApplicationContext from the registered ones + * + * @param context the context instance to remove + */ + public static void removeContext(TopiaApplicationContext context) { + + Iterator<TopiaApplicationContext> it = contextCache.values().iterator(); + + while (it.hasNext()) { + TopiaApplicationContext curr = it.next(); + if (curr == context) { + it.remove(); + break; + } + } + } + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaContextFactory.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaContextFactory.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaContextFactory.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,93 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +package org.nuiton.topia.persistence; + +import org.hibernate.cfg.Environment; + +/** + * TODO-FD20100507 : Need javadoc + translate the one on methods. + * <p/> + * Created: 3 janv. 2006 21:19:37 + * + * @author poussin <poussin@codelutin.com> + * @author tchemit <tchemit@codelutin.com> + * @version $Id$ + */ +@Deprecated +public class TopiaContextFactory { + + private static final String DEFAULT_CONFIG_PROPERTIES = + "TopiaContextImpl.properties"; + + public final static String CONFIG_DEFAULT_SCHEMA = Environment.DEFAULT_SCHEMA; + + public final static String CONFIG_USER = Environment.USER; + + public final static String CONFIG_PASS = Environment.PASS; + + public final static String CONFIG_DRIVER = Environment.DRIVER; + + public final static String CONFIG_DIALECT = Environment.DIALECT; + + public final static String CONFIG_CONNECTION_PROVIDER = Environment.CONNECTION_PROVIDER; + + public final static String CONFIG_BYTECODE_PROVIDER = Environment.BYTECODE_PROVIDER; + + public final static String CONFIG_CURRENT_SESSION_CONTEXT_CLASS = Environment.CURRENT_SESSION_CONTEXT_CLASS; + + public final static String CONFIG_GENERATE_STATISTICS = Environment.GENERATE_STATISTICS; + + public final static String CONFIG_FORMAT_SQL = Environment.FORMAT_SQL; + + public final static String CONFIG_HBM2DDL_AUTO = Environment.HBM2DDL_AUTO; + + public final static String CONFIG_POOL_SIZE = Environment.POOL_SIZE; + + public final static String CONFIG_SHOW_SQL = Environment.SHOW_SQL; + + public final static String CONFIG_URL = Environment.URL; + + public final static String CONFIG_PERSISTENCE_DIRECTORIES = + "topia.persistence.directories"; + + public final static String CONFIG_PERSISTENCE_CLASSES = + "topia.persistence.classes"; + + public final static String CONFIG_PERSISTENCE_PROPERTIES_FILE = + "topia.persistence.properties.file"; + + /** + * Configuration directive to change topia Ids generation strategy. + * <p/> + * Expected value is an fqn to a class which implements + * {@link org.nuiton.topia.persistence.TopiaIdFactory} + * + * @since 3.0 + */ + public final static String CONFIG_PERSISTENCE_TOPIA_ID_FACTORY_CLASS_NAME = + "topia.persistence.topiaIdFactoryClassName"; + +} 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-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -25,9 +25,8 @@ */ import com.google.common.base.Optional; -import org.nuiton.topia.TopiaNoResultException; -import org.nuiton.topia.event.TopiaEntityListener; -import org.nuiton.topia.event.TopiaEntityVetoable; +import org.nuiton.topia.persistence.event.TopiaEntityListener; +import org.nuiton.topia.persistence.event.TopiaEntityVetoable; import org.nuiton.topia.persistence.pager.TopiaPagerBean; import java.util.List; Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDaoSupplier.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDaoSupplier.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDaoSupplier.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDaoSupplier.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,54 @@ +package org.nuiton.topia.persistence; + +/* + * #%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.nuiton.topia.persistence.TopiaDao; +import org.nuiton.topia.persistence.TopiaEntity; + +/** + * @author bleny + */ +public interface TopiaDaoSupplier { + + /** + * Get Dao for specified class. If the specialized Dao exists then it is + * returned otherwise a TopiaException will be thrown + * + * @param entityClass type of entity + * @return the expected dao + */ + <E extends TopiaEntity> TopiaDao<E> getDao(Class<E> entityClass); + + /** + * Get Dao for specified class. If the specialized Dao exists then it is + * returned otherwise a TopiaException will be thrown + * + * @param entityClass type of entity + * @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); + +} Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -37,8 +37,6 @@ package org.nuiton.topia.persistence; -import org.nuiton.topia.TopiaException; - import java.beans.PropertyChangeListener; import java.beans.VetoableChangeListener; import java.io.Serializable; Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -25,8 +25,7 @@ package org.nuiton.topia.persistence; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaFiresSupport; +import org.nuiton.topia.persistence.internal.support.TopiaFiresSupport; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityContextable.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityContextable.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityContextable.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -25,8 +25,6 @@ package org.nuiton.topia.persistence; -import org.nuiton.topia.TopiaDaoSupplier; - /** * {@link TopiaEntity} with {@link TopiaContext} support (injected by * {@link TopiaContext} into entities). Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaException.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaException.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaException.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaException.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,76 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +package org.nuiton.topia.persistence; + +/** + * Main exception for any Topia error + * <p/> + * Created: 23 déc. 2005 23:03:36 + * + * @author poussin <poussin@codelutin.com> + * @version $Id$ + */ +public class TopiaException extends RuntimeException { + + /** Version UID */ + private static final long serialVersionUID = -1251439453383121393L; + + /** + * Default constructor. + */ + public TopiaException() { + } + + /** + * Constructor with {@code message}. + * + * @param message exception message + */ + public TopiaException(String message) { + super(message); + } + + /** + * Constructor for a wrapped TopiaException over a {@code cause} + * with a {@code message}. + * + * @param message exception message + * @param cause exception cause + */ + public TopiaException(String message, Throwable cause) { + super(message, cause); + } + + /** + * Constructor for a wrapped TopiaException over a {@code cause}. + * + * @param cause exception cause + */ + public TopiaException(Throwable cause) { + super(cause); + } + +} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaHibernateSessionRegistry.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaHibernateSessionRegistry.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaHibernateSessionRegistry.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,95 +0,0 @@ -package org.nuiton.topia.persistence; - -/* - * #%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.lang.ref.WeakReference; -import java.util.WeakHashMap; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.Session; -import org.nuiton.topia.TopiaPersistenceContext; - -import com.google.common.base.Preconditions; - -/** - * Class used to keep an association between an Hibernate Session and a TopiaPersistenceContext - * - * @author Arnaud Thimel <thimel@codelutin.com> - * @since 3.0 - */ -public class TopiaHibernateSessionRegistry { - - private static final Log log = LogFactory.getLog(TopiaHibernateSessionRegistry.class); - - protected WeakHashMap<Session, WeakReference<TopiaPersistenceContext>> registry = - new WeakHashMap<Session, WeakReference<TopiaPersistenceContext>>(); - - /** - * Register the Session<->TopiaPersistenceContext couple - * - * @param session the currently used Session - * @param persistenceContext the current TopiaPersistenceContext using this Session - */ - public void register(Session session, TopiaPersistenceContext persistenceContext) { - if (log.isDebugEnabled()) { - log.debug("New Session<->TopiaPersistenceContext registration"); - } - Preconditions.checkArgument(session != null); - Preconditions.checkArgument(persistenceContext != null); - WeakReference<TopiaPersistenceContext> reference = new WeakReference<TopiaPersistenceContext>(persistenceContext); - registry.put(session, reference); - } - - /** - * Look for the TopiaPersistenceContext based on the given Hibernate session - * - * @param session the Hibernate Session to use - * @return the TopiaPersistenceContext using this Session, or null if not found - */ - public TopiaPersistenceContext getPersistenceContext(Session session) { - Preconditions.checkArgument(session != null); - WeakReference<TopiaPersistenceContext> reference = registry.get(session); - TopiaPersistenceContext result = reference.get(); - if (log.isDebugEnabled()) { - log.debug("Get TopiaPersistenceContext from Session : " + (result == null ? "Not found" : "HIT !")); - } - return result; - } - - /** - * Removes the Session<->TopiaPersistenceContext association from the registry - * - * @param session the Hibernate Session to remove - */ - public void unregister(Session session) { - Preconditions.checkArgument(session != null); - WeakReference<TopiaPersistenceContext> reference = registry.remove(session); - if (log.isDebugEnabled()) { - log.debug("Remove TopiaPersistenceContext from Session : " + (reference != null)); - } - } - -} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaNoResultException.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNoResultException.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaNoResultException.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaNoResultException.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,42 @@ +package org.nuiton.topia.persistence; + +/* + * #%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; + +/** + * Exception raised when a query returned no result while at least one + * result was expected. + * + * @since 3.0 + */ +public class TopiaNoResultException extends TopiaQueryException { + + private static final long serialVersionUID = 1L; + + public TopiaNoResultException(String hql, Map<String, Object> hqlParameters) { + super("given query doesn't returns any result (at least one expected)", hql, hqlParameters); + } +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaNonUniqueResultException.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNonUniqueResultException.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaNonUniqueResultException.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaNonUniqueResultException.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,43 @@ +package org.nuiton.topia.persistence; + +/* + * #%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; + +/** + * Exception raised when a query returns more than one result while it was + * expected to return only one (or no result). + * + * @since 3.0 + */ +public class TopiaNonUniqueResultException extends TopiaQueryException { + + private static final long serialVersionUID = 1L; + + public TopiaNonUniqueResultException(String hql, Map<String, Object> hqlParameters) { + super("given query returns more than one result", hql, hqlParameters); + } + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaNotFoundException.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNotFoundException.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaNotFoundException.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaNotFoundException.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,75 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +package org.nuiton.topia.persistence; + +/** + * Exception thrown if one of the entry from the configuration is missing at runtime + * + * Created: 23 déc. 2005 23:04:28 + * + * @author poussin <poussin@codelutin.com> + * @version $Id$ + */ +public class TopiaNotFoundException extends TopiaException { + + /** Version UID */ + private static final long serialVersionUID = -8206486077608923797L; + + /** + * Default constructor. + */ + public TopiaNotFoundException() { + } + + /** + * Constructor with {@code message}. + * + * @param message exception message + */ + public TopiaNotFoundException(String message) { + super(message); + } + + /** + * Constructor for a wrapped TopiaNotFoundException over a {@code cause} + * with a {@code message}. + * + * @param message exception message + * @param cause exception cause + */ + public TopiaNotFoundException(String message, Throwable cause) { + super(message, cause); + } + + /** + * Constructor for a wrapped TopiaNotFoundException over a {@code cause}. + * + * @param cause exception cause + */ + public TopiaNotFoundException(Throwable cause) { + super(cause); + } +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaPersistenceContext.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaPersistenceContext.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaPersistenceContext.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,90 @@ +package org.nuiton.topia.persistence; + +/* + * #%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.nuiton.topia.persistence.internal.support.TopiaFiresSupport; +import org.nuiton.topia.persistence.support.TopiaReplicationSupport; + +/** + * This API provides all methods related to persistence : + * <ul> + * <li>Generic entity find</li> + * <li>DAO factory</li> + * <li>Schema management</li> + * </ul> + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public interface TopiaPersistenceContext extends TopiaReplicationSupport, TopiaReplicationDestination, + TopiaDaoSupplier, TopiaTransaction { + + /** + * 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 + */ + <E extends TopiaEntity> E findByTopiaId(String topiaId); + + /** + * Add into this TopiaContext an entity created by another TopiaContext + * + * @param entity the entity to add + */ + void update(TopiaEntity entity); + + /** + * Get the currently configured {@link TopiaIdFactory}. + * + * @return the {@link TopiaIdFactory} in use + * @see {@link TopiaIdFactory} + * @since 3.0 + */ + TopiaIdFactory getTopiaIdFactory(); + + /** + * 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(); + + /** + * Get the currently configured {@link TopiaFiresSupport}. + * + * @return the {@link TopiaFiresSupport} in use + * @see {@link TopiaFiresSupport} + * @since 3.0 + */ + TopiaFiresSupport getTopiaFiresSupport(); + +} Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -25,9 +25,6 @@ */ import com.google.common.base.Optional; -import org.nuiton.topia.QueryMissingOrderException; -import org.nuiton.topia.TopiaNoResultException; -import org.nuiton.topia.TopiaNonUniqueResultException; import org.nuiton.topia.persistence.pager.TopiaPagerBean; import java.util.List; Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryException.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaQueryException.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryException.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryException.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,80 @@ +package org.nuiton.topia.persistence; + +/* + * #%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; + +/** + * Exception raised when an error occur in the context of a + * particular query. Catching this exception class allow you + * to get the buggy request and its parameters. + * + * When cathing such an exception you may ease development by + * logging all the provided information given by {@link #getHql()} + * and {@link #getHqlParameters()} but it's considered dangerous + * since parameters can contain sensible data (such as passwords) + * that should not be printed anywhere. + * + * @since 3.0 + */ +public class TopiaQueryException extends TopiaException { + + private static final long serialVersionUID = 1L; + + protected String hql; + + protected Map<String, Object> hqlParameters; + + public TopiaQueryException(String hql, Map<String, Object> hqlParameters) { + this.hql = hql; + this.hqlParameters = hqlParameters; + } + + public TopiaQueryException(String message, String hql, Map<String, Object> hqlParameters) { + super(message); + this.hql = hql; + this.hqlParameters = hqlParameters; + } + + public TopiaQueryException(String message, Throwable cause, String hql, Map<String, Object> hqlParameters) { + super(message, cause); + this.hql = hql; + this.hqlParameters = hqlParameters; + } + + public TopiaQueryException(Throwable cause, String hql, Map<String, Object> hqlParameters) { + super(cause); + this.hql = hql; + this.hqlParameters = hqlParameters; + } + + public String getHql() { + return hql; + } + + public Map<String, Object> getHqlParameters() { + return hqlParameters; + } +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaReplicationDestination.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationDestination.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaReplicationDestination.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaReplicationDestination.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,44 @@ +package org.nuiton.topia.persistence; + +/* + * #%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.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.support.TopiaReplicationSupport; + +/** + * Represent the destination of a replication process. The source is + * {@link TopiaReplicationSupport} + */ +public interface TopiaReplicationDestination { + + /** + * Must replicate given entity in current database + * + * @since 3.0 + * @param entity + */ + void replicate(TopiaEntity entity); + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaService.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaService.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaService.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaService.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,88 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +/* * + * TopiaService.java + * + * Created: 8 oct. 06 17:15:52 + * + * @author poussin <poussin@codelutin.com> + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ + +package org.nuiton.topia.persistence; + +import org.nuiton.topia.persistence.internal.AbstractTopiaApplicationContext; + +/** + * Used to implement a service for Topia. You have to provide a static property + * called SERVICE_NAME that identify the service : + * <p/> + * <li>public static final String SERVICE_NAME = "monservice"; + * <p/> + * The value of this attribute need to be returned when using + * {@link #getServiceName()} method. + * + * @author poussin <poussin@codelutin.com> + * @version $Id$ + */ +public interface TopiaService { + + /** + * Return the name of the service, this name need to match with + * configuration file, for example for index service, we need to have : + * "topia.service.index" and this method will returned "index". + * + * @return the service name + */ + String getServiceName(); + + /** + * Retrieve entities of this service needed for persistence. + * + * @return List of entities full qualified name separated by a comma + */ + Class<?>[] getPersistenceClasses(); + + /** + * Initiliaze the service before create the {@code context}. + * + * @param context + * @return true if service need to be activated or not + */ + boolean preInit(AbstractTopiaApplicationContext context); + + /** + * Initiliaze the service after create the {@code context}. + * + * @param context + * @return true if service need to be activated or not + */ + boolean postInit(TopiaApplicationContext context); + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaTransaction.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaTransaction.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaTransaction.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,48 @@ +package org.nuiton.topia.persistence; + +/* + * #%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 { + + /** + * Applies all the modifications made to this context on the persistence + * device. Once commit is done, a new transaction is started. + */ + void commit(); + + /** + * 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 rollback(); + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaTransactionAware.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaTransactionAware.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaTransactionAware.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaTransactionAware.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,56 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2011 CodeLutin, Tony Chemit + * %% + * 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% + */ +package org.nuiton.topia.persistence; + +/** + * Use this contract on a object which use a {@code TopiaContext} as a + * transaction. + * <p/> + * The method {@link #getTransaction()} returns the internal transaction used. + * <p/> + * the method {@link #setTransaction(TopiaTransaction)} put the internal + * transaction. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.6.1 + */ +public interface TopiaTransactionAware { + + /** + * Obtains the internal transaction. + * <p/> + * If no transaction was opened, can return the {@code null} object. + * + * @return the current transaction (can be null or closed...). + */ + TopiaTransaction getTransaction(); + + /** + * Put in the instance, the given transaction. + * + * @param transaction the transaction to push + */ + void setTransaction(TopiaTransaction transaction); +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaVetoException.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaVetoException.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaVetoException.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaVetoException.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,75 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +package org.nuiton.topia.persistence; + +/** + * Exception thrown when something went wrong during event firing + * <p/> + * Created: 5 janv. 2006 00:47:51 + * + * @author poussin <poussin@codelutin.com> + * @version $Id$ + */ +public class TopiaVetoException extends TopiaException { + + private static final long serialVersionUID = 6809613247516488399L; + + /** + * Default constructor. + */ + public TopiaVetoException() { + } + + /** + * Constructor with {@code message}. + * + * @param message exception message + */ + public TopiaVetoException(String message) { + super(message); + } + + /** + * Constructor for a wrapped TopiaVetoException over a {@code cause} + * with a {@code message}. + * + * @param message exception message + * @param cause exception cause + */ + public TopiaVetoException(String message, Throwable cause) { + super(message, cause); + } + + /** + * Constructor for a wrapped TopiaVetoException over a {@code cause}. + * + * @param cause exception cause + */ + public TopiaVetoException(Throwable cause) { + super(cause); + } + +} Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/TopiaCsvCommons.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/TopiaCsvCommons.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/TopiaCsvCommons.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -26,7 +26,7 @@ import com.google.common.collect.Lists; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.util.StringUtil; import org.nuiton.csv.Common; Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/ImportStrategy.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/ImportStrategy.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/ImportStrategy.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -23,7 +23,7 @@ * #L% */ -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityEnum; import org.nuiton.topia.persistence.metadata.AssociationMeta; Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -29,9 +29,9 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaHibernateSupport; -import org.nuiton.topia.TopiaSqlSupport; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.support.TopiaHibernateSupport; +import org.nuiton.topia.persistence.support.TopiaSqlSupport; import org.nuiton.topia.persistence.TopiaDao; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityEnum; Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/ExportEntityVisitor.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/ExportEntityVisitor.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/ExportEntityVisitor.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -27,7 +27,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.EntityVisitor; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityEnum; Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/TopiaCsvExports.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/TopiaCsvExports.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/TopiaCsvExports.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -32,7 +32,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityEnum; import org.nuiton.topia.persistence.metadata.AssociationMeta; Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/EntityState.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/EntityState.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/EntityState.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/EntityState.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,156 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +/* * + * EntityState.java + * + * Created: 22 nov. 06 12:10:57 + * + * @author poussin <poussin@codelutin.com> + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ + +package org.nuiton.topia.persistence.event; + +/** + * Used to know the state of entity during transaction. + * + * @author poussin <poussin@codelutin.com> + */ +public class EntityState implements Comparable<EntityState>{ + + final static int NULL = 0; + + final static int LOAD = 1; + + final static int READ = 2; + + final static int CREATE = 4; + + final static int UPDATE = 8; + + final static int DELETE = 16; + + /** internal representation of all states of entity (use bitwise operation). */ + protected int state = NULL; + + /** + * Add load state. + * <p/> + * After the invocation, method {@link #isLoad()} will always return {@code true}. + */ + public void addLoad() { + state |= LOAD; + } + + /** + * Add read state + * <p/> + * After the invocation, method {@link #isRead()} will always return {@code true}. + */ + public void addRead() { + state |= READ; + } + + /** + * Add create state. + * <p/> + * After the invocation, method {@link #isCreate()} will always return {@code true}. + */ + public void addCreate() { + state |= CREATE; + } + + /** + * Add update state. + * <p/> + * After the invocation, method {@link #isUpdate()} will always return {@code true}. + */ + public void addUpdate() { + state |= UPDATE; + } + + /** + * Add delete state. + * <p/> + * After the invocation, method {@link #isDelete()} will always return {@code true}. + */ + public void addDelete() { + state |= DELETE; + } + + /** + * Tells if the {@link #LOAD} state is on. + * + * @return {@code true} if {@link #LOAD} state is on, {@code false} otherwise. + */ + public boolean isLoad() { + return (state & LOAD) == LOAD; + } + + /** + * Tells if the {@link #READ} state is on. + * + * @return {@code true} if {@link #READ} state is on, {@code false} otherwise. + */ + public boolean isRead() { + return (state & READ) == READ; + } + + /** + * Tells if the {@link #CREATE} state is on. + * + * @return {@code true} if {@link #CREATE} state is on, {@code false} otherwise. + */ + public boolean isCreate() { + return (state & CREATE) == CREATE; + } + + /** + * Tells if the {@link #UPDATE} state is on. + * + * @return {@code true} if {@link #UPDATE} state is on, {@code false} otherwise. + */ + public boolean isUpdate() { + return (state & UPDATE) == UPDATE; + } + + /** + * Tells if the {@link #DELETE} state is on. + * + * @return {@code true} if {@link #DELETE} state is on, {@code false} otherwise. + */ + public boolean isDelete() { + return (state & DELETE) == DELETE; + } + + @Override + public int compareTo(EntityState o) { + return state - o.state; + } +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaContextAdapter.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextAdapter.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaContextAdapter.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaContextAdapter.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,69 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ +package org.nuiton.topia.persistence.event; + +/** + * Adapter pattern of {@link TopiaSchemaListener}. + * <p/> + * This implementation does nothing but permits developpers to use this adapater + * without to have to implements all methods. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.3.4 + */ +public class TopiaContextAdapter implements TopiaSchemaListener { + + @Override + public void preDropSchema(TopiaContextEvent event) { + } + + @Override + public void postDropSchema(TopiaContextEvent event) { + } + + @Override + public void preCreateSchema(TopiaContextEvent event) { + } + + @Override + public void postCreateSchema(TopiaContextEvent event) { + } + + @Override + public void preUpdateSchema(TopiaContextEvent event) { + } + + @Override + public void postUpdateSchema(TopiaContextEvent event) { + } + + @Override + public void preRestoreSchema(TopiaContextEvent event) { + } + + @Override + public void postRestoreSchema(TopiaContextEvent event) { + } +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaContextEvent.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextEvent.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaContextEvent.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaContextEvent.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,58 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +package org.nuiton.topia.persistence.event; + +import java.util.EventObject; + +import org.nuiton.topia.persistence.TopiaPersistenceContext; + +/** + * TODO-fdesbois-20100507 : Need javadoc. + * Used for Migration service. + * + * @author chatellier <chatellier@codelutin.com> + * @version $Id$ + */ +public class TopiaContextEvent extends EventObject { + + /** Version UID */ + private static final long serialVersionUID = 560256125962144181L; + + /** + * Constructor + * + * @param source + */ + public TopiaContextEvent(TopiaPersistenceContext source) { + super(source); + } + + @Override + public TopiaPersistenceContext getSource() { + return (TopiaPersistenceContext) source; + } + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntitiesEvent.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaEntitiesEvent.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntitiesEvent.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntitiesEvent.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,59 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +package org.nuiton.topia.persistence.event; + +import org.nuiton.topia.persistence.support.TopiaJpaSupport; +import org.nuiton.topia.persistence.TopiaEntity; + +import java.util.EventObject; +import java.util.List; + +/** + * TODO-fdesbois-20100507 : Need javadoc. + * + * @author jruchaud <jruchaud@codelutin.com> + * @version $Id$ + */ +public class TopiaEntitiesEvent<E extends TopiaEntity> extends EventObject { + + private static final long serialVersionUID = 1L; + + private List<E> entities; + + public TopiaEntitiesEvent(TopiaJpaSupport source, List<E> entities) { + super(source); + this.entities = entities; + } + + public List<E> getEntities() { + return entities; + } + + @Override + public TopiaJpaSupport getSource() { + return (TopiaJpaSupport) super.getSource(); + } +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntitiesVetoable.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaEntitiesVetoable.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntitiesVetoable.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntitiesVetoable.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,43 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +package org.nuiton.topia.persistence.event; + +import org.nuiton.topia.persistence.TopiaEntity; + +import java.util.EventListener; +import java.util.List; + +/** + * Permet de lancer des événements liés au récupération des données + * + * @author jruchaud <jruchaud@codelutin.com> + * @version $Id$ + */ +public interface TopiaEntitiesVetoable extends EventListener { + + <E extends TopiaEntity> List<E> load(TopiaEntitiesEvent<E> event); + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntityEvent.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaEntityEvent.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntityEvent.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntityEvent.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,66 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +package org.nuiton.topia.persistence.event; + +import org.nuiton.topia.persistence.TopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaEntity; + +import java.util.EventObject; + +/** + * TODO-fdesbois-20100507 : Need javadoc. + * + * @author jruchaud <jruchaud@codelutin.com> + * @version $Id$ + */ +public class TopiaEntityEvent extends EventObject { + + private static final long serialVersionUID = 1L; + + private TopiaEntity entity; + + private Object[] state; + + public TopiaEntityEvent(TopiaPersistenceContext source, TopiaEntity entity, Object[] state) { + super(source); + this.entity = entity; + this.state = state; + } + + public TopiaEntity getEntity() { + return entity; + } + + @Override + public TopiaPersistenceContext getSource() { + return (TopiaPersistenceContext) super.getSource(); + } + + public Object[] getState() { + return state; + } + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntityListener.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaEntityListener.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntityListener.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntityListener.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,47 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +package org.nuiton.topia.persistence.event; + +import java.util.EventListener; + +/** + * TODO-fdesbois-20100507 : Need javadoc. + * + * @author poussin <poussin@codelutin.com> + * @author tchemit <tchemit@codelutin.com> + * @version $Id$ + */ +public interface TopiaEntityListener extends EventListener { + + void create(TopiaEntityEvent event); + + void load(TopiaEntityEvent event); + + void update(TopiaEntityEvent event); + + void delete(TopiaEntityEvent event); + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntityVetoable.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaEntityVetoable.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntityVetoable.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaEntityVetoable.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,47 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +package org.nuiton.topia.persistence.event; + +import java.util.EventListener; + +/** + * TODO-fdesbois-20100507 : Need javadoc. + * + * @author jruchaud <jruchaud@codelutin.com> + * @author tchemit <tchemit@codelutin.com> + * @version $Id$ + */ +public interface TopiaEntityVetoable extends EventListener { + + void create(TopiaEntityEvent event); + + void load(TopiaEntityEvent event); + + void update(TopiaEntityEvent event); + + void delete(TopiaEntityEvent event); + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaSchemaListener.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaSchemaListener.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaSchemaListener.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaSchemaListener.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,102 @@ +package org.nuiton.topia.persistence.event; + +/* + * #%L + * ToPIA :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import java.util.EventListener; + +/** + * Listener for TopiaContext actions. + * <p/> + * Listener are notified for action such as : + * <ul> + * <li>createSchema</li> + * <li>updateSchema</li> + * <li>...</li> + * </ul> + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public interface TopiaSchemaListener extends EventListener { + + /** + * Called before createSchema call + * + * @param event event + */ + void preCreateSchema(TopiaContextEvent event); + + /** + * Called after createSchema call + * + * @param event event + */ + void postCreateSchema(TopiaContextEvent event); + + /** + * Called before updateSchema call + * + * @param event event + */ + void preUpdateSchema(TopiaContextEvent event); + + /** + * Called after updateSchema call + * + * @param event event + */ + void postUpdateSchema(TopiaContextEvent event); + + /** + * Called after updateSchema call + * + * @param event event + */ + void preRestoreSchema(TopiaContextEvent event); + + /** + * Called after updateSchema call + * + * @param event event + */ + void postRestoreSchema(TopiaContextEvent event); + + /** + * Called before dropSchema call + * + * @param event event + * @since 3.0 + */ + void preDropSchema(TopiaContextEvent event); + + /** + * Called after dropSchema call + * + * @param event event + * @since 3.0 + */ + void postDropSchema(TopiaContextEvent event); + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaTransactionEvent.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaTransactionEvent.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaTransactionEvent.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaTransactionEvent.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,107 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +package org.nuiton.topia.persistence.event; + +import org.apache.commons.collections.map.IdentityMap; +import org.nuiton.topia.persistence.TopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaEntity; + +import java.util.EventObject; +import java.util.Map; +import java.util.Set; + +/** + * Event fires for {@link TopiaTransactionListener}. + * + * @author poussin <poussin@codelutin.com> + * @version $Id$ + * @see TopiaTransactionListener + */ +public class TopiaTransactionEvent extends EventObject { + + private static final long serialVersionUID = 1L; + + private Map<TopiaEntity, EntityState> entities = new IdentityMap(); + + public TopiaTransactionEvent(TopiaPersistenceContext source) { + super(source); + } + + public TopiaTransactionEvent(TopiaPersistenceContext source, + Map<TopiaEntity, EntityState> entities) { + this(source); + this.entities.putAll(entities); + } + + public Set<TopiaEntity> getEntities() { + return entities.keySet(); + } + + public boolean isLoad(TopiaEntity entity) { + EntityState state = entities.get(entity); + return state != null && state.isLoad(); + } + + public boolean isRead(TopiaEntity entity) { + EntityState state = entities.get(entity); + return state != null && state.isRead(); + } + + public boolean isCreate(TopiaEntity entity) { + EntityState state = entities.get(entity); + return state != null && state.isCreate(); + } + + public boolean isUpdate(TopiaEntity entity) { + EntityState state = entities.get(entity); + return state != null && state.isUpdate(); + } + + public boolean isDelete(TopiaEntity entity) { + EntityState state = entities.get(entity); + return state != null && state.isDelete(); + } + + public boolean isModification(TopiaEntity entity) { + EntityState state = entities.get(entity); + return state != null + && (state.isCreate() || state.isUpdate() || state.isDelete()); + } + + @Override + public TopiaPersistenceContext getSource() { + return (TopiaPersistenceContext) super.getSource(); + } + + @Override + protected void finalize() throws Throwable { + super.finalize(); + if (entities != null) { + entities.clear(); + entities = null; + } + } +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaTransactionListener.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaTransactionListener.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaTransactionListener.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaTransactionListener.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,70 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +package org.nuiton.topia.persistence.event; + +import org.nuiton.topia.persistence.internal.support.TopiaFiresSupport; + +import java.util.EventListener; + +/** + * To listen transaction operations as commit and rollback. + * <p/> + * <b>Warning:</b> Must be attached to the current transaction. + * <p/> + * {@link TopiaContext} listens such listeners via {@code javaBeans} methods : + * <ul> + * <li>{@link TopiaContext#addTopiaTransactionListener(TopiaTransactionListener)}</li> + * <li>{@link TopiaContext#removeTopiaTransactionListener(TopiaTransactionListener)}</li> + * </ul> + * + * @author poussin <poussin@codelutin.com> + * @version $Id$ + * @see TopiaContext + * @see TopiaTransactionEvent + * @see TopiaFiresSupport#fireOnPostCommit(TopiaContextImplementor) + * @see TopiaFiresSupport#fireOnPostRollback(TopiaContextImplementor) + */ +public interface TopiaTransactionListener extends EventListener { + + /** + * Fired by {@link TopiaFiresSupport#fireOnPostCommit(TopiaContextImplementor)}. + * <p/> + * Says after a commit was performed on listened transaction. + * + * @param event the transaction event + */ + void commit(TopiaTransactionEvent event); + + /** + * Fired by {@link TopiaFiresSupport#fireOnPostRollback(TopiaContextImplementor)}. + * <p/> + * Says after a rollback was performed on listened transaction. + * + * @param event the transaction event + */ + void rollback(TopiaTransactionEvent event); + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaTransactionVetoable.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaTransactionVetoable.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaTransactionVetoable.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/TopiaTransactionVetoable.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,41 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +package org.nuiton.topia.persistence.event; + +import java.util.EventListener; + +/** + * TODO-fdesbois-20100507 : Need javadoc. + * + * @author jruchaud <jruchaud@codelutin.com> + * @author tchemit <tchemit@codelutin.com> + * @version $Id$ + */ +public interface TopiaTransactionVetoable extends EventListener { + + void beginTransaction(TopiaTransactionEvent event); + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/package-info.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/event/package-info.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/package-info.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/event/package-info.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,29 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ +/** + * Events used for topia services. + * TODO-fdesbois-20100507 : Need more javadoc. + */ +package org.nuiton.topia.persistence.event; \ No newline at end of file Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaApplicationContext.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaApplicationContext.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaApplicationContext.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,416 @@ +package org.nuiton.topia.persistence.internal; + +/* + * #%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 com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.HibernateException; +import org.hibernate.cfg.Configuration; +import org.hibernate.tool.hbm2ddl.SchemaExport; +import org.hibernate.tool.hbm2ddl.SchemaUpdate; +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaContextFactory; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaNotFoundException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; +import org.nuiton.topia.persistence.internal.support.TopiaServiceSupportImpl; +import org.nuiton.topia.persistence.event.TopiaEntitiesVetoable; +import org.nuiton.topia.persistence.event.TopiaEntityListener; +import org.nuiton.topia.persistence.event.TopiaEntityVetoable; +import org.nuiton.topia.persistence.event.TopiaSchemaListener; +import org.nuiton.topia.persistence.event.TopiaTransactionListener; +import org.nuiton.topia.persistence.event.TopiaTransactionVetoable; +import org.nuiton.topia.persistence.internal.support.TopiaFiresSupport; +import org.nuiton.topia.persistence.TopiaService; +import org.nuiton.topia.persistence.support.TopiaListenableSupport; +import org.nuiton.topia.persistence.support.TopiaServiceSupport; +import org.nuiton.topia.persistence.util.TopiaUtil; +import org.nuiton.topia.persistence.DefaultTopiaIdFactory; +import org.nuiton.topia.persistence.HibernateProvider; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaIdFactory; + +import java.beans.PropertyChangeListener; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.WeakHashMap; + +/** + * The application context is the main class in ToPIA usage. This class is a kind of equivalent of the RootTopiaContext. + * It contains only high level methods and new contexts creation (transaction begin, ...). This class has to be extended + * by the user, even if some default one could be automatically generated. + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public abstract class AbstractTopiaApplicationContext<K extends TopiaPersistenceContext> implements TopiaApplicationContext<K> { + + private static final Log log = LogFactory.getLog(AbstractTopiaApplicationContext.class); + + protected TopiaIdFactory topiaIdFactory; + + protected ImmutableMap<String, String> configuration; + + protected TopiaFiresSupport topiaFiresSupport = new TopiaFiresSupport(); + + protected TopiaServiceSupport topiaServiceSupport; + + protected HibernateProvider hibernateProvider; + + protected TopiaHibernateSessionRegistry sessionRegistry = new TopiaHibernateSessionRegistry(); + + protected boolean closed = false; + + protected Set<TopiaPersistenceContext> persistenceContexts = Collections.newSetFromMap( + new WeakHashMap<TopiaPersistenceContext, Boolean>()); + + public AbstractTopiaApplicationContext(Properties properties) { + // TODO arnaud 11/10/13 vérifier le comportement + this((Map) ImmutableMap.copyOf(properties)); + } + + public AbstractTopiaApplicationContext(Map<String, String> configuration) { + Map<String, String> configurationCopy = Maps.newHashMap(); + configurationCopy.putAll(configuration); + if ( ! configuration.containsKey(TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES)) { + configurationCopy.put(TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES, getImplementationClassesAsString()); + } + this.configuration = ImmutableMap.copyOf(configurationCopy); + this.topiaServiceSupport = new TopiaServiceSupportImpl(this); + // FIXME AThimel 11/10/13 This is not nice, need a 2-step init because of mutual dependency with hibernateProvider + ((TopiaServiceSupportImpl)this.topiaServiceSupport).init(); + } + + protected abstract Class<? extends TopiaEntity>[] getImplementationClasses(); + + protected String getImplementationClassesAsString() { + StringBuilder buffer = new StringBuilder(); + for (Class<? extends TopiaEntity> aClass : getImplementationClasses()) { + buffer.append(',').append(aClass.getName()); + } + return buffer.substring(1); + } + + protected void registerPersistenceContext(TopiaPersistenceContext persistenceContext) { + persistenceContexts.add(persistenceContext); + } + + // FIXME AThimel 25/11/13 I don't like it to be public, but necessary for services. Review it + public HibernateProvider getHibernateProvider() { + if (hibernateProvider == null) { + hibernateProvider = new HibernateProvider(configuration, topiaServiceSupport, sessionRegistry); + } + return hibernateProvider; + } + + protected TopiaListenableSupport getTopiaListenableSupport() { + return topiaFiresSupport; + } + + @Override + public ImmutableMap<String, String> getConfiguration() { + return configuration; + } + + protected TopiaIdFactory getTopiaIdFactory() { + if (topiaIdFactory == null) { + String topiaIdFactoryClassName = + getConfiguration().get(TopiaContextFactory.CONFIG_PERSISTENCE_TOPIA_ID_FACTORY_CLASS_NAME); + if (StringUtils.isEmpty(topiaIdFactoryClassName)) { + topiaIdFactory = new DefaultTopiaIdFactory(); + } else { + try { + Class topiaIdFactoryClass = Class.forName(topiaIdFactoryClassName); + Preconditions.checkState(TopiaIdFactory.class.isAssignableFrom(topiaIdFactoryClass), + topiaIdFactoryClassName + " is not a valid class name. The class must implements " + + TopiaIdFactory.class.getSimpleName()); + + topiaIdFactory = (TopiaIdFactory) topiaIdFactoryClass.newInstance(); + } catch (ClassNotFoundException e) { + throw new TopiaException("Unable to create user specified TopiaIdFactory", e); + } catch (InstantiationException e) { + throw new TopiaException("Unable to create user specified TopiaIdFactory", e); + } catch (IllegalAccessException e) { + throw new TopiaException("Unable to create user specified TopiaIdFactory", e); + } + } + + } + return topiaIdFactory; + } + + public TopiaHibernateSessionRegistry getSessionRegistry() { + return sessionRegistry; + } + + @Override + public void addTopiaEntityListener(TopiaEntityListener listener) { + topiaFiresSupport.addTopiaEntityListener(listener); + } + + @Override + public void addTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener) { + topiaFiresSupport.addTopiaEntityListener(entityClass, listener); + } + + @Override + public void removeTopiaEntityListener(TopiaEntityListener listener) { + topiaFiresSupport.removeTopiaEntityListener(listener); + } + + @Override + public void removeTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener) { + topiaFiresSupport.removeTopiaEntityListener(entityClass, listener); + } + + @Override + public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) { + topiaFiresSupport.addTopiaEntityVetoable(vetoable); + } + + @Override + public void addTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable) { + topiaFiresSupport.addTopiaEntityVetoable(entityClass, vetoable); + } + + @Override + public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) { + topiaFiresSupport.removeTopiaEntityVetoable(vetoable); + } + + @Override + public void removeTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable) { + topiaFiresSupport.removeTopiaEntityVetoable(entityClass, vetoable); + } + + @Override + public void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) { + topiaFiresSupport.addTopiaEntitiesVetoable(vetoable); + } + + @Override + public void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) { + topiaFiresSupport.removeTopiaEntitiesVetoable(vetoable); + } + + @Override + public void addTopiaTransactionListener(TopiaTransactionListener listener) { + topiaFiresSupport.addTopiaTransactionListener(listener); + } + + @Override + public void removeTopiaTransactionListener(TopiaTransactionListener listener) { + topiaFiresSupport.removeTopiaTransactionListener(listener); + } + + @Override + public void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable) { + topiaFiresSupport.addTopiaTransactionVetoable(vetoable); + } + + @Override + public void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable) { + topiaFiresSupport.removeTopiaTransactionVetoable(vetoable); + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener listener) { + topiaFiresSupport.addPropertyChangeListener(listener); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener listener) { + topiaFiresSupport.removePropertyChangeListener(listener); + } + + @Override + public void addTopiaSchemaListener(TopiaSchemaListener listener) { + topiaFiresSupport.addTopiaSchemaListener(listener); + } + + @Override + public void removeTopiaSchemaListener(TopiaSchemaListener listener) { + topiaFiresSupport.removeTopiaSchemaListener(listener); + } + + @Override + public <E extends TopiaService> boolean serviceEnabled(Class<E> interfaceService) { + return topiaServiceSupport.serviceEnabled(interfaceService); + } + + @Override + public <E extends TopiaService> E getService(Class<E> interfaceService) throws TopiaNotFoundException { + return topiaServiceSupport.getService(interfaceService); + } + + @Override + public Map<String, TopiaService> getServices() { + return topiaServiceSupport.getServices(); + } + + @Override + public List<Class<?>> getPersistenceClasses() { + return getHibernateProvider().getPersistentClasses(); + } + + @Override + public boolean isSchemaEmpty() { + Configuration configuration = getHibernateProvider().getHibernateConfiguration(); + boolean result = TopiaUtil.isSchemaEmpty(configuration); + return result; + } + + @Override + public boolean isTableExists(Class<?> clazz) { + Configuration configuration = getHibernateProvider().getHibernateConfiguration(); + boolean result = TopiaUtil.isSchemaExist(configuration, clazz.getName()); + return result; + } + + @Override + public String getSchemaName() { + // TODO AThimel 02/08/13 I absolutely don't know if it works + return getConfiguration().get(TopiaContextFactory.CONFIG_DEFAULT_SCHEMA); + } + + @Override + public void createSchema() { + try { + boolean showSchema = false; + if (log.isDebugEnabled()) { + showSchema = true; + } + // TODO brendan 11/10/13 reable event + // topiaFiresSupport.firePreCreateSchema(this); + new SchemaExport(getHibernateProvider().getHibernateConfiguration()).execute(showSchema, true, false, true); + // TODO brendan 11/10/13 reable event + // topiaFiresSupport.firePostCreateSchema(this); + } catch (HibernateException eee) { + throw new TopiaException( + String.format("Could not create schema for reason: %s", + eee.getMessage()), eee); + } + } + + @Override + public void showCreateSchema() { + try { + new SchemaExport(getHibernateProvider().getHibernateConfiguration()). + execute(true, false, false, true); + } catch (HibernateException eee) { + throw new TopiaException( + String.format("Could not show create schema for reason: %s", + eee.getMessage()), eee); + } + + } + + @Override + public void updateSchema() { + try { + boolean showSchema = false; + if (log.isDebugEnabled()) { + showSchema = true; + } + + // TODO brendan 11/10/13 reable event + // topiaFiresSupport.firePreUpdateSchema(this); + new SchemaUpdate(getHibernateProvider().getHibernateConfiguration()).execute(showSchema, + true); + // topiaFiresSupport.firePostUpdateSchema(this); + } catch (HibernateException eee) { + throw new TopiaException( + String.format("Could not update schema for reason: %s", + eee.getMessage()), eee); + } + } + + @Override + public void dropSchema() { + try { + boolean showSchema = false; + if (log.isDebugEnabled()) { + showSchema = true; + } + + // TODO brendan 11/10/13 reable event + // topiaFiresSupport.firePreDropSchema(this); + new SchemaExport(getHibernateProvider().getHibernateConfiguration()).execute(showSchema, true, true, false); +// topiaFiresSupport.firePostDropSchema(this); + } catch (HibernateException eee) { + throw new TopiaException( + String.format("Could not drop schema for reason: %s", + eee.getMessage()), eee); + } + } + + @Override + public void closeContext() throws TopiaException { + + // Throw exception if context is already closed + Preconditions.checkState(!closed, "Context was already closed"); + + // Iterate over the children PersistenceContexts and close them + for (TopiaPersistenceContext persistenceContext : persistenceContexts) { + if (persistenceContext == null) { + if (log.isWarnEnabled()) { + log.warn("null TopiaPersistenceContext found in #persistenceContexts"); + } + } else { + // Avoid to have exception from checkClosed method on child + try { + if (!persistenceContext.isClosed()) { + persistenceContext.closeContext(); + } + } catch (Exception eee) { + // Don't let any exception stop the application closing + if (log.isWarnEnabled()) { + log.warn("Unable to close TopiaPersistenceContext", eee); + } + } + } + } + + hibernateProvider.close(); + closed = true; + + if (log.isDebugEnabled()) { + log.debug("TopiaApplicationContext closed"); + } + } + + @Override + public boolean isClosed() { + return closed; + } + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaPersistenceContext.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaPersistenceContext.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaPersistenceContext.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,443 @@ +package org.nuiton.topia.persistence.internal; + +/* + * #%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 com.google.common.base.Preconditions; +import com.google.common.collect.Maps; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.FlushMode; +import org.hibernate.HibernateException; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.cfg.Configuration; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaReplicationDestination; +import org.nuiton.topia.persistence.internal.support.HibernateTopiaJpaSupport; +import org.nuiton.topia.persistence.internal.support.HibernateTopiaReplicationSupport; +import org.nuiton.topia.persistence.internal.support.HibernateTopiaSqlSupport; +import org.nuiton.topia.persistence.internal.support.TopiaFiresSupport; +import org.nuiton.topia.persistence.AbstractTopiaDao; +import org.nuiton.topia.persistence.HibernateProvider; +import org.nuiton.topia.persistence.TopiaDao; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaIdFactory; +import org.nuiton.topia.persistence.support.TopiaHibernateSupport; +import org.nuiton.topia.persistence.support.TopiaJpaSupport; +import org.nuiton.topia.persistence.support.TopiaListenableSupport; +import org.nuiton.topia.persistence.support.TopiaSqlSupport; + +import java.lang.reflect.InvocationTargetException; +import java.util.List; +import java.util.Map; + +/** + * Abstract implementation of the TopiaPersistenceContext. This class will be extended by a generated one in order to + * generate getXxxDao methods. + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public abstract class AbstractTopiaPersistenceContext implements TopiaPersistenceContext { + + private static final Log log = LogFactory.getLog(AbstractTopiaPersistenceContext.class); + + /** + * Already loaded DAO cache within this persistence context + */ + protected Map<Class<? extends TopiaEntity>, TopiaDao<? extends TopiaEntity>> daoCache = Maps.newConcurrentMap(); + + protected HibernateTopiaReplicationSupport hibernateTopiaReplicationSupport; + + // TODO AThimel 27/09/13 Javadoc + protected TopiaListenableSupport listenableSupport; + + /** + * Used to affect a new topiaId when create is called. + */ + protected TopiaIdFactory topiaIdFactory; + + /** + * The shared instance of TopiaHibernateSessionRegistry + */ + protected TopiaHibernateSessionRegistry sessionRegistry; + + // TODO AThimel 27/09/13 Javadoc + protected TopiaFiresSupport firesSupport; + + /** + * This subclass of TopiaHibernateSupport is made to be used only internally within this persistence context. This + * instance is created by the persistence context itself. + */ + protected InternalTopiaHibernateSupport hibernateSupport; + + /** + * This instance of TopiaJpaSupport is created by the persistence context itself. It is actually using the + * TopiaHibernateSupport instance. + */ + protected TopiaJpaSupport jpaSupport; + + /** + * This instance of TopiaSqlSupport is created by the persistence context itself. It is actually using the + * TopiaHibernateSupport instance. + */ + protected TopiaSqlSupport sqlSupport; + + /** + * Flog used to check if this persistence context is closed + */ + protected boolean closed = false; + + /** + * Creating a new TopiaPersistenceContext is equivalent to creating a new transaction + * + * @param hibernateProvider holds the Hibernate configuration and session factory + * @param listenableSupport the listenableSupport instance to use within this persistence context + * @param topiaIdFactory the TopiaIdFactory instance created according to the application's configuration + */ + public AbstractTopiaPersistenceContext(HibernateProvider hibernateProvider, + TopiaListenableSupport listenableSupport, + TopiaIdFactory topiaIdFactory, + TopiaHibernateSessionRegistry sessionRegistry) { + + this.listenableSupport = listenableSupport; + this.topiaIdFactory = topiaIdFactory; + this.sessionRegistry = sessionRegistry; + this.firesSupport = new TopiaFiresSupport(); + + // Hibernate support can be created using the given hibernateProvider + this.hibernateSupport = new InternalTopiaHibernateSupport(hibernateProvider); + + // Now starts the transaction, as this persistenceContext IS the TopiaTransaction + startTransaction(); + + // Create the different supports that may be needed by the DAOs + this.jpaSupport = new HibernateTopiaJpaSupport(hibernateSupport, firesSupport); + this.sqlSupport = new HibernateTopiaSqlSupport(hibernateSupport); + } + + protected TopiaFiresSupport getFiresSupport() { + return firesSupport; + } + + public TopiaHibernateSupport getHibernateSupport() { + return hibernateSupport; + } + + public TopiaSqlSupport getSqlSupport() { + return sqlSupport; + } + + @Override + public TopiaIdFactory getTopiaIdFactory() { + return topiaIdFactory; + } + + @Override + public TopiaFiresSupport getTopiaFiresSupport() { + return firesSupport; + } + + /** + * This subclass of TopiaHibernateSupport is made to be used only internally within this persistence context. This + * class only acts as an information container (as a structure does). + */ + protected class InternalTopiaHibernateSupport implements TopiaHibernateSupport { + + protected HibernateProvider hibernateProvider; + protected Session hibernateSession; + + protected InternalTopiaHibernateSupport(HibernateProvider hibernateProvider) { + this.hibernateProvider = hibernateProvider; + } + + public void setHibernateSession(Session hibernateSession) { + this.hibernateSession = hibernateSession; + } + + @Override + public Session getHibernateSession() { + Preconditions.checkState(hibernateSession != null, "Session is not yet initialized"); + return hibernateSession; + } + + @Override + public SessionFactory getHibernateFactory() { + return hibernateProvider.getSessionFactory(); + } + + @Override + public Configuration getHibernateConfiguration() { + return hibernateProvider.getHibernateConfiguration(); + } + } + + protected void startTransaction() throws TopiaException { + + SessionFactory factory = hibernateSupport.getHibernateFactory(); + Session result = factory.openSession(); + hibernateSupport.setHibernateSession(result); + + // new TopiaInterceptor(result)); + // on ne synchronise jamais les données avec la base tant que + // l'utilisateur n'a pas fait de commit du context + result.setFlushMode(FlushMode.MANUAL); + + // tchemit 2010-12-06 propagates the value of the flag +// result.useFlushMode = useFlushMode; + + sessionRegistry.register(result, this); + + // 20060926 poussin ajouter pour voir si ca regle les problemes de + // deadlock h2. Conclusion, il faut bien ouvrir une transaction + // maintenant, sinon lorsque l'on fait des acces a la base, une + // transaction par defaut est utilisé mais elle n'est jamais vraiment + // fermé ce qui pose des problemes de lock sur les tables. + try { + result.beginTransaction(); + } catch (Exception eee) { + + // on a pas pu ouvrir la transaction, on faut donc tout fermer + // et declancher une exception + try { + result.close(); + sessionRegistry.unregister(result); + } catch (HibernateException e1) { + if (log.isErrorEnabled()) { + log.error("Could not close hibernate session", e1); + } + } + + String message = String.format("An error occurs while asking a new transaction: %1$s", eee.getMessage()); + throw new TopiaException(message, eee); + } + + // fire event + getFiresSupport().fireOnBeginTransaction(this); + } + + protected void checkClosed() throws TopiaException { + if (closed) { + throw new TopiaException("This context is closed, it is not possible to use it anymore"); + } + } + + @Override + public <E extends TopiaEntity> E findByTopiaId(String topiaId) { + checkClosed(); + + Class<E> entityClass = getTopiaIdFactory().getClassName(topiaId); + TopiaDao<E> dao = getDao(entityClass); + E result = dao.findByTopiaId(topiaId); + return result; + } + + @Override + public void update(TopiaEntity entity) { + checkClosed(); + + String topiaId = entity.getTopiaId(); + Class<TopiaEntity> entityClass = getTopiaIdFactory().getClassName(topiaId); + TopiaDao<TopiaEntity> dao = getDao(entityClass); + dao.update(entity); + + } + + @Override + public <E extends TopiaEntity> TopiaDao<E> getDao(Class<E> entityClass) { + Preconditions.checkArgument(entityClass != null, "The method 'getDao' requires a non null 'entityClass' parameter"); + + SessionFactory hibernateFactory = hibernateSupport.getHibernateFactory(); + if (hibernateFactory.getClassMetadata(entityClass) == null && + hibernateFactory.getClassMetadata(entityClass.getName() + "Impl") == null && + hibernateFactory.getClassMetadata(entityClass.getName() + "Abstract") == null) { + + if (log.isInfoEnabled()) { + String format = "List of supported persistence classes: %s"; + String message = String.format(format, hibernateFactory.getAllClassMetadata().keySet()); + log.info(message); + } + String format = "The following entity type %s is not managed by this context, you probably forgot to declare it."; + String message = String.format(format, entityClass.getName()); + throw new TopiaException(message); + } + + TopiaDao<E> dao = (TopiaDao<E>) daoCache.get(entityClass); + if (dao == null) { + + // Looking for specialized DAO + // This DAO is supposed to exist, as created by generation + String daoClassName = entityClass.getName() + "TopiaDao"; + try { + Class<TopiaDao<E>> daoClass = (Class<TopiaDao<E>>) Class.forName(daoClassName); + dao = daoClass.getConstructor().newInstance(); + } catch (InstantiationException e) { + log.fatal("Unable to instantiate DAO class " + daoClassName, e); + throw new TopiaException("unable to instantiate DAO class " + daoClassName, e); + } catch (IllegalAccessException e) { + log.fatal("Unable to instantiate DAO class " + daoClassName, e); + throw new TopiaException("unable to instantiate DAO class " + daoClassName, e); + } catch (InvocationTargetException e) { + log.fatal("Unable to instantiate DAO class " + daoClassName, e); + throw new TopiaException("unable to instantiate DAO class " + daoClassName, e); + } catch (NoSuchMethodException e) { + log.fatal("Unable to instantiate DAO class " + daoClassName, e); + throw new TopiaException("unable to instantiate DAO class " + daoClassName, e); + } catch (ClassNotFoundException e) { + log.fatal("Unable to find DAO class " + daoClassName, e); + throw new TopiaException("unable to find DAO class " + daoClassName, e); + } + + if (dao instanceof AbstractTopiaDao) { + AbstractTopiaDao abstractTopiaDao = (AbstractTopiaDao) dao; + abstractTopiaDao.init(jpaSupport, sqlSupport, listenableSupport, topiaIdFactory, firesSupport, this); + } + + daoCache.put(entityClass, dao); + + } + + return dao; + } + + @Override + public <E extends TopiaEntity, D extends TopiaDao<E>> D getDao(Class<E> entityClass, Class<D> daoClass) { + TopiaDao<E> dao = getDao(entityClass); + D result = (D) dao; + return result; + } + + @Override + public void commit() { + checkClosed(); + + try { + + Session hibernateSession = hibernateSupport.getHibernateSession(); + + Transaction transaction = hibernateSession.getTransaction(); + hibernateSession.flush(); + transaction.commit(); + + getFiresSupport().fireOnPostCommit(this); +// TopiaContextImplementor parent = getParentContext(); +// if (parent != null) { +// parent.getFiresSupport().fireOnPostCommit(this); +// } + + hibernateSession.beginTransaction(); + + // it's seem necessary to change session after commit + // NON, NON, NON, il ne faut surtout pas le faire, ca pose plein de + // probleme + // hibernate = getHibernateFactory().openSession(); + // hibernate.setFlushMode(FlushMode.NEVER); + } catch (Exception eee) { + String message = String.format("An error occurred during commit operation: %1$s", eee.getMessage()); + throw new TopiaException(message, eee); + } + } + + @Override + public void rollback() { + checkClosed(); + try { + Session hibernateSession = hibernateSupport.getHibernateSession(); + + Transaction transaction = hibernateSession.getTransaction(); + hibernateSession.clear(); + transaction.rollback(); + hibernateSession.close(); + + sessionRegistry.unregister(hibernateSession); + + // it's very important to change the session after rollback + // otherwise there are many error during next Entity's modification + hibernateSession = hibernateSupport.getHibernateFactory().openSession(); + hibernateSupport.setHibernateSession(hibernateSession); + hibernateSession.setFlushMode(FlushMode.MANUAL); + + sessionRegistry.register(hibernateSession, this); + + hibernateSession.beginTransaction(); + + getFiresSupport().fireOnPostRollback(this); +// TopiaContextImplementor parent = getParentContext(); +// if (parent != null) { +// parent.getFiresSupport().fireOnPostRollback(this); +// } + + } catch (HibernateException eee) { + String message = String.format("An error occurred during rollback operation: %1$s", eee.getMessage()); + throw new TopiaException(message, eee); + } + } + + @Override + public void closeContext() { + checkClosed(); + closed = true; + + // Now close the current Hibernate session + Session hibernateSession = hibernateSupport.getHibernateSession(); + hibernateSession.close(); + + sessionRegistry.unregister(hibernateSession); + } + + @Override + public boolean isClosed() { + return closed; + } + + protected HibernateTopiaReplicationSupport getHibernateTopiaReplicationSupport() { + if (hibernateTopiaReplicationSupport == null) { + hibernateTopiaReplicationSupport = new HibernateTopiaReplicationSupport(hibernateSupport); + } + return hibernateTopiaReplicationSupport; + } + + @Override + public void replicate(TopiaEntity entity) { + getHibernateTopiaReplicationSupport().replicate(entity); + } + + @Override + public <T extends TopiaEntity> void replicateEntities(TopiaReplicationDestination topiaReplicationDestination, List<T> entities) throws IllegalArgumentException { + getHibernateTopiaReplicationSupport().replicateEntities(topiaReplicationDestination, entities); + } + + @Override + public <T extends TopiaEntity> void replicateEntity(TopiaReplicationDestination topiaReplicationDestination, T entity) throws IllegalArgumentException { + getHibernateTopiaReplicationSupport().replicateEntity(topiaReplicationDestination, entity); + } + + @Override + public void replicate(TopiaReplicationDestination topiaReplicationDestination, Object... entityAndCondition) throws IllegalArgumentException { + getHibernateTopiaReplicationSupport().replicate(topiaReplicationDestination, entityAndCondition); + } +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/TopiaConnectionProvider.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaConnectionProvider.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/TopiaConnectionProvider.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/TopiaConnectionProvider.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,361 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2011 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% + */ +package org.nuiton.topia.persistence.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.HibernateException; +import org.hibernate.cfg.Environment; +import org.hibernate.internal.util.ReflectHelper; +import org.hibernate.internal.util.config.ConfigurationHelper; +import org.hibernate.service.UnknownUnwrapTypeException; +import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator; +import org.hibernate.service.jdbc.connections.spi.ConnectionProvider; +import org.hibernate.service.spi.Configurable; +import org.hibernate.service.spi.Stoppable; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +/** + * Customized connection provider. + * <p/> + * This provider fix the following bug : + * http://nuiton.org/issues/show/561 + * <p/> + * To use this connection provider, add this property to topia configuration + * <p/> + * <pre> + * config.setProperty(Environment.CONNECTION_PROVIDER, TopiaConnectionProvider.class.getName()); + * </pre> + * <p/> + * or in a properties file : + * <p/> + * <pre> + * hibernate.connection.provider_class=org.nuiton.topia.persistence.internal.TopiaConnectionProvider + * </pre> + * + * @author tchemit <chemit@codelutin.com> + * @since 2.5.3 + */ +public class TopiaConnectionProvider implements ConnectionProvider, Configurable, Stoppable {//}, ServiceRegistryAwareService { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(TopiaConnectionProvider.class); + + private static final long serialVersionUID = -8190835231054317644L; + + /** + * JDBC url of connection. + * <p/> + * This is a mandatory hibernate configuration vi the property + * {@link Environment#URL}. + */ + protected String url; + + /** All grabbed connection properties */ + protected Properties connectionProps; + + /** + * Sql isolation level to use in connection. + * <p/> + * Can be configured by hibernate property {@link Environment#ISOLATION_LEVELS}. + * + * @see Connection#getTransactionIsolation() + */ + protected Integer isolation; + + /** + * auto commit connection state. + * <p/> + * Can be configured by hibernate property {@link Environment#AUTOCOMMIT}. + * + * @see Connection#getAutoCommit() + */ + protected boolean autocommit; + + /** + * Size of connection pool. + * <p/> + * By default use {@code 20}, can be specify by using the hibernate + * configuration property {@link Environment#POOL_SIZE}. + */ + protected int poolSize; + + private boolean stopped; + + /** Our pool of connections which are not closed and availables. */ + protected final List<Connection> pool; + +// protected ServiceRegistryImplementor serviceRegistry; + + public TopiaConnectionProvider() { + pool = new ArrayList<Connection>(); + } + + @Override + public void configure(Map configurationValues) throws HibernateException { + + poolSize = ConfigurationHelper.getInt(Environment.POOL_SIZE, configurationValues, 20); //default pool size 20 + if (log.isDebugEnabled()) { + log.debug("Connection pool size: " + poolSize); + } + + autocommit = ConfigurationHelper.getBoolean(Environment.AUTOCOMMIT, configurationValues); + if (log.isDebugEnabled()) { + log.debug("autocommit mode: " + autocommit); + } + + isolation = ConfigurationHelper.getInteger(Environment.ISOLATION, configurationValues); + if (isolation != null) { + if (log.isDebugEnabled()) { + log.debug("JDBC isolation level: " + + Environment.isolationLevelToString(isolation)); + } + } + + String driverClass = ConfigurationHelper.getString(Environment.DRIVER, configurationValues); + if (driverClass == null) { + + if (log.isWarnEnabled()) { + log.warn("no JDBC Driver class was specified by property " + + Environment.DRIVER); + } + } else { + try { + // trying via forName() first to be as close to DriverManager's semantics + Class.forName(driverClass); + } catch (ClassNotFoundException cnfe) { + try { + ReflectHelper.classForName(driverClass); + } catch (ClassNotFoundException e) { + String msg = "JDBC Driver class not found: " + driverClass; + log.error(msg, e); + throw new HibernateException(msg, e); + } + } + } + + url = (String) configurationValues.get(Environment.URL); + if (url == null) { + String msg = "JDBC URL was not specified by property " + Environment.URL; + if (log.isErrorEnabled()) { + log.error(msg); + } + throw new HibernateException(msg); + } + + connectionProps = + ConnectionProviderInitiator.getConnectionProperties(configurationValues); + + if (log.isDebugEnabled()) { + log.debug("using driver: " + driverClass + " at URL: " + url); + } + + // if debug level is enabled, then log the password, otherwise mask it + if (log.isTraceEnabled()) { + log.debug("connection properties: " + connectionProps); + } else if (log.isDebugEnabled()) { + log.debug("connection properties: " + + ConfigurationHelper.maskOut(connectionProps, "password")); + } + } + + @Override + public Connection getConnection() throws SQLException { + + Connection connection = null; + + synchronized (pool) { + + // try to use a connection from the pool (if any) + + while (!pool.isEmpty() && connection == null) { + int last = pool.size() - 1; + if (log.isTraceEnabled()) { + log.trace("using pooled JDBC connection, pool size: " + + last); + } + + connection = pool.remove(last); + if (connection.isClosed()) { + + // this connection is closed!, don't use it + connection = null; + + if (log.isDebugEnabled()) { + log.debug("Remove already closed connection from pool " + + connection); + } + } + } + } + + if (connection == null) { + + // the pool was empty, creates a new connection + + if (log.isDebugEnabled()) { + log.debug("opening new JDBC connection to " + url); + } + connection = DriverManager.getConnection(url, connectionProps); + } + + // configure connection + + if (isolation != null) { + connection.setTransactionIsolation(isolation); + } + if (connection.getAutoCommit() != autocommit) { + connection.setAutoCommit(autocommit); + } + + return connection; + } + + @Override + public void closeConnection(Connection conn) throws SQLException { + + // if connection is already closed, nothing has to be done + // we can't keep this connection (and can not be push in pool) + + if (conn.isClosed()) { + + if (log.isDebugEnabled()) { + log.debug("Connection [" + conn + + "] alreay closed!, will not use it any longer "); + } + return; + } + + // connection was not closed, can push it in the pool (if pool is not + // full) + + synchronized (pool) { + int currentSize = pool.size(); + if (currentSize < getPoolSize()) { + if (log.isTraceEnabled()) { + log.trace("returning connection to pool, pool size: " + + (currentSize + 1)); + } + pool.add(conn); + return; + } + } + + // pool was full, must release the connection which will be loose + + if (log.isDebugEnabled()) { + log.debug("closing JDBC connection"); + } + + conn.close(); + } + + @Override + protected void finalize() throws Throwable { + if (!stopped) { + stop(); + } + super.finalize(); + } + + @Override + public void stop() { + + if (log.isDebugEnabled()) { + log.debug("cleaning up connection pool: " + url); + } + + for (Connection connection : pool) { + try { + connection.close(); + } catch (SQLException sqle) { + if (log.isWarnEnabled()) { + log.warn("problem closing pooled connection", sqle); + } + } + } + pool.clear(); + stopped = true; + } + + @Override + public boolean supportsAggressiveRelease() { + return false; + } + + public String getUrl() { + return url; + } + + public Properties getConnectionProps() { + return connectionProps; + } + + public Integer getIsolation() { + return isolation; + } + + public List<Connection> getPool() { + return pool; + } + + public int getPoolSize() { + return poolSize; + } + + public boolean isAutocommit() { + return autocommit; + } + +// @Override +// public void injectServices(ServiceRegistryImplementor serviceRegistry) { +// this.serviceRegistry = serviceRegistry; +// } + + @Override + public boolean isUnwrappableAs(Class unwrapType) { + return ConnectionProvider.class.equals(unwrapType) || + getClass().isAssignableFrom(unwrapType); + } + + @Override + @SuppressWarnings({"unchecked"}) + public <T> T unwrap(Class<T> unwrapType) { + if (ConnectionProvider.class.equals(unwrapType) || + getClass().isAssignableFrom(unwrapType)) { + return (T) this; + } else { + throw new UnknownUnwrapTypeException(unwrapType); + } + } +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/TopiaHibernateSessionRegistry.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaHibernateSessionRegistry.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/TopiaHibernateSessionRegistry.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/TopiaHibernateSessionRegistry.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,95 @@ +package org.nuiton.topia.persistence.internal; + +/* + * #%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.lang.ref.WeakReference; +import java.util.WeakHashMap; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Session; +import org.nuiton.topia.persistence.TopiaPersistenceContext; + +import com.google.common.base.Preconditions; + +/** + * Class used to keep an association between an Hibernate Session and a TopiaPersistenceContext + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public class TopiaHibernateSessionRegistry { + + private static final Log log = LogFactory.getLog(TopiaHibernateSessionRegistry.class); + + protected WeakHashMap<Session, WeakReference<TopiaPersistenceContext>> registry = + new WeakHashMap<Session, WeakReference<TopiaPersistenceContext>>(); + + /** + * Register the Session<->TopiaPersistenceContext couple + * + * @param session the currently used Session + * @param persistenceContext the current TopiaPersistenceContext using this Session + */ + public void register(Session session, TopiaPersistenceContext persistenceContext) { + if (log.isDebugEnabled()) { + log.debug("New Session<->TopiaPersistenceContext registration"); + } + Preconditions.checkArgument(session != null); + Preconditions.checkArgument(persistenceContext != null); + WeakReference<TopiaPersistenceContext> reference = new WeakReference<TopiaPersistenceContext>(persistenceContext); + registry.put(session, reference); + } + + /** + * Look for the TopiaPersistenceContext based on the given Hibernate session + * + * @param session the Hibernate Session to use + * @return the TopiaPersistenceContext using this Session, or null if not found + */ + public TopiaPersistenceContext getPersistenceContext(Session session) { + Preconditions.checkArgument(session != null); + WeakReference<TopiaPersistenceContext> reference = registry.get(session); + TopiaPersistenceContext result = reference.get(); + if (log.isDebugEnabled()) { + log.debug("Get TopiaPersistenceContext from Session : " + (result == null ? "Not found" : "HIT !")); + } + return result; + } + + /** + * Removes the Session<->TopiaPersistenceContext association from the registry + * + * @param session the Hibernate Session to remove + */ + public void unregister(Session session) { + Preconditions.checkArgument(session != null); + WeakReference<TopiaPersistenceContext> reference = registry.remove(session); + if (log.isDebugEnabled()) { + log.debug("Remove TopiaPersistenceContext from Session : " + (reference != null)); + } + } + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/HibernateTopiaJpaSupport.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/HibernateTopiaJpaSupport.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/HibernateTopiaJpaSupport.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,224 @@ +package org.nuiton.topia.persistence.internal.support; + +/* + * #%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.Collection; +import java.util.List; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.FlushMode; +import org.hibernate.HibernateException; +import org.hibernate.Query; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.support.TopiaHibernateSupport; +import org.nuiton.topia.persistence.support.TopiaJpaSupport; + +/** + * This class is the Hibernate implementation of TopiaJpaSupport. It realizes the bridge between the JPA specification + * and the technical choice made for its implementation : Hibernate. + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public class HibernateTopiaJpaSupport implements TopiaJpaSupport { + + private static final Log log = LogFactory.getLog(HibernateTopiaJpaSupport.class); + + // TODO AThimel 27/09/13 Javadoc + protected TopiaHibernateSupport hibernateSupport; + + // TODO AThimel 27/09/13 Javadoc + protected TopiaFiresSupport firesSupport; + + /** + * 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, Map<String, Object>)} or {@link #find(String, int, int, Map<String, 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; + + public HibernateTopiaJpaSupport(TopiaHibernateSupport hibernateSupport, TopiaFiresSupport firesSupport) { + this.hibernateSupport = hibernateSupport; + this.firesSupport = firesSupport; + } + + public TopiaHibernateSupport getHibernateSupport() { + return hibernateSupport; + } + + @Override + public void setUseFlushMode(boolean useFlushMode) { + this.useFlushMode = useFlushMode; + } + + protected Query prepareQuery(String jpaql, Map<String, Object> parameters) { + Query query = hibernateSupport.getHibernateSession().createQuery(jpaql); + for (Map.Entry<String, Object> entry : parameters.entrySet()) { + String name = entry.getKey(); + Object value = entry.getValue(); + if (value.getClass().isArray()) { + query.setParameterList(name, (Object[]) value); + } else if (value instanceof Collection<?>) { + query.setParameterList(name, (Collection<?>) value); + } else { + query.setParameter(name, value); + } + } + // tchemit 2010-11-30 reproduce the same behaviour than before with the dao legacy + if (useFlushMode) { + query.setFlushMode(FlushMode.AUTO); + } + return query; + } + + @Override + public <T> List<T> findAll(String jpaql, Map<String, Object> parameters) { + try { + Query query = prepareQuery(jpaql, parameters); + + List result = query.list(); + result = firesSupport.fireEntitiesLoad(this, result); + return result; + } catch (HibernateException eee) { + throw new TopiaException(String.format("An error occurs during query operation: %1$s : %2$s", + jpaql, eee.getMessage()), eee); + } catch (RuntimeException e) { + if (log.isWarnEnabled()) { + log.warn("exception occurred for query \n" + jpaql + "\nwith parameters " + parameters); + } + throw e; + } + } + + @Override + public <T> T findUnique(String jpaql, Map<String, Object> parameters) { + + // Execute query, and ask for up to 2 results only + List<T> results = find(jpaql, 0, 1, parameters); + + // 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", jpaql); + throw new TopiaException(message); + } + + // otherwise return the first one, or null + T result = null; + if (!results.isEmpty()) { + result = results.get(0); + } + return result; + } + + @Override + public <T> List<T> find(String jpaql, int startIndex, int endIndex, Map<String, Object> parameters) { + try { + Query query = prepareQuery(jpaql, parameters); + + // Set bounds + query.setFirstResult(startIndex); + query.setMaxResults(endIndex - startIndex + 1); + + List result = query.list(); + result = firesSupport.fireEntitiesLoad(this, result); + return result; + } catch (HibernateException eee) { + throw new TopiaException(String.format("An error occurs during query operation: %1$s : %2$s", + jpaql, eee.getMessage()), eee); + } catch (RuntimeException e) { + if (log.isWarnEnabled()) { + log.warn("exception occurred for query \n" + jpaql + "\nwith parameters " + parameters); + } + throw e; + } + } + + @Override + public int execute(String jpaql, Map<String, Object> parameters) { + try { + Query query = prepareQuery(jpaql, parameters); + + int result = query.executeUpdate(); + return result; + } catch (HibernateException eee) { + throw new TopiaException(String.format("An error occurs during execute operation: %1$s : %2$s", + jpaql, eee.getMessage()), eee); + } catch (RuntimeException e) { + if (log.isWarnEnabled()) { + log.warn("exception occurred for query \n" + jpaql + "\nwith parameters " + parameters); + } + throw e; + } + } + + @Override + public void save(Object object) { + try { + hibernateSupport.getHibernateSession().save(object); + } catch (HibernateException eee) { + throw new TopiaException("Unable to 'save' instance", eee); + } + } + + @Override + public void update(Object object) { + try { + hibernateSupport.getHibernateSession().update(object); + } catch (HibernateException eee) { + throw new TopiaException("Unable to 'update' instance", eee); + } + } + + @Override + public void saveOrUpdate(Object object) { + try { + hibernateSupport.getHibernateSession().saveOrUpdate(object); + } catch (HibernateException eee) { + throw new TopiaException("Unable to 'saveOrUpdate' instance", eee); + } + } + + @Override + public void delete(Object object) { + try { + hibernateSupport.getHibernateSession().delete(object); + } catch (HibernateException eee) { + throw new TopiaException("Unable to 'delete' instance", eee); + } + } + +} // HibernateTopiaJpaSupport Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/HibernateTopiaReplicationSupport.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaReplicationSupport.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/HibernateTopiaReplicationSupport.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/HibernateTopiaReplicationSupport.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,184 @@ +package org.nuiton.topia.persistence.internal.support; + +/* + * #%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.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.HibernateException; +import org.hibernate.ReplicationMode; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaReplicationDestination; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.support.TopiaHibernateSupport; +import org.nuiton.topia.persistence.support.TopiaReplicationSupport; + +import java.util.List; +import java.util.Map; + +public class HibernateTopiaReplicationSupport implements TopiaReplicationSupport, TopiaReplicationDestination { + + private static final Log log = LogFactory.getLog(HibernateTopiaReplicationSupport.class); + + protected TopiaHibernateSupport topiaHibernateSupport; + + public HibernateTopiaReplicationSupport(TopiaHibernateSupport topiaHibernateSupport) { + this.topiaHibernateSupport = topiaHibernateSupport; + } + + @Override + public void replicate( + TopiaReplicationDestination topiaReplicationDestination, + Object... entityAndCondition) throws IllegalArgumentException { + + String[] queries = buildQueries(entityAndCondition); + + try { + for (String query : queries) { + if (log.isDebugEnabled()) { + log.debug("acquire entities " + query); + } + // acquire data to replicate + List<?> entities = topiaHibernateSupport.getHibernateSession().createQuery(query).list(); + replicate0(topiaReplicationDestination, entities.toArray()); + if (log.isDebugEnabled()) { + log.debug("replication of entities " + query + + " was sucessfully done."); + } + } + } catch (HibernateException eee) { + throw new TopiaException(String.format("An error occurs while a replication operation: %s", + eee.getMessage()), eee); + } + } + + @Override + public <T extends TopiaEntity> void replicateEntity( + TopiaReplicationDestination topiaReplicationDestination, + T entity) throws IllegalArgumentException { + + replicate0(topiaReplicationDestination, entity); + + } + + @Override + public <T extends TopiaEntity> void replicateEntities( + TopiaReplicationDestination topiaReplicationDestination, + List<T> entities) throws IllegalArgumentException { + + replicate0(topiaReplicationDestination, entities.toArray()); + + } + + protected void replicate0(TopiaReplicationDestination topiaReplicationDestination, + Object... entities) { + try { + for (Object entity : entities) { + // dettach entity to source session, to make possible copy of + // collection without a hibernate exception (list opened in + // two session...) + topiaHibernateSupport.getHibernateSession().evict(entity); + topiaReplicationDestination.replicate((TopiaEntity) entity); + } + + } catch (HibernateException eee) { + throw new TopiaException(String.format("An error occurs while a replication operation : %s", + eee.getMessage()), eee); + } + } + + /** + * Build the list of queries from the given parameter + * <code>entityAndCondition</code>. + * <p/> + * If no parameter is given, then build the queries for all entities is db, + * with no condition. + * + * @param entityAndCondition the list of tuples (Class,String) + * @return the list of queries. + * @throws TopiaException if any pb of db while getting entities + * classes. + * @throws IllegalArgumentException if any pb with the given parameter + * (mainly ClassCastException). + */ + protected String[] buildQueries(Object... entityAndCondition) + throws TopiaException, IllegalArgumentException { + Class<?> entityClass; + String condition; + + // si entityAndcondition est vide alors il faut le remplir + // avec toutes les entités du mapping (class, null) + if (entityAndCondition.length == 0) { + Map<?, ?> classMetadata = topiaHibernateSupport.getHibernateFactory().getAllClassMetadata(); + entityAndCondition = new Object[classMetadata.size() * 2]; + int i = 0; + for (Object className : classMetadata.keySet()) { + try { + entityAndCondition[i++] = Class.forName((String) className); + } catch (ClassNotFoundException e) { + // should never happen! + throw new TopiaException( + "class cast exception for entity " + className); + } + entityAndCondition[i++] = null; + + } + } + + // prepare queries to perform beofre opening any transaction + if (entityAndCondition.length % 2 != 0) { + throw new IllegalArgumentException( + "entityAndCondition must be a couple of (Class, String)"); + } + String queries[] = new String[entityAndCondition.length / 2]; + for (int i = 0; i < entityAndCondition.length; ) { + try { + entityClass = (Class<?>) entityAndCondition[i++]; + condition = (String) entityAndCondition[i++]; + String query = "from " + entityClass.getName(); + if (condition != null && !condition.isEmpty()) { + query += " where " + condition; + } + queries[(i - 1) / 2] = query; + } catch (ClassCastException e) { + if (i % 2 == 0) { + throw new IllegalArgumentException( + "Others arguement must be String not " + + entityAndCondition[i - 1], e); + } else { + throw new IllegalArgumentException( + "Others arguement must be Class not " + + entityAndCondition[i - 1], e); + } + } + } + return queries; + } + + @Override + public void replicate(TopiaEntity entity) { + topiaHibernateSupport.getHibernateSession().replicate(entity, ReplicationMode.EXCEPTION); + } + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/HibernateTopiaSqlSupport.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaSqlSupport.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/HibernateTopiaSqlSupport.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/HibernateTopiaSqlSupport.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,173 @@ +package org.nuiton.topia.persistence.internal.support; + +/* + * #%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.HibernateException; +import org.hibernate.jdbc.Work; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.support.TopiaHibernateSupport; +import org.nuiton.topia.persistence.support.TopiaSqlQuery; +import org.nuiton.topia.persistence.support.TopiaSqlSupport; +import org.nuiton.topia.persistence.support.TopiaSqlWork; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Arnaud Thimel <thimel@codelutin.com> + */ +public class HibernateTopiaSqlSupport implements TopiaSqlSupport { + + protected TopiaHibernateSupport hibernateSupport; + + public HibernateTopiaSqlSupport(TopiaHibernateSupport hibernateSupport) { + this.hibernateSupport = hibernateSupport; + } + + public static class HibernateSqlWork implements Work { + + protected final String script; + + public HibernateSqlWork(String script) { + this.script = script; + } + + @Override + public void execute(Connection connection) throws SQLException { + PreparedStatement sta = connection.prepareStatement(script); + try { + sta.execute(); + } finally { + sta.close(); + } + } + } + + public static class HibernateTopiaSqlWork implements Work { + + protected final TopiaSqlWork work; + + public HibernateTopiaSqlWork(TopiaSqlWork work) { + this.work = work; + } + + @Override + public void execute(Connection connection) throws SQLException { + work.execute(connection); + } + } + + public static class HibernateTopiaSqlQueryWork<O> implements Work { + + protected final TopiaSqlQuery<O> query; + + protected final boolean multipleResult; + + protected final List<O> result = new ArrayList<O>(); + + public HibernateTopiaSqlQueryWork(TopiaSqlQuery<O> query, boolean multipleResult) { + this.query = query; + this.multipleResult = multipleResult; + } + + @Override + public void execute(Connection connection) throws SQLException { + + PreparedStatement ps = query.prepareQuery(connection); + try { + ResultSet set = ps.executeQuery(); + + query.afterExecuteQuery(set); + + if (set.next()) { + O singleResult = query.prepareResult(set); + if (singleResult != null) { + result.add(singleResult); + } + if (multipleResult) { + while (set.next()) { + singleResult = query.prepareResult(set); + if (singleResult != null) { + result.add(singleResult); + } + } + } + } + + } catch (Exception e) { + throw new TopiaException("Could not execute query", e); + } finally { + ps.close(); + } + } + + public List<O> getResult() { + return result; + } + } + + @Override + public void executeSql(String sqlScript) { + HibernateSqlWork work = new HibernateSqlWork(sqlScript); + try { + hibernateSupport.getHibernateSession().doWork(work); + } catch (HibernateException e) { + throw new TopiaException("Could not execute sql code", e); + } + } + + @Override + public void doSqlWork(TopiaSqlWork sqlWork) { + HibernateTopiaSqlWork work = new HibernateTopiaSqlWork(sqlWork); + try { + hibernateSupport.getHibernateSession().doWork(work); + } catch (HibernateException e) { + throw new TopiaException("Could not execute sql code", e); + } + } + + @Override + public <O> O findSingleResult(final TopiaSqlQuery<O> query) throws TopiaException { + + HibernateTopiaSqlQueryWork<O> work = new HibernateTopiaSqlQueryWork<O>(query, false); + hibernateSupport.getHibernateSession().doWork(work); + final List<O> result = work.getResult(); + return result.isEmpty() ? null : result.get(0); + } + + @Override + public <O> List<O> findMultipleResult(final TopiaSqlQuery<O> query) throws TopiaException { + + HibernateTopiaSqlQueryWork<O> work = new HibernateTopiaSqlQueryWork<O>(query, true); + hibernateSupport.getHibernateSession().doWork(work); + final List<O> result = work.getResult(); + return result; + } + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaFiresSupport.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaFiresSupport.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaFiresSupport.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,823 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +package org.nuiton.topia.persistence.internal.support; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.beans.VetoableChangeSupport; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.collections.map.IdentityMap; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.support.TopiaJpaSupport; +import org.nuiton.topia.persistence.support.TopiaListenableSupport; +import org.nuiton.topia.persistence.TopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaVetoException; +import org.nuiton.topia.persistence.event.TopiaContextEvent; +import org.nuiton.topia.persistence.event.TopiaEntitiesEvent; +import org.nuiton.topia.persistence.event.TopiaEntitiesVetoable; +import org.nuiton.topia.persistence.event.TopiaEntityEvent; +import org.nuiton.topia.persistence.event.TopiaEntityListener; +import org.nuiton.topia.persistence.event.TopiaEntityVetoable; +import org.nuiton.topia.persistence.event.TopiaSchemaListener; +import org.nuiton.topia.persistence.event.TopiaTransactionEvent; +import org.nuiton.topia.persistence.event.TopiaTransactionListener; +import org.nuiton.topia.persistence.event.TopiaTransactionVetoable; +import org.nuiton.topia.persistence.event.EntityState; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.util.CategorisedListenerSet; +import org.nuiton.util.ListenerSet; + +/** + * TODO-fdesbois-20100507 : Need translation of javadoc. + * <p/> + * Contient l'ensemble de la partie listener et vetoable c'est à dire la + * gestion, les fires, ... + * + * @author jruchaud <jruchaud@codelutin.com> + * @version $Id$ + */ +public class TopiaFiresSupport implements TopiaListenableSupport { + + private static final Log log = LogFactory.getLog(TopiaFiresSupport.class); + + /** used to fire read event */ + final static Object NO_CHANGE = new Object(); + + /** used to collect entity modification during transaction */ + protected Map<TopiaEntity, EntityState> transactionEntities = new IdentityMap(); + + protected Set<PropertyChangeListener> propertyChangeListeners = new HashSet<PropertyChangeListener>(); + + /* Pour la transaction */ + protected ListenerSet<TopiaTransactionListener> transactionListeners = new ListenerSet<TopiaTransactionListener>(); + + protected ListenerSet<TopiaTransactionVetoable> transactionVetoables = new ListenerSet<TopiaTransactionVetoable>(); + + /* Pour les entités */ + protected CategorisedListenerSet<TopiaEntityListener> entityListeners = new CategorisedListenerSet<TopiaEntityListener>(); + + protected CategorisedListenerSet<TopiaEntityVetoable> entityVetoables = new CategorisedListenerSet<TopiaEntityVetoable>(); + + /* Pour les listes d'entités */ + protected ListenerSet<TopiaEntitiesVetoable> entitiesVetoables = new ListenerSet<TopiaEntitiesVetoable>(); + + /* Pour les actions du topia context */ + protected ListenerSet<TopiaSchemaListener> topiaSchemaListeners = new ListenerSet<TopiaSchemaListener>(); + + /** + * used to register objects loaded during transaction. + * + * @param entity the loaded entity + */ + public void warnOnLoadEntity(TopiaEntity entity) { + if (log.isDebugEnabled()) { + log.debug("warnOnReadEntity"); + } + EntityState state = transactionEntities.get(entity); + if (state == null) { + state = new EntityState(); + transactionEntities.put(entity, state); + } + state.addLoad(); + } + + /** + * used to register objects created during transaction. + * + * @param entity the created entity + */ + public void warnOnCreateEntity(TopiaEntity entity) { + if (log.isDebugEnabled()) { + log.debug("warnOnCreateEntity"); + } + EntityState state = transactionEntities.get(entity); + if (state == null) { + state = new EntityState(); + transactionEntities.put(entity, state); + } + state.addCreate(); + } + + /** + * used to register objects loaded during transaction. + * + * @param entity the read entity + */ + public void warnOnReadEntity(TopiaEntity entity) { + if (log.isDebugEnabled()) { + log.debug("warnOnReadEntity"); + } + EntityState state = transactionEntities.get(entity); + if (state == null) { + state = new EntityState(); + transactionEntities.put(entity, state); + } + state.addRead(); + } + + /** + * used to register objects modified during transaction. + * + * @param entity the updated entity + */ + public void warnOnUpdateEntity(TopiaEntity entity) { + if (log.isDebugEnabled()) { + log.debug("warnOnUpdateEntity"); + } + + EntityState state = transactionEntities.get(entity); + if (state == null) { + state = new EntityState(); + transactionEntities.put(entity, state); + } + state.addUpdate(); + } + + /** + * used to register objects deleted during transaction. + * + * @param entity the deleted entity + */ + public void warnOnDeleteEntity(TopiaEntity entity) { + if (log.isDebugEnabled()) { + log.debug("warnOnDeleteEntity"); + } + EntityState state = transactionEntities.get(entity); + if (state == null) { + state = new EntityState(); + transactionEntities.put(entity, state); + } + state.addDelete(); + } + + /* Fires sur les transactions */ + + public void fireOnBeginTransaction(TopiaPersistenceContext context) { + if (log.isDebugEnabled()) { + log.debug("fireOnBeginTransaction"); + } + TopiaTransactionEvent e = new TopiaTransactionEvent(context); + for (TopiaTransactionVetoable listener : transactionVetoables) { + try { + listener.beginTransaction(e); + } catch (Exception eee) { + throw new TopiaVetoException(eee); + } + } + } + + public void fireOnPostCommit(TopiaPersistenceContext context) { + if (log.isDebugEnabled()) { + log.debug("fireOnPostCommit"); + } + TopiaTransactionEvent e = new TopiaTransactionEvent(context, transactionEntities); + for (TopiaTransactionListener listener : transactionListeners) { + try { + listener.commit(e); + } catch (Exception eee) { + if (log.isErrorEnabled()) { + log.error("Can't fireOnPostCommit", eee); + } + } + } + transactionEntities.clear(); + } + + public void fireOnPostRollback(TopiaPersistenceContext context) { + if (log.isDebugEnabled()) { + log.debug("fireOnPostRollback"); + } + TopiaTransactionEvent e = new TopiaTransactionEvent(context, transactionEntities); + for (TopiaTransactionListener listener : transactionListeners) { + try { + listener.rollback(e); + } catch (Exception eee) { + if (log.isErrorEnabled()) { + log.error("Can't fireOnPostRollback", eee); + } + } + } + transactionEntities.clear(); + } + + /* Fires sur les entités */ + + public void fireOnPreCreate(TopiaPersistenceContext context, + TopiaEntity entity, Object[] state) { + if (log.isDebugEnabled()) { + log.debug("fireOnPreCreate"); + } + TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state); + for (Iterator<TopiaEntityVetoable> l = entityVetoables.iterator(entity.getClass()); l.hasNext();) { + try { + l.next().create(event); + } catch (Exception eee) { + throw new TopiaVetoException(eee); + } + } + } + + public void fireOnPostCreate(TopiaPersistenceContext context, + TopiaEntity entity, Object[] state) { + if (log.isDebugEnabled()) { + log.debug("fireOnPostCreate"); + } + warnOnCreateEntity(entity); + TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state); + for (Iterator<TopiaEntityListener> l = entityListeners.iterator(entity.getClass()); l.hasNext();) { + try { + l.next().create(event); + } catch (Exception eee) { + if (log.isErrorEnabled()) { + log.error("Can't fireOnPostCreate for entity: " + entity, eee); + } + } + } + } + + public void fireOnPreLoad(TopiaPersistenceContext context, + TopiaEntity entity, Object[] state) { + if (log.isDebugEnabled()) { + log.debug("fireOnPreLoad"); + } + TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state); + for (Iterator<TopiaEntityVetoable> l = entityVetoables.iterator(entity .getClass()); l.hasNext();) { + try { + l.next().load(event); + } catch (Exception eee) { + throw new TopiaVetoException(eee); + } + } + } + + public void fireOnPostLoad(TopiaPersistenceContext context, + TopiaEntity entity, Object[] state) { + if (log.isDebugEnabled()) { + log.debug("fireOnPostLoad"); + } + warnOnLoadEntity(entity); + TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state); + for (Iterator<TopiaEntityListener> l = entityListeners.iterator(entity.getClass()); l.hasNext();) { + try { + l.next().load(event); + } catch (Exception eee) { + if (log.isErrorEnabled()) { + log.error("Can't fireOnPostLoad for entity: " + entity, eee); + } + } + } + } + + public void fireOnPreUpdate(TopiaPersistenceContext context, + TopiaEntity entity, Object[] state) { + if (log.isDebugEnabled()) { + log.debug("fireOnPreUpdate"); + } + TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state); + for (Iterator<TopiaEntityVetoable> l = entityVetoables.iterator(entity.getClass()); l.hasNext();) { + try { + l.next().update(event); + } catch (Exception eee) { + throw new TopiaVetoException(eee); + } + } + } + + public void fireOnPostUpdate(TopiaPersistenceContext context, + TopiaEntity entity, Object[] state) { + if (log.isDebugEnabled()) { + log.debug("fireOnPostUpdate"); + } + warnOnUpdateEntity(entity); + TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state); + for (Iterator<TopiaEntityListener> l = entityListeners.iterator(entity.getClass()); l.hasNext();) { + try { + l.next().update(event); + } catch (Exception eee) { + if (log.isErrorEnabled()) { + log.error("Can't fireOnPostUpdate for entity: " + entity, eee); + } + } + } + } + + public void fireOnPreDelete(TopiaPersistenceContext context, + TopiaEntity entity, Object[] state) { + if (log.isDebugEnabled()) { + log.debug("fireOnPreDelete"); + } + TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state); + for (Iterator<TopiaEntityVetoable> l = entityVetoables.iterator(entity.getClass()); l.hasNext();) { + try { + l.next().delete(event); + } catch (Exception eee) { + throw new TopiaVetoException(eee); + } + } + } + + public void fireOnPostDelete(TopiaPersistenceContext context, + TopiaEntity entity, Object[] state) { + if (log.isDebugEnabled()) { + log.debug("fireOnPostDelete"); + } + warnOnDeleteEntity(entity); + TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state); + for (Iterator<TopiaEntityListener> l = entityListeners.iterator(entity.getClass()); l.hasNext();) { + try { + l.next().delete(event); + } catch (Exception eee) { + if (log.isErrorEnabled()) { + log.error("Can't fireOnPostDelete for entity: " + entity, eee); + } + } + } + } + + /* Fires sur les propriétés */ + + public void fireOnPreRead(VetoableChangeSupport vetoables, + TopiaEntity entity, + String propertyName, + Object value) { + + if (log.isDebugEnabled()) { + log.debug("fireOnPreRead"); + } + try { + vetoables.fireVetoableChange(propertyName, value, NO_CHANGE); + } catch (Exception eee) { + throw new TopiaVetoException(eee); + } + } + + public void fireOnPostRead(PropertyChangeSupport listeners, + TopiaEntity entity, String propertyName, + Object value) { + + if (log.isDebugEnabled()) { + log.debug("fireOnPostRead"); + } + warnOnReadEntity(entity); + try { + listeners.firePropertyChange(propertyName, value, NO_CHANGE); + } catch (Exception eee) { + if (log.isErrorEnabled()) { + log.error("Can't fireOnPostRead", eee); + } + } + + } + + public void fireOnPostRead(PropertyChangeSupport listeners, + TopiaEntity entity, + String propertyName, + int index, + Object value) { + + if (log.isDebugEnabled()) { + log.debug("fireOnPostRead"); + } + warnOnReadEntity(entity); + try { + listeners.fireIndexedPropertyChange(propertyName, index, value, NO_CHANGE); + } catch (Exception eee) { + if (log.isErrorEnabled()) { + log.error("Can't fireOnPostRead", eee); + } + } + + } + + public void fireOnPreWrite(VetoableChangeSupport vetoables, + TopiaEntity entity, + String propertyName, + Object oldValue, + Object newValue) { + + if (log.isDebugEnabled()) { + log.debug("fireOnPreWrite"); + } + try { + vetoables.fireVetoableChange(propertyName, oldValue, newValue); + } catch (Exception eee) { + throw new TopiaVetoException(eee); + } + } + + public void fireOnPostWrite(PropertyChangeSupport listeners, + TopiaEntity entity, + String propertyName, + Object oldValue, + Object newValue) { + + if (log.isDebugEnabled()) { + log.debug("fireOnPostWrite"); + } + warnOnUpdateEntity(entity); + if (propertyChangeListeners.size() > 0) { + PropertyChangeEvent e = new PropertyChangeEvent(entity, propertyName, oldValue, newValue); + for (PropertyChangeListener l : propertyChangeListeners) { + try { + l.propertyChange(e); + } catch (Exception eee) { + if (log.isErrorEnabled()) { + log.error("Can't fire property change for: " + propertyName, eee); + } + } + } + } + try { + listeners.firePropertyChange(propertyName, oldValue, newValue); + } catch (Exception eee) { + if (log.isErrorEnabled()) { + log.error("Can't fireOnPostWrite: " + propertyName, eee); + } + } + } + + public void fireOnPostWrite(PropertyChangeSupport listeners, + TopiaEntity entity, + String propertyName, + int index, + Object oldValue, + Object newValue) { + + if (log.isDebugEnabled()) { + log.debug("fireOnPostWrite"); + } + warnOnUpdateEntity(entity); + try { + listeners.fireIndexedPropertyChange(propertyName, index, oldValue, newValue); + } catch (Exception eee) { + if (log.isErrorEnabled()) { + log.error("Can't fireOnPostWrite", eee); + } + } + } + + /** + * Notify topia context listeners for create schema pre operation + * + * @param context topia context + */ + public void firePreCreateSchema(TopiaPersistenceContext context) { + if (log.isDebugEnabled()) { + log.debug("firePreCreateSchema"); + } + TopiaContextEvent event = new TopiaContextEvent(context); + for (TopiaSchemaListener topiaSchemaListener : topiaSchemaListeners) { + try { + topiaSchemaListener.preCreateSchema(event); + } catch (Exception eee) { + throw new TopiaVetoException(eee); + } + } + } + + /** + * Notify topia context listeners for create schema post operation + * + * @param context topia context + */ + public void firePostCreateSchema(TopiaPersistenceContext context) { + if (log.isDebugEnabled()) { + log.debug("firePostCreateSchema"); + } + TopiaContextEvent event = new TopiaContextEvent(context); + for (TopiaSchemaListener topiaSchemaListener : topiaSchemaListeners) { + try { + topiaSchemaListener.postCreateSchema(event); + } catch (Exception eee) { + throw new TopiaVetoException(eee); + } + } + } + + /** + * Notify topia context listeners for create schema pre operation + * + * @param context topia context + */ + public void firePreUpdateSchema(TopiaPersistenceContext context) { + if (log.isDebugEnabled()) { + log.debug("firePostCreateSchema"); + } + TopiaContextEvent event = new TopiaContextEvent(context); + for (TopiaSchemaListener topiaSchemaListener : topiaSchemaListeners) { + try { + topiaSchemaListener.preUpdateSchema(event); + } catch (Exception eee) { + throw new TopiaVetoException(eee); + } + } + } + + /** + * Notify topia context listeners for create schema post operation + * + * @param context topia context + */ + public void firePostUpdateSchema(TopiaPersistenceContext context) { + if (log.isDebugEnabled()) { + log.debug("firePostCreateSchema"); + } + TopiaContextEvent event = new TopiaContextEvent(context); + for (TopiaSchemaListener topiaSchemaListener : topiaSchemaListeners) { + try { + topiaSchemaListener.postUpdateSchema(event); + } catch (Exception eee) { + throw new TopiaVetoException(eee); + } + } + } + + /** + * Notify topia context listeners for schema restore pre operation + * + * @param context topia context + */ + public void firePreRestoreSchema(TopiaPersistenceContext context) { + if (log.isDebugEnabled()) { + log.debug("firePreRestoreSchema"); + } + TopiaContextEvent event = new TopiaContextEvent(context); + for (TopiaSchemaListener topiaSchemaListener : topiaSchemaListeners) { + try { + topiaSchemaListener.preRestoreSchema(event); + } catch (Exception eee) { + throw new TopiaVetoException(eee); + } + } + } + + /** + * Notify topia context listeners for schema restore post operation + * + * @param context topia context + */ + public void firePostRestoreSchema(TopiaPersistenceContext context) { + if (log.isDebugEnabled()) { + log.debug("firePostRestoreSchema"); + } + TopiaContextEvent event = new TopiaContextEvent(context); + for (TopiaSchemaListener topiaSchemaListener : topiaSchemaListeners) { + try { + topiaSchemaListener.postRestoreSchema(event); + } catch (Exception eee) { + throw new TopiaVetoException(eee); + } + } + } + + /** + * Notify topia context listeners for drop schema pre operation + * + * @param context topia context + * @since 3.0 + */ + public void firePreDropSchema(TopiaPersistenceContext context) { + if (log.isDebugEnabled()) { + log.debug("firePreDropSchema"); + } + TopiaContextEvent event = new TopiaContextEvent(context); + for (TopiaSchemaListener topiaSchemaListener : topiaSchemaListeners) { + try { + topiaSchemaListener.preDropSchema(event); + } catch (Exception eee) { + throw new TopiaVetoException(eee); + } + } + } + + /** + * Notify topia context listeners for drop schema post operation + * + * @param context topia context + * @since 3.0 + */ + public void firePostDropSchema(TopiaPersistenceContext context) { + if (log.isDebugEnabled()) { + log.debug("firePostDropSchema"); + } + TopiaContextEvent event = new TopiaContextEvent(context); + for (TopiaSchemaListener topiaSchemaListener : topiaSchemaListeners) { + try { + topiaSchemaListener.postDropSchema(event); + } catch (Exception eee) { + throw new TopiaVetoException(eee); + } + } + } + + + /** + * Notify entities listeners for load operation + * + * @param <E> type of entities + * @param context context used + * @param entities entities loaded + * @return the list of entities loaded + */ + public <E extends TopiaEntity> List<E> fireEntitiesLoad( + TopiaJpaSupport context, List<E> entities) { + if (log.isDebugEnabled()) { + log.debug("fireEntitiesLoad"); + } + + List<E> result = entities; + for (TopiaEntitiesVetoable entitiesVetoable : entitiesVetoables) { + try { + //FIXME tchemit 20100513 Why instanciate n events? if necessary MUST add a comment + TopiaEntitiesEvent<E> event = new TopiaEntitiesEvent<E>(context, result); + result = entitiesVetoable.load(event); + } catch (Exception eee) { + throw new TopiaVetoException(eee); + } + } + return result; + } + + /* Getters */ + + public CategorisedListenerSet<TopiaEntityListener> getEntityListeners() { + return entityListeners; + } + + public CategorisedListenerSet<TopiaEntityVetoable> getEntityVetoables() { + return entityVetoables; + } + + public ListenerSet<TopiaTransactionListener> getTransactionListeners() { + return transactionListeners; + } + + public ListenerSet<TopiaTransactionVetoable> getTransactionVetoable() { + return transactionVetoables; + } + + public ListenerSet<TopiaSchemaListener> getTopiaSchemaListeners() { + return topiaSchemaListeners; + } + + public ListenerSet<TopiaEntitiesVetoable> getTopiaEntitiesVetoable() { + return entitiesVetoables; + } + + /* Adders */ + + public void addTopiaEntityListener(TopiaEntityListener listener) { + addTopiaEntityListener(TopiaEntity.class, listener); + } + + public void addTopiaEntityListener( + Class<? extends TopiaEntity> entityClass, + TopiaEntityListener listener) { + if (listener == null) { + throw new NullPointerException("listener can not be null."); + } + entityListeners.add(entityClass, listener); + } + + public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) { + addTopiaEntityVetoable(TopiaEntity.class, vetoable); + } + + public void addTopiaEntityVetoable( + Class<? extends TopiaEntity> entityClass, + TopiaEntityVetoable vetoable) { + if (vetoable == null) { + throw new NullPointerException("listener can not be null."); + } + entityVetoables.add(entityClass, vetoable); + } + + public void addTopiaTransactionListener(TopiaTransactionListener listener) { + if (listener == null) { + throw new NullPointerException("listener can not be null."); + } + transactionListeners.add(listener); + } + + public void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable) { + if (vetoable== null) { + throw new NullPointerException("listener can not be null."); + } + transactionVetoables.add(vetoable); + } + + public void addPropertyChangeListener(PropertyChangeListener listener) { + if (listener == null) { + throw new NullPointerException("listener can not be null."); + } + propertyChangeListeners.add(listener); + } + + public void addTopiaSchemaListener(TopiaSchemaListener listener) { + if (listener == null) { + throw new NullPointerException("listener can not be null."); + } + topiaSchemaListeners.add(listener); + } + + public void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) { + if (vetoable == null) { + throw new NullPointerException("listener can not be null."); + } + entitiesVetoables.add(vetoable); + } + + /* Removers */ + + public void removeTopiaEntityListener(TopiaEntityListener listener) { + removeTopiaEntityListener(TopiaEntity.class, listener); + } + + public void removeTopiaEntityListener( + Class<? extends TopiaEntity> entityClass, + TopiaEntityListener listener) { + if (listener == null) { + throw new NullPointerException("listener can not be null."); + } + entityListeners.remove(entityClass, listener); + } + + public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) { + removeTopiaEntityVetoable(TopiaEntity.class, vetoable); + } + + public void removeTopiaEntityVetoable( + Class<? extends TopiaEntity> entityClass, + TopiaEntityVetoable vetoable) { + if (vetoable == null) { + throw new NullPointerException("listener can not be null."); + } + entityVetoables.remove(entityClass, vetoable); + } + + public void removeTopiaTransactionListener(TopiaTransactionListener listener) { + if (listener == null) { + throw new NullPointerException("listener can not be null."); + } + transactionListeners.remove(listener); + } + + public void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable) { + if (vetoable == null) { + throw new NullPointerException("listener can not be null."); + } + transactionVetoables.remove(vetoable); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + if (listener == null) { + throw new NullPointerException("listener can not be null."); + } + propertyChangeListeners.remove(listener); + } + + public void removeTopiaSchemaListener(TopiaSchemaListener listener) { + if (listener == null) { + throw new NullPointerException("listener can not be null."); + } + topiaSchemaListeners.remove(listener); + } + + public void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) { + if (vetoable == null) { + throw new NullPointerException("listener can not be null."); + } + entitiesVetoables.remove(vetoable); + } + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaHibernateEventListener.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaHibernateEventListener.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaHibernateEventListener.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,247 @@ +package org.nuiton.topia.persistence.internal.support; + +/* + * #%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.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.HibernateException; +import org.hibernate.event.spi.AbstractEvent; +import org.hibernate.event.spi.EventSource; +import org.hibernate.event.spi.PostDeleteEvent; +import org.hibernate.event.spi.PostDeleteEventListener; +import org.hibernate.event.spi.PostInsertEvent; +import org.hibernate.event.spi.PostInsertEventListener; +import org.hibernate.event.spi.PostLoadEvent; +import org.hibernate.event.spi.PostLoadEventListener; +import org.hibernate.event.spi.PostUpdateEvent; +import org.hibernate.event.spi.PostUpdateEventListener; +import org.hibernate.event.spi.PreDeleteEvent; +import org.hibernate.event.spi.PreDeleteEventListener; +import org.hibernate.event.spi.PreInsertEvent; +import org.hibernate.event.spi.PreInsertEventListener; +import org.hibernate.event.spi.PreLoadEvent; +import org.hibernate.event.spi.PreLoadEventListener; +import org.hibernate.event.spi.PreUpdateEvent; +import org.hibernate.event.spi.PreUpdateEventListener; +import org.hibernate.event.spi.SaveOrUpdateEvent; +import org.hibernate.event.spi.SaveOrUpdateEventListener; +import org.nuiton.topia.persistence.TopiaDaoSupplier; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.internal.TopiaHibernateSessionRegistry; +import org.nuiton.topia.persistence.TopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaEntityContextable; + +import com.google.common.base.Preconditions; + +/** + * @author Arnaud Thimel <thimel@codelutin.com> + */ +public class TopiaHibernateEventListener implements PreInsertEventListener, PostInsertEventListener, + PreLoadEventListener, PostLoadEventListener, PreUpdateEventListener, PostUpdateEventListener, + PreDeleteEventListener, PostDeleteEventListener, SaveOrUpdateEventListener { + + private static final Log log = LogFactory.getLog(TopiaHibernateEventListener.class); + + private static final long serialVersionUID = -9206039888626756924L; + + protected TopiaHibernateSessionRegistry registry; + + public TopiaHibernateEventListener(TopiaHibernateSessionRegistry registry) { + Preconditions.checkArgument(registry != null); + this.registry = registry; + } + + /** + * Look for the TopiaPersistenceContext based on the given Hibernate session + * + * @param event the Hibernate event that contains the Session to use + * @return the TopiaPersistenceContext using this Session, or null if not found + */ + protected TopiaPersistenceContext getContext(AbstractEvent event) { + EventSource session = event.getSession(); + TopiaPersistenceContext result = registry.getPersistenceContext(session); + return result; + } + + private void attachContext(Object entity, + TopiaDaoSupplier daoSupplier) { + if (entity instanceof TopiaEntityContextable) { + TopiaEntityContextable topiaEntityContextable = (TopiaEntityContextable) entity; + if (topiaEntityContextable.getTopiaDAOSupplier() == null) { + try { + topiaEntityContextable.setTopiaDAOSupplier(daoSupplier); + } catch (TopiaException eee) { + if (log.isWarnEnabled()) { + log.warn("Impossible d'initialiser le TopiaContext" + + " sur cette entité : " + topiaEntityContextable, + eee); + } + } + } + } + } + + /* Création */ + + @Override + public boolean onPreInsert(PreInsertEvent event) { + TopiaPersistenceContext context = getContext(event); + if (context != null && event.getEntity() instanceof TopiaEntity) { + TopiaEntity entity = (TopiaEntity) event.getEntity(); + + context.getTopiaFiresSupport().fireOnPreCreate(context, entity, event.getState()); + + // when using composition, hibernate will persist entities by him self + // entity must have an id in this case. + if (StringUtils.isBlank(entity.getTopiaId())) { + if (log.isDebugEnabled()) { + log.debug("Adding topia id on entity " + entity.getClass().getSimpleName()); + } + } + } + + return false; + } + + @Override + public void onPostInsert(PostInsertEvent event) { + TopiaPersistenceContext context = getContext(event); + if (context != null && event.getEntity() instanceof TopiaEntity) { + TopiaEntity entity = (TopiaEntity) event.getEntity(); + context.getTopiaFiresSupport().fireOnPostCreate(context, entity, event.getState()); + } + } + +// @Override +// public boolean requiresPostCommitHanding(EntityPersister persister) { +// // TODO AThimel 17/12/13 I don't know what to return +// return false; +// } + + /* Chargement */ + + @Override + public void onPreLoad(PreLoadEvent event) { + TopiaPersistenceContext context = getContext(event); + if (context != null && event.getEntity() instanceof TopiaEntity) { + // try { + TopiaEntity entity = (TopiaEntity) event.getEntity(); + context.getTopiaFiresSupport().fireOnPreLoad(context, entity, event.getState()); + //TODO (thimel 20071213) On commente pour le moment @see(TopiaDAOHibernate#filterElements) + // } catch (TopiaVetoException tve) { + // //On ne fait pas de remontee d'exception + // vers Hibernate pour le preLoad, on va agir au niveau du DAO + // } + } + } + + @Override + public void onPostLoad(PostLoadEvent event) { + TopiaPersistenceContext context = getContext(event); + if (context != null && event.getEntity() instanceof TopiaEntity) { + attachContext(event.getEntity(), context); + TopiaEntity entity = (TopiaEntity) event.getEntity(); + context.getTopiaFiresSupport().fireOnPostLoad(context, entity, new Object[]{}); + } + } + + /* Modification */ + + @Override + public boolean onPreUpdate(PreUpdateEvent event) { + TopiaPersistenceContext context = getContext(event); + if (context != null && event.getEntity() instanceof TopiaEntity) { + TopiaEntity entity = (TopiaEntity) event.getEntity(); + context.getTopiaFiresSupport().fireOnPreUpdate(context, entity, event.getOldState()); + } + return false; + } + + @Override + public void onPostUpdate(PostUpdateEvent event) { + TopiaPersistenceContext context = getContext(event); + if (context != null && event.getEntity() instanceof TopiaEntity) { + TopiaEntity entity = (TopiaEntity) event.getEntity(); + context.getTopiaFiresSupport().fireOnPostUpdate(context, entity, event.getState()); + } + // FIXME indexation + // if (!(entity instanceof NotIndexable) && context.isIndexEnabled()) { + // context.getIndexEnginImplementor().recordForIndexation(id, event.getState()); + // } + } + + /* Suppression */ + + @Override + public boolean onPreDelete(PreDeleteEvent event) { + TopiaPersistenceContext context = getContext(event); + if (context != null && event.getEntity() instanceof TopiaEntity) { + TopiaEntity entity = (TopiaEntity) event.getEntity(); + context.getTopiaFiresSupport().fireOnPreDelete(context, entity, event.getDeletedState()); + } + return false; + } + + @Override + public void onPostDelete(PostDeleteEvent event) { + TopiaPersistenceContext context = getContext(event); + if (context != null && event.getEntity() instanceof TopiaEntity) { + TopiaEntity entity = (TopiaEntity) event.getEntity(); + context.getTopiaFiresSupport().fireOnPostDelete(context, entity, event.getDeletedState()); + } +// FIXME indexation +// if (!(entity instanceof NotIndexable) && context.isIndexEnabled()) { +// context.getIndexEnginImplementor().recordForIndexation(id, null); +// } + } + + @Override + public void onSaveOrUpdate(SaveOrUpdateEvent event) throws HibernateException { + try { + // this event is called when hibernate try to persist entities using cascade (save) + TopiaPersistenceContext context = getContext(event); + // warning, event.getEntity() return null here :( + + if (event.getObject() instanceof TopiaEntity) { + TopiaEntity entity = (TopiaEntity) event.getObject(); + + if (StringUtils.isBlank(entity.getTopiaId())) { + if (log.isDebugEnabled()) { + log.debug("Adding topiaId into entity " + entity.getClass()); + } + // FIXME echatellier 20130713 : hack to find interface for current entity class + // #newTopiaId only accept interface + Class entityInterface = Class.forName(event.getEntityName().replace("Impl", "")); + String topiaId = context.getTopiaIdFactory().newTopiaId(entityInterface, entity); + entity.setTopiaId(topiaId); + } + } + } catch (ClassNotFoundException ex) { + throw new HibernateException("Can't set id", ex); + } + } +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaServiceSupportImpl.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupportImpl.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaServiceSupportImpl.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaServiceSupportImpl.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,179 @@ +package org.nuiton.topia.persistence.internal.support; + +/* + * #%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.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.TopiaNotFoundException; +import org.nuiton.topia.persistence.TopiaService; + +import com.google.common.collect.ImmutableMap; +import org.nuiton.topia.persistence.internal.AbstractTopiaApplicationContext; +import org.nuiton.topia.persistence.support.TopiaServiceSupport; + +/** + * FIXME AThimel 11/10/13 All this life-cycle has to be reviewed + * + * @author Arnaud Thimel <thimel@codelutin.com> + */ +public class TopiaServiceSupportImpl implements TopiaServiceSupport { + + private static final Log log = LogFactory.getLog(TopiaServiceSupportImpl.class); + + protected ImmutableMap<String, TopiaService> services; + protected AbstractTopiaApplicationContext applicationContext; + + public TopiaServiceSupportImpl(AbstractTopiaApplicationContext applicationContext) { + this.applicationContext = applicationContext; + this.services = loadServices(applicationContext.getConfiguration()); + } + + public void init() { + preInitServices(this.services); + applicationContext.getHibernateProvider().getHibernateConfiguration(); // force mapping loading + postInitServices(this.services); + } + + protected void preInitServices(Map<String, TopiaService> services) { + for (TopiaService service : services.values()) { + if (!service.preInit(applicationContext)) { + log.warn(String.format("The service named '%1$s' could not be post-initialized (service not activated)", + service.getServiceName())); + } + } + } + + protected void postInitServices(Map<String, TopiaService> services) { + for (TopiaService service : services.values()) { + if (!service.postInit(applicationContext)) { + log.warn(String.format("The service named '%1$s' could not be pre-initialized (service not activated)", + service.getServiceName())); + } + } + } + + /** + * Retrieve service name using SERVICE_NAME static field on service + * interface. + * + * @param interfaceService class of the service + * @param <E> type of the service that extends {@link + * TopiaService} + * @return the service name + * @throws IllegalAccessException if field SERVICE_NAME can't be accessed + * @throws NoSuchFieldException if no field SERVICE_NAME is defined + */ + protected <E extends TopiaService> String getServiceName( + Class<E> interfaceService) + throws IllegalAccessException, NoSuchFieldException { + Field f = interfaceService.getField("SERVICE_NAME"); + String name = (String) f.get(null); + return name; + } + + protected String getProperExceptionMessage(Throwable eee) { + return eee.getClass().getSimpleName() + " : " + eee.getMessage(); + } + + protected ImmutableMap<String, TopiaService> loadServices(ImmutableMap<String, String> configuration) { + Map<String, TopiaService> result = new HashMap<String, TopiaService>(); + // recherche des services present dans la config + for (String key : configuration.keySet()) { + if (key.matches("^topia\\.service\\.\\w+$")) { + String serviceClass = configuration.get(key); + try { + Class<?> forName = Class.forName(serviceClass); + Object newInstance = forName.getConstructor().newInstance(); + TopiaService service = (TopiaService) newInstance; + if (key.equals("topia.service." + service.getServiceName())) { + result.put(service.getServiceName(), service); + log.info(String.format("Service '%1$s' loaded (implementation %2$s)", + key, serviceClass)); + } else { + log.warn(String.format("The service with key '%1$s' has a different name '%2$s'! (service not activated)", + key, service.getServiceName())); + } + } catch (Throwable eee) { + String message = + String.format("The service %1$s of type %2$s was not found.", + key, serviceClass); + if (log.isDebugEnabled()) { + log.debug(message, eee); + } else if (log.isErrorEnabled()) { + log.error(message); + } + } + } + } + return ImmutableMap.copyOf(result); + } + + + @Override + public <E extends TopiaService> boolean serviceEnabled(Class<E> interfaceService) { + boolean result = false; + try { + String name = getServiceName(interfaceService); + result = getServices().containsKey(name); + } catch (Exception eee) { + String format = "The service named '%1$s' could not be found for following reason: %2$s"; + String message = String.format(format, interfaceService, getProperExceptionMessage(eee)); + if (log.isDebugEnabled()) { + log.debug(message, eee); + } else if (log.isWarnEnabled()) { + log.warn(message); + } + } + return result; + } + + @Override + public <E extends TopiaService> E getService(Class<E> interfaceService) throws TopiaNotFoundException { + E result; + try { + String name = getServiceName(interfaceService); + result = (E) getServices().get(name); + } catch (Exception eee) { + String format = "Could not retreave service %1$s for following reason: %2$s"; + String message = String.format(format, interfaceService, getProperExceptionMessage(eee)); + throw new TopiaNotFoundException(message, eee); + } + if (result == null) { + String message = String.format("The service %1$s was not found.", interfaceService); + throw new TopiaNotFoundException(message); + } + return result; + } + + @Override + public Map<String, TopiaService> getServices() { + return services; + } + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/Collector.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Collector.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/Collector.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/Collector.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,275 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +package org.nuiton.topia.persistence.legacy; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.DepthEntityVisitor; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaEntityEnum; +import org.nuiton.topia.persistence.util.TopiaEntityHelper; + +import java.util.ArrayDeque; +import java.util.Collection; +import java.util.Deque; + +/** + * Un objet qui permet de parcourir des entites (via un + * {@link CollectorVisitor}) et de collecter des donnees pendant le parcours. + * <p/> + * La classe a un type qui est le type de retour de la methode + * {@link #detect(TopiaEntity...)}. + * <p/> + * On peut donc très facilement en faire un collecteur de donnees. + * + * @author tchemit <chemit@codelutin.com> + * @param <R> les donnes a retourner + * @since 2.2.0 + */ +public abstract class Collector<R> { + + private static final Log log = LogFactory.getLog(Collector.class); + + /** le visiteur utiliser pour trouver les types */ + protected CollectorVisitor visitor; + + /** la liste des contracts des entites connues. */ + protected TopiaEntityEnum[] contracts; + + public Collector(CollectorVisitor visitor, TopiaEntityEnum[] contracts) { + this.visitor = visitor == null ? new CollectorVisitor() : visitor; + this.visitor.setCollector(this); + this.contracts = contracts; + } + + public Collector(TopiaEntityEnum[] contracts) { + this(null, contracts); + } + + protected void clear() { + visitor.clear(); + } + + protected boolean onStarting(TopiaEntity e) { + return true; + } + + protected void onStarted(TopiaEntity e, boolean enter) { + } + + protected boolean onVisiting(TopiaEntity e, String name, Class<?> type, + Object value) { + return true; + } + + protected void onVisited(TopiaEntity e, String name, Class<?> type, + Object value, boolean enter) { + } + + protected boolean onVisiting(TopiaEntity e, String name, + Class<?> collectionType, + Class<?> type, Object value) { + return true; + } + + protected void onVisited(TopiaEntity e, String name, + Class<?> collectionType, + Class<?> type, Object value, boolean enter) { + } + + protected boolean onVisiting(TopiaEntity e, String name, + Class<?> collectionType, + Class<?> type, int index, Object value) { + return true; + } + + protected void onVisited(TopiaEntity e, String name, + Class<?> collectionType, + Class<?> type, + int index, Object value, boolean enter) { + } + + protected boolean onEnding(TopiaEntity e) { + return true; + } + + protected void onEnded(TopiaEntity e, boolean enter) { + } + + protected void beforeAll(CollectorVisitor visitor, + TopiaEntity... entities) { + } + + protected void before(CollectorVisitor visitor, TopiaEntity entity) { + if (log.isDebugEnabled()) { + log.debug("Will detect "+entity.getTopiaId()); + } + } + + protected void after(CollectorVisitor visitor, TopiaEntity entity) { + } + + protected abstract R afterAll(CollectorVisitor visitor, + TopiaEntity... entities); + + public R detect(TopiaEntity... entities) throws TopiaException { + + try { + beforeAll(visitor, entities); + + for (TopiaEntity e : entities) { + before(visitor, e); + e.accept(visitor); + after(visitor, e); + } + + R result = afterAll(visitor, entities); + + return result; + } finally { + clear(); + } + } + + public static class CollectorVisitor extends DepthEntityVisitor { + + /** la pile des entites en cours de parcours */ + protected Deque<TopiaEntity> stack = new ArrayDeque<TopiaEntity>(); + + Collector<?> collector; + + protected void setCollector(Collector<?> collector) { + this.collector = collector; + } + + protected Deque<TopiaEntity> getStack() { + return stack; + } + + protected Collection<TopiaEntity> getAlreadyExplored() { + return alreadyExplored; + } + + @Override + public void start(TopiaEntity e) { + // on ajoute l'objet courant dans la pile + stack.offerLast(e); + boolean canContinue = collector.onStarting(e); + if (canContinue) { + super.start(e); + } + collector.onStarted(e, canContinue); + } + + @Override + public void end(TopiaEntity e) { + boolean canContinue = collector.onEnding(e); + if (canContinue) { + super.end(e); + } + stack.removeLast(); + // on retire l'objet courant de la pile + collector.onEnded(e, canContinue); + } + + @Override + public void visit(TopiaEntity e, String name, Class<?> type, + Object value) { + boolean canContinue = collector.onVisiting(e, name, type, value); + if (canContinue) { + super.visit(e, name, type, value); + } + collector.onVisited(e, name, type, value, canContinue); + } + + @Override + public void visit(TopiaEntity e, String name, Class<?> collectionType, + Class<?> type, Object value) { + boolean canContinue = + collector.onVisiting(e, name, collectionType, type, value); + if (canContinue) { + super.visit(e, name, collectionType, type, value); + } + collector.onVisited(e, name, collectionType, type, value, + canContinue); + } + + @Override + public void visit(TopiaEntity e, String name, Class<?> collectionType, + Class<?> type, int index, Object value) { + boolean canContinue = + collector.onVisiting(e, name, collectionType, type, index, + value); + if (canContinue) { + super.visit(e, name, collectionType, type, index, value); + } + collector.onVisited(e, name, collectionType, type, index, value, + canContinue); + } + + @Override + public void clear() { + super.clear(); + stack.clear(); + } + } + + protected int stackSize() { + return visitor.getStack().size(); + } + + protected Deque<TopiaEntity> getStack() { + return visitor.getStack(); + } + + protected Collection<TopiaEntity> getAlreadyExplored() { + return visitor.getAlreadyExplored(); + } + + @Override + protected void finalize() throws Throwable { + super.finalize(); + clear(); + } + + protected Class<? extends TopiaEntity> getContractClass(TopiaEntity e) { + if (contracts.length == 0) { + return null; + } + Class<? extends TopiaEntity> contractClass = + TopiaEntityHelper.getContractClass(contracts, e.getClass()); + if (contractClass != null) { + return contractClass; + } + return null; + } + + protected TopiaEntity getTopiaValue(Object value) { + return (TopiaEntity) (value != null && + value instanceof TopiaEntity ? value : null); + } +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/DBMapping.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/DBMapping.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/DBMapping.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,455 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +package org.nuiton.topia.persistence.legacy; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.exception.SQLGrammarException; +import org.nuiton.topia.persistence.internal.AbstractTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; +import org.nuiton.topia.persistence.support.TopiaSqlQuery; +import org.nuiton.topia.persistence.support.TopiaSqlSupport; +import org.nuiton.topia.persistence.TopiaEntity; + +import java.io.IOException; +import java.io.InputStream; +import java.math.BigInteger; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.TreeMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Une classe qui permet d'obtenir les mapping de noms entre les entités et les objets de la base. + * <p/> + * On retrouve aussi ici des méthodes utils pour executer du code sql sur la base (notamment la gestion des séquences). + * + * @author tchemit <chemit@codelutin.com> + */ +public abstract class DBMapping { + + /** log */ + protected static final Log log = LogFactory.getLog(DBMapping.class); + + protected static final String CLASS_PATTERN = "(.+)\\.class\\.tagvalue\\.dbName"; + + protected static final String DBNAME_ATTRIBUTE_PATTERN = "(.+).attribute.(\\w+)\\.tagvalue\\.dbName"; + + protected static final String SEQUENCE_ATTRIBUTE_PATTERN = "(.+).attribute.(\\w+)\\.tagvalue\\.sequence"; + + protected static final String CREATE_SEQUENCE_FORMAT = "create sequence %1$s%2$s_%3$s_sequence start (select max(%3$s) from %1$s%2$s);"; + + protected static final String UPDATE_SEQUENCE_FORMAT = "alter sequence %1$s%2$s_%3$s_sequence restart with (select max(%3$s) from %1$s%2$s);"; + + protected static final String CURRENT_VALUE_SEQUENCE_FORMAT = "select %1$s%2$s_%3$s_sequence.currval"; + + protected static final String NEXT_VALUE_SEQUENCE_FORMAT = "select %1$s%2$s_%3$s_sequence.nextval"; + + protected static final String SCHEMA_FORMAT = "model.tagvalue.dbSchema"; + + protected static final String DOT = "."; + + protected Map<String, String> mappingBeanToDb; + + protected Map<String, Class<? extends TopiaEntity>> sequences; + + protected String schema; + + protected abstract Class<? extends TopiaEntity> getContractClass(Class<? extends TopiaEntity> entityClass) throws TopiaException; + + public DBMapping(String propertyFile, String path) throws IOException { + mappingBeanToDb = new TreeMap<String, String>(); + sequences = new TreeMap<String, Class<? extends TopiaEntity>>(); + + if (propertyFile == null) { + propertyFile = path; + } + + InputStream stream = getClass().getResourceAsStream(propertyFile); + if (stream == null) { + throw new IllegalStateException("no tagsvalues defined (did not find the resource : " + propertyFile + ")"); + } + + Properties props = new Properties(); + + try { + + props.load(stream); + + initMapping(props); + + } finally { + props.clear(); + stream.close(); + } + } + + public void init(TopiaApplicationContext ctxt, boolean doCreate, boolean doUpdate) throws TopiaException { + if (sequences.isEmpty()) { + // no sequence registed + return; + } + String firstSequenceKey = sequences.keySet().iterator().next(); + TopiaPersistenceContext newContext = ctxt.newPersistenceContext(); + TopiaSqlSupport sqlSupport = ((AbstractTopiaPersistenceContext)newContext).getSqlSupport(); + boolean exists = existSequence(firstSequenceKey, sqlSupport); + + if (!exists) { + if (!doCreate) { + // not exists and do not create + return; + } + createSequences(sqlSupport); + } else { + if (doUpdate) { + updateSequences(sqlSupport); + } + } + newContext.commit(); + newContext.closeContext(); + } + + public void createSequences(TopiaSqlSupport ctxt) throws TopiaException { + if (log.isInfoEnabled()) { + log.info("start create db sequences..."); + } + for (String sequenceKey : sequences.keySet()) { + createSequence(sequenceKey, ctxt, false); + } + } + + public void updateSequences(TopiaSqlSupport ctxt) throws TopiaException { + if (log.isInfoEnabled()) { + log.info("start update db sequences..."); + } + for (String sequenceKey : sequences.keySet()) { + updateSequence(sequenceKey, ctxt, false); + } + } + + public boolean existSequence(String sequenceKey, TopiaSqlSupport ctxt) throws TopiaException { + return existSequence(sequenceKey, ctxt, true); + } + + public void createSequence(String sequenceKey, TopiaSqlSupport ctxt) throws TopiaException { + createSequence(sequenceKey, ctxt, true); + } + + public void updateSequence(String sequenceKey, TopiaSqlSupport ctxt) throws TopiaException { + updateSequence(sequenceKey, ctxt, true); + } + + public BigInteger getCurrentValueFromSequence(String sequenceKey, TopiaSqlSupport ctxt) throws TopiaException { + return getCurrentValueFromSequence(sequenceKey, ctxt, true); + } + + public BigInteger getNextValueFromSequence(String sequenceKey, TopiaSqlSupport ctxt) throws TopiaException { + return getNextValueFromSequence(sequenceKey, ctxt, true); + } + + public boolean existSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaSqlSupport ctxt) throws TopiaException { + String sequenceKey = checkSequence(entityClass, propertyName); + return existSequence(sequenceKey, ctxt, false); + } + + public void createSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaSqlSupport ctxt) throws TopiaException { + String sequenceKey = checkSequence(entityClass, propertyName); + createSequence(sequenceKey, ctxt, false); + } + + public void updateSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaSqlSupport ctxt) throws TopiaException { + String sequenceKey = checkSequence(entityClass, propertyName); + updateSequence(sequenceKey, ctxt, false); + } + + public BigInteger getCurrentValueFromSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaSqlSupport ctxt) throws TopiaException { + String sequenceKey = checkSequence(entityClass, propertyName); + return getCurrentValueFromSequence(sequenceKey, ctxt, false); + } + + public BigInteger getNextValueFromSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaSqlSupport ctxt) throws TopiaException { + String sequenceKey = checkSequence(entityClass, propertyName); + return getNextValueFromSequence(sequenceKey, ctxt, false); + } + + public Iterator<String> getSequenceKeysIterator() { + return sequences.keySet().iterator(); + } + + public boolean existSequence(String sequenceKey, TopiaSqlSupport ctxt, boolean check) throws TopiaException { + if (check) { + checkSequence(sequenceKey); + } + try { + getCurrentValueFromSequence(sequenceKey, ctxt, false); + + } catch (TopiaException e) { + // the sequence's name does not exist in database, so it is a grammer exception + if (e.getCause() != null && e.getCause().getClass() == SQLGrammarException.class) { + return false; + } + throw e; + } + return true; + } + + public void createSequence(String sequenceKey, TopiaSqlSupport ctxt, boolean check) throws TopiaException { + if (check) { + checkSequence(sequenceKey); + } + String sql = getSequenceSQL(CREATE_SEQUENCE_FORMAT, sequenceKey); + doSQLWork(ctxt, sql); + BigInteger currentValue = getNextValueFromSequence(sequenceKey, ctxt, false); + + if (log.isDebugEnabled()) { + log.debug(sequenceKey + " currentValue " + currentValue.intValue()); + } + } + + public void updateSequence(String sequenceKey, TopiaSqlSupport sqlSupport, boolean check) throws TopiaException { + if (check) { + checkSequence(sequenceKey); + } + String sql = getSequenceSQL(UPDATE_SEQUENCE_FORMAT, sequenceKey); + doSQLWork(sqlSupport, sql); + BigInteger currentValue = getNextValueFromSequence(sequenceKey, sqlSupport, false); + if (log.isDebugEnabled()) { + log.debug(sequenceKey + " currentValue " + currentValue.intValue()); + } + } + + public BigInteger getCurrentValueFromSequence(String sequenceKey, TopiaSqlSupport ctxt, boolean check) throws TopiaException { + if (check) { + checkSequence(sequenceKey); + } + String sql = getSequenceSQL(CURRENT_VALUE_SEQUENCE_FORMAT, sequenceKey); +// TopiaContext newCtxt = ctxt.beginTransaction(); + BigInteger bigInteger = getBigInteger(ctxt, sql, BigInteger.ZERO); +// newCtxt.closeContext(); + return bigInteger; + } + + public BigInteger getNextValueFromSequence(String sequenceKey, TopiaSqlSupport ctxt, boolean check) throws TopiaException { + if (check) { + checkSequence(sequenceKey); + } + String sql = getSequenceSQL(NEXT_VALUE_SEQUENCE_FORMAT, sequenceKey); + return getBigInteger(ctxt, sql, BigInteger.ZERO); + } + + /** + * @param entityClass the seek entity class + * @param property the name of the property to translate + * @return the DB name for the given property + * @throws TopiaException + * if any db pb + */ + protected String getDBProperty(Class<? extends TopiaEntity> entityClass, String property) throws TopiaException { + Class<? extends TopiaEntity> contractClass = getContractClass(entityClass); + String key = contractClass.getName() + DOT + property; + + String colName = mappingBeanToDb.get(key); + if (colName == null) { + colName = property; + } + return colName; + } + + /** + * @param entityClass the seek entity class + * @return the DB name for the given property + * @throws TopiaException + * if any db pb + */ + protected String getDBTable(Class<? extends TopiaEntity> entityClass) throws TopiaException { + Class<? extends TopiaEntity> contractClass = getContractClass(entityClass); + String key = contractClass.getName(); + String colName = mappingBeanToDb.get(key); + + if (colName == null) { + colName = contractClass.getSimpleName().toLowerCase(); + } + return colName; + } + + protected String getSequenceSQL(String pattern, Class<? extends TopiaEntity> entityClass, String propertyName) throws TopiaException { + String dbTable = getDBTable(entityClass); + String dbPropertyName = getDBProperty(entityClass, propertyName); + String sql = String.format(pattern, schema, dbTable, dbPropertyName); + if (log.isTraceEnabled()) { + log.trace("sql : " + sql); + } + return sql; + } + + protected String getSequenceSQL(String pattern, String sequenceKey) throws TopiaException { + Class<? extends TopiaEntity> entityClass = sequences.get(sequenceKey); + String dbTable = getDBTable(entityClass); + String propertyName = getSequencePropertyName(sequenceKey); + String dbPropertyName = getDBProperty(entityClass, propertyName); + String sql = String.format(pattern, schema, dbTable, dbPropertyName); + if (log.isTraceEnabled()) { + log.trace("sql : " + sql); + } + return sql; + } + + protected BigInteger getBigInteger(TopiaSqlSupport sqlSupport, final String sql, BigInteger defaultSize) throws TopiaException { + BigInteger size = defaultSize; + if (sqlSupport != null) { +// try { +// SQLQuery query = ((AbstractTopiaContext) ctxt).getHibernate().createSQLQuery(sql); +// size = (BigInteger) query.list().get(0); +// } catch (SQLGrammarException e) { +// // could not obtain sequence +// throw new TopiaException(e); +// } + size = sqlSupport.findSingleResult(new TopiaSqlQuery<BigInteger>() { + @Override + protected PreparedStatement prepareQuery(Connection connection) throws SQLException { + return connection.prepareStatement(sql); + } + + @Override + protected BigInteger prepareResult(ResultSet set) throws SQLException { + return set.getBigDecimal(0).unscaledValue(); // TODO AThimel 23/11/13 Don't know if it may work or not + } + }); + + } + return size; + } + + protected void doSQLWork(TopiaSqlSupport sqlSupport, final String sql) throws TopiaException { + sqlSupport.executeSql(sql); + } + + protected String getSequencePropertyName(String sequenceKey) { + int dotIndex = sequenceKey.lastIndexOf(DOT); + return sequenceKey.substring(dotIndex + 1); + } + + protected String checkSequence(Class<? extends TopiaEntity> entityClass, String propertyName) throws IllegalArgumentException, TopiaException { + Class<? extends TopiaEntity> contractClass = getContractClass(entityClass); + String sequenceKey = contractClass.getName() + DOT + propertyName; + if (!sequences.containsKey(sequenceKey)) { + throw new IllegalArgumentException("could not find the sequence " + sequenceKey); + } + return sequenceKey; + } + + protected String checkSequence(String sequenceKey) throws IllegalArgumentException, TopiaException { + if (!sequences.containsKey(sequenceKey)) { + throw new IllegalArgumentException("could not find the sequence " + sequenceKey); + } + return sequenceKey; + } + + @SuppressWarnings({"unchecked"}) + protected void initMapping(Properties props) throws IOException { + + if (props.containsKey(SCHEMA_FORMAT)) { + schema = props.getProperty(SCHEMA_FORMAT) + DOT; + } else { + schema = ""; + } + + Pattern classPattern = Pattern.compile(CLASS_PATTERN); + + Pattern dbNameAttributePattern = Pattern.compile(DBNAME_ATTRIBUTE_PATTERN); + + Pattern sequenceAttributePattern = Pattern.compile(SEQUENCE_ATTRIBUTE_PATTERN); + + for (Entry<Object, Object> entry : props.entrySet()) { + String key = String.valueOf(entry.getKey()); + String value = String.valueOf(entry.getValue()); + Matcher matcher; + + matcher = dbNameAttributePattern.matcher(key); + if (matcher.matches()) { + // find a attribute property + String clazz = matcher.group(1); + String attribute = matcher.group(2); + mappingBeanToDb.put(clazz + "." + attribute, value); + + continue; + } + matcher = classPattern.matcher(key); + if (matcher.matches()) { + // find a class property + String clazz = matcher.group(1); + mappingBeanToDb.put(clazz, value); + continue; + } + matcher = sequenceAttributePattern.matcher(key); + if (matcher.matches()) { + // find a attribute property + String clazz = matcher.group(1); + String attribute = matcher.group(2); + try { + boolean useSequence = Boolean.valueOf(value); + if (useSequence) { + Class<?> value1 = Class.forName(clazz); + if (TopiaEntity.class.isAssignableFrom(value1)) { + sequences.put(clazz + "." + attribute, (Class<? extends TopiaEntity>) value1); + } else { + log.warn("can not create a sequence on a non TopiaEntity class " + clazz); + } + + } + } catch (Exception e) { + log.warn("could not convert sequence value for entry " + key+" for reason "+e.getMessage()); + } + + } + } + } + + @Override + protected void finalize() throws Throwable { + super.finalize(); + close(); + } + + public void close() { + if (mappingBeanToDb != null) { + mappingBeanToDb.clear(); + } + if (sequences != null) { + sequences.clear(); + } + } + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/EntityListUpdator.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityListUpdator.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/EntityListUpdator.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/EntityListUpdator.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,158 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +package org.nuiton.topia.persistence.legacy; + +import org.apache.commons.beanutils.PropertyUtilsBean; +import org.apache.commons.lang3.StringUtils; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaEntity; + +import java.beans.PropertyDescriptor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Collection; + +/** + * A implementation of {@link ListUpdator} for {@link TopiaEntity} type. + * <p/> + * Some factory methods are defined to simplify the generic cast, prefer used them + * instead of the (protected) constructor. + * + * @author tchemit <chemit@codelutin.com> + * @param <P> type of parent of childs + * @param <E> type of child + */ +public class EntityListUpdator<P extends TopiaEntity, E extends TopiaEntity> implements ListUpdator<P, E> { + + public static <P extends TopiaEntity, E extends TopiaEntity> EntityListUpdator<P, E> newEntityListUpdator(Class<P> parentClass, Class<E> childClass, String propertyName) { + return new EntityListUpdator<P, E>(parentClass, childClass, propertyName); + } + + /** name of the field containing the childs */ + protected String propertyName; + + /** descriptor of the filed containing the childs */ + protected PropertyDescriptor descriptor; + + protected Method getMethod; + + protected Method addMethod; + + protected Method removeMethod; + + protected Method removeAllMethod; + + protected Method sizeMethod; + + protected Method emptyMethod; + + protected EntityListUpdator(Class<P> parentClass, Class<E> childClass, String propertyName) { + this.propertyName = propertyName; + + for (PropertyDescriptor propertyDescriptor : new PropertyUtilsBean().getPropertyDescriptors(parentClass)) { + if (propertyDescriptor.getName().equals(propertyName)) { + descriptor = propertyDescriptor; + } + } + String cap = StringUtils.capitalize(propertyName); + try { + getMethod = parentClass.getMethod("get" + cap + "ByTopiaId", String.class); + addMethod = parentClass.getMethod("add" + cap, childClass); + removeMethod = parentClass.getMethod("remove" + cap, childClass); + removeAllMethod = parentClass.getMethod("clear" + cap); + sizeMethod = parentClass.getMethod("size" + cap); + emptyMethod = parentClass.getMethod("is" + cap + "Empty"); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + } + + @Override + public String getPropertyName() { + return propertyName; + } + + @Override + public E getChild(P parent, String topiaId) { + return EntityListUpdator.<E>invokeWithResult(getMethod, parent, topiaId); + } + + @Override + public Collection<E> getChilds(P parent) { + return EntityListUpdator.<Collection<E>>invokeWithResult(descriptor.getReadMethod(), parent); + } + + @Override + public int size(P parent) { + return EntityListUpdator.<Integer>invokeWithResult(sizeMethod, parent); + } + + @Override + public boolean isEmpty(P parent) { + return EntityListUpdator.<Boolean>invokeWithResult(emptyMethod, parent); + } + + @Override + public void setChilds(P parent, Collection<E> childs) { + invoke(descriptor.getWriteMethod(), parent, childs); + } + + @Override + public void addToList(P parent, E bean) throws TopiaException { + invoke(addMethod, parent, bean); + } + + @Override + public void removeFromList(P parent, E bean) throws TopiaException { + invoke(removeMethod, parent, bean); + } + + @Override + public void removeAll(P parent) { + invoke(removeAllMethod, parent); + } + + protected static void invoke(Method m, Object bean, Object... args) { + try { + m.invoke(bean, args); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } + } + + @SuppressWarnings({"unchecked"}) + protected static <V> V invokeWithResult(Method m, Object bean, Object... args) { + try { + return (V) m.invoke(bean, args); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } + } +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/ListUpdator.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/ListUpdator.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/ListUpdator.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/ListUpdator.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,117 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +package org.nuiton.topia.persistence.legacy; + +import org.nuiton.topia.persistence.TopiaException; + +import java.util.Collection; + +/** + * A simple contract to allow you to update some collections of an entity. + * <p/> + * The purpose of the contract is to make possible (via a StorageService for example) some + * automatic and generic behaviour when you want to set a collection of childs into a entity. + * + * @author tchemit <chemit@codelutin.com> + * @param <P> the type of the entity which contains the collection to update. + * @param <E> the type of entities in the collection. + */ +public interface ListUpdator<P, E> { + + /** + * Obtain the name of the property containing childs. + * + * @return the name of the property containing childs. + */ + String getPropertyName(); + + /** + * Obtain a child from the entity given his id. + * + * @param parent the entity to query + * @param topiaId the id of the researched child entity. + * @return the child entity or <code>null</code>, if not found. + */ + + E getChild(P parent, String topiaId); + + /** + * Obtain the collection of childs from the entity. + * + * @param parent the entity to query. + * @return the collection of childs + */ + Collection<E> getChilds(P parent); + + /** + * Obtain the number of childs for the given parent. + * + * @param parent the entity to query + * @return the number of childs for the given entity + */ + int size(P parent); + + /** + * Tests if the given entity has some childs. + * + * @param parent the entity to query + * @return {@code true} is the given parent has no child. + */ + boolean isEmpty(P parent); + + /** + * Set the childs of an entity + * + * @param parent the entity to be setted + * @param childs the collection of childs to set. + */ + void setChilds(P parent, Collection<E> childs); + + /** + * Add a erntity to his parent + * + * @param parent the entity to modifiy + * @param e the entity to add in parent. + * @throws TopiaException if any db problem while operation + */ + void addToList(P parent, E e) throws TopiaException; + + /** + * Remove from a prent entity a given child. + * + * @param parent the entity to modifiy + * @param e the child to remove. + * @throws TopiaException if any pb while operation. + */ + void removeFromList(P parent, E e) throws TopiaException; + + /** + * Remove all childs of the given parent. + * + * @param parent the entity to modify + */ + void removeAll(P parent); +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/Loador.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/Loador.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/legacy/Loador.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,74 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ + +package org.nuiton.topia.persistence.legacy; + +import java.io.Serializable; +import java.util.Map; + +/** + * A simple contract to load an object from another one. + * + * @author tchemit <chemit@codelutin.com> + * @param <E> type of bean to load + */ +public interface Loador<E> extends Serializable { + + /** + * Obtains the type of the entity. + * + * @return the type of entity + */ + Class<E> getSourceType(); + + /** + * Obtain from an entity all data to bind to another one according the + * definition of the loador. + * <p/> + * This method is usefull when you can not directly used the + * {@link #load(Object, Object, boolean, String...)} method. + * <p/> + * For example, when an entity has a immutable business key (says with an + * hibernate naturalId for example), + * and that you want to create the data in a db, you must give all the + * properties at the create time so this method allow you to do it). + * + * @param from the entity to bind + * @param propertyNames subset of properties to load + * @return the map of properties to bind from the given entity. + */ + Map<String, Object> obtainProperties(E from, String... propertyNames); + + /** + * Bind an entity to another. + * + * @param from the source entity + * @param dst the destination entity + * @param tech a flag to bind or not the technical values of the entity + * (says TopiaId, TopiaVersion and TopiaCreateDate). + * @param propertyNames subset of properties to load + */ + void load(E from, E dst, boolean tech, String... propertyNames); +} Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/AssociationMeta.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/AssociationMeta.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/AssociationMeta.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -24,7 +24,7 @@ */ import com.google.common.base.Charsets; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityEnum; import org.nuiton.topia.persistence.util.EntityOperator; Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TableMeta.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TableMeta.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TableMeta.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -27,7 +27,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityEnum; import org.nuiton.topia.persistence.TopiaPersistenceHelper; Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaHibernateSupport.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernateSupport.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaHibernateSupport.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaHibernateSupport.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,54 @@ +package org.nuiton.topia.persistence.support; + +/* + * #%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(); + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaJpaSupport.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaJpaSupport.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaJpaSupport.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,146 @@ +package org.nuiton.topia.persistence.support; + +/* + * #%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.Map; + +/** + * This API provides methods to use persistence using JPA queries + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public interface TopiaJpaSupport { + + /** + * 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 + * + * @param jpaql the JPA-QL query + * @param parameters a map which keys are the attribute names and values are the attributes expected values + * @return The result list + */ + <T> List<T> findAll(String jpaql, + Map<String, Object> parameters); + + /** + * 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 parameters a map which keys are the attribute names and values are the attributes expected values + * @return The result list + */ + <T> List<T> find(String jpaql, + int startIndex, + int endIndex, + Map<String, Object> parameters); + + /** + * 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/> + * WARNING : Depending on the registered service, this method may not + * support something else than queries on TopiaEntity + * + * @param jpaql the JPA-QL query + * @param parameters a map which keys are the attribute names and values are the attributes expected values + * @return The result instance or null + */ + <T> T findUnique(String jpaql, + Map<String, Object> parameters); + + /** + * Execute JPA-QL operation on data (Update, Delete). + * + * @param jpaql the JPA-QL query + * @param parameters a map which keys are the attribute names and values are the attributes expected values + * @return The number of entities updated or deleted. + */ + int execute(String jpaql, + Map<String, Object> parameters); + + /** + * 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 disable it setting the value to {@code false}. + * + * @param useFlushMode the new value to set + * @since 2.5 + */ + void setUseFlushMode(boolean useFlushMode); + + /** + * Persist the given transient instance, first assigning a generated identifier. This method is JPA implementation + * independent. + * <p/> + * This method is "inspired" of the Hibernate's Session#save method. + * + * @param object a transient instance of a persistent class + */ + void save(Object object); + + /** + * Update the persistent instance with the identifier of the given detached instance. + * <p/> + * This method is "inspired" of the Hibernate's Session#update method. + * + * @param object a detached instance containing updated state + */ + void update(Object object); + + /** + * Either {@link #save(Object)} or {@link #update(Object)} the given instance. + * <p/> + * This method is "inspired" of the Hibernate's Session#saveOrUpdate method. + * + * @param object a transient or detached instance containing new or updated state + * @see #save(java.lang.Object) + * @see #update(Object object) + */ + void saveOrUpdate(Object object); + + /** + * Remove a persistent instance. + * <p/> + * This method is "inspired" of the Hibernate's Session#delete method. + * + * @param object the instance to be removed + */ + void delete(Object object); + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaListenableSupport.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenableSupport.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaListenableSupport.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaListenableSupport.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,227 @@ +package org.nuiton.topia.persistence.support; + +/* + * #%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.persistence.event.TopiaEntitiesVetoable; +import org.nuiton.topia.persistence.event.TopiaEntityListener; +import org.nuiton.topia.persistence.event.TopiaEntityVetoable; +import org.nuiton.topia.persistence.event.TopiaSchemaListener; +import org.nuiton.topia.persistence.event.TopiaTransactionListener; +import org.nuiton.topia.persistence.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); + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaReplicationSupport.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaReplicationSupport.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaReplicationSupport.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,87 @@ +package org.nuiton.topia.persistence.support; + +/* + * #%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.nuiton.topia.persistence.TopiaReplicationDestination; +import org.nuiton.topia.persistence.TopiaEntity; + +import java.util.List; + +/** + * This API provides methods about entities replication to a destination + * + * @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. + * <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(TopiaReplicationDestination, java.util.List)}. + * + * @param topiaReplicationDestination 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 IllegalArgumentException if one of the context is closed or if + * trying to replicate within the same + * database + */ + void replicate(TopiaReplicationDestination topiaReplicationDestination, + Object... entityAndCondition) throws IllegalArgumentException; + + /** + * Replicate a given entity from this context to the given context. + * + * @param topiaReplicationDestination the destination context + * @param entity the entity instance to replicate + * @throws IllegalArgumentException if one of the context is closed or if + * trying to replicate within the same + * database + */ + <T extends TopiaEntity> void replicateEntity(TopiaReplicationDestination topiaReplicationDestination, + T entity) throws IllegalArgumentException; + + /** + * Makes a replication of some entities from this context to the given + * context without any entity modification. + * + * @param topiaReplicationDestination the destination context + * @param entities the list of entities instance to replicate + * @throws IllegalArgumentException if one of the context is closed or if + * trying to replicate within the same + * database + */ + <T extends TopiaEntity> void replicateEntities(TopiaReplicationDestination topiaReplicationDestination, + List<T> entities) throws IllegalArgumentException; + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaServiceSupport.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaServiceSupport.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaServiceSupport.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,65 @@ +package org.nuiton.topia.persistence.support; + +/* + * #%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.persistence.TopiaNotFoundException; +import org.nuiton.topia.persistence.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 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 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(); + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaSqlQuery.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlQuery.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaSqlQuery.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaSqlQuery.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,142 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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% + */ +package org.nuiton.topia.persistence.support; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Wrap a Sql query some object. + * + * Implements the {@link #prepareResult(ResultSet)} to transforma result set + * row to an object. + * + * You can also do some stuff on the result set just after the query was + * executed using method {@link #afterExecuteQuery(ResultSet)}. + * + * @param <O> the type of result data + * @since 2.5 + */ +public abstract class TopiaSqlQuery<O> { + + /** + * Prepare the statement used to do the sql query. + * + * @param connection jdbc connection to use + * @return the statement containing the query to execute + * @throws SQLException if any problem + */ + protected abstract PreparedStatement prepareQuery(Connection connection) throws SQLException; + + /** + * given a result set, extract the data. + * + * @param set the result set + * @return the data extracted from the current set, or {@code null} + * @throws SQLException if any prob + */ + protected abstract O prepareResult(ResultSet set) throws SQLException; + + /** + * A hook to obtain the result set just after the query execute. + * + * @param set the result set just obtained + * @throws SQLException if any prob + * @since 2.6.4 + */ + protected void afterExecuteQuery(ResultSet set) throws SQLException { + // by default do nothing + } + + /** + * Obtain the column names of a given result set using his metadata. + * + * @param set the result set to inspect + * @return the column names of the result set + * @throws SQLException if any pb + * @since 2.6.4 + */ + protected String[] getColumnNames(ResultSet set) throws SQLException { + ResultSetMetaData metaData = set.getMetaData(); + int columnCount = metaData.getColumnCount(); + String[] result = new String[columnCount]; + for (int i = 0; i < columnCount; i++) { + result[i] = metaData.getColumnName(i + 1); + } + return result; + } + + /** + * From a given result set, let's count his number of row. + * <p/> + * <strong>Note:</strong> the result set must be scrollable to go back to + * before first row. + * + * @param set the result set to inspect + * @return the number of row of the given result set + * @throws SQLException if any pb + * @since 2.6.4 + */ + protected long getNbRows(ResultSet set) throws SQLException { + + //FIXME tchemit-2012-11-22 use set.last() + long nbRows = 0; + while (set.next()) { + nbRows++; + } + // go back before first row (be ware the resultset must be scrollable) + set.beforeFirst(); + return nbRows; + } + + /** + * Given the column names of the result set, transform the row of the + * result set to a map with column name as key. + * + * @param columnNames column names of the result set + * @param set the set to inspect + * @return the map for the given row of the result set + * @throws SQLException if any pb + * @since 2.6.4 + */ + protected Map<String, Object> getRowAsMap(String[] columnNames, + ResultSet set) throws SQLException { + + Map<String, Object> result = new LinkedHashMap<String, Object>(); + int length = columnNames.length; + for (int i = 0; i < length; i++) { + String name = columnNames[i]; + Object value = set.getObject(i + 1); + result.put(name, value); + } + return result; + } + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaSqlSupport.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaSqlSupport.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaSqlSupport.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,71 @@ +package org.nuiton.topia.persistence.support; + +/* + * #%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.nuiton.topia.persistence.TopiaException; + +import java.util.List; + +/** + * This API provides methods to run SQL queries + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public interface TopiaSqlSupport { + + /** + * Execute a given SQL code inside this transaction. + * + * @param sqlScript the sql script to execute + */ + void executeSql(String sqlScript); + + /** + * Runs the given SQL work on the current context + * + * @param sqlWork the SQL work instance to execute + */ + void doSqlWork(TopiaSqlWork sqlWork); + + /** + * Runs the given SQL query and return its first result if there is some. + * + * @param query query to play + * @return the single result or {@code null} if none found. + * @throws TopiaException for any pb + */ + <O> O findSingleResult(TopiaSqlQuery<O> query) throws TopiaException; + + /** + * Runs the given SQL query and return all his result if there is some. + * + * @param query query to play + * @return the list of results (the list is empty if query returns no result). + * @throws TopiaException for any pb + */ + <O> List<O> findMultipleResult(TopiaSqlQuery<O> query) throws TopiaException; + +} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaSqlWork.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlWork.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaSqlWork.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaSqlWork.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,49 @@ +package org.nuiton.topia.persistence.support; + +/* + * #%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.sql.Connection; +import java.sql.SQLException; + +/** + * Interface used for any native SQL batch. This interface is highly inspired + * of org.hibernate.jdbc.Work. + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public interface TopiaSqlWork { + + /** + * Execute the discrete work encapsulated by this work instance using the + * supplied connection. + * + * @param connection The connection on which to perform the work. + * @throws SQLException Thrown during execution of the underlying JDBC + * interaction. + */ + void execute(Connection connection) throws SQLException; + +} \ No newline at end of file Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Collector.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Collector.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Collector.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,274 +0,0 @@ -/* - * #%L - * ToPIA :: Persistence - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 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% - */ - -package org.nuiton.topia.persistence.util; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.DepthEntityVisitor; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.TopiaEntityEnum; - -import java.util.ArrayDeque; -import java.util.Collection; -import java.util.Deque; - -/** - * Un objet qui permet de parcourir des entites (via un - * {@link CollectorVisitor}) et de collecter des donnees pendant le parcours. - * <p/> - * La classe a un type qui est le type de retour de la methode - * {@link #detect(TopiaEntity...)}. - * <p/> - * On peut donc très facilement en faire un collecteur de donnees. - * - * @author tchemit <chemit@codelutin.com> - * @param <R> les donnes a retourner - * @since 2.2.0 - */ -public abstract class Collector<R> { - - private static final Log log = LogFactory.getLog(Collector.class); - - /** le visiteur utiliser pour trouver les types */ - protected CollectorVisitor visitor; - - /** la liste des contracts des entites connues. */ - protected TopiaEntityEnum[] contracts; - - public Collector(CollectorVisitor visitor, TopiaEntityEnum[] contracts) { - this.visitor = visitor == null ? new CollectorVisitor() : visitor; - this.visitor.setCollector(this); - this.contracts = contracts; - } - - public Collector(TopiaEntityEnum[] contracts) { - this(null, contracts); - } - - protected void clear() { - visitor.clear(); - } - - protected boolean onStarting(TopiaEntity e) { - return true; - } - - protected void onStarted(TopiaEntity e, boolean enter) { - } - - protected boolean onVisiting(TopiaEntity e, String name, Class<?> type, - Object value) { - return true; - } - - protected void onVisited(TopiaEntity e, String name, Class<?> type, - Object value, boolean enter) { - } - - protected boolean onVisiting(TopiaEntity e, String name, - Class<?> collectionType, - Class<?> type, Object value) { - return true; - } - - protected void onVisited(TopiaEntity e, String name, - Class<?> collectionType, - Class<?> type, Object value, boolean enter) { - } - - protected boolean onVisiting(TopiaEntity e, String name, - Class<?> collectionType, - Class<?> type, int index, Object value) { - return true; - } - - protected void onVisited(TopiaEntity e, String name, - Class<?> collectionType, - Class<?> type, - int index, Object value, boolean enter) { - } - - protected boolean onEnding(TopiaEntity e) { - return true; - } - - protected void onEnded(TopiaEntity e, boolean enter) { - } - - protected void beforeAll(CollectorVisitor visitor, - TopiaEntity... entities) { - } - - protected void before(CollectorVisitor visitor, TopiaEntity entity) { - if (log.isDebugEnabled()) { - log.debug("Will detect "+entity.getTopiaId()); - } - } - - protected void after(CollectorVisitor visitor, TopiaEntity entity) { - } - - protected abstract R afterAll(CollectorVisitor visitor, - TopiaEntity... entities); - - public R detect(TopiaEntity... entities) throws TopiaException { - - try { - beforeAll(visitor, entities); - - for (TopiaEntity e : entities) { - before(visitor, e); - e.accept(visitor); - after(visitor, e); - } - - R result = afterAll(visitor, entities); - - return result; - } finally { - clear(); - } - } - - public static class CollectorVisitor extends DepthEntityVisitor { - - /** la pile des entites en cours de parcours */ - protected Deque<TopiaEntity> stack = new ArrayDeque<TopiaEntity>(); - - Collector<?> collector; - - protected void setCollector(Collector<?> collector) { - this.collector = collector; - } - - protected Deque<TopiaEntity> getStack() { - return stack; - } - - protected Collection<TopiaEntity> getAlreadyExplored() { - return alreadyExplored; - } - - @Override - public void start(TopiaEntity e) { - // on ajoute l'objet courant dans la pile - stack.offerLast(e); - boolean canContinue = collector.onStarting(e); - if (canContinue) { - super.start(e); - } - collector.onStarted(e, canContinue); - } - - @Override - public void end(TopiaEntity e) { - boolean canContinue = collector.onEnding(e); - if (canContinue) { - super.end(e); - } - stack.removeLast(); - // on retire l'objet courant de la pile - collector.onEnded(e, canContinue); - } - - @Override - public void visit(TopiaEntity e, String name, Class<?> type, - Object value) { - boolean canContinue = collector.onVisiting(e, name, type, value); - if (canContinue) { - super.visit(e, name, type, value); - } - collector.onVisited(e, name, type, value, canContinue); - } - - @Override - public void visit(TopiaEntity e, String name, Class<?> collectionType, - Class<?> type, Object value) { - boolean canContinue = - collector.onVisiting(e, name, collectionType, type, value); - if (canContinue) { - super.visit(e, name, collectionType, type, value); - } - collector.onVisited(e, name, collectionType, type, value, - canContinue); - } - - @Override - public void visit(TopiaEntity e, String name, Class<?> collectionType, - Class<?> type, int index, Object value) { - boolean canContinue = - collector.onVisiting(e, name, collectionType, type, index, - value); - if (canContinue) { - super.visit(e, name, collectionType, type, index, value); - } - collector.onVisited(e, name, collectionType, type, index, value, - canContinue); - } - - @Override - public void clear() { - super.clear(); - stack.clear(); - } - } - - protected int stackSize() { - return visitor.getStack().size(); - } - - protected Deque<TopiaEntity> getStack() { - return visitor.getStack(); - } - - protected Collection<TopiaEntity> getAlreadyExplored() { - return visitor.getAlreadyExplored(); - } - - @Override - protected void finalize() throws Throwable { - super.finalize(); - clear(); - } - - protected Class<? extends TopiaEntity> getContractClass(TopiaEntity e) { - if (contracts.length == 0) { - return null; - } - Class<? extends TopiaEntity> contractClass = - TopiaEntityHelper.getContractClass(contracts, e.getClass()); - if (contractClass != null) { - return contractClass; - } - return null; - } - - protected TopiaEntity getTopiaValue(Object value) { - return (TopiaEntity) (value != null && - value instanceof TopiaEntity ? value : null); - } -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,455 +0,0 @@ -/* - * #%L - * ToPIA :: Persistence - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 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% - */ - -package org.nuiton.topia.persistence.util; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.exception.SQLGrammarException; -import org.nuiton.topia.AbstractTopiaApplicationContext; -import org.nuiton.topia.AbstractTopiaPersistenceContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; -import org.nuiton.topia.TopiaSqlQuery; -import org.nuiton.topia.TopiaSqlSupport; -import org.nuiton.topia.persistence.TopiaEntity; - -import java.io.IOException; -import java.io.InputStream; -import java.math.BigInteger; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.TreeMap; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Une classe qui permet d'obtenir les mapping de noms entre les entités et les objets de la base. - * <p/> - * On retrouve aussi ici des méthodes utils pour executer du code sql sur la base (notamment la gestion des séquences). - * - * @author tchemit <chemit@codelutin.com> - */ -public abstract class DBMapping { - - /** log */ - protected static final Log log = LogFactory.getLog(DBMapping.class); - - protected static final String CLASS_PATTERN = "(.+)\\.class\\.tagvalue\\.dbName"; - - protected static final String DBNAME_ATTRIBUTE_PATTERN = "(.+).attribute.(\\w+)\\.tagvalue\\.dbName"; - - protected static final String SEQUENCE_ATTRIBUTE_PATTERN = "(.+).attribute.(\\w+)\\.tagvalue\\.sequence"; - - protected static final String CREATE_SEQUENCE_FORMAT = "create sequence %1$s%2$s_%3$s_sequence start (select max(%3$s) from %1$s%2$s);"; - - protected static final String UPDATE_SEQUENCE_FORMAT = "alter sequence %1$s%2$s_%3$s_sequence restart with (select max(%3$s) from %1$s%2$s);"; - - protected static final String CURRENT_VALUE_SEQUENCE_FORMAT = "select %1$s%2$s_%3$s_sequence.currval"; - - protected static final String NEXT_VALUE_SEQUENCE_FORMAT = "select %1$s%2$s_%3$s_sequence.nextval"; - - protected static final String SCHEMA_FORMAT = "model.tagvalue.dbSchema"; - - protected static final String DOT = "."; - - protected Map<String, String> mappingBeanToDb; - - protected Map<String, Class<? extends TopiaEntity>> sequences; - - protected String schema; - - protected abstract Class<? extends TopiaEntity> getContractClass(Class<? extends TopiaEntity> entityClass) throws TopiaException; - - public DBMapping(String propertyFile, String path) throws IOException { - mappingBeanToDb = new TreeMap<String, String>(); - sequences = new TreeMap<String, Class<? extends TopiaEntity>>(); - - if (propertyFile == null) { - propertyFile = path; - } - - InputStream stream = getClass().getResourceAsStream(propertyFile); - if (stream == null) { - throw new IllegalStateException("no tagsvalues defined (did not find the resource : " + propertyFile + ")"); - } - - Properties props = new Properties(); - - try { - - props.load(stream); - - initMapping(props); - - } finally { - props.clear(); - stream.close(); - } - } - - public void init(AbstractTopiaApplicationContext ctxt, boolean doCreate, boolean doUpdate) throws TopiaException { - if (sequences.isEmpty()) { - // no sequence registed - return; - } - String firstSequenceKey = sequences.keySet().iterator().next(); - TopiaPersistenceContext newContext = ctxt.newPersistenceContext(); - TopiaSqlSupport sqlSupport = ((AbstractTopiaPersistenceContext)newContext).getSqlSupport(); - boolean exists = existSequence(firstSequenceKey, sqlSupport); - - if (!exists) { - if (!doCreate) { - // not exists and do not create - return; - } - createSequences(sqlSupport); - } else { - if (doUpdate) { - updateSequences(sqlSupport); - } - } - newContext.commit(); - newContext.closeContext(); - } - - public void createSequences(TopiaSqlSupport ctxt) throws TopiaException { - if (log.isInfoEnabled()) { - log.info("start create db sequences..."); - } - for (String sequenceKey : sequences.keySet()) { - createSequence(sequenceKey, ctxt, false); - } - } - - public void updateSequences(TopiaSqlSupport ctxt) throws TopiaException { - if (log.isInfoEnabled()) { - log.info("start update db sequences..."); - } - for (String sequenceKey : sequences.keySet()) { - updateSequence(sequenceKey, ctxt, false); - } - } - - public boolean existSequence(String sequenceKey, TopiaSqlSupport ctxt) throws TopiaException { - return existSequence(sequenceKey, ctxt, true); - } - - public void createSequence(String sequenceKey, TopiaSqlSupport ctxt) throws TopiaException { - createSequence(sequenceKey, ctxt, true); - } - - public void updateSequence(String sequenceKey, TopiaSqlSupport ctxt) throws TopiaException { - updateSequence(sequenceKey, ctxt, true); - } - - public BigInteger getCurrentValueFromSequence(String sequenceKey, TopiaSqlSupport ctxt) throws TopiaException { - return getCurrentValueFromSequence(sequenceKey, ctxt, true); - } - - public BigInteger getNextValueFromSequence(String sequenceKey, TopiaSqlSupport ctxt) throws TopiaException { - return getNextValueFromSequence(sequenceKey, ctxt, true); - } - - public boolean existSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaSqlSupport ctxt) throws TopiaException { - String sequenceKey = checkSequence(entityClass, propertyName); - return existSequence(sequenceKey, ctxt, false); - } - - public void createSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaSqlSupport ctxt) throws TopiaException { - String sequenceKey = checkSequence(entityClass, propertyName); - createSequence(sequenceKey, ctxt, false); - } - - public void updateSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaSqlSupport ctxt) throws TopiaException { - String sequenceKey = checkSequence(entityClass, propertyName); - updateSequence(sequenceKey, ctxt, false); - } - - public BigInteger getCurrentValueFromSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaSqlSupport ctxt) throws TopiaException { - String sequenceKey = checkSequence(entityClass, propertyName); - return getCurrentValueFromSequence(sequenceKey, ctxt, false); - } - - public BigInteger getNextValueFromSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaSqlSupport ctxt) throws TopiaException { - String sequenceKey = checkSequence(entityClass, propertyName); - return getNextValueFromSequence(sequenceKey, ctxt, false); - } - - public Iterator<String> getSequenceKeysIterator() { - return sequences.keySet().iterator(); - } - - public boolean existSequence(String sequenceKey, TopiaSqlSupport ctxt, boolean check) throws TopiaException { - if (check) { - checkSequence(sequenceKey); - } - try { - getCurrentValueFromSequence(sequenceKey, ctxt, false); - - } catch (TopiaException e) { - // the sequence's name does not exist in database, so it is a grammer exception - if (e.getCause() != null && e.getCause().getClass() == SQLGrammarException.class) { - return false; - } - throw e; - } - return true; - } - - public void createSequence(String sequenceKey, TopiaSqlSupport ctxt, boolean check) throws TopiaException { - if (check) { - checkSequence(sequenceKey); - } - String sql = getSequenceSQL(CREATE_SEQUENCE_FORMAT, sequenceKey); - doSQLWork(ctxt, sql); - BigInteger currentValue = getNextValueFromSequence(sequenceKey, ctxt, false); - - if (log.isDebugEnabled()) { - log.debug(sequenceKey + " currentValue " + currentValue.intValue()); - } - } - - public void updateSequence(String sequenceKey, TopiaSqlSupport sqlSupport, boolean check) throws TopiaException { - if (check) { - checkSequence(sequenceKey); - } - String sql = getSequenceSQL(UPDATE_SEQUENCE_FORMAT, sequenceKey); - doSQLWork(sqlSupport, sql); - BigInteger currentValue = getNextValueFromSequence(sequenceKey, sqlSupport, false); - if (log.isDebugEnabled()) { - log.debug(sequenceKey + " currentValue " + currentValue.intValue()); - } - } - - public BigInteger getCurrentValueFromSequence(String sequenceKey, TopiaSqlSupport ctxt, boolean check) throws TopiaException { - if (check) { - checkSequence(sequenceKey); - } - String sql = getSequenceSQL(CURRENT_VALUE_SEQUENCE_FORMAT, sequenceKey); -// TopiaContext newCtxt = ctxt.beginTransaction(); - BigInteger bigInteger = getBigInteger(ctxt, sql, BigInteger.ZERO); -// newCtxt.closeContext(); - return bigInteger; - } - - public BigInteger getNextValueFromSequence(String sequenceKey, TopiaSqlSupport ctxt, boolean check) throws TopiaException { - if (check) { - checkSequence(sequenceKey); - } - String sql = getSequenceSQL(NEXT_VALUE_SEQUENCE_FORMAT, sequenceKey); - return getBigInteger(ctxt, sql, BigInteger.ZERO); - } - - /** - * @param entityClass the seek entity class - * @param property the name of the property to translate - * @return the DB name for the given property - * @throws TopiaException - * if any db pb - */ - protected String getDBProperty(Class<? extends TopiaEntity> entityClass, String property) throws TopiaException { - Class<? extends TopiaEntity> contractClass = getContractClass(entityClass); - String key = contractClass.getName() + DOT + property; - - String colName = mappingBeanToDb.get(key); - if (colName == null) { - colName = property; - } - return colName; - } - - /** - * @param entityClass the seek entity class - * @return the DB name for the given property - * @throws TopiaException - * if any db pb - */ - protected String getDBTable(Class<? extends TopiaEntity> entityClass) throws TopiaException { - Class<? extends TopiaEntity> contractClass = getContractClass(entityClass); - String key = contractClass.getName(); - String colName = mappingBeanToDb.get(key); - - if (colName == null) { - colName = contractClass.getSimpleName().toLowerCase(); - } - return colName; - } - - protected String getSequenceSQL(String pattern, Class<? extends TopiaEntity> entityClass, String propertyName) throws TopiaException { - String dbTable = getDBTable(entityClass); - String dbPropertyName = getDBProperty(entityClass, propertyName); - String sql = String.format(pattern, schema, dbTable, dbPropertyName); - if (log.isTraceEnabled()) { - log.trace("sql : " + sql); - } - return sql; - } - - protected String getSequenceSQL(String pattern, String sequenceKey) throws TopiaException { - Class<? extends TopiaEntity> entityClass = sequences.get(sequenceKey); - String dbTable = getDBTable(entityClass); - String propertyName = getSequencePropertyName(sequenceKey); - String dbPropertyName = getDBProperty(entityClass, propertyName); - String sql = String.format(pattern, schema, dbTable, dbPropertyName); - if (log.isTraceEnabled()) { - log.trace("sql : " + sql); - } - return sql; - } - - protected BigInteger getBigInteger(TopiaSqlSupport sqlSupport, final String sql, BigInteger defaultSize) throws TopiaException { - BigInteger size = defaultSize; - if (sqlSupport != null) { -// try { -// SQLQuery query = ((AbstractTopiaContext) ctxt).getHibernate().createSQLQuery(sql); -// size = (BigInteger) query.list().get(0); -// } catch (SQLGrammarException e) { -// // could not obtain sequence -// throw new TopiaException(e); -// } - size = sqlSupport.findSingleResult(new TopiaSqlQuery<BigInteger>() { - @Override - protected PreparedStatement prepareQuery(Connection connection) throws SQLException { - return connection.prepareStatement(sql); - } - - @Override - protected BigInteger prepareResult(ResultSet set) throws SQLException { - return set.getBigDecimal(0).unscaledValue(); // TODO AThimel 23/11/13 Don't know if it may work or not - } - }); - - } - return size; - } - - protected void doSQLWork(TopiaSqlSupport sqlSupport, final String sql) throws TopiaException { - sqlSupport.executeSql(sql); - } - - protected String getSequencePropertyName(String sequenceKey) { - int dotIndex = sequenceKey.lastIndexOf(DOT); - return sequenceKey.substring(dotIndex + 1); - } - - protected String checkSequence(Class<? extends TopiaEntity> entityClass, String propertyName) throws IllegalArgumentException, TopiaException { - Class<? extends TopiaEntity> contractClass = getContractClass(entityClass); - String sequenceKey = contractClass.getName() + DOT + propertyName; - if (!sequences.containsKey(sequenceKey)) { - throw new IllegalArgumentException("could not find the sequence " + sequenceKey); - } - return sequenceKey; - } - - protected String checkSequence(String sequenceKey) throws IllegalArgumentException, TopiaException { - if (!sequences.containsKey(sequenceKey)) { - throw new IllegalArgumentException("could not find the sequence " + sequenceKey); - } - return sequenceKey; - } - - @SuppressWarnings({"unchecked"}) - protected void initMapping(Properties props) throws IOException { - - if (props.containsKey(SCHEMA_FORMAT)) { - schema = props.getProperty(SCHEMA_FORMAT) + DOT; - } else { - schema = ""; - } - - Pattern classPattern = Pattern.compile(CLASS_PATTERN); - - Pattern dbNameAttributePattern = Pattern.compile(DBNAME_ATTRIBUTE_PATTERN); - - Pattern sequenceAttributePattern = Pattern.compile(SEQUENCE_ATTRIBUTE_PATTERN); - - for (Entry<Object, Object> entry : props.entrySet()) { - String key = String.valueOf(entry.getKey()); - String value = String.valueOf(entry.getValue()); - Matcher matcher; - - matcher = dbNameAttributePattern.matcher(key); - if (matcher.matches()) { - // find a attribute property - String clazz = matcher.group(1); - String attribute = matcher.group(2); - mappingBeanToDb.put(clazz + "." + attribute, value); - - continue; - } - matcher = classPattern.matcher(key); - if (matcher.matches()) { - // find a class property - String clazz = matcher.group(1); - mappingBeanToDb.put(clazz, value); - continue; - } - matcher = sequenceAttributePattern.matcher(key); - if (matcher.matches()) { - // find a attribute property - String clazz = matcher.group(1); - String attribute = matcher.group(2); - try { - boolean useSequence = Boolean.valueOf(value); - if (useSequence) { - Class<?> value1 = Class.forName(clazz); - if (TopiaEntity.class.isAssignableFrom(value1)) { - sequences.put(clazz + "." + attribute, (Class<? extends TopiaEntity>) value1); - } else { - log.warn("can not create a sequence on a non TopiaEntity class " + clazz); - } - - } - } catch (Exception e) { - log.warn("could not convert sequence value for entry " + key+" for reason "+e.getMessage()); - } - - } - } - } - - @Override - protected void finalize() throws Throwable { - super.finalize(); - close(); - } - - public void close() { - if (mappingBeanToDb != null) { - mappingBeanToDb.clear(); - } - if (sequences != null) { - sequences.clear(); - } - } - -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityListUpdator.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityListUpdator.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityListUpdator.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,158 +0,0 @@ -/* - * #%L - * ToPIA :: Persistence - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 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% - */ - -package org.nuiton.topia.persistence.util; - -import org.apache.commons.beanutils.PropertyUtilsBean; -import org.apache.commons.lang3.StringUtils; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaEntity; - -import java.beans.PropertyDescriptor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Collection; - -/** - * A implementation of {@link ListUpdator} for {@link TopiaEntity} type. - * <p/> - * Some factory methods are defined to simplify the generic cast, prefer used them - * instead of the (protected) constructor. - * - * @author tchemit <chemit@codelutin.com> - * @param <P> type of parent of childs - * @param <E> type of child - */ -public class EntityListUpdator<P extends TopiaEntity, E extends TopiaEntity> implements ListUpdator<P, E> { - - public static <P extends TopiaEntity, E extends TopiaEntity> EntityListUpdator<P, E> newEntityListUpdator(Class<P> parentClass, Class<E> childClass, String propertyName) { - return new EntityListUpdator<P, E>(parentClass, childClass, propertyName); - } - - /** name of the field containing the childs */ - protected String propertyName; - - /** descriptor of the filed containing the childs */ - protected PropertyDescriptor descriptor; - - protected Method getMethod; - - protected Method addMethod; - - protected Method removeMethod; - - protected Method removeAllMethod; - - protected Method sizeMethod; - - protected Method emptyMethod; - - protected EntityListUpdator(Class<P> parentClass, Class<E> childClass, String propertyName) { - this.propertyName = propertyName; - - for (PropertyDescriptor propertyDescriptor : new PropertyUtilsBean().getPropertyDescriptors(parentClass)) { - if (propertyDescriptor.getName().equals(propertyName)) { - descriptor = propertyDescriptor; - } - } - String cap = StringUtils.capitalize(propertyName); - try { - getMethod = parentClass.getMethod("get" + cap + "ByTopiaId", String.class); - addMethod = parentClass.getMethod("add" + cap, childClass); - removeMethod = parentClass.getMethod("remove" + cap, childClass); - removeAllMethod = parentClass.getMethod("clear" + cap); - sizeMethod = parentClass.getMethod("size" + cap); - emptyMethod = parentClass.getMethod("is" + cap + "Empty"); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } - } - - @Override - public String getPropertyName() { - return propertyName; - } - - @Override - public E getChild(P parent, String topiaId) { - return EntityListUpdator.<E>invokeWithResult(getMethod, parent, topiaId); - } - - @Override - public Collection<E> getChilds(P parent) { - return EntityListUpdator.<Collection<E>>invokeWithResult(descriptor.getReadMethod(), parent); - } - - @Override - public int size(P parent) { - return EntityListUpdator.<Integer>invokeWithResult(sizeMethod, parent); - } - - @Override - public boolean isEmpty(P parent) { - return EntityListUpdator.<Boolean>invokeWithResult(emptyMethod, parent); - } - - @Override - public void setChilds(P parent, Collection<E> childs) { - invoke(descriptor.getWriteMethod(), parent, childs); - } - - @Override - public void addToList(P parent, E bean) throws TopiaException { - invoke(addMethod, parent, bean); - } - - @Override - public void removeFromList(P parent, E bean) throws TopiaException { - invoke(removeMethod, parent, bean); - } - - @Override - public void removeAll(P parent) { - invoke(removeAllMethod, parent); - } - - protected static void invoke(Method m, Object bean, Object... args) { - try { - m.invoke(bean, args); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } - } - - @SuppressWarnings({"unchecked"}) - protected static <V> V invokeWithResult(Method m, Object bean, Object... args) { - try { - return (V) m.invoke(bean, args); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } - } -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/ListUpdator.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/ListUpdator.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/ListUpdator.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,117 +0,0 @@ -/* - * #%L - * ToPIA :: Persistence - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 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% - */ - -package org.nuiton.topia.persistence.util; - -import org.nuiton.topia.TopiaException; - -import java.util.Collection; - -/** - * A simple contract to allow you to update some collections of an entity. - * <p/> - * The purpose of the contract is to make possible (via a StorageService for example) some - * automatic and generic behaviour when you want to set a collection of childs into a entity. - * - * @author tchemit <chemit@codelutin.com> - * @param <P> the type of the entity which contains the collection to update. - * @param <E> the type of entities in the collection. - */ -public interface ListUpdator<P, E> { - - /** - * Obtain the name of the property containing childs. - * - * @return the name of the property containing childs. - */ - String getPropertyName(); - - /** - * Obtain a child from the entity given his id. - * - * @param parent the entity to query - * @param topiaId the id of the researched child entity. - * @return the child entity or <code>null</code>, if not found. - */ - - E getChild(P parent, String topiaId); - - /** - * Obtain the collection of childs from the entity. - * - * @param parent the entity to query. - * @return the collection of childs - */ - Collection<E> getChilds(P parent); - - /** - * Obtain the number of childs for the given parent. - * - * @param parent the entity to query - * @return the number of childs for the given entity - */ - int size(P parent); - - /** - * Tests if the given entity has some childs. - * - * @param parent the entity to query - * @return {@code true} is the given parent has no child. - */ - boolean isEmpty(P parent); - - /** - * Set the childs of an entity - * - * @param parent the entity to be setted - * @param childs the collection of childs to set. - */ - void setChilds(P parent, Collection<E> childs); - - /** - * Add a erntity to his parent - * - * @param parent the entity to modifiy - * @param e the entity to add in parent. - * @throws TopiaException if any db problem while operation - */ - void addToList(P parent, E e) throws TopiaException; - - /** - * Remove from a prent entity a given child. - * - * @param parent the entity to modifiy - * @param e the child to remove. - * @throws TopiaException if any pb while operation. - */ - void removeFromList(P parent, E e) throws TopiaException; - - /** - * Remove all childs of the given parent. - * - * @param parent the entity to modify - */ - void removeAll(P parent); -} Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -1,74 +0,0 @@ -/* - * #%L - * ToPIA :: Persistence - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 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% - */ - -package org.nuiton.topia.persistence.util; - -import java.io.Serializable; -import java.util.Map; - -/** - * A simple contract to load an object from another one. - * - * @author tchemit <chemit@codelutin.com> - * @param <E> type of bean to load - */ -public interface Loador<E> extends Serializable { - - /** - * Obtains the type of the entity. - * - * @return the type of entity - */ - Class<E> getSourceType(); - - /** - * Obtain from an entity all data to bind to another one according the - * definition of the loador. - * <p/> - * This method is usefull when you can not directly used the - * {@link #load(Object, Object, boolean, String...)} method. - * <p/> - * For example, when an entity has a immutable business key (says with an - * hibernate naturalId for example), - * and that you want to create the data in a db, you must give all the - * properties at the create time so this method allow you to do it). - * - * @param from the entity to bind - * @param propertyNames subset of properties to load - * @return the map of properties to bind from the given entity. - */ - Map<String, Object> obtainProperties(E from, String... propertyNames); - - /** - * Bind an entity to another. - * - * @param from the source entity - * @param dst the destination entity - * @param tech a flag to bind or not the technical values of the entity - * (says TopiaId, TopiaVersion and TopiaCreateDate). - * @param propertyNames subset of properties to load - */ - void load(E from, E dst, boolean tech, String... propertyNames); -} Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -26,6 +26,7 @@ package org.nuiton.topia.persistence.util; import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.legacy.Loador; import org.nuiton.util.beans.Binder; /** Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -28,19 +28,13 @@ import com.google.common.base.Preconditions; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; -import org.nuiton.topia.TopiaReplicationSupport; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.topia.persistence.TopiaDao; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityEnum; -import org.nuiton.util.FileUtil; +import org.nuiton.topia.persistence.legacy.Collector; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.net.URI; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaH2Util.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaH2Util.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaH2Util.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -29,13 +29,11 @@ import java.io.InputStream; import java.util.zip.GZIPInputStream; -import javax.persistence.Query; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; +import org.nuiton.topia.persistence.support.TopiaSqlSupport; +import org.nuiton.topia.persistence.internal.support.TopiaFiresSupport; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; -import org.nuiton.topia.TopiaSqlSupport; -import org.nuiton.topia.framework.TopiaFiresSupport; - /** * @author Arnaud Thimel <thimel@codelutin.com> */ Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaUtil.java (from rev 2939, trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaUtil.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaUtil.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaUtil.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -0,0 +1,579 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2013 CodeLutin, Chatellier Eric + * %% + * 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% + */ +package org.nuiton.topia.persistence.util; + +import com.google.common.base.Preconditions; +import com.google.common.base.Supplier; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.cfg.Configuration; +import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.mapping.Table; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.service.ServiceRegistryBuilder; +import org.hibernate.service.jdbc.connections.spi.ConnectionProvider; +import org.hibernate.service.spi.ServiceRegistryImplementor; +import org.hibernate.tool.hbm2ddl.DatabaseMetadata; +import org.hibernate.tool.hbm2ddl.TableMetadata; +import org.nuiton.topia.persistence.TopiaContextFactory; +import org.nuiton.topia.persistence.support.TopiaHibernateSupport; +import org.nuiton.topia.persistence.TopiaNotFoundException; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.util.RecursiveProperties; +import org.nuiton.util.Resource; + +import java.io.Closeable; +import java.io.IOException; +import java.net.URL; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Properties; +import java.util.StringTokenizer; +import java.util.regex.Pattern; + +/** + * TODO-fdesbois-20100507 : Need javadoc + translations for existing methods. + * + * @author bpoussin <poussin@codelutin.com> + * @author tchemit <chemit@codelutin.com> + * @version $Id$ + */ +public class TopiaUtil { + + private static final Log log = LogFactory.getLog(TopiaUtil.class); + + /** + * Permet de récupérer le fichier de propriété ayant le nom passé en + * argument. + * + * @param pathOrUrl le nom du fichier de propriété à charger, s'il est null + * ou vide retourne un objet Properties vide. + * @return Un nouvel objet de propriete + * @throws TopiaNotFoundException Si pathOrUrl n'est pas null ou vide et que + * le fichier devant contenir les propriétés + * n'est pas retrouvé. + */ + public static Properties getProperties(String pathOrUrl) + throws TopiaNotFoundException { + return getProperties(null, pathOrUrl); + } + + /** + * Permet de récupérer le fichier de propriété ayant le nom passé en + * argument. + * + * @param parent l'objet properties utilisé comme parent de l'objet + * retourné + * @param pathOrUrl le nom du fichier de propriété à charger, s'il est null + * ou vide retourne un objet Properties vide. + * @return Un nouvel objet de propriete + * @throws TopiaNotFoundException Si pathOrUrl n'est pas null ou vide et que + * le fichier devant contenir les propriétés + * n'est pas retrouvé. + */ + public static Properties getProperties(Properties parent, String pathOrUrl) + throws TopiaNotFoundException { + Properties result = new RecursiveProperties(parent); + + // load properties for helper + if (pathOrUrl != null && !pathOrUrl.equals("")) { + try { + URL propURL = Resource.getURL(pathOrUrl); + log.info("Properties file used for " + pathOrUrl + " is: " + propURL); + result.load(propURL.openStream()); + } catch (Exception eee) { + throw new TopiaNotFoundException( + "Properties file can't be found: " + pathOrUrl, eee); + } + } + return result; + } + + /** + * Compute a regex pattern given a format string. + * <p/> + * A {@link String#format(String, Object...)} will be apply to + * <code>format</code>, with for parameters the list of <code>klass</code> + * transformed in topia pattern via method {@link #getTopiaIdPattern(Class)} + * ready to be capture (enclosed by ()). + * + * @param format the format + * @param classes the list of class to use + * @return the pattern computed + */ + public static Pattern getTopiaPattern(String format, + Class<? extends TopiaEntity>... classes) { + String[] entityPatterns = new String[classes.length]; + for (int i = 0; i < classes.length; i++) { + Class<? extends TopiaEntity> aClass = classes[i]; + entityPatterns[i] = "(" + getTopiaIdPattern(aClass) + ")"; + } + String s = String.format(format, (Object[]) entityPatterns); + if (log.isDebugEnabled()) { + log.debug(s); + } + return Pattern.compile(s); + } + + /** + * Compute the pattern to be used to capture a topia id for a given entity + * class. + * + * @param klass the entity class + * @return the pattern to capture a topia id for the given entity class. + */ + public static String getTopiaIdPattern(Class<? extends TopiaEntity> klass) { + StringBuilder buffer = new StringBuilder(); + StringTokenizer stk = new StringTokenizer(klass.getName(), "."); + while (stk.hasMoreTokens()) { + buffer.append("\\.").append(stk.nextToken()); + } + buffer.append("#(?:\\d+?)#(?:\\d+)\\.(?:\\d+)"); + return buffer.substring(2); + } + + /** + * Test si une entite donnee correspondant a une configuration existe en + * base. + * + * @param topiaHibernateSupport the Hibernate support required for this operation + * @param entityName le nom de l'entite a tester + * @return <tt>true</tt> si le schema de la table existe + * @since 2.6.4 + */ + public static boolean isSchemaExist(TopiaHibernateSupport topiaHibernateSupport, + String entityName) { + + SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) topiaHibernateSupport.getHibernateFactory(); + ServiceRegistryImplementor serviceRegistry = sessionFactoryImplementor.getServiceRegistry(); + ConnectionProviderSupplier connectionProviderSupplier = new ConnectionProviderSupplier(serviceRegistry); + + // TODO AThimel 18/12/13 Check this code compatibility with Hibernate 4.3.0.Final +// SessionFactory sessionFactory = topiaHibernateSupport.getHibernateFactory(); +// SessionFactory.SessionFactoryOptions sessionFactoryOptions = sessionFactory.getSessionFactoryOptions(); +// StandardServiceRegistry standardServiceRegistry = sessionFactoryOptions.getServiceRegistry(); +// ConnectionProviderSupplier connectionProviderSupplier = new ConnectionProviderSupplier(standardServiceRegistry); + + boolean exist = false; + + try { + + Configuration configuration = topiaHibernateSupport.getHibernateConfiguration(); + PersistentClass classMapping = + configuration.getClassMapping(entityName); + if (classMapping == null) { + if (log.isInfoEnabled()) { + Iterator<?> itr = configuration.getClassMappings(); + while (itr.hasNext()) { + log.info("available mapping " + itr.next()); + } + } + throw new IllegalArgumentException( + "could not find entity with name " + entityName); + } + Table testTable = classMapping.getTable(); + + if (testTable == null) { + throw new IllegalArgumentException( + "could not find entity with name " + entityName); + } + + ConnectionProvider connectionProvider = + connectionProviderSupplier.get(); + + Dialect dialect = Dialect.getDialect(configuration.getProperties()); + + Connection connection = null; + try { + connection = connectionProvider.getConnection(); + + DatabaseMetadata meta = new DatabaseMetadata(connection, dialect, configuration); + + TableMetadata tmd = meta.getTableMetadata( + testTable.getName(), testTable.getSchema(), + testTable.getCatalog(), testTable.isQuoted()); + + if (tmd != null) { + //table exist + exist = true; + } + } finally { + connectionProvider.closeConnection(connection); + } + + } catch (SQLException e) { + log.error("Cant connect to database", e); + } catch (TopiaNotFoundException e) { + log.error("Cant connect to database", e); + } + + return exist; + } + + /** + * Test si une entite donnee correspondant a une configuration existe en + * base. + * + * @param configuration la configuration hibernate + * @param entityName le nom de l'entite a tester + * @return <tt>true</tt> si le schema de la table existe + */ + public static boolean isSchemaExist(Configuration configuration, + String entityName) { + + ConnectionProviderSupplier connectionProviderSupplier = + new ConnectionProviderSupplier(configuration); + + boolean exist = false; + + try { + PersistentClass classMapping = + configuration.getClassMapping(entityName); + if (classMapping == null) { + if (log.isInfoEnabled()) { + Iterator<?> itr = configuration.getClassMappings(); + while (itr.hasNext()) { + log.info("available mapping " + itr.next()); + } + } + throw new IllegalArgumentException( + "could not find entity with name " + entityName); + } + Table testTable = classMapping.getTable(); + + if (testTable == null) { + throw new IllegalArgumentException( + "could not find entity with name " + entityName); + } + + ConnectionProvider connectionProvider = + connectionProviderSupplier.get(); + + Dialect dialect = Dialect.getDialect(configuration.getProperties()); + + Connection connection = null; + try { + connection = connectionProvider.getConnection(); + + DatabaseMetadata meta = new DatabaseMetadata(connection, dialect, configuration); + + TableMetadata tmd = meta.getTableMetadata( + testTable.getName(), testTable.getSchema(), + testTable.getCatalog(), testTable.isQuoted()); + + if (tmd != null) { + //table exist + exist = true; + } + } finally { + connectionProvider.closeConnection(connection); + } + + } catch (SQLException e) { + log.error("Cant connect to database", e); + } + + // close connectionProviderSupplier + try { + connectionProviderSupplier.close(); + } catch (IOException e) { + log.error("Cant close connection provider", e); + } + + return exist; + } + + /** + * Test if the db associated to the given {@code configuration} contaisn any of + * the dealed entities. + * + * @param configuration hibernate db configuration + * @return {@code true} if there is no schema for any of the dealed entities, + * {@code false} otherwise. + * @since 2.5.3 + */ + public static boolean isSchemaEmpty(Configuration configuration) { + + ConnectionProviderSupplier connectionProviderSupplier = + new ConnectionProviderSupplier(configuration); + + try { + + ConnectionProvider connectionProvider = + connectionProviderSupplier.get(); + + Dialect dialect = Dialect.getDialect(configuration.getProperties()); + + Connection connection = null; + try { + connection = connectionProvider.getConnection(); + + DatabaseMetadata meta = new DatabaseMetadata(connection, dialect, configuration); + + Iterator<?> itr = configuration.getClassMappings(); + while (itr.hasNext()) { + PersistentClass classMapping = (PersistentClass) itr.next(); + Table testTable = classMapping.getTable(); + + if (testTable == null) { + throw new IllegalArgumentException( + "could not find entity with name " + + classMapping.getClassName()); + } + + + TableMetadata tmd = meta.getTableMetadata( + testTable.getName(), testTable.getSchema(), + testTable.getCatalog(), testTable.isQuoted()); + + if (tmd != null) { + //table exist + + + if (log.isDebugEnabled()) { + log.debug("Existing table found " + + testTable.getName() + " for entity " + + classMapping.getClassName() + + ", db is not empty."); + } + + return false; + } + } + + } finally { + connectionProvider.closeConnection(connection); + } + + } catch (SQLException e) { + log.error("Cant connect to database", e); + } + + // close connectionProviderSupplier + try { + connectionProviderSupplier.close(); + } catch (IOException e) { + log.error("Cant close connection provider", e); + } + + return true; + } + + /** + * Test if the db associated to the given {@code configuration} contains any of + * the dealed entities. + * + * @param topiaHibernateSupport the Hibernate support required for this operation + * @return {@code true} if there is no schema for any of the dealed entities, + * {@code false} otherwise. + * @since 2.5.3 + */ + public static boolean isSchemaEmpty(TopiaHibernateSupport topiaHibernateSupport) { + + Configuration configuration = topiaHibernateSupport.getHibernateConfiguration(); + + SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) topiaHibernateSupport.getHibernateFactory(); + ServiceRegistryImplementor serviceRegistry = sessionFactoryImplementor.getServiceRegistry(); + ConnectionProviderSupplier connectionProviderSupplier = new ConnectionProviderSupplier(serviceRegistry); + + // TODO AThimel 18/12/13 Check this code compatibility with Hibernate 4.3.0.Final +// SessionFactory sessionFactory = topiaHibernateSupport.getHibernateFactory(); +// SessionFactory.SessionFactoryOptions sessionFactoryOptions = sessionFactory.getSessionFactoryOptions(); +// StandardServiceRegistry standardServiceRegistry = sessionFactoryOptions.getServiceRegistry(); +// ConnectionProviderSupplier connectionProviderSupplier = new ConnectionProviderSupplier(standardServiceRegistry); + + try { + + ConnectionProvider connectionProvider = + connectionProviderSupplier.get(); + + Dialect dialect = Dialect.getDialect(configuration.getProperties()); + + Connection connection = null; + try { + connection = connectionProvider.getConnection(); + + DatabaseMetadata meta = new DatabaseMetadata(connection, dialect, configuration); + + Iterator<?> itr = configuration.getClassMappings(); + while (itr.hasNext()) { + PersistentClass classMapping = (PersistentClass) itr.next(); + Table testTable = classMapping.getTable(); + + if (testTable == null) { + throw new IllegalArgumentException( + "could not find entity with name " + + classMapping.getClassName()); + } + + + TableMetadata tmd = meta.getTableMetadata( + testTable.getName(), testTable.getSchema(), + testTable.getCatalog(), testTable.isQuoted()); + + if (tmd != null) { + //table exist + + if (log.isDebugEnabled()) { + log.debug("Existing table found " + + testTable.getName() + " for entity " + + classMapping.getClassName() + + ", db is not empty."); + } + + return false; + } + } + + } finally { + connectionProvider.closeConnection(connection); + } + + } catch (SQLException e) { + log.error("Cant connect to database", e); + } + + // close connectionProviderSupplier + try { + connectionProviderSupplier.close(); + } catch (IOException e) { + log.error("Cant close connection provider", e); + } + + return true; + } + + /** + * @param configuration + * @return + * @deprecated since 3.0, will be remove soon, do not use it, prefer use {@link ConnectionProviderSupplier}. + */ + @Deprecated + protected static ConnectionProvider getConnectionProvider(Configuration configuration) { + Properties properties = configuration.getProperties(); + ServiceRegistryBuilder builder = new ServiceRegistryBuilder().applySettings(properties); + ServiceRegistry serviceRegistry = builder.buildServiceRegistry(); + ConnectionProvider result = serviceRegistry.getService(ConnectionProvider.class); + + // TODO AThimel 18/12/13 Check this code compatibility with Hibernate 4.3.0.Final +// StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder(); +// Properties properties = configuration.getProperties(); +// StandardServiceRegistry standardServiceRegistry = builder.applySettings(properties).build(); +// ConnectionProvider result = standardServiceRegistry.getService(ConnectionProvider.class); + return result; + } + + /** + * Return hibernate schema name + * + * @param config of hibernate + * @return schema name + */ + public static String getSchemaName(Configuration config) { + return config.getProperty(TopiaContextFactory.CONFIG_DEFAULT_SCHEMA); + } + + public static Map<String, Object> convertPropertiesArrayToMap(Object... propertyNamesAndValues) throws IllegalArgumentException { + int propertiesLength = propertyNamesAndValues.length; + Preconditions.checkArgument(propertiesLength % 2 == 0, + "Wrong number of argument " + + propertiesLength + + ", you must have even number."); + Map<String, Object> properties = new LinkedHashMap<String, Object>(); + for (int i = 0; i < propertyNamesAndValues.length; ) { + Object aPropertyName = propertyNamesAndValues[i++]; + Object value = propertyNamesAndValues[i++]; + Preconditions.checkArgument( + aPropertyName instanceof String, + "Argument at position [" + (i - 1) + "] " + + "should be a property name (says a String) but was " + + aPropertyName); + properties.put((String) aPropertyName, value); + } + return properties; + } + + public static Map<String, Object> convertPropertiesArrayToMap( + String propertyName, Object propertyValue, Object... otherPropertyNamesAndValues) throws IllegalArgumentException { + Map<String, Object> properties = new HashMap<String, Object>(); + properties.put(propertyName, propertyValue); + properties.putAll(convertPropertiesArrayToMap(otherPropertyNamesAndValues)); + return properties; + } + + public static class ConnectionProviderSupplier implements Supplier<ConnectionProvider>, Closeable { + + protected ServiceRegistry serviceRegistry; + + // TODO AThimel 18/12/13 Check this code compatibility with Hibernate 4.3.0.Final +// protected StandardServiceRegistry standardServiceRegistry; + + protected ConnectionProvider connectionProvider; + + protected final boolean inlineRegistry; + + public ConnectionProviderSupplier(ServiceRegistry standardServiceRegistry) { + inlineRegistry = false; + this.serviceRegistry = standardServiceRegistry; + } + + public ConnectionProviderSupplier(Configuration configuration) { + inlineRegistry = true; + + Properties properties = configuration.getProperties(); + ServiceRegistryBuilder builder = new ServiceRegistryBuilder().applySettings(properties); + this.serviceRegistry = builder.buildServiceRegistry(); + + // TODO AThimel 18/12/13 Check this code compatibility with Hibernate 4.3.0.Final +// StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder(); +// Properties properties = configuration.getProperties(); +// this.standardServiceRegistry = builder.applySettings(properties).build(); + + } + + @Override + public ConnectionProvider get() { + if (connectionProvider == null) { + connectionProvider = serviceRegistry.getService(ConnectionProvider.class); + } + return connectionProvider; + } + + @Override + public void close() throws IOException { + if (inlineRegistry) { + ServiceRegistryBuilder.destroy(serviceRegistry); + // TODO AThimel 18/12/13 Check this code compatibility with Hibernate 4.3.0.Final +// StandardServiceRegistryBuilder.destroy(standardServiceRegistry); + } + } + } +} Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java =================================================================== --- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -26,10 +26,10 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.AbstractTopiaApplicationContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; -import org.nuiton.topia.TopiaSqlSupport; +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; +import org.nuiton.topia.persistence.support.TopiaSqlSupport; import org.nuiton.util.StringUtil; import org.nuiton.util.Version; @@ -94,7 +94,7 @@ * ggrement * @return {@code true} si la migration est accepté, {@code false} autrement. */ - public boolean doMigration(AbstractTopiaApplicationContext<PersistenceContext> applicationContext, + public boolean doMigration(TopiaApplicationContext<PersistenceContext> applicationContext, Version dbVersion, boolean showSql, boolean showProgression, Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByClass.java =================================================================== --- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByClass.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByClass.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -24,10 +24,10 @@ */ package org.nuiton.topia.migration; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaHibernateSupport; -import org.nuiton.topia.TopiaPersistenceContext; -import org.nuiton.topia.TopiaSqlSupport; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.support.TopiaHibernateSupport; +import org.nuiton.topia.persistence.TopiaPersistenceContext; +import org.nuiton.topia.persistence.support.TopiaSqlSupport; import org.nuiton.util.ObjectUtil; import org.nuiton.util.Version; Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByClassNG.java =================================================================== --- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByClassNG.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByClassNG.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -26,8 +26,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.util.Version; import org.nuiton.util.VersionUtil; Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByMethod.java =================================================================== --- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByMethod.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByMethod.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -26,9 +26,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaHibernateSupport; -import org.nuiton.topia.TopiaPersistenceContext; -import org.nuiton.topia.TopiaSqlSupport; +import org.nuiton.topia.persistence.support.TopiaHibernateSupport; +import org.nuiton.topia.persistence.TopiaPersistenceContext; +import org.nuiton.topia.persistence.support.TopiaSqlSupport; import org.nuiton.util.Version; import java.lang.reflect.Method; Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java =================================================================== --- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -32,19 +32,20 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.cfg.Configuration; -import org.nuiton.topia.AbstractTopiaApplicationContext; -import org.nuiton.topia.AbstractTopiaPersistenceContext; +import org.nuiton.topia.persistence.internal.AbstractTopiaApplicationContext; +import org.nuiton.topia.persistence.internal.AbstractTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaApplicationContext; import org.nuiton.topia.persistence.HibernateProvider; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaHibernateSupport; -import org.nuiton.topia.TopiaNotFoundException; -import org.nuiton.topia.TopiaPersistenceContext; -import org.nuiton.topia.event.TopiaContextAdapter; -import org.nuiton.topia.event.TopiaContextEvent; -import org.nuiton.topia.event.TopiaSchemaListener; -import org.nuiton.topia.event.TopiaTransactionEvent; -import org.nuiton.topia.event.TopiaTransactionVetoable; -import org.nuiton.topia.framework.TopiaUtil; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.support.TopiaHibernateSupport; +import org.nuiton.topia.persistence.TopiaNotFoundException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; +import org.nuiton.topia.persistence.event.TopiaContextAdapter; +import org.nuiton.topia.persistence.event.TopiaContextEvent; +import org.nuiton.topia.persistence.event.TopiaSchemaListener; +import org.nuiton.topia.persistence.event.TopiaTransactionEvent; +import org.nuiton.topia.persistence.event.TopiaTransactionVetoable; +import org.nuiton.topia.persistence.util.TopiaUtil; import org.nuiton.topia.migration.mappings.TMSVersion; import org.nuiton.topia.migration.mappings.TMSVersionDAO; import org.nuiton.util.Version; @@ -273,7 +274,7 @@ } @Override - public boolean postInit(AbstractTopiaApplicationContext context) { + public boolean postInit(TopiaApplicationContext context) { // nothing to do in post-init return true; } Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationService.java =================================================================== --- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationService.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationService.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -25,7 +25,7 @@ package org.nuiton.topia.migration; -import org.nuiton.topia.framework.TopiaService; +import org.nuiton.topia.persistence.TopiaService; /** * TopiaMigrationService.java Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersionDAO.java =================================================================== --- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersionDAO.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersionDAO.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -32,9 +32,9 @@ import org.hibernate.cfg.Configuration; import org.hibernate.jdbc.Work; import org.hibernate.tool.hbm2ddl.SchemaExport; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaHibernateSupport; -import org.nuiton.topia.framework.TopiaUtil; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.support.TopiaHibernateSupport; +import org.nuiton.topia.persistence.util.TopiaUtil; import org.nuiton.util.Version; import org.nuiton.util.VersionUtil; Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationContext.java =================================================================== --- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationContext.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationContext.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -26,11 +26,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.AbstractTopiaApplicationContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; -import org.nuiton.topia.TopiaReplicationDestination; -import org.nuiton.topia.TopiaReplicationSupport; +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityEnum; import org.nuiton.topia.persistence.util.TopiaEntityHelper; @@ -70,13 +68,13 @@ * root context of incoming data source (says where to obtain entities * to replicate). */ - protected final AbstractTopiaApplicationContext sourceTx; + protected final TopiaApplicationContext sourceTx; /** * root context of outcmoing data source (says where to replicate * entities). */ - protected final AbstractTopiaApplicationContext targetTx; + protected final TopiaApplicationContext targetTx; /** dictionnary of data to replicate. */ protected TopiaEntityIdsMap data; @@ -91,8 +89,8 @@ public TopiaReplicationContext(TopiaReplicationOperationProvider operationProvider, ReplicationModel replicationModel, - AbstractTopiaApplicationContext sourceTx, - AbstractTopiaApplicationContext targetTx) { + TopiaApplicationContext sourceTx, + TopiaApplicationContext targetTx) { this.operationProvider = operationProvider; this.replicationModel = replicationModel; this.sourceTx = sourceTx; @@ -259,11 +257,11 @@ return treated; } - protected AbstractTopiaApplicationContext getSourceTx() { + protected TopiaApplicationContext getSourceTx() { return sourceTx; } - protected AbstractTopiaApplicationContext getTargetTx() { + protected TopiaApplicationContext getTargetTx() { return targetTx; } Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationModelBuilder.java =================================================================== --- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationModelBuilder.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationModelBuilder.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -26,9 +26,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.AbstractTopiaApplicationContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityEnum; import org.nuiton.topia.persistence.util.TopiaEntityHelper; @@ -80,7 +80,7 @@ * @return le modele pour la replication * @throws TopiaException pour toute erreur rencontree */ - public ReplicationModel prepare(AbstractTopiaApplicationContext context, + public ReplicationModel prepare(TopiaApplicationContext context, TopiaEntityEnum[] contracts, boolean computeOrder, String... topiaIds) throws TopiaException { @@ -205,7 +205,7 @@ * @return le modèle crée mais non initialisé. * @throws TopiaException pour toute erreur lors de la création du modèle */ - public ReplicationModel createModel(AbstractTopiaApplicationContext context, + public ReplicationModel createModel(TopiaApplicationContext context, TopiaEntityEnum[] contracts, boolean computeOrder, String... topiaIds) @@ -255,7 +255,7 @@ return model; } - protected Set<Class<? extends TopiaEntity>> detectTypes(AbstractTopiaApplicationContext context, + protected Set<Class<? extends TopiaEntity>> detectTypes(TopiaApplicationContext context, TopiaEntityEnum[] contracts, String... ids) throws TopiaException { Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationOperation.java =================================================================== --- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationOperation.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationOperation.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -25,10 +25,7 @@ package org.nuiton.topia.replication; -import org.nuiton.topia.TopiaPersistenceContext; -import org.nuiton.topia.TopiaReplicationDestination; -import org.nuiton.topia.TopiaReplicationSupport; -import org.nuiton.topia.TopiaTransaction; +import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityEnum; import org.nuiton.topia.replication.model.ReplicationModel; Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationOperationUndoable.java =================================================================== --- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationOperationUndoable.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationOperationUndoable.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -25,7 +25,7 @@ package org.nuiton.topia.replication; -import org.nuiton.topia.TopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.topia.replication.model.ReplicationOperationDef; /** Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationService.java =================================================================== --- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationService.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationService.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -24,10 +24,9 @@ */ package org.nuiton.topia.replication; -import org.nuiton.topia.AbstractTopiaApplicationContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; -import org.nuiton.topia.framework.TopiaService; +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaService; import org.nuiton.topia.persistence.TopiaEntityEnum; import org.nuiton.topia.replication.model.ReplicationModel; @@ -43,7 +42,7 @@ * <li> - prepare the replication model - ({@link #prepare(TopiaEntityEnum[], boolean, String...)} - ({@link #prepareForAll(TopiaEntityEnum[])} * <p/> * <li> - lanch replication {@link #doReplicate(ReplicationModel, - * AbstractTopiaApplicationContext)} + * TopiaApplicationContext)} * * @author tchemit <chemit@codelutin.com> * @since 2.2.0 @@ -113,7 +112,7 @@ * @throws Exception pour toute erreur pendant la replication */ void doReplicate(ReplicationModel model, - AbstractTopiaApplicationContext dstCtxt) throws Exception; + TopiaApplicationContext dstCtxt) throws Exception; /** * Pour revenir en arrière lorsque la réplication a échouée . Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationServiceImpl.java =================================================================== --- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationServiceImpl.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationServiceImpl.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -27,11 +27,10 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.AbstractTopiaApplicationContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; -import org.nuiton.topia.TopiaReplicationDestination; -import org.nuiton.topia.TopiaReplicationSupport; +import org.nuiton.topia.persistence.internal.AbstractTopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityEnum; import org.nuiton.topia.persistence.util.TopiaEntityHelper; @@ -54,7 +53,7 @@ LogFactory.getLog(TopiaReplicationServiceImpl.class); /** le contexte sur la base source de la replication */ - protected AbstractTopiaApplicationContext context; + protected TopiaApplicationContext context; /** * le constructeur de modèle de réplication. @@ -85,7 +84,7 @@ } @Override - public boolean postInit(AbstractTopiaApplicationContext context) { + public boolean postInit(TopiaApplicationContext context) { // set the incoming root context from topia this.context = context; //TODO avoir un objet pour lire les contrainte de resolution de cycle @@ -128,7 +127,7 @@ @Override public void doReplicate(ReplicationModel model, - AbstractTopiaApplicationContext targetTx) throws Exception { + TopiaApplicationContext targetTx) throws Exception { TopiaEntityHelper.checkNotNull("doReplicate", "model", model); TopiaEntityHelper.checkNotNull("doReplicate", "dstCtxt", targetTx); Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/model/ReplicationModel.java =================================================================== --- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/model/ReplicationModel.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/model/ReplicationModel.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -28,7 +28,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityEnum; import org.nuiton.topia.persistence.util.EntityOperator; Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachLink.java =================================================================== --- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachLink.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachLink.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -31,8 +31,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.EntityOperator; import org.nuiton.topia.persistence.util.TopiaEntityHelper; Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/DettachAssociation.java =================================================================== --- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/DettachAssociation.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/DettachAssociation.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -29,8 +29,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.EntityOperator; import org.nuiton.topia.replication.TopiaReplicationContext; Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/Duplicate.java =================================================================== --- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/Duplicate.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/Duplicate.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -28,9 +28,9 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.AbstractTopiaPersistenceContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; +import org.nuiton.topia.persistence.internal.AbstractTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.topia.persistence.TopiaDao; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.replication.TopiaReplicationContext; Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/LoadLink.java =================================================================== --- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/LoadLink.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/LoadLink.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -27,8 +27,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.EntityOperator; import org.nuiton.topia.replication.TopiaReplicationContext; Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -27,10 +27,10 @@ import org.apache.commons.logging.Log; import org.junit.Assert; -import org.nuiton.topia.AbstractTopiaApplicationContext; -import org.nuiton.topia.TopiaDaoSupplier; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaDaoSupplier; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.topia.it.legacy.TopiaTestTopiaApplicationContext; import org.nuiton.topia.persistence.TopiaDao; import org.nuiton.topia.persistence.TopiaEntity; @@ -66,11 +66,11 @@ */ public abstract class AbstractTopiaReplicationServiceTest extends Assert { - protected static AbstractTopiaApplicationContext sourceContext; + protected static TopiaApplicationContext sourceContext; protected static TopiaPersistenceContext sourcePC; - protected AbstractTopiaApplicationContext destinationContext; + protected TopiaApplicationContext destinationContext; protected TopiaReplicationService service; @@ -84,9 +84,9 @@ private static final String TEST_BASEDIR = "target%1$ssurefire-tests%1$s%2$td_%2$tm_%2$tY%1$s%2$tH_%2$tM_%2$tS"; - protected static final Function<Properties,AbstractTopiaApplicationContext> CREATE_TOPIA_TEST_APPLICATION_CONTEXT = new Function<Properties, AbstractTopiaApplicationContext>() { + protected static final Function<Properties,TopiaApplicationContext> CREATE_TOPIA_TEST_APPLICATION_CONTEXT = new Function<Properties, TopiaApplicationContext>() { @Override - public AbstractTopiaApplicationContext apply(Properties input) { + public TopiaApplicationContext apply(Properties input) { return new TopiaTestTopiaApplicationContext(input); } }; @@ -130,12 +130,12 @@ return service.getModelBuilder(); } - protected abstract AbstractTopiaApplicationContext createDb2(String name) throws Exception; + protected abstract TopiaApplicationContext createDb2(String name) throws Exception; - protected abstract AbstractTopiaApplicationContext createDb(String name) throws Exception; + protected abstract TopiaApplicationContext createDb(String name) throws Exception; - protected AbstractTopiaApplicationContext createReplicateDb(Object contract) throws Exception { - AbstractTopiaApplicationContext rootCtxt = createDb2(contract.toString() + dbCounter++); + protected TopiaApplicationContext createReplicateDb(Object contract) throws Exception { + TopiaApplicationContext rootCtxt = createDb2(contract.toString() + dbCounter++); return rootCtxt; } @@ -410,7 +410,7 @@ protected void doReplicate(TopiaEntityEnum contract, TopiaEntity... entity) throws Exception { - AbstractTopiaApplicationContext rootCtxt = createReplicateDb("doReplicate_" + contract); + TopiaApplicationContext rootCtxt = createReplicateDb("doReplicate_" + contract); List<String> ids = TopiaEntityHelper.getTopiaIdList(Arrays.asList(entity)); getLog().info("entity " + ids); @@ -442,7 +442,7 @@ protected void doReplicateAll() throws Exception { - AbstractTopiaApplicationContext rootCtxt = createReplicateDb("doReplicateAll"); + TopiaApplicationContext rootCtxt = createReplicateDb("doReplicateAll"); prepareModelAll(); @@ -461,7 +461,7 @@ protected void doReplicateWithComputedOrder(TopiaEntity... entity) throws Exception { - AbstractTopiaApplicationContext rootCtxt = createReplicateDb("doReplicateWithComputedOrder"); + TopiaApplicationContext rootCtxt = createReplicateDb("doReplicateWithComputedOrder"); List<String> ids = TopiaEntityHelper.getTopiaIdList(Arrays.asList(entity)); Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -32,9 +32,9 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.nuiton.topia.AbstractTopiaApplicationContext; -import org.nuiton.topia.TopiaApplicationContextCache; -import org.nuiton.topia.TopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaApplicationContextCache; +import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.topia.it.TopiaConfigurationHelper; import org.nuiton.topia.it.legacy.TopiaTestEntityEnum; import org.nuiton.topia.it.legacy.test.entities.Person; @@ -279,7 +279,7 @@ } @Override - protected AbstractTopiaApplicationContext createDb(String name) throws Exception { + protected TopiaApplicationContext createDb(String name) throws Exception { // File localDB = new File(getTestDir(getClass()), "db_" + name); @@ -332,7 +332,7 @@ } @Override - protected AbstractTopiaApplicationContext createDb2(String name) throws Exception { + protected TopiaApplicationContext createDb2(String name) throws Exception { throw new UnsupportedOperationException("Not supported yet."); } Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -32,10 +32,10 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.nuiton.topia.AbstractTopiaApplicationContext; -import org.nuiton.topia.TopiaApplicationContextCache; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaApplicationContextCache; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.topia.it.TopiaConfigurationHelper; import org.nuiton.topia.it.legacy.TopiaTestEntityEnum; import org.nuiton.topia.it.legacy.test.entities.Person; @@ -226,7 +226,7 @@ } @Override - protected AbstractTopiaApplicationContext createDb(String name) throws Exception { + protected TopiaApplicationContext createDb(String name) throws Exception { // File localDB = new File(getTestDir(getClass()), "db_" + name); @@ -253,7 +253,7 @@ } @Override - protected AbstractTopiaApplicationContext createDb2(String name) throws Exception { + protected TopiaApplicationContext createDb2(String name) throws Exception { // File localDB = new File(getTestDir(getClass()), "db_" + name); Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -32,10 +32,10 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.nuiton.topia.AbstractTopiaApplicationContext; -import org.nuiton.topia.TopiaApplicationContextCache; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaApplicationContextCache; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.topia.it.TopiaConfigurationHelper; import org.nuiton.topia.it.legacy.TopiaTestEntityEnum; import org.nuiton.topia.it.legacy.test.entities.Person; @@ -261,7 +261,7 @@ @Test(expected = TopiaException.class) public void testSimpleReplicateFailed() throws Exception { - AbstractTopiaApplicationContext dstRootCtxt = createDb2("testSimpleReplicateFailed"); + TopiaApplicationContext dstRootCtxt = createDb2("testSimpleReplicateFailed"); //model = service.prepare(contracts, pet.getTopiaId()); @@ -293,7 +293,7 @@ @Test public void testSimpleReplicateNotSure() throws Exception { - AbstractTopiaApplicationContext dstRootCtxt = createDb2("testSimpleReplicateNotSure"); + TopiaApplicationContext dstRootCtxt = createDb2("testSimpleReplicateNotSure"); //model = service.prepare(contracts, pet.getTopiaId()); @@ -346,7 +346,7 @@ @Test public void testSimpleReplicateSure() throws Exception { - AbstractTopiaApplicationContext dstRootCtxt = createDb2("testSimpleReplicateSure"); + TopiaApplicationContext dstRootCtxt = createDb2("testSimpleReplicateSure"); //model = service.prepare(contracts, pet.getTopiaId()); @@ -385,7 +385,7 @@ } @Override - protected AbstractTopiaApplicationContext createDb(String name) throws Exception { + protected TopiaApplicationContext createDb(String name) throws Exception { // File localDB = new File(getTestDir(getClass()), "db_" + name); @@ -412,7 +412,7 @@ } @Override - protected AbstractTopiaApplicationContext createDb2(String name) throws Exception { + protected TopiaApplicationContext createDb2(String name) throws Exception { // File localDB = new File(getTestDir(getClass()), "db_" + name); // Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/FakeOperation.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/FakeOperation.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/FakeOperation.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -25,8 +25,8 @@ package org.nuiton.topia.replication.operation; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.TopiaEntityHelper; import org.nuiton.topia.replication.TopiaReplicationContext; Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UncreatableOperation.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UncreatableOperation.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UncreatableOperation.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -25,8 +25,8 @@ package org.nuiton.topia.replication.operation; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.replication.TopiaReplicationContext; import org.nuiton.topia.replication.TopiaReplicationOperation; Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UnregistredOperation.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UnregistredOperation.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UnregistredOperation.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -25,8 +25,8 @@ package org.nuiton.topia.replication.operation; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.replication.TopiaReplicationContext; import org.nuiton.topia.replication.TopiaReplicationOperation; Modified: trunk/topia-templates/src/main/java/org/nuiton/topia/templates/ApplicationContextTransformer.java =================================================================== --- trunk/topia-templates/src/main/java/org/nuiton/topia/templates/ApplicationContextTransformer.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-templates/src/main/java/org/nuiton/topia/templates/ApplicationContextTransformer.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -33,7 +33,7 @@ import org.nuiton.eugene.models.object.ObjectModelClass; import org.nuiton.eugene.models.object.ObjectModelJavaModifier; import org.nuiton.eugene.models.object.ObjectModelOperation; -import org.nuiton.topia.AbstractTopiaApplicationContext; +import org.nuiton.topia.persistence.internal.AbstractTopiaApplicationContext; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.EntityOperator; Modified: trunk/topia-templates/src/main/java/org/nuiton/topia/templates/DAOHelperTransformer.java =================================================================== --- trunk/topia-templates/src/main/java/org/nuiton/topia/templates/DAOHelperTransformer.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-templates/src/main/java/org/nuiton/topia/templates/DAOHelperTransformer.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -34,11 +34,9 @@ import org.nuiton.eugene.models.object.ObjectModelEnumeration; import org.nuiton.eugene.models.object.ObjectModelJavaModifier; import org.nuiton.eugene.models.object.ObjectModelOperation; -import org.nuiton.eugene.models.object.ObjectModelType; import org.nuiton.eugene.models.object.xml.ObjectModelAttributeImpl; -import org.nuiton.eugene.models.object.xml.ObjectModelEnumerationImpl; -import org.nuiton.topia.TopiaDaoSupplier; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaDaoSupplier; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.TopiaDao; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityEnum; Modified: trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityDaoTransformer.java =================================================================== --- trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityDaoTransformer.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityDaoTransformer.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -46,8 +46,8 @@ import org.nuiton.eugene.models.object.ObjectModelInterface; import org.nuiton.eugene.models.object.ObjectModelJavaModifier; import org.nuiton.eugene.models.object.ObjectModelOperation; -import org.nuiton.topia.HibernateTopiaJpaSupport; -import org.nuiton.topia.TopiaHibernateSupport; +import org.nuiton.topia.persistence.internal.support.HibernateTopiaJpaSupport; +import org.nuiton.topia.persistence.support.TopiaHibernateSupport; import org.nuiton.topia.persistence.AbstractTopiaDao; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaQueryBuilderAddCriteriaOrRunQueryStep; Modified: trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityEnumTransformer.java =================================================================== --- trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityEnumTransformer.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityEnumTransformer.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -44,7 +44,7 @@ import org.nuiton.eugene.models.object.ObjectModelJavaModifier; import org.nuiton.eugene.models.object.ObjectModelOperation; import org.nuiton.eugene.models.object.xml.ObjectModelAttributeImpl; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityEnum; import org.nuiton.topia.persistence.util.EntityOperator; Modified: trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityTransformer.java =================================================================== --- trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityTransformer.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityTransformer.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -39,9 +39,8 @@ import org.nuiton.eugene.models.object.ObjectModelModifier; import org.nuiton.eugene.models.object.ObjectModelOperation; import org.nuiton.eugene.models.object.ObjectModelParameter; -import org.nuiton.topia.TopiaDaoSupplier; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.AbstractTopiaDao; +import org.nuiton.topia.persistence.TopiaDaoSupplier; +import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.EntityVisitor; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityAbstract; Modified: trunk/topia-templates/src/main/java/org/nuiton/topia/templates/PersistenceContextTransformer.java =================================================================== --- trunk/topia-templates/src/main/java/org/nuiton/topia/templates/PersistenceContextTransformer.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-templates/src/main/java/org/nuiton/topia/templates/PersistenceContextTransformer.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -33,11 +33,11 @@ import org.nuiton.eugene.models.object.ObjectModelInterface; import org.nuiton.eugene.models.object.ObjectModelJavaModifier; import org.nuiton.eugene.models.object.ObjectModelOperation; -import org.nuiton.topia.AbstractTopiaPersistenceContext; -import org.nuiton.topia.TopiaDaoSupplier; +import org.nuiton.topia.persistence.internal.AbstractTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaDaoSupplier; import org.nuiton.topia.persistence.HibernateProvider; -import org.nuiton.topia.persistence.TopiaHibernateSessionRegistry; -import org.nuiton.topia.TopiaListenableSupport; +import org.nuiton.topia.persistence.internal.TopiaHibernateSessionRegistry; +import org.nuiton.topia.persistence.support.TopiaListenableSupport; import org.nuiton.topia.persistence.TopiaIdFactory; import java.util.List; Modified: trunk/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaTagValues.java =================================================================== --- trunk/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaTagValues.java 2013-12-20 14:04:05 UTC (rev 2948) +++ trunk/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaTagValues.java 2013-12-20 14:59:42 UTC (rev 2949) @@ -30,9 +30,9 @@ import org.nuiton.eugene.models.object.ObjectModelClass; import org.nuiton.eugene.models.object.ObjectModelClassifier; import org.nuiton.eugene.models.object.ObjectModelElement; -import org.nuiton.topia.AbstractTopiaApplicationContext; -import org.nuiton.topia.AbstractTopiaPersistenceContext; -import org.nuiton.topia.TopiaDaoSupplier; +import org.nuiton.topia.persistence.internal.AbstractTopiaApplicationContext; +import org.nuiton.topia.persistence.internal.AbstractTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaDaoSupplier; import org.nuiton.topia.persistence.AbstractTopiaDao; import org.nuiton.topia.persistence.TopiaDao; import org.nuiton.topia.persistence.TopiaEntity;