Author: tchemit Date: 2008-11-17 09:39:40 +0000 (Mon, 17 Nov 2008) New Revision: 1227 Added: topia/tags/2.0.29/ topia/tags/2.0.29/changelog topia/tags/2.0.29/pom.xml topia/tags/2.0.29/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java Removed: topia/tags/2.0.29/changelog topia/tags/2.0.29/pom.xml topia/tags/2.0.29/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java Log: [maven-release-plugin] copy for tag 2.0.29 Copied: topia/tags/2.0.29 (from rev 1223, topia/trunk) Deleted: topia/tags/2.0.29/changelog =================================================================== --- topia/trunk/changelog 2008-11-14 11:16:46 UTC (rev 1223) +++ topia/tags/2.0.29/changelog 2008-11-17 09:39:40 UTC (rev 1227) @@ -1,146 +0,0 @@ -ver-2-0-28 ?? 2008?? - * 20081113 [chorlet] add support for lazy loading on attribute with 0..* multiplicity - * 20081113 [chorlet] fix bug on bidirectional association by adding inverse attribute in the one side of two hibernate mapping files - * 20081107 [chatellier] fix "result" named attribute generation in model - * 20081107 [chatellier] fix ant:ant, org.apache.ant:ant conflict - * 20081107 [chatellier] set lutingenerator provided scope - * 20081101 [chemit] bump lutingenerator to 0.61 - * 20081101 [chemit] add a EntityEnum to have a generic way to access Entities. - * 20081101 [chemit] improve generators : - - can exclude some generators on TopiaMetaGenerator - - refactor TopiaMetaGenerator to use a simple List of Generator to launch - - refactor Generators to have a default public constructor - - * 20081029 [chemit] fix infinitive recursion on method findByPrimaryKey and findByProperty in TopiaDAODeleagtor class - * 20081026 [chemit] add dbName of table if explicit in javadoc - * 20081024 [chemit] fix bug when no entity defined in model - -ver-2-0-27 chemit 20081021 - * 20081021 [chemit] clean pom, use lutingenerator 0.60 - * 20080922 [thimel] Switched to lutinproject 3.0 - * 20080922 [thimel] Sources are correctly maven2 structuted (src/main/xxx) - * 20080922 [thimel] Fixed maven-processor-plugin usage - * 20080922 [thimel] License switched to LGPL - -ver-2-0-26 thimel 20080922 - * 20080922 [thimel] Last version with lutinproject 2.2 - * 20082608 [chemit] permettre de recuperer uniquement une fenetre de resultat en hql (TopiaContext#find(String hql,int startIndex,int endIndex, Object ... args) - * 20082907 [chemit] Suppression des dependances en dur sur les implantations d'entites - * 20072012 [thimel] Support des index sur les attibuts - * 20072012 [ruchaud] Récupération des classes persistées - * 20072012 [ruchaud] Création d'un vetoable sur les finds - -ver-2-0-25 poussin 20071214 - - * 20071120 [chatellier] modify service init methods, return boolean to stay - activated - * 20071116 [chatellier] add support for topia context listeners - * 20071114 [chatellier] add support for service without persitent classes - * 20071109 [chatellier] add type="string" on topiaId in templates - - update hibernate version to 3.2.5.ga (event patch) - - jetty version 5.1.10 (better pom.xml) - * 20071001 [chatellier] move tapestry version to 5.0.5 - * 20070528 [chatellier] add stateModel generation support - - tapestry generation templates - - tapestry 5.0.4 dependency - - * 20071106 [poussin] add removeContext on TopiaContextFactory and call it - in TopiaContextImpl.closeContext(). - - * 20071107 [thimel] add db schema support - * 20071107 [thimel] several .hbm.xml refactoring - * 20071108 [thimel] add DTO generator - * 20071108 [thimel] add copyright support in generators - * 20071108 [thimel] add serialVersionUID support in EntityAbstractGenerator - -ver-2-0-24 poussin 20070425 - - * 20070420 [chatellier] add services interfaces generation (stereotype=service) - * 20070420 [chatellier] add topia services support - * 20070330 [poussin] TopiaContextFactory return new TopiaContext if context is closed - * 20070331 [poussin] change many string argument to class argument - * 20070331 [poussin] add getService(Class) method on TopiaContext - * 20070331 [poussin] remove helper in service that only return service instant - * 20070331 [poussin] add Devel.rst documentation - * 20070402 [poussin] replace init to preInit and postInit in TopiaService - -ver-2-0-22 ruchaud 20061023 - - * 20061023 [ruchaud][improve] manage events - * 20061023 [ruchaud][bug fix] in generator of DAO Abstract on delete - -ver-2-0-21 poussin 20061019 - - * add support for auto-import entities for hql - * add getComposite and getAggregate on TopiaEntity - * bug fix for association hibernate mapping wit have attributeh - cascade="delete" for not navigable link to prevent constraint exception - * bug fix in delete, remove link before do delete - -ver-2-0-20 poussin 20061017 - - * add support for TopiaService mechanisme - -ver-2-0-16 poussin 20060907 - - * Implantation des méthodes update et delete sur les TopiaUserImpl et TopiaEntityPermissionImpl - * add backup/restore method on TopiaContext (backup only works for h2) - * TopiaContext is set in Entity during preload - * add updateSchema in TopiaContext interface - * add methods update et delete on TopiaUserImpl and TopiaEntityPermissionImpl - -ver-2-0-13 thimel 20060822 - - * [Secu] ajout d'un champ notes sur les TopiaUser - * [Secu] ajout d'un champ linkApplication sur les TopiaUser (permettant de faire le lien avec une application externe) - * [Secu] ajout de commits et rollbacks sur les Manager - * [Secu] ajout d'un setPassword (sans verification ancien mdp) sur les TopiaUser - -ver-2-0-12 thimel 20060721 - - * ajout des projections sur les DAO - * positionnement unique des userManager et permissionManager au niveau du contexte racine - * ajout de la possibilite de tester des permissions sur le permissionManager - -ver-2-0-11 thimel 20060703 - - * support de la fermeture d'un contexte - * support de la recherche sur tous les attributs d'une entite / annotation sur les interfaces - -ver-2-0-8 thimel 20060606 - - * amelioration detection des classes abstraites - * correction du polymorphisme avec les proxies d'Hibernate - * Hibernate 3.2 - -ver-2-0-7 thimel 20060523 - - * import/export XML "experimental" - * one-to-one transformes en many-to-one + unique="true" - * bug au niveau de la detection des parents abstract - -ver-2-0-6 thimel 20060504 - - * support des annotations sur les attributs des XXXAbstract - * re-correction du support des relations unidirectionnelles 1-n avec classes d'heritage du cote n - * ajout de la validation pour les attributs sans inverses (pour les objectmodel faits a la main) - -ver-2-0-5 thimel 20060427 - - * isIndexed remplace isOrdered dans le mapping hibernate - * add postCreate and postLoad on AbstractTopiaEntity - * findContains sur les DAO (implante hors Hibernate pour l'instant) - * support plus coherent des classes abstraites - * projet compatible maven2 - * correction du support des relations unidirectionnelles 1-n avec classes d'heritage du cote n - -ver-2-0-4 thimel 20060303 - - * Correction du support des interfaces et classes abstraites (conjointement a LutinGenerator 0.30) - * Ajout des exceptions sur le operations (conjointement a LutinGenerator 0.30) - -ver-2-0-3 thimel 20060228 - - * Correction du support des classes d'associations (mauvais mapping Hibernate) - * Support de super classes pour les classes d'association (LutinGenerator 0.29) - Copied: topia/tags/2.0.29/changelog (from rev 1225, topia/trunk/changelog) =================================================================== --- topia/tags/2.0.29/changelog (rev 0) +++ topia/tags/2.0.29/changelog 2008-11-17 09:39:40 UTC (rev 1227) @@ -0,0 +1,149 @@ +ver-2-0-29 chatellier 20081117 + * 20081117 [chemit] improve EntityEnum + * 20081117 [chemit] add method findAllWithOrder in DAO to make have sorted lists +ver-2-0-28 chatellier 20081114 + * 20081113 [chorlet] add support for lazy loading on attribute with 0..* multiplicity + * 20081113 [chorlet] fix bug on bidirectional association by adding inverse attribute in the one side of two hibernate mapping files + * 20081107 [chatellier] fix "result" named attribute generation in model + * 20081107 [chatellier] fix ant:ant, org.apache.ant:ant conflict + * 20081107 [chatellier] set lutingenerator provided scope + * 20081101 [chemit] bump lutingenerator to 0.61 + * 20081101 [chemit] add a EntityEnum to have a generic way to access Entities. + * 20081101 [chemit] improve generators : + - can exclude some generators on TopiaMetaGenerator + - refactor TopiaMetaGenerator to use a simple List of Generator to launch + - refactor Generators to have a default public constructor + + * 20081029 [chemit] fix infinitive recursion on method findByPrimaryKey and findByProperty in TopiaDAODeleagtor class + * 20081026 [chemit] add dbName of table if explicit in javadoc + * 20081024 [chemit] fix bug when no entity defined in model + +ver-2-0-27 chemit 20081021 + * 20081021 [chemit] clean pom, use lutingenerator 0.60 + * 20080922 [thimel] Switched to lutinproject 3.0 + * 20080922 [thimel] Sources are correctly maven2 structuted (src/main/xxx) + * 20080922 [thimel] Fixed maven-processor-plugin usage + * 20080922 [thimel] License switched to LGPL + +ver-2-0-26 thimel 20080922 + * 20080922 [thimel] Last version with lutinproject 2.2 + * 20082608 [chemit] permettre de recuperer uniquement une fenetre de resultat en hql (TopiaContext#find(String hql,int startIndex,int endIndex, Object ... args) + * 20082907 [chemit] Suppression des dependances en dur sur les implantations d'entites + * 20072012 [thimel] Support des index sur les attibuts + * 20072012 [ruchaud] Récupération des classes persistées + * 20072012 [ruchaud] Création d'un vetoable sur les finds + +ver-2-0-25 poussin 20071214 + + * 20071120 [chatellier] modify service init methods, return boolean to stay + activated + * 20071116 [chatellier] add support for topia context listeners + * 20071114 [chatellier] add support for service without persitent classes + * 20071109 [chatellier] add type="string" on topiaId in templates + - update hibernate version to 3.2.5.ga (event patch) + - jetty version 5.1.10 (better pom.xml) + * 20071001 [chatellier] move tapestry version to 5.0.5 + * 20070528 [chatellier] add stateModel generation support + - tapestry generation templates + - tapestry 5.0.4 dependency + + * 20071106 [poussin] add removeContext on TopiaContextFactory and call it + in TopiaContextImpl.closeContext(). + + * 20071107 [thimel] add db schema support + * 20071107 [thimel] several .hbm.xml refactoring + * 20071108 [thimel] add DTO generator + * 20071108 [thimel] add copyright support in generators + * 20071108 [thimel] add serialVersionUID support in EntityAbstractGenerator + +ver-2-0-24 poussin 20070425 + + * 20070420 [chatellier] add services interfaces generation (stereotype=service) + * 20070420 [chatellier] add topia services support + * 20070330 [poussin] TopiaContextFactory return new TopiaContext if context is closed + * 20070331 [poussin] change many string argument to class argument + * 20070331 [poussin] add getService(Class) method on TopiaContext + * 20070331 [poussin] remove helper in service that only return service instant + * 20070331 [poussin] add Devel.rst documentation + * 20070402 [poussin] replace init to preInit and postInit in TopiaService + +ver-2-0-22 ruchaud 20061023 + + * 20061023 [ruchaud][improve] manage events + * 20061023 [ruchaud][bug fix] in generator of DAO Abstract on delete + +ver-2-0-21 poussin 20061019 + + * add support for auto-import entities for hql + * add getComposite and getAggregate on TopiaEntity + * bug fix for association hibernate mapping wit have attributeh + cascade="delete" for not navigable link to prevent constraint exception + * bug fix in delete, remove link before do delete + +ver-2-0-20 poussin 20061017 + + * add support for TopiaService mechanisme + +ver-2-0-16 poussin 20060907 + + * Implantation des méthodes update et delete sur les TopiaUserImpl et TopiaEntityPermissionImpl + * add backup/restore method on TopiaContext (backup only works for h2) + * TopiaContext is set in Entity during preload + * add updateSchema in TopiaContext interface + * add methods update et delete on TopiaUserImpl and TopiaEntityPermissionImpl + +ver-2-0-13 thimel 20060822 + + * [Secu] ajout d'un champ notes sur les TopiaUser + * [Secu] ajout d'un champ linkApplication sur les TopiaUser (permettant de faire le lien avec une application externe) + * [Secu] ajout de commits et rollbacks sur les Manager + * [Secu] ajout d'un setPassword (sans verification ancien mdp) sur les TopiaUser + +ver-2-0-12 thimel 20060721 + + * ajout des projections sur les DAO + * positionnement unique des userManager et permissionManager au niveau du contexte racine + * ajout de la possibilite de tester des permissions sur le permissionManager + +ver-2-0-11 thimel 20060703 + + * support de la fermeture d'un contexte + * support de la recherche sur tous les attributs d'une entite / annotation sur les interfaces + +ver-2-0-8 thimel 20060606 + + * amelioration detection des classes abstraites + * correction du polymorphisme avec les proxies d'Hibernate + * Hibernate 3.2 + +ver-2-0-7 thimel 20060523 + + * import/export XML "experimental" + * one-to-one transformes en many-to-one + unique="true" + * bug au niveau de la detection des parents abstract + +ver-2-0-6 thimel 20060504 + + * support des annotations sur les attributs des XXXAbstract + * re-correction du support des relations unidirectionnelles 1-n avec classes d'heritage du cote n + * ajout de la validation pour les attributs sans inverses (pour les objectmodel faits a la main) + +ver-2-0-5 thimel 20060427 + + * isIndexed remplace isOrdered dans le mapping hibernate + * add postCreate and postLoad on AbstractTopiaEntity + * findContains sur les DAO (implante hors Hibernate pour l'instant) + * support plus coherent des classes abstraites + * projet compatible maven2 + * correction du support des relations unidirectionnelles 1-n avec classes d'heritage du cote n + +ver-2-0-4 thimel 20060303 + + * Correction du support des interfaces et classes abstraites (conjointement a LutinGenerator 0.30) + * Ajout des exceptions sur le operations (conjointement a LutinGenerator 0.30) + +ver-2-0-3 thimel 20060228 + + * Correction du support des classes d'associations (mauvais mapping Hibernate) + * Support de super classes pour les classes d'association (LutinGenerator 0.29) + Deleted: topia/tags/2.0.29/pom.xml =================================================================== --- topia/trunk/pom.xml 2008-11-14 11:16:46 UTC (rev 1223) +++ topia/tags/2.0.29/pom.xml 2008-11-17 09:39:40 UTC (rev 1227) @@ -1,207 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - - <modelVersion>4.0.0</modelVersion> - - <!-- ************************************************************* --> - <!-- *** POM Relationships *************************************** --> - <!-- ************************************************************* --> - - <parent> - <groupId>org.codelutin</groupId> - <artifactId>lutinproject</artifactId> - <version>3.0</version> - </parent> - - <artifactId>topia</artifactId> - - <dependencies> - <!--Compile--> - <dependency> - <groupId>org.codelutin</groupId> - <artifactId>lutinutil</artifactId> - <version>0.31</version> - <scope>compile</scope> - </dependency> - - <dependency> - <groupId>org.codelutin</groupId> - <artifactId>lutingenerator</artifactId> - <version>0.61</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> - <version>3.2.1</version> - <scope>compile</scope> - </dependency> - - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-core</artifactId> - <version>3.3.1.GA</version> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>javassist</groupId> - <artifactId>javassist</artifactId> - <version>3.4.GA</version> - </dependency> - - <!--Test--> - <dependency> - <groupId>postgresql</groupId> - <artifactId>postgresql</artifactId> - <version>8.2-507.jdbc4</version> - <scope>test</scope> - </dependency> - - <!-- <dependency> - <groupId>mysql</groupId> - <artifactId>mysql-connector-java</artifactId> - <version>5.1.5</version> - <scope>test</scope> - </dependency> --> - - <!-- Dependencies for services --> - <dependency> - <groupId>org.apache.xmlrpc</groupId> - <artifactId>xmlrpc-server</artifactId> - <version>3.1</version> - <scope>compile</scope> - </dependency> - - <dependency> - <groupId>org.apache.xmlrpc</groupId> - <artifactId>xmlrpc-client</artifactId> - <version>3.1</version> - <scope>compile</scope> - </dependency> - - <dependency> - <groupId>commons-httpclient</groupId> - <artifactId>commons-httpclient</artifactId> - <version>3.1</version> - <scope>runtime</scope> - </dependency> - - <dependency> - <groupId>org.codehaus.xfire</groupId> - <artifactId>xfire-java5</artifactId> - <version>1.2.6</version> - <exclusions> - <!-- Fix org.apache.ant conflict) --> - <exclusion> - <groupId>ant</groupId> - <artifactId>ant</artifactId> - </exclusion> - </exclusions> - </dependency> - - <!-- branch 5.1 : ne fonctionne pas en 6+ --> - <dependency> - <groupId>jetty</groupId> - <artifactId>jetty</artifactId> - <version>5.1.10</version> - </dependency> - - <!-- Dependencies for class generation --> - <dependency> - <groupId>asm</groupId> - <artifactId>asm</artifactId> - <version>1.5.3</version> - <scope>compile</scope> - </dependency> - - <dependency> - <groupId>org.apache.tapestry</groupId> - <artifactId>tapestry-core</artifactId> - <version>5.0.7</version> - <scope>compile</scope> - </dependency> - - <!--BD H2 pour le test--> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - <version>1.0.79</version> - <scope>test</scope> - </dependency> - </dependencies> - - <!-- ************************************************************* --> - <!-- *** Project Information ************************************* --> - <!-- ************************************************************* --> - - <name>ToPIA - Tools for Portable and Independent Architecture</name> - <version>2.0.29-SNAPSHOT</version> - <description>Framework de persistance et de distribution d'application.</description> - <inceptionYear>2004</inceptionYear> - - <!-- ************************************************************* --> - <!-- *** Build Settings ****************************************** --> - <!-- ************************************************************* --> - - <packaging>jar</packaging> - - <properties> - <!-- id du projet du labs --> - <labs.id>21</labs.id> - - <!-- nom du projet sur le labs --> - <labs.project>topia</labs.project> - - <!-- Test FIXME : --> - <maven.test.skip>true</maven.test.skip> - </properties> - - <build> - <plugins> - <!--Attaching processor plugin to the Build Lifecycle--> - <plugin> - <groupId>org.codelutin</groupId> - <artifactId>maven-processor-plugin</artifactId> - <version>0.16</version> - <executions> - <execution> - <phase>generate-sources</phase> - <goals> - <goal>process</goal> - </goals> - </execution> - </executions> - <configuration> - <!-- You might change defaut directories --> - <!-- srcDir>${basedir}/src/main/java</srcDir> - <destDir>${basedir}/target/processed-sources/java</destDir--> - <addCompileDirectory>true</addCompileDirectory> - <includes> - <include>**/*.java</include> - </includes> - <filters> - org.codelutin.processor.filters.GeneratorTemplatesFilter, - org.codelutin.processor.filters.ActiveLogsCodeFilter - </filters> - <verbose>${maven.verbose}</verbose> - </configuration> - </plugin> - - <plugin> - <artifactId>maven-javadoc-plugin</artifactId> - </plugin> - - </plugins> - </build> - - <!-- ************************************************************* --> - <!-- *** Build Environment ************************************** --> - <!-- ************************************************************* --> - <scm> - <connection>${maven.scm.connection}</connection> - <developerConnection>${maven.scm.developerConnection}</developerConnection> - <url>${maven.scm.url}</url> - </scm> - -</project> Copied: topia/tags/2.0.29/pom.xml (from rev 1226, topia/trunk/pom.xml) =================================================================== --- topia/tags/2.0.29/pom.xml (rev 0) +++ topia/tags/2.0.29/pom.xml 2008-11-17 09:39:40 UTC (rev 1227) @@ -0,0 +1,207 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <!-- ************************************************************* --> + <!-- *** POM Relationships *************************************** --> + <!-- ************************************************************* --> + + <parent> + <groupId>org.codelutin</groupId> + <artifactId>lutinproject</artifactId> + <version>3.0</version> + </parent> + + <artifactId>topia</artifactId> + + <dependencies> + <!--Compile--> + <dependency> + <groupId>org.codelutin</groupId> + <artifactId>lutinutil</artifactId> + <version>0.31</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.codelutin</groupId> + <artifactId>lutingenerator</artifactId> + <version>0.61</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + <version>3.2.1</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-core</artifactId> + <version>3.3.1.GA</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>javassist</groupId> + <artifactId>javassist</artifactId> + <version>3.4.GA</version> + </dependency> + + <!--Test--> + <dependency> + <groupId>postgresql</groupId> + <artifactId>postgresql</artifactId> + <version>8.2-507.jdbc4</version> + <scope>test</scope> + </dependency> + + <!-- <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <version>5.1.5</version> + <scope>test</scope> + </dependency> --> + + <!-- Dependencies for services --> + <dependency> + <groupId>org.apache.xmlrpc</groupId> + <artifactId>xmlrpc-server</artifactId> + <version>3.1</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.xmlrpc</groupId> + <artifactId>xmlrpc-client</artifactId> + <version>3.1</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>commons-httpclient</groupId> + <artifactId>commons-httpclient</artifactId> + <version>3.1</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.codehaus.xfire</groupId> + <artifactId>xfire-java5</artifactId> + <version>1.2.6</version> + <exclusions> + <!-- Fix org.apache.ant conflict) --> + <exclusion> + <groupId>ant</groupId> + <artifactId>ant</artifactId> + </exclusion> + </exclusions> + </dependency> + + <!-- branch 5.1 : ne fonctionne pas en 6+ --> + <dependency> + <groupId>jetty</groupId> + <artifactId>jetty</artifactId> + <version>5.1.10</version> + </dependency> + + <!-- Dependencies for class generation --> + <dependency> + <groupId>asm</groupId> + <artifactId>asm</artifactId> + <version>1.5.3</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.tapestry</groupId> + <artifactId>tapestry-core</artifactId> + <version>5.0.7</version> + <scope>compile</scope> + </dependency> + + <!--BD H2 pour le test--> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <version>1.0.79</version> + <scope>test</scope> + </dependency> + </dependencies> + + <!-- ************************************************************* --> + <!-- *** Project Information ************************************* --> + <!-- ************************************************************* --> + + <name>ToPIA - Tools for Portable and Independent Architecture</name> + <version>2.0.29</version> + <description>Framework de persistance et de distribution d'application.</description> + <inceptionYear>2004</inceptionYear> + + <!-- ************************************************************* --> + <!-- *** Build Settings ****************************************** --> + <!-- ************************************************************* --> + + <packaging>jar</packaging> + + <properties> + <!-- id du projet du labs --> + <labs.id>21</labs.id> + + <!-- nom du projet sur le labs --> + <labs.project>topia</labs.project> + + <!-- Test FIXME : --> + <maven.test.skip>true</maven.test.skip> + </properties> + + <build> + <plugins> + <!--Attaching processor plugin to the Build Lifecycle--> + <plugin> + <groupId>org.codelutin</groupId> + <artifactId>maven-processor-plugin</artifactId> + <version>0.16</version> + <executions> + <execution> + <phase>generate-sources</phase> + <goals> + <goal>process</goal> + </goals> + </execution> + </executions> + <configuration> + <!-- You might change defaut directories --> + <!-- srcDir>${basedir}/src/main/java</srcDir> + <destDir>${basedir}/target/processed-sources/java</destDir--> + <addCompileDirectory>true</addCompileDirectory> + <includes> + <include>**/*.java</include> + </includes> + <filters> + org.codelutin.processor.filters.GeneratorTemplatesFilter, + org.codelutin.processor.filters.ActiveLogsCodeFilter + </filters> + <verbose>${maven.verbose}</verbose> + </configuration> + </plugin> + + <plugin> + <artifactId>maven-javadoc-plugin</artifactId> + </plugin> + + </plugins> + </build> + + <!-- ************************************************************* --> + <!-- *** Build Environment ************************************** --> + <!-- ************************************************************* --> + <scm> + <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.0.29</connection> + <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.0.29</developerConnection> + <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia/tags/2.0.29?root=topia</url> + </scm> + +</project> Deleted: topia/tags/2.0.29/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java 2008-11-14 11:16:46 UTC (rev 1223) +++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java 2008-11-17 09:39:40 UTC (rev 1227) @@ -1,251 +0,0 @@ -/* *##% ToPIA - Tools for Portable and Independent Architecture - * Copyright (C) 2004 - 2008 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>. ##%*/ - -/******************************************************************************* - * EntityProviderGenerator.java - * - */ - -package org.codelutin.topia.generator; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.generator.Generator; -import org.codelutin.generator.ObjectModelGenerator; -import org.codelutin.generator.models.object.ObjectModel; -import org.codelutin.generator.models.object.ObjectModelClass; - -import java.io.File; -import java.io.IOException; -import java.io.Writer; -import java.util.Iterator; -import java.util.List; - -/** - * Ce generateur permet d'avoir une énumeration sur les entités du model. - * <p/> - * Chaque entité est associée à un {@link org.codelutin.topia.persistence.TopiaEntityEnumEntry}. - * - * @author chemit - * @see org.codelutin.topia.persistence.TopiaEntityEnumEntry - */ -public class EntityEnumGenerator extends ObjectModelGenerator { - - private Log log = LogFactory.getLog(EntityEnumGenerator.class); - - public EntityEnumGenerator() { - super(); - } - - public EntityEnumGenerator(Generator parent) { - super(parent); - } - - @Override - public String getFilenameForModel(ObjectModel model) { - return (getProperty("defaultPackage") + ".").replace('.', - File.separatorChar) - + model.getName() + "EntityEnum.java"; - } - - @Override - public void generateFromModel(Writer output, ObjectModel model) - throws IOException { - String copyright = GeneratorUtil.getCopyright(model); - String modelName = model.getName(); - String className = modelName + "EntityEnum"; - if (log.isDebugEnabled()) { - log.debug("generating " + className); - } - if (GeneratorUtil.notEmpty(copyright)) { -/*{<%=copyright%> -}*/ - } -/*{package <%=getProperty("defaultPackage")%>; - -import org.codelutin.topia.TopiaContext; -import org.codelutin.topia.TopiaException; -import org.codelutin.topia.persistence.TopiaDAO; -import org.codelutin.topia.persistence.TopiaEntity; -import org.codelutin.topia.persistence.TopiaEntityEnumEntry; - - -@SuppressWarnings({"unchecked"}) -}*/ - -/*{public enum <%=className%> { -}*/ - List<ObjectModelClass> classes = GeneratorUtil.getEntityClasses(model, true); - if (classes.isEmpty()) { -/*{ - TopiaEntity(TopiaEntity.class); -}*/ - } else { - for (Iterator i = classes.iterator(); i.hasNext();) { - ObjectModelClass clazz = (ObjectModelClass) i.next(); - boolean hasNext = i.hasNext(); - if (log.isDebugEnabled()) { - log.debug("generating entry " + clazz + " (hasNext:" + hasNext + ")"); - } -/*{ <%=clazz.getName()%>(<%=clazz.getQualifiedName()%>.class)<%=(hasNext?",":";")%> -}*/ - } - } -/*{ - private TopiaEntityEnumEntry<TopiaEntity> entry; - - <%=className%>(Class<? extends TopiaEntity> contractClass) { - entry = new TopiaEntityEnumEntry(contractClass); - } -}*/ - -/* public Class<? extends TopiaEntity> getContractClass() { - return entry.getContractClass(); - } - - public Class<? extends TopiaEntity> getImplementationClass() { - return entry.getImplementationClass(); - } - - public TopiaDAO getDAO(TopiaContext ctxt) throws TopiaException { - return entry.getDAO(ctxt); - } - - public TopiaEntity create(TopiaContext ctxt) throws TopiaException { - return entry.create(ctxt); - } - - public TopiaEntity update(TopiaEntity entity, TopiaContext - ctxt) throws TopiaException - { - return entry.update(entity, ctxt); - } - - public void delete(TopiaEntity entity, TopiaContext ctxt) throws TopiaException { - entry.delete(entity, ctxt); - } -*/ - -/*{ - public static <%=className%> valueOf(TopiaEntity entity) { - return valueOf(entity.getClass()); - } - - public static <%=className%> valueOf(Class<?> klass) { - if (klass.isInterface()) { - return <%=modelName%>EntityEnum.valueOf(klass.getSimpleName()); - } - for (<%=className%> entityEnum : <%=className%>.values()) { - if (entityEnum.entry.getContractClass().isAssignableFrom(klass)) { - return entityEnum; - } - } - throw new IllegalArgumentException("no entity defined for the class " + klass + " in : " + java.util.Arrays.toString(<%=className%>.values())); - } - - public static <T extends TopiaEntity> Class<T> getContractClass(Class<T> klass) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - <%=className%> e = <%=className%>.valueOf(klass); - return (Class<T>) e.entry.getContractClass(); - } - - public static <T extends TopiaEntity> Class<T> getImplementationClass(Class<T> klass) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - <%=className%> e = <%=className%>.valueOf(klass); - return (Class<T>) e.entry.getImplementationClass(); - } - - public static Class<? extends TopiaEntity>[] getContractClasses() { - <%=className%>[] values = <%=className%>.values(); - Class<? extends TopiaEntity>[] result = (Class<? extends TopiaEntity>[]) java.lang.reflect.Array.newInstance(Class.class, values.length); - for (int i = 0; i < values.length; i++) { - result[i] = values[i].entry.getContractClass(); - } - return result; - } - - public static Class<? extends TopiaEntity>[] getImplementationClasses() { - <%=className%>[] values = <%=className%>.values(); - Class<? extends TopiaEntity>[] result = (Class<? extends TopiaEntity>[]) java.lang.reflect.Array.newInstance(Class.class, values.length); - for (int i = 0; i < values.length; i++) { - result[i] = values[i].entry.getImplementationClass(); - } - return result; - } - - public static String getImplementationClassesAsString() { - StringBuilder buffer = new StringBuilder(); - for (Class<? extends TopiaEntity> aClass : getImplementationClasses()) { - buffer.append(',').append(aClass.getName()); - } - return buffer.substring(1); - } - - public static <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDAO(Class<T> klass, TopiaContext ctxt) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - <%=className%> e = <%=className%>.valueOf(klass); - return (D) e.entry.getDAO(ctxt); - } - - public static <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDAO(T entity, TopiaContext ctxt) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(entity); - <%=className%> e = <%=className%>.valueOf(entity); - return (D) e.entry.getDAO(ctxt); - } - - public static <T extends TopiaEntity> T create(Class<T> klass, TopiaContext ctxt) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - <%=className%> e = <%=className%>.valueOf(klass); - return (T) e.entry.create(ctxt); - } - - public static <T extends TopiaEntity> T update(T entity, TopiaContext ctxt) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(entity); - <%=className%> e = <%=className%>.valueOf(entity); - return (T) e.entry.update(entity, ctxt); - } - - public static <T extends TopiaEntity> void delete(T entity, TopiaContext ctxt) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(entity); - <%=className%> e = <%=className%>.valueOf(entity); - e.entry.delete(entity, ctxt); - } - - public static <T extends TopiaEntity> java.util.List<T> findAll(Class<T> klass, TopiaContext ctxt) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.findAll(ctxt); - } - - public static <T extends TopiaEntity> T findByTopiaId(Class<T> klass, TopiaContext ctxt,String topiaId) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.findByTopiaId(topiaId,ctxt); - } - - public static <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry(T entity) throws TopiaException { - <%=className%> e = <%=className%>.valueOf(entity); - return (TopiaEntityEnumEntry<T>)e.entry; - } - - public static <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry(Class<T> klass) throws TopiaException { - <%=className%> e = <%=className%>.valueOf(klass); - return (TopiaEntityEnumEntry<T>)e.entry; - } -} -}*/ - } - -} // EntityEnumGenerator Copied: topia/tags/2.0.29/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java (from rev 1224, topia/trunk/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java) =================================================================== --- topia/tags/2.0.29/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java (rev 0) +++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java 2008-11-17 09:39:40 UTC (rev 1227) @@ -0,0 +1,309 @@ +/* *##% ToPIA - Tools for Portable and Independent Architecture + * Copyright (C) 2004 - 2008 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>. ##%*/ + +/******************************************************************************* + * EntityProviderGenerator.java + * + */ + +package org.codelutin.topia.generator; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.generator.Generator; +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModel; +import org.codelutin.generator.models.object.ObjectModelClass; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; +import java.util.List; + +/** + * Ce generateur permet d'avoir une énumeration sur les entités du model. + * <p/> + * Chaque entité est associée à un {@link org.codelutin.topia.persistence.TopiaEntityEnumEntry}. + * + * @author chemit + * @see org.codelutin.topia.persistence.TopiaEntityEnumEntry + */ +public class EntityEnumGenerator extends ObjectModelGenerator { + + private Log log = LogFactory.getLog(EntityEnumGenerator.class); + + public EntityEnumGenerator() { + super(); + } + + public EntityEnumGenerator(Generator parent) { + super(parent); + } + + @Override + public String getFilenameForModel(ObjectModel model) { + return (getProperty("defaultPackage") + ".").replace('.', + File.separatorChar) + + model.getName() + "EntityEnum.java"; + } + + @Override + public void generateFromModel(Writer output, ObjectModel model) + throws IOException { + String copyright = GeneratorUtil.getCopyright(model); + String modelName = model.getName(); + String className = modelName + "EntityEnum"; + if (log.isDebugEnabled()) { + log.debug("generating " + className); + } + if (GeneratorUtil.notEmpty(copyright)) { +/*{<%=copyright%> +}*/ + } +/*{package <%=getProperty("defaultPackage")%>; + +import java.util.Map; +import java.util.List; +import java.util.Collection; + +import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.TopiaException; +import org.codelutin.topia.persistence.TopiaDAO; +import org.codelutin.topia.persistence.TopiaEntity; +import org.codelutin.topia.persistence.TopiaEntityEnumEntry; + + +@SuppressWarnings({"unchecked"}) +}*/ + +/*{public enum <%=className%> { +}*/ + List<ObjectModelClass> classes = GeneratorUtil.getEntityClasses(model, true); + if (classes.isEmpty()) { +/*{ + TopiaEntity(TopiaEntity.class); +}*/ + } else { + for (Iterator i = classes.iterator(); i.hasNext();) { + ObjectModelClass clazz = (ObjectModelClass) i.next(); + boolean hasNext = i.hasNext(); + if (log.isDebugEnabled()) { + log.debug("generating entry " + clazz + " (hasNext:" + hasNext + ")"); + } +/*{ <%=clazz.getName()%>(<%=clazz.getQualifiedName()%>.class)<%=(hasNext?",":";")%> +}*/ + } + } +/*{ + private TopiaEntityEnumEntry<TopiaEntity> entry; + + <%=className%>(Class<? extends TopiaEntity> contractClass) { + entry = new TopiaEntityEnumEntry(contractClass); + } + + public <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry() { + return (TopiaEntityEnumEntry<T>)entry; + } + + public static <%=className%> valueOf(TopiaEntity entity) { + return valueOf(entity.getClass()); + } + + public static <%=className%> valueOf(Class<?> klass) { + if (klass.isInterface()) { + return <%=modelName%>EntityEnum.valueOf(klass.getSimpleName()); + } + for (<%=className%> entityEnum : <%=className%>.values()) { + if (entityEnum.entry.getContractClass().isAssignableFrom(klass)) { + return entityEnum; + } + } + throw new IllegalArgumentException("no entity defined for the class " + klass + " in : " + java.util.Arrays.toString(<%=className%>.values())); + } + + public static <T extends TopiaEntity> Class<T> getContractClass(Class<T> klass) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.getContractClass(); + } + + public static <T extends TopiaEntity> Class<T> getImplementationClass(Class<T> klass) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.getImplementationClass(); + } + + public static Class<? extends TopiaEntity>[] getContractClasses() { + <%=className%>[] values = <%=className%>.values(); + Class<? extends TopiaEntity>[] result = (Class<? extends TopiaEntity>[]) java.lang.reflect.Array.newInstance(Class.class, values.length); + for (int i = 0; i < values.length; i++) { + result[i] = values[i].entry.getContractClass(); + } + return result; + } + + public static Class<? extends TopiaEntity>[] getImplementationClasses() { + <%=className%>[] values = <%=className%>.values(); + Class<? extends TopiaEntity>[] result = (Class<? extends TopiaEntity>[]) java.lang.reflect.Array.newInstance(Class.class, values.length); + for (int i = 0; i < values.length; i++) { + result[i] = values[i].entry.getImplementationClass(); + } + return result; + } + + public static String getImplementationClassesAsString() { + StringBuilder buffer = new StringBuilder(); + for (Class<? extends TopiaEntity> aClass : getImplementationClasses()) { + buffer.append(',').append(aClass.getName()); + } + return buffer.substring(1); + } + + public static <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry(T entity) { + <%=className%> e = <%=className%>.valueOf(entity); + return (TopiaEntityEnumEntry<T>)e.entry; + } + + public static <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry(Class<T> klass) { + <%=className%> e = <%=className%>.valueOf(klass); + return (TopiaEntityEnumEntry<T>)e.entry; + } + + public static <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry(String constantName) { + <%=className%> e = <%=className%>.valueOf(constantName); + return (TopiaEntityEnumEntry<T>)e.entry; + } + + public static <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDAO(TopiaContext ctxt, Class<T> klass) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return (D) entry.getDAO(ctxt); + } + + public static <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDAO(TopiaContext ctxt, T entity) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(entity); + return (D) entry.getDAO(ctxt); + } + + public static <T extends TopiaEntity> T create(TopiaContext ctxt, Class<T> klass) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.create(ctxt); + } + + public static <T extends TopiaEntity> T create(TopiaContext ctxt, Class<T> klass, Object... properties) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.create(ctxt, properties); + } + + public static <T extends TopiaEntity> T create(TopiaContext ctxt, Class<T> klass, Map<String, Object> properties) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.create(ctxt, properties); + } + + public static <T extends TopiaEntity> T update(TopiaContext ctxt, T entity) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(entity); + return entry.update(entity, ctxt); + } + + public static <T extends TopiaEntity> void delete(TopiaContext ctxt, T entity) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(entity); + entry.delete(entity, ctxt); + } + + public static <T extends TopiaEntity> int size(TopiaContext ctxt, Class<T> klass) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.size(ctxt); + } + + public static <T extends TopiaEntity> List<T> findAll(TopiaContext ctxt, Class<T> klass) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.findAll(ctxt); + } + + public static <T extends TopiaEntity> List<T> findAllWithOrder(TopiaContext ctxt, Class<T> klass,String... propertyNames) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.findAllWithOrder(ctxt, propertyNames); + } + + public static <T extends TopiaEntity> T findByTopiaId(TopiaContext ctxt, Class<T> klass,String topiaId) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.findByTopiaId(topiaId,ctxt); + } + + public static <T extends TopiaEntity> T findByPrimaryKey(TopiaContext ctxt, Class<T> klass, Map<String, Object> keys) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.findByPrimaryKey(ctxt, keys); + } + + public static <T extends TopiaEntity> T findByPrimaryKey(TopiaContext ctxt, Class<T> klass, Object... k) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.findByPrimaryKey(ctxt, k); + } + + public static <T extends TopiaEntity> T findByProperty(TopiaContext ctxt, Class<T> klass, String propertyName, Object value) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.findByProperty(ctxt, propertyName, value); + } + + public static <T extends TopiaEntity> T findByProperties(TopiaContext ctxt, Class<T> klass, String propertyName, Object value, Object... others) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.findByProperties(ctxt, propertyName, value, others); + } + + public static <T extends TopiaEntity> T findByProperties(TopiaContext ctxt, Class<T> klass, Map<String, Object> properties) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.findByProperties(ctxt, properties); + } + + public static <T extends TopiaEntity> List<T> findAllByProperty(TopiaContext ctxt, Class<T> klass, String propertyName, Object value) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.findAllByProperty(ctxt, propertyName, value); + } + + public static <T extends TopiaEntity> List<T> findAllByProperties(TopiaContext ctxt, Class<T> klass, String propertyName, Object value, Object... others) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.findAllByProperties(ctxt, propertyName, value, others); + } + + public static <T extends TopiaEntity> List<T> findAllByProperties(TopiaContext ctxt, Class<T> klass, Map<String, Object> properties) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.findAllByProperties(ctxt, properties); + } + + public static <T extends TopiaEntity> T findContainsProperties(TopiaContext ctxt, Class<T> klass, Map<String, Collection> properties) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.findContainsProperties(ctxt, properties); + } + + public static <T extends TopiaEntity> T findContainsProperties(TopiaContext ctxt, Class<T> klass, String propertyName, Collection values, Object... others) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.findContainsProperties(ctxt, propertyName, values, others); + } + + public static <T extends TopiaEntity> List<T> findAllContainsProperties(TopiaContext ctxt, Class<T> klass, Map<String, Collection> properties) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.findAllContainsProperties(ctxt, properties); + } + + public static <T extends TopiaEntity> List<T> findAllContainsProperties(TopiaContext ctxt, Class<T> klass, String propertyName, Collection values, Object... others) throws TopiaException { + TopiaEntityEnumEntry<T> entry = getEntry(klass); + return entry.findAllContainsProperties(ctxt, propertyName, values, others); + } + +} +}*/ + } + +} // EntityEnumGenerator Deleted: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java 2008-11-14 11:16:46 UTC (rev 1223) +++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java 2008-11-17 09:39:40 UTC (rev 1227) @@ -1,228 +0,0 @@ -/* *##% ToPIA - Tools for Portable and Independent Architecture - * Copyright (C) 2004 - 2008 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>. ##%*/ - -/* * - * TopiaDAO.java - * - * Created: 30 déc. 2005 03:00:57 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - -package org.codelutin.topia.persistence; - -import java.security.Permission; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import org.codelutin.topia.TopiaException; -import org.codelutin.topia.event.TopiaEntityListener; -import org.codelutin.topia.event.TopiaEntityVetoable; -import org.codelutin.topia.event.TopiaTransactionListener; -import org.codelutin.topia.event.TopiaTransactionVetoable; -import org.codelutin.topia.framework.TopiaContextImplementor; - -/** - * @author poussin - * - * @param <Entity> - */ -public interface TopiaDAO<Entity extends TopiaEntity> { - - /** - * When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just - * after - * - * @param entityClass - */ - public void init(TopiaContextImplementor context, Class<Entity> entityClass) throws TopiaException; - - /** - * Return class of entity managed by this DAO - * @return - */ - public abstract Class<Entity> getEntityClass(); - - /** - * @return Returns the context. - */ - public abstract TopiaContextImplementor getContext(); - - /** - * appelé lorsque le context a eu un commit de fait - * TODO il faudrait peut-etre plutot faire un commit a deux phase - * car plusieurs type de persistence peuvent etre melangé, et il - * serait bien que si l'une echoué les autres echoue aussi. - */ - public void commitTransaction() throws TopiaException; - /** appelé lorsque le context a eu un commit de fait */ - public void rollbackTransaction() throws TopiaException; - - /** - * Construit une nouvelle instance de l'objet géré par ce DAO - * @param properties la liste des propriétés que doit avoir l'objet créé - * les arguments vont par paire (propertyName, value) - * @return un nouvel objet - * @throws TopiaException si un problème est rencontré durant l'instanciation - * @throws IllegalArgumentException Si le nombre on le type des arguments - * n'est pas bon ou que le type ou le nom d'une propriété est fausse - */ - public abstract Entity create(Object ... properties) throws TopiaException; - - /** - * Construit une nouvelle instance de l'objet géré par ce DAO - * @param properties la liste des propriétés que doit avoir l'objet créé - * @return un nouvel objet - * @throws TopiaException si un problème est rencontré durant l'instanciation - * @throws IllegalArgumentException Si le nombre on le type des arguments - * n'est pas bon ou que le type ou le nom d'une propriété est fausse - */ - public Entity create(Map<String, Object> properties) throws TopiaException; - - /** - * Permet d'ajouter ou de mettre a jour un objet. Cela permet d'ajouter - * par exemple un objet provenant d'un autre context mais du meme type - * de DAO - * @param e l'entite a ajouter ou mettre a jour - * @return l'entity passé en paramètre. - * @throws TopiaException - */ - public abstract Entity update(Entity e) throws TopiaException; - - public abstract void delete(Entity e) throws TopiaException; - - public abstract Entity findByTopiaId(String k) throws TopiaException; - - public abstract List<Entity> findAll() throws TopiaException; - - /** - * TODO modifier l'implantation pour faire un simple count sur la base - * - * @return - * @throws TopiaException - */ - public abstract int size() throws TopiaException; - - /** - * Recherche la classe en utilisant la cle naturelle, chaque champs de la - * cle naturelle est une entre de la map passe en argument. - * - * @param keys la liste des champs de la cle naturelle avec leur valeur - * @return - * @throws TopiaException - */ - public abstract Entity findByPrimaryKey(Map<String, Object> keys) throws TopiaException; - - /** - * Recherche la classe en utilisant la cle naturelle, si la cle naturelle - * est composé de plusieurs champs alors les arguments passés doivent être - * dans l'ordre de declaration dans le fichier de mapping - * - * @param k l'objet cle naturelle de la classe - * @return - * @throws TopiaException - */ - public abstract Entity findByPrimaryKey(Object... k) throws TopiaException; - - public abstract Entity findByProperty(String propertyName, Object value) - throws TopiaException; - - /** - * - * @param propertyName - * @param value - * @param others les autres proprietes doivent aller par 2 propertyName, - * value - * @return - * @throws TopiaException - */ - public abstract Entity findByProperties(String propertyName, Object value, - Object... others) throws TopiaException; - - public abstract Entity findByProperties(Map<String, Object> properties) - throws TopiaException; - - public abstract List<Entity> findAllByProperty(String propertyName, Object value) - throws TopiaException; - - /** - * - * @param propertyName - * @param value - * @param others les autres proprietes doivent aller par 2 propertyName, - * value - * @return - * @throws TopiaException - */ - public abstract List<Entity> findAllByProperties(String propertyName, Object value, - Object... others) throws TopiaException; - - public abstract List<Entity> findAllByProperties(Map<String, Object> properties) - throws TopiaException; - - /* - * Find Contains - */ - /** - * Cherche et renvoie la première entité trouvée dont les propriétés en clé - * de Map contiennent toutes les valeurs de la Collection. - */ - public abstract Entity findContainsProperties(Map<String, Collection> properties) - throws TopiaException; - - /** - * Cherche et renvoie la première entité trouvée dont la propriété - * propertyName contient values, ainsi de suite avec others. - */ - public abstract Entity findContainsProperties(String propertyName, Collection values, Object... others) - throws TopiaException; - - /** - * Cherche et renvoie la première entité trouvée dont les propriétés en clé - * de Map contiennent toutes les valeurs de la Collection. - */ - public abstract List<Entity> findAllContainsProperties(Map<String, Collection> properties) - throws TopiaException; - - /** - * Cherche et renvoie toutes les entités trouvées dont la propriété - * propertyName contient values, ainsi de suite avec others. - */ - public abstract List<Entity> findAllContainsProperties(String propertyName, Collection values, Object... others) - throws TopiaException; - - /** - * Retourne les permissions a verifier pour l'acces a l'entite pour le service Taas - * @param topiaId topiaId d'une entite - * @return la liste des permissions - */ - public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException; - - /* Adders */ - public void addTopiaEntityListener(TopiaEntityListener listener); - public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable); - - /* Removers */ - public void removeTopiaEntityListener(TopiaEntityListener listener); - public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable); - -} //TopiaDAO Copied: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java (from rev 1224, topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java) =================================================================== --- topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java (rev 0) +++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java 2008-11-17 09:39:40 UTC (rev 1227) @@ -0,0 +1,230 @@ +/* *##% ToPIA - Tools for Portable and Independent Architecture + * Copyright (C) 2004 - 2008 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>. ##%*/ + +/* * + * TopiaDAO.java + * + * Created: 30 déc. 2005 03:00:57 + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ + +package org.codelutin.topia.persistence; + +import java.security.Permission; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.codelutin.topia.TopiaException; +import org.codelutin.topia.event.TopiaEntityListener; +import org.codelutin.topia.event.TopiaEntityVetoable; +import org.codelutin.topia.event.TopiaTransactionListener; +import org.codelutin.topia.event.TopiaTransactionVetoable; +import org.codelutin.topia.framework.TopiaContextImplementor; + +/** + * @author poussin + * + * @param <Entity> + */ +public interface TopiaDAO<Entity extends TopiaEntity> { + + /** + * When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just + * after + * + * @param entityClass + */ + public void init(TopiaContextImplementor context, Class<Entity> entityClass) throws TopiaException; + + /** + * Return class of entity managed by this DAO + * @return + */ + public abstract Class<Entity> getEntityClass(); + + /** + * @return Returns the context. + */ + public abstract TopiaContextImplementor getContext(); + + /** + * appelé lorsque le context a eu un commit de fait + * TODO il faudrait peut-etre plutot faire un commit a deux phase + * car plusieurs type de persistence peuvent etre melangé, et il + * serait bien que si l'une echoué les autres echoue aussi. + */ + public void commitTransaction() throws TopiaException; + /** appelé lorsque le context a eu un commit de fait */ + public void rollbackTransaction() throws TopiaException; + + /** + * Construit une nouvelle instance de l'objet géré par ce DAO + * @param properties la liste des propriétés que doit avoir l'objet créé + * les arguments vont par paire (propertyName, value) + * @return un nouvel objet + * @throws TopiaException si un problème est rencontré durant l'instanciation + * @throws IllegalArgumentException Si le nombre on le type des arguments + * n'est pas bon ou que le type ou le nom d'une propriété est fausse + */ + public abstract Entity create(Object ... properties) throws TopiaException; + + /** + * Construit une nouvelle instance de l'objet géré par ce DAO + * @param properties la liste des propriétés que doit avoir l'objet créé + * @return un nouvel objet + * @throws TopiaException si un problème est rencontré durant l'instanciation + * @throws IllegalArgumentException Si le nombre on le type des arguments + * n'est pas bon ou que le type ou le nom d'une propriété est fausse + */ + public Entity create(Map<String, Object> properties) throws TopiaException; + + /** + * Permet d'ajouter ou de mettre a jour un objet. Cela permet d'ajouter + * par exemple un objet provenant d'un autre context mais du meme type + * de DAO + * @param e l'entite a ajouter ou mettre a jour + * @return l'entity passé en paramètre. + * @throws TopiaException + */ + public abstract Entity update(Entity e) throws TopiaException; + + public abstract void delete(Entity e) throws TopiaException; + + public abstract Entity findByTopiaId(String k) throws TopiaException; + + public abstract List<Entity> findAll() throws TopiaException; + + public abstract List<Entity> findAllWithOrder(String... propertyNames) throws TopiaException; + + /** + * TODO modifier l'implantation pour faire un simple count sur la base + * + * @return + * @throws TopiaException + */ + public abstract int size() throws TopiaException; + + /** + * Recherche la classe en utilisant la cle naturelle, chaque champs de la + * cle naturelle est une entre de la map passe en argument. + * + * @param keys la liste des champs de la cle naturelle avec leur valeur + * @return + * @throws TopiaException + */ + public abstract Entity findByPrimaryKey(Map<String, Object> keys) throws TopiaException; + + /** + * Recherche la classe en utilisant la cle naturelle, si la cle naturelle + * est composé de plusieurs champs alors les arguments passés doivent être + * dans l'ordre de declaration dans le fichier de mapping + * + * @param k l'objet cle naturelle de la classe + * @return + * @throws TopiaException + */ + public abstract Entity findByPrimaryKey(Object... k) throws TopiaException; + + public abstract Entity findByProperty(String propertyName, Object value) + throws TopiaException; + + /** + * + * @param propertyName + * @param value + * @param others les autres proprietes doivent aller par 2 propertyName, + * value + * @return + * @throws TopiaException + */ + public abstract Entity findByProperties(String propertyName, Object value, + Object... others) throws TopiaException; + + public abstract Entity findByProperties(Map<String, Object> properties) + throws TopiaException; + + public abstract List<Entity> findAllByProperty(String propertyName, Object value) + throws TopiaException; + + /** + * + * @param propertyName + * @param value + * @param others les autres proprietes doivent aller par 2 propertyName, + * value + * @return + * @throws TopiaException + */ + public abstract List<Entity> findAllByProperties(String propertyName, Object value, + Object... others) throws TopiaException; + + public abstract List<Entity> findAllByProperties(Map<String, Object> properties) + throws TopiaException; + + /* + * Find Contains + */ + /** + * Cherche et renvoie la première entité trouvée dont les propriétés en clé + * de Map contiennent toutes les valeurs de la Collection. + */ + public abstract Entity findContainsProperties(Map<String, Collection> properties) + throws TopiaException; + + /** + * Cherche et renvoie la première entité trouvée dont la propriété + * propertyName contient values, ainsi de suite avec others. + */ + public abstract Entity findContainsProperties(String propertyName, Collection values, Object... others) + throws TopiaException; + + /** + * Cherche et renvoie la première entité trouvée dont les propriétés en clé + * de Map contiennent toutes les valeurs de la Collection. + */ + public abstract List<Entity> findAllContainsProperties(Map<String, Collection> properties) + throws TopiaException; + + /** + * Cherche et renvoie toutes les entités trouvées dont la propriété + * propertyName contient values, ainsi de suite avec others. + */ + public abstract List<Entity> findAllContainsProperties(String propertyName, Collection values, Object... others) + throws TopiaException; + + /** + * Retourne les permissions a verifier pour l'acces a l'entite pour le service Taas + * @param topiaId topiaId d'une entite + * @return la liste des permissions + */ + public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException; + + /* Adders */ + public void addTopiaEntityListener(TopiaEntityListener listener); + public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable); + + /* Removers */ + public void removeTopiaEntityListener(TopiaEntityListener listener); + public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable); + +} //TopiaDAO Deleted: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java 2008-11-14 11:16:46 UTC (rev 1223) +++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java 2008-11-17 09:39:40 UTC (rev 1227) @@ -1,707 +0,0 @@ -/* *##% ToPIA - Tools for Portable and Independent Architecture - * Copyright (C) 2004 - 2008 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>. ##%*/ - -/* * - * TopiaDAOAbstract.java - * - * Created: 31 déc. 2005 13:10:34 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - -package org.codelutin.topia.persistence; - -import java.io.Serializable; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.apache.commons.beanutils.PropertyUtils; -import org.apache.commons.lang.ObjectUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.topia.TopiaException; -import org.codelutin.topia.event.TopiaEntityListener; -import org.codelutin.topia.event.TopiaEntityVetoable; -import org.codelutin.topia.framework.TopiaContextImplementor; -import org.codelutin.topia.persistence.hibernate.TopiaDAOHibernate; -import org.hibernate.HibernateException; -import org.hibernate.criterion.Criterion; -import org.hibernate.criterion.Restrictions; -import org.hibernate.metadata.ClassMetadata; - - -/** - * Cette classe permet d'avoir un ensemble de méthode implantée de façon - * standard pour les différents DAO existant (FlatFile, Hibernate). - * Certaine méthode implanté ici sont particulièrement inéficace et il - * est conseillé de les surcharger dans les classes DAO spécifiques. - * - * Certain accès à Hibernate est tout de même fait ici, car on a pris le - * choix de se basé entièrement sur hibernate pour la persistence, et il - * est ainsi possible d'accèder au meta information hibernate sur les classes - * lorque l'on en a besoin. - * - * @author poussin - * - */ - -public abstract class TopiaDAOAbstract<Entity extends TopiaEntity> implements TopiaDAO<Entity> { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(TopiaDAOAbstract.class); - - protected Class<Entity> entityClass = null; - - protected TopiaContextImplementor context = null; - - public Class<Entity> getEntityClass() { - throw new UnsupportedOperationException("This method must be overided in generated DAO"); - } - - /** - * Retourne l'id de l'entity - * @param e l'entity - * @return l'id de l'entity ou null si pas trouvé - * @throws TopiaException Si une erreur survient durant la recherche - */ - protected Serializable getId(Entity e) throws TopiaException { - ClassMetadata meta = getClassMetadata(); - String idPropName = meta.getIdentifierPropertyName(); - - Serializable result; - try { - result = (Serializable)PropertyUtils.getSimpleProperty(e, idPropName); - } catch (IllegalAccessException eee) { - throw new TopiaException("Impossible de récuperer l'identifiant " + - idPropName + " de l'entite: " + e); - } catch (InvocationTargetException eee) { - throw new TopiaException("Impossible de récuperer l'identifiant " + - idPropName + " de l'entite: " + e); - } catch (NoSuchMethodException eee) { - throw new TopiaException("Impossible de récuperer l'identifiant " + - idPropName + " de l'entite: " + e); - } - return result; - } - - /** - * Retourne l'id de l'entity representer comme une map - * @param map l'entity en representation map - * @return l'id de l'entity ou null si pas trouvé - * @throws TopiaException Si une erreur survient durant la recherche - */ - protected Serializable getId(Map map) throws TopiaException { - try { - ClassMetadata meta = getClassMetadata(); - String idPropName = meta.getIdentifierPropertyName(); - - Serializable id = (Serializable)map.get(idPropName); - return id; - } catch (HibernateException eee) { - throw new TopiaException(eee); - } - } - - - /** - * When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just - * after - * - * @param entityClass - */ - public void init(TopiaContextImplementor context, Class<Entity> entityClass) throws TopiaException { - log.debug("init dao for " + entityClass.getName()); - this.context = context; - this.entityClass = entityClass; - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#getContext() - */ - public TopiaContextImplementor getContext() { - return context; - } - - @SuppressWarnings("unchecked") - protected Entity instanciateNew() throws TopiaException { - Entity result = null; - String classname = entityClass.getName(); - try { - // on commence par essayer d'instancier le Impl - result = ((Class<Entity>)Class.forName(classname+"Impl")).newInstance(); - if (log.isDebugEnabled()) { - log.debug("Utilisation de la classe " + classname+"Impl" + " pour " + classname); - } - } catch (InstantiationException eee) { - if (log.isWarnEnabled()) { - log.warn("Impossible d'instancier " + classname+"Impl"); - } - if (log.isDebugEnabled()) { - log.debug("StackTrace", eee); - } - } catch (IllegalAccessException eee) { - if (log.isWarnEnabled()) { - log.warn("Impossible d'instancier " + classname+"Impl"); - } - if (log.isDebugEnabled()) { - log.debug("StackTrace", eee); - } - } catch (ClassNotFoundException eee) { - if (log.isWarnEnabled()) { - log.warn("Impossible de trouver la classe " + classname+"Impl"); - } - if (log.isDebugEnabled()) { - log.debug("StackTrace", eee); - } - } - - if (result == null) { - // le impl n'est pas trouvé on essai avec la classe elle meme - try { - result = entityClass.newInstance(); - if (log.isDebugEnabled()) { - log.debug("Utilisation de la classe " + classname + " pour " + classname); - } - } catch (InstantiationException eee) { - if (log.isWarnEnabled()) { - log.warn("Impossible d'instancier " + classname); - } - if (log.isDebugEnabled()) { - log.debug("StackTrace", eee); - } - } catch (IllegalAccessException eee) { - if (log.isWarnEnabled()) { - log.warn("Impossible d'instancier " + classname); - } - if (log.isDebugEnabled()) { - log.debug("StackTrace", eee); - } - } - } - - if (result == null) { - throw new TopiaException("Impossible de trouver ou d'instancier la classe " + classname); - } - - return result; - } - - /** - * Par defaut ne fait rien - */ - public void commitTransaction() throws TopiaException { - } - - /** - * Par defaut ne fait rien - */ - public void rollbackTransaction() throws TopiaException { - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#create(java.lang.String, java.lang.Object, java.lang.Object) - */ - public Entity create(Object ... properties) throws TopiaException{ - Map<String, Object> map = new HashMap<String, Object>(); - Object propertyName = null; - Object value = null; - try { - for(int i=0; i<properties.length;) { - propertyName = properties[i++]; - value = properties[i++]; - map.put((String)propertyName, value); - } - } catch (ArrayIndexOutOfBoundsException eee) { - throw new IllegalArgumentException("Wrong number of argument " + properties.length + ", you must have even number. Last property name read: " + propertyName); - } catch (ClassCastException eee) { - throw new IllegalArgumentException("Wrong argument type, wait property name as String and have " + propertyName.getClass().getName()); - } - - Entity result = create(map); - return result; - } - - /** - * Cette methode appelle fireVetoableCreate et fireOnCreated - * Si vous la surchargé, faites attention a appeler le super - * ou a appeler vous aussi ces deux methodes. - */ - public Entity create(Map<String, Object> properties) throws TopiaException { - Entity result = instanciateNew(); - - // TODO reflechir s'il ne faudrait pas creer l'id avant l'event precedent - // reflechir toujours dans un context on les Entity pourrait ne pas - // etre des TopiaEntity - if (result instanceof TopiaEntity) { - String topiaId = TopiaId.create(entityClass); - TopiaEntityAbstract entity = (TopiaEntityAbstract)result; - entity.setTopiaId(topiaId); - entity.setTopiaContext(getContext()); - } - try { - for(Map.Entry<String, Object> e : properties.entrySet()) { - String propertyName = e.getKey(); - Object value = e.getValue(); - PropertyUtils.setProperty(result, (String)propertyName, value); - } - } catch (IllegalAccessException eee) { - throw new IllegalArgumentException("Can't put properties on new Object", eee); - } catch (InvocationTargetException eee) { - throw new IllegalArgumentException("Can't put properties on new Object", eee); - } catch (NoSuchMethodException eee) { - throw new IllegalArgumentException("Can't put properties on new Object", eee); - } - - result.postCreate(); - - return result; - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#size() - */ - public int size() throws TopiaException { - int result = findAll().size(); - return result; - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.util.Map) - */ - public Entity findByPrimaryKey(Map<String, Object> keys) throws TopiaException { - try { - // we used hibernate meta information for all persistence type - // it's more easy than create different for all persistence - ClassMetadata meta = getClassMetadata(); - if (meta.hasNaturalIdentifier()) { - Entity result = findByProperties(keys); - return result; - } - } catch (HibernateException eee) { - throw new TopiaException(eee); - } - throw new TopiaException("La classe " + entityClass.getName() - + " n'a pas de cle primaire naturelle"); - - } - - /** - * private method because this is hibernate specific method and we don't - * want expose it - * - * @return - * @throws TopiaException - */ - private ClassMetadata getClassMetadata() throws TopiaException { - ClassMetadata meta = getContext().getHibernateFactory() - .getClassMetadata(entityClass); - if (meta == null) { - meta = getContext().getHibernateFactory() - .getClassMetadata(entityClass.getName() + "Impl"); - } - return meta; - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.lang.Object) - */ - public Entity findByPrimaryKey(Object... k) throws TopiaException { - // TODO pour une meilleur gestion des problemes a la compilation - // mettre un premier couple (propName, value) en argument ca evitera - // de pouvoir appeler cette methode sans argument - try { - ClassMetadata meta = getClassMetadata(); - if (meta.hasNaturalIdentifier()) { - int[] ikeys = meta.getNaturalIdentifierProperties(); - String[] pnames = meta.getPropertyNames(); - - Map<String, Object> keys = new HashMap<String, Object>(); - for (int ikey : ikeys) { - keys.put(pnames[ikey], k[ikey]); - } - - Entity result = findByProperties(keys); - return result; - } - } catch (HibernateException eee) { - throw new TopiaException(eee); - } - throw new TopiaException("La classe " + entityClass.getName() - + " n'a pas de cle primaire naturelle"); - - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findByProperties(java.lang.String, java.lang.Object, java.lang.Object) - */ - public Entity findByProperties(String propertyName, Object value, - Object... others) throws TopiaException { - Map<String, Object> properties = new HashMap<String, Object>(); - properties.put(propertyName, value); - Object name = null; - for (int i = 0; i < others.length;) { - try { - name = others[i++]; - value = others[i++]; - properties.put((String) name, value); - } catch (ClassCastException eee) { - throw new IllegalArgumentException( - "Les noms des propriétés doivent être des chaines et non pas " - + propertyName.getClass().getName(), eee); - } catch (ArrayIndexOutOfBoundsException eee) { - throw new IllegalArgumentException( - "Le nombre d'argument n'est pas un nombre pair: " - + (others.length + 2) + " La dernière propriété était: " + name, eee); - } - } - Entity result = findByProperties(properties); - return result; - } - - /** - * Recherche une entity contenant certain propriété. Pour l'instant on - * charche toute les entités existantes pour faire la recherche - * - * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.util.Map) - */ - public List<Entity> findAllByProperties(Map<String, Object> properties) - throws TopiaException { - List<Entity> all = findAll(); - List<Entity> result = new ArrayList<Entity>(); - for (Entity e : all) { - boolean ok = true; - try { - for(Entry<String, Object> kv : properties.entrySet()) { - Object entityValue = PropertyUtils.getProperty(e, kv.getKey()); - Object value = kv.getValue(); - if (!ObjectUtils.equals(entityValue, value)) { - ok = false; - break; - } - } - } catch (IllegalAccessException eee) { - ok = false; - if (log.isWarnEnabled()) { - log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee); - } - } catch (InvocationTargetException eee) { - ok = false; - if (log.isWarnEnabled()) { - log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee); - } - } catch (NoSuchMethodException eee) { - ok = false; - if (log.isWarnEnabled()) { - log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee); - } - } - if (ok) { - result.add(e); - } - } - return result; - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.lang.String, java.lang.Object, java.lang.Object) - */ - public List<Entity> findAllByProperties(String propertyName, Object value, - Object... others) throws TopiaException { - Map<String, Object> properties = new HashMap<String, Object>(); - properties.put(propertyName, value); - Object name = null; - for (int i = 0; i < others.length;) { - try { - name = others[i++]; - value = others[i++]; - properties.put((String) name, value); - } catch (ClassCastException eee) { - throw new IllegalArgumentException( - "Les noms des propriétés doivent être des chaines et non pas " - + propertyName.getClass().getName(), eee); - } catch (ArrayIndexOutOfBoundsException eee) { - throw new IllegalArgumentException( - "Le nombre d'argument n'est pas un nombre pair: " - + (others.length + 2) + " La dernière propriété était: " + name, eee); - } - } - List<Entity> result = findAllByProperties(properties); - return result; - } - - /* (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map) - */ - public Entity findContainsProperties(Map<String, Collection> properties) - throws TopiaException { - List<Entity> results = findAllContainsProperties(properties); - Entity result = null; - if (results.size() > 0) { - result = results.get(0); - } - return result; - } - - /* (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[]) - */ - public Entity findContainsProperties(String propertyName, Collection values, Object... others) - throws TopiaException { - Map<String, Collection> properties = new HashMap<String, Collection>(); - properties.put(propertyName, values); - Object name = null; - for (int i = 0; i < others.length;) { - try { - name = others[i++]; - values = (Collection)others[i++]; - properties.put((String) name, values); - } catch (ClassCastException eee) { - throw new IllegalArgumentException( - "Les noms des propriétés doivent être des chaines et non pas " - + propertyName.getClass().getName(), eee); - } catch (ArrayIndexOutOfBoundsException eee) { - throw new IllegalArgumentException( - "Le nombre d'argument n'est pas un nombre pair: " - + (others.length + 2) + " La dernière propriété était: " + name, eee); - } - } - Entity result = findContainsProperties(properties); - return result; - } - - /* (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map) - */ - public List<Entity> findAllContainsProperties(Map<String, Collection> properties) - throws TopiaException { - List<Entity> all = findAll(); - List<Entity> result = new ArrayList<Entity>(); - for (Entity e : all) { - boolean ok = true; - try { - for(Entry<String, Collection> kv : properties.entrySet()) { - Collection entityValues = (Collection)PropertyUtils.getProperty(e, kv.getKey()); - Collection values = kv.getValue(); - if (!entityValues.containsAll(values)) { - ok = false; - break; - } - } - } catch (IllegalAccessException eee) { - ok = false; - if (log.isWarnEnabled()) { - log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee); - } - } catch (InvocationTargetException eee) { - ok = false; - if (log.isWarnEnabled()) { - log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee); - } - } catch (NoSuchMethodException eee) { - ok = false; - if (log.isWarnEnabled()) { - log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee); - } - } - if (ok) { - result.add(e); - } - } - return result; - } - - /* (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[]) - */ - public List<Entity> findAllContainsProperties(String propertyName, Collection values, Object... others) - throws TopiaException { - Map<String, Collection> properties = new HashMap<String, Collection>(); - properties.put(propertyName, values); - Object name = null; - for (int i = 0; i < others.length;) { - try { - name = others[i++]; - values = (Collection)others[i++]; - properties.put((String) name, values); - } catch (ClassCastException eee) { - throw new IllegalArgumentException( - "Les noms des propriétés doivent être des chaines et non pas " - + propertyName.getClass().getName(), eee); - } catch (ArrayIndexOutOfBoundsException eee) { - throw new IllegalArgumentException( - "Le nombre d'argument n'est pas un nombre pair: " - + (others.length + 2) + " La dernière propriété était: " + name, eee); - } - } - List<Entity> result = findAllContainsProperties(properties); - return result; - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findByTopiaId() - */ - public Entity findByTopiaId(String k) throws TopiaException { - Entity result = findByProperty("topiaId", k); - return result; - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findAll() - */ - public List<Entity> findAll() throws TopiaException { - Map<String, Object> properties = new HashMap<String, Object>(); - List<Entity> result = findAllByProperties(properties); - return result; - } - - /* (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#findAllByProperty(java.lang.String, java.lang.Object) - */ - public List<Entity> findAllByProperty(String propertyName, Object value) throws TopiaException { - Map<String, Object> properties = new HashMap<String, Object>(); - properties.put(propertyName, value); - List<Entity> result = findAllByProperties(properties); - return result; - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findByProperty(java.lang.String, java.lang.Object) - */ - public Entity findByProperty(String propertyName, Object value) - throws TopiaException { - Map<String, Object> properties = new HashMap<String, Object>(); - properties.put(propertyName, value); - Entity result = findByProperties(properties); - return result; - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findByProperties(java.util.Map) - */ - public Entity findByProperties(Map<String, Object> properties) - throws TopiaException { - List<Entity> listResult = findAllByProperties(properties); - Entity result = null; - if (listResult.size() > 0) { - result = listResult.get(0); - } - return result; - } - - @Deprecated - private Criterion computeCriterions(Object ... values) { - if (values == null) { - return null; - } - Criterion criterion = null; - for (Object value : values) { - criterion = or(criterion, computeCriterion(value)); - } - return criterion; - } - - @Deprecated - private Criterion computeCriterion(Object value) { - Criterion criterion = null; - SearchFields fields = entityClass.getAnnotation(SearchFields.class); - String textValue = "%" + value + "%"; - //textFields - String[] textFields = fields.txtFields(); - for (String propName : textFields) { - criterion = or(criterion, Restrictions.like(propName, textValue)); - } - //numFields - boolean isNumber = (value instanceof Number); - if (value instanceof String) { - try { - Double.parseDouble((String) value); - isNumber = true; - } catch (NumberFormatException nfe) { - isNumber = false; - } - - } - if (isNumber) { - String[] numFields = fields.numFields(); - for (String propName : numFields) { - criterion = or(criterion, Restrictions.sqlRestriction(propName + " like '" + textValue + "'")); - } - } - //boolFields - boolean isBoolean = (value instanceof Boolean); - if (value instanceof String) { - isBoolean |= ("true".equalsIgnoreCase((String)value) - || "false".equalsIgnoreCase((String)value)); - } - if (isBoolean) { - Boolean booleanValue; - if (value instanceof String) { - booleanValue = Boolean.valueOf((String)value); - } else { - booleanValue = (Boolean)value; - } - String[] boolFields = fields.numFields(); - for (String propName : boolFields) { - criterion = or(criterion, Restrictions.eq(propName, booleanValue)); - } - } - //timeFields - String[] timeFields = fields.dateFields(); - for (String propName : timeFields) { - criterion = or(criterion, Restrictions.sqlRestriction(propName + " like '" + textValue + "'")); - } - return criterion; - } - - @Deprecated - private Criterion or(Criterion crit1, Criterion crit2) { - if (crit1 == null) { - return crit2; - } - if (crit2 == null) { - return crit1; - } - return Restrictions.or(crit1, crit2); - } - - public void addTopiaEntityListener(TopiaEntityListener listener) { - getContext().addTopiaEntityListener((Class<TopiaEntity>) entityClass, listener); - } - - public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) { - getContext().addTopiaEntityVetoable((Class<TopiaEntity>) entityClass, vetoable); - } - - public void removeTopiaEntityListener(TopiaEntityListener listener) { - getContext().removeTopiaEntityListener((Class<TopiaEntity>) entityClass, listener); - } - - public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) { - getContext().removeTopiaEntityVetoable((Class<TopiaEntity>) entityClass, vetoable); - } - - -} //TopiaDAOAbstract Copied: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java (from rev 1224, topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java) =================================================================== --- topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java (rev 0) +++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java 2008-11-17 09:39:40 UTC (rev 1227) @@ -0,0 +1,707 @@ +/* *##% ToPIA - Tools for Portable and Independent Architecture + * Copyright (C) 2004 - 2008 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>. ##%*/ + +/* * + * TopiaDAOAbstract.java + * + * Created: 31 déc. 2005 13:10:34 + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ + +package org.codelutin.topia.persistence; + +import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.commons.beanutils.PropertyUtils; +import org.apache.commons.lang.ObjectUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.topia.TopiaException; +import org.codelutin.topia.event.TopiaEntityListener; +import org.codelutin.topia.event.TopiaEntityVetoable; +import org.codelutin.topia.framework.TopiaContextImplementor; +import org.codelutin.topia.persistence.hibernate.TopiaDAOHibernate; +import org.hibernate.HibernateException; +import org.hibernate.criterion.Criterion; +import org.hibernate.criterion.Restrictions; +import org.hibernate.metadata.ClassMetadata; + + +/** + * Cette classe permet d'avoir un ensemble de méthode implantée de façon + * standard pour les différents DAO existant (FlatFile, Hibernate). + * Certaine méthode implanté ici sont particulièrement inéficace et il + * est conseillé de les surcharger dans les classes DAO spécifiques. + * + * Certain accès à Hibernate est tout de même fait ici, car on a pris le + * choix de se basé entièrement sur hibernate pour la persistence, et il + * est ainsi possible d'accèder au meta information hibernate sur les classes + * lorque l'on en a besoin. + * + * @author poussin + * + */ + +public abstract class TopiaDAOAbstract<Entity extends TopiaEntity> implements TopiaDAO<Entity> { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(TopiaDAOAbstract.class); + + protected Class<Entity> entityClass = null; + + protected TopiaContextImplementor context = null; + + public Class<Entity> getEntityClass() { + throw new UnsupportedOperationException("This method must be overided in generated DAO"); + } + + /** + * Retourne l'id de l'entity + * @param e l'entity + * @return l'id de l'entity ou null si pas trouvé + * @throws TopiaException Si une erreur survient durant la recherche + */ + protected Serializable getId(Entity e) throws TopiaException { + ClassMetadata meta = getClassMetadata(); + String idPropName = meta.getIdentifierPropertyName(); + + Serializable result; + try { + result = (Serializable)PropertyUtils.getSimpleProperty(e, idPropName); + } catch (IllegalAccessException eee) { + throw new TopiaException("Impossible de récuperer l'identifiant " + + idPropName + " de l'entite: " + e); + } catch (InvocationTargetException eee) { + throw new TopiaException("Impossible de récuperer l'identifiant " + + idPropName + " de l'entite: " + e); + } catch (NoSuchMethodException eee) { + throw new TopiaException("Impossible de récuperer l'identifiant " + + idPropName + " de l'entite: " + e); + } + return result; + } + + /** + * Retourne l'id de l'entity representer comme une map + * @param map l'entity en representation map + * @return l'id de l'entity ou null si pas trouvé + * @throws TopiaException Si une erreur survient durant la recherche + */ + protected Serializable getId(Map map) throws TopiaException { + try { + ClassMetadata meta = getClassMetadata(); + String idPropName = meta.getIdentifierPropertyName(); + + Serializable id = (Serializable)map.get(idPropName); + return id; + } catch (HibernateException eee) { + throw new TopiaException(eee); + } + } + + + /** + * When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just + * after + * + * @param entityClass + */ + public void init(TopiaContextImplementor context, Class<Entity> entityClass) throws TopiaException { + log.debug("init dao for " + entityClass.getName()); + this.context = context; + this.entityClass = entityClass; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#getContext() + */ + public TopiaContextImplementor getContext() { + return context; + } + + @SuppressWarnings("unchecked") + protected Entity instanciateNew() throws TopiaException { + Entity result = null; + String classname = entityClass.getName(); + try { + // on commence par essayer d'instancier le Impl + result = ((Class<Entity>)Class.forName(classname+"Impl")).newInstance(); + if (log.isDebugEnabled()) { + log.debug("Utilisation de la classe " + classname+"Impl" + " pour " + classname); + } + } catch (InstantiationException eee) { + if (log.isWarnEnabled()) { + log.warn("Impossible d'instancier " + classname+"Impl"); + } + if (log.isDebugEnabled()) { + log.debug("StackTrace", eee); + } + } catch (IllegalAccessException eee) { + if (log.isWarnEnabled()) { + log.warn("Impossible d'instancier " + classname+"Impl"); + } + if (log.isDebugEnabled()) { + log.debug("StackTrace", eee); + } + } catch (ClassNotFoundException eee) { + if (log.isWarnEnabled()) { + log.warn("Impossible de trouver la classe " + classname+"Impl"); + } + if (log.isDebugEnabled()) { + log.debug("StackTrace", eee); + } + } + + if (result == null) { + // le impl n'est pas trouvé on essai avec la classe elle meme + try { + result = entityClass.newInstance(); + if (log.isDebugEnabled()) { + log.debug("Utilisation de la classe " + classname + " pour " + classname); + } + } catch (InstantiationException eee) { + if (log.isWarnEnabled()) { + log.warn("Impossible d'instancier " + classname); + } + if (log.isDebugEnabled()) { + log.debug("StackTrace", eee); + } + } catch (IllegalAccessException eee) { + if (log.isWarnEnabled()) { + log.warn("Impossible d'instancier " + classname); + } + if (log.isDebugEnabled()) { + log.debug("StackTrace", eee); + } + } + } + + if (result == null) { + throw new TopiaException("Impossible de trouver ou d'instancier la classe " + classname); + } + + return result; + } + + /** + * Par defaut ne fait rien + */ + public void commitTransaction() throws TopiaException { + } + + /** + * Par defaut ne fait rien + */ + public void rollbackTransaction() throws TopiaException { + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#create(java.lang.String, java.lang.Object, java.lang.Object) + */ + public Entity create(Object ... properties) throws TopiaException{ + Map<String, Object> map = new HashMap<String, Object>(); + Object propertyName = null; + Object value = null; + try { + for(int i=0; i<properties.length;) { + propertyName = properties[i++]; + value = properties[i++]; + map.put((String)propertyName, value); + } + } catch (ArrayIndexOutOfBoundsException eee) { + throw new IllegalArgumentException("Wrong number of argument " + properties.length + ", you must have even number. Last property name read: " + propertyName); + } catch (ClassCastException eee) { + throw new IllegalArgumentException("Wrong argument type, wait property name as String and have " + propertyName.getClass().getName()); + } + + Entity result = create(map); + return result; + } + + /** + * Cette methode appelle fireVetoableCreate et fireOnCreated + * Si vous la surchargé, faites attention a appeler le super + * ou a appeler vous aussi ces deux methodes. + */ + public Entity create(Map<String, Object> properties) throws TopiaException { + Entity result = instanciateNew(); + + // TODO reflechir s'il ne faudrait pas creer l'id avant l'event precedent + // reflechir toujours dans un context on les Entity pourrait ne pas + // etre des TopiaEntity + if (result instanceof TopiaEntity) { + String topiaId = TopiaId.create(entityClass); + TopiaEntityAbstract entity = (TopiaEntityAbstract)result; + entity.setTopiaId(topiaId); + entity.setTopiaContext(getContext()); + } + try { + for(Map.Entry<String, Object> e : properties.entrySet()) { + String propertyName = e.getKey(); + Object value = e.getValue(); + PropertyUtils.setProperty(result, (String)propertyName, value); + } + } catch (IllegalAccessException eee) { + throw new IllegalArgumentException("Can't put properties on new Object", eee); + } catch (InvocationTargetException eee) { + throw new IllegalArgumentException("Can't put properties on new Object", eee); + } catch (NoSuchMethodException eee) { + throw new IllegalArgumentException("Can't put properties on new Object", eee); + } + + result.postCreate(); + + return result; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#size() + */ + public int size() throws TopiaException { + int result = findAll().size(); + return result; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.util.Map) + */ + public Entity findByPrimaryKey(Map<String, Object> keys) throws TopiaException { + try { + // we used hibernate meta information for all persistence type + // it's more easy than create different for all persistence + ClassMetadata meta = getClassMetadata(); + if (meta.hasNaturalIdentifier()) { + Entity result = findByProperties(keys); + return result; + } + } catch (HibernateException eee) { + throw new TopiaException(eee); + } + throw new TopiaException("La classe " + entityClass.getName() + + " n'a pas de cle primaire naturelle"); + + } + + /** + * private method because this is hibernate specific method and we don't + * want expose it + * + * @return + * @throws TopiaException + */ + private ClassMetadata getClassMetadata() throws TopiaException { + ClassMetadata meta = getContext().getHibernateFactory() + .getClassMetadata(entityClass); + if (meta == null) { + meta = getContext().getHibernateFactory() + .getClassMetadata(entityClass.getName() + "Impl"); + } + return meta; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.lang.Object) + */ + public Entity findByPrimaryKey(Object... k) throws TopiaException { + // TODO pour une meilleur gestion des problemes a la compilation + // mettre un premier couple (propName, value) en argument ca evitera + // de pouvoir appeler cette methode sans argument + try { + ClassMetadata meta = getClassMetadata(); + if (meta.hasNaturalIdentifier()) { + int[] ikeys = meta.getNaturalIdentifierProperties(); + String[] pnames = meta.getPropertyNames(); + + Map<String, Object> keys = new HashMap<String, Object>(); + for (int ikey : ikeys) { + keys.put(pnames[ikey], k[ikey]); + } + + Entity result = findByProperties(keys); + return result; + } + } catch (HibernateException eee) { + throw new TopiaException(eee); + } + throw new TopiaException("La classe " + entityClass.getName() + + " n'a pas de cle primaire naturelle"); + + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findByProperties(java.lang.String, java.lang.Object, java.lang.Object) + */ + public Entity findByProperties(String propertyName, Object value, + Object... others) throws TopiaException { + Map<String, Object> properties = new HashMap<String, Object>(); + properties.put(propertyName, value); + Object name = null; + for (int i = 0; i < others.length;) { + try { + name = others[i++]; + value = others[i++]; + properties.put((String) name, value); + } catch (ClassCastException eee) { + throw new IllegalArgumentException( + "Les noms des propriétés doivent être des chaines et non pas " + + propertyName.getClass().getName(), eee); + } catch (ArrayIndexOutOfBoundsException eee) { + throw new IllegalArgumentException( + "Le nombre d'argument n'est pas un nombre pair: " + + (others.length + 2) + " La dernière propriété était: " + name, eee); + } + } + Entity result = findByProperties(properties); + return result; + } + + /** + * Recherche une entity contenant certain propriété. Pour l'instant on + * charche toute les entités existantes pour faire la recherche + * + * @see org.codelutin.topia.persistence.TopiaDAO#findAllByProperties(java.util.Map) + */ + public List<Entity> findAllByProperties(Map<String, Object> properties) + throws TopiaException { + List<Entity> all = findAll(); + List<Entity> result = new ArrayList<Entity>(); + for (Entity e : all) { + boolean ok = true; + try { + for(Entry<String, Object> kv : properties.entrySet()) { + Object entityValue = PropertyUtils.getProperty(e, kv.getKey()); + Object value = kv.getValue(); + if (!ObjectUtils.equals(entityValue, value)) { + ok = false; + break; + } + } + } catch (IllegalAccessException eee) { + ok = false; + if (log.isWarnEnabled()) { + log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee); + } + } catch (InvocationTargetException eee) { + ok = false; + if (log.isWarnEnabled()) { + log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee); + } + } catch (NoSuchMethodException eee) { + ok = false; + if (log.isWarnEnabled()) { + log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee); + } + } + if (ok) { + result.add(e); + } + } + return result; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.lang.String, java.lang.Object, java.lang.Object) + */ + public List<Entity> findAllByProperties(String propertyName, Object value, + Object... others) throws TopiaException { + Map<String, Object> properties = new HashMap<String, Object>(); + properties.put(propertyName, value); + Object name = null; + for (int i = 0; i < others.length;) { + try { + name = others[i++]; + value = others[i++]; + properties.put((String) name, value); + } catch (ClassCastException eee) { + throw new IllegalArgumentException( + "Les noms des propriétés doivent être des chaines et non pas " + + propertyName.getClass().getName(), eee); + } catch (ArrayIndexOutOfBoundsException eee) { + throw new IllegalArgumentException( + "Le nombre d'argument n'est pas un nombre pair: " + + (others.length + 2) + " La dernière propriété était: " + name, eee); + } + } + List<Entity> result = findAllByProperties(properties); + return result; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map) + */ + public Entity findContainsProperties(Map<String, Collection> properties) + throws TopiaException { + List<Entity> results = findAllContainsProperties(properties); + Entity result = null; + if (results.size() > 0) { + result = results.get(0); + } + return result; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[]) + */ + public Entity findContainsProperties(String propertyName, Collection values, Object... others) + throws TopiaException { + Map<String, Collection> properties = new HashMap<String, Collection>(); + properties.put(propertyName, values); + Object name = null; + for (int i = 0; i < others.length;) { + try { + name = others[i++]; + values = (Collection)others[i++]; + properties.put((String) name, values); + } catch (ClassCastException eee) { + throw new IllegalArgumentException( + "Les noms des propriétés doivent être des chaines et non pas " + + propertyName.getClass().getName(), eee); + } catch (ArrayIndexOutOfBoundsException eee) { + throw new IllegalArgumentException( + "Le nombre d'argument n'est pas un nombre pair: " + + (others.length + 2) + " La dernière propriété était: " + name, eee); + } + } + Entity result = findContainsProperties(properties); + return result; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map) + */ + public List<Entity> findAllContainsProperties(Map<String, Collection> properties) + throws TopiaException { + List<Entity> all = findAll(); + List<Entity> result = new ArrayList<Entity>(); + for (Entity e : all) { + boolean ok = true; + try { + for(Entry<String, Collection> kv : properties.entrySet()) { + Collection entityValues = (Collection)PropertyUtils.getProperty(e, kv.getKey()); + Collection values = kv.getValue(); + if (!entityValues.containsAll(values)) { + ok = false; + break; + } + } + } catch (IllegalAccessException eee) { + ok = false; + if (log.isWarnEnabled()) { + log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee); + } + } catch (InvocationTargetException eee) { + ok = false; + if (log.isWarnEnabled()) { + log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee); + } + } catch (NoSuchMethodException eee) { + ok = false; + if (log.isWarnEnabled()) { + log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee); + } + } + if (ok) { + result.add(e); + } + } + return result; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[]) + */ + public List<Entity> findAllContainsProperties(String propertyName, Collection values, Object... others) + throws TopiaException { + Map<String, Collection> properties = new HashMap<String, Collection>(); + properties.put(propertyName, values); + Object name = null; + for (int i = 0; i < others.length;) { + try { + name = others[i++]; + values = (Collection)others[i++]; + properties.put((String) name, values); + } catch (ClassCastException eee) { + throw new IllegalArgumentException( + "Les noms des propriétés doivent être des chaines et non pas " + + propertyName.getClass().getName(), eee); + } catch (ArrayIndexOutOfBoundsException eee) { + throw new IllegalArgumentException( + "Le nombre d'argument n'est pas un nombre pair: " + + (others.length + 2) + " La dernière propriété était: " + name, eee); + } + } + List<Entity> result = findAllContainsProperties(properties); + return result; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findByTopiaId() + */ + public Entity findByTopiaId(String k) throws TopiaException { + Entity result = findByProperty("topiaId", k); + return result; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findAll() + */ + public List<Entity> findAll() throws TopiaException { + Map<String, Object> properties = new HashMap<String, Object>(); + List<Entity> result = findAllByProperties(properties); + return result; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#findAllByProperty(java.lang.String, java.lang.Object) + */ + public List<Entity> findAllByProperty(String propertyName, Object value) throws TopiaException { + Map<String, Object> properties = new HashMap<String, Object>(); + properties.put(propertyName, value); + List<Entity> result = findAllByProperties(properties); + return result; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findByProperty(java.lang.String, java.lang.Object) + */ + public Entity findByProperty(String propertyName, Object value) + throws TopiaException { + Map<String, Object> properties = new HashMap<String, Object>(); + properties.put(propertyName, value); + Entity result = findByProperties(properties); + return result; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findByProperties(java.util.Map) + */ + public Entity findByProperties(Map<String, Object> properties) + throws TopiaException { + List<Entity> listResult = findAllByProperties(properties); + Entity result = null; + if (listResult.size() > 0) { + result = listResult.get(0); + } + return result; + } + + @Deprecated + private Criterion computeCriterions(Object ... values) { + if (values == null) { + return null; + } + Criterion criterion = null; + for (Object value : values) { + criterion = or(criterion, computeCriterion(value)); + } + return criterion; + } + + @Deprecated + private Criterion computeCriterion(Object value) { + Criterion criterion = null; + SearchFields fields = entityClass.getAnnotation(SearchFields.class); + String textValue = "%" + value + "%"; + //textFields + String[] textFields = fields.txtFields(); + for (String propName : textFields) { + criterion = or(criterion, Restrictions.like(propName, textValue)); + } + //numFields + boolean isNumber = (value instanceof Number); + if (value instanceof String) { + try { + Double.parseDouble((String) value); + isNumber = true; + } catch (NumberFormatException nfe) { + isNumber = false; + } + + } + if (isNumber) { + String[] numFields = fields.numFields(); + for (String propName : numFields) { + criterion = or(criterion, Restrictions.sqlRestriction(propName + " like '" + textValue + "'")); + } + } + //boolFields + boolean isBoolean = (value instanceof Boolean); + if (value instanceof String) { + isBoolean |= ("true".equalsIgnoreCase((String)value) + || "false".equalsIgnoreCase((String)value)); + } + if (isBoolean) { + Boolean booleanValue; + if (value instanceof String) { + booleanValue = Boolean.valueOf((String)value); + } else { + booleanValue = (Boolean)value; + } + String[] boolFields = fields.numFields(); + for (String propName : boolFields) { + criterion = or(criterion, Restrictions.eq(propName, booleanValue)); + } + } + //timeFields + String[] timeFields = fields.dateFields(); + for (String propName : timeFields) { + criterion = or(criterion, Restrictions.sqlRestriction(propName + " like '" + textValue + "'")); + } + return criterion; + } + + @Deprecated + private Criterion or(Criterion crit1, Criterion crit2) { + if (crit1 == null) { + return crit2; + } + if (crit2 == null) { + return crit1; + } + return Restrictions.or(crit1, crit2); + } + + public void addTopiaEntityListener(TopiaEntityListener listener) { + getContext().addTopiaEntityListener((Class<TopiaEntity>) entityClass, listener); + } + + public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) { + getContext().addTopiaEntityVetoable((Class<TopiaEntity>) entityClass, vetoable); + } + + public void removeTopiaEntityListener(TopiaEntityListener listener) { + getContext().removeTopiaEntityListener((Class<TopiaEntity>) entityClass, listener); + } + + public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) { + getContext().removeTopiaEntityVetoable((Class<TopiaEntity>) entityClass, vetoable); + } + + +} //TopiaDAOAbstract Deleted: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java 2008-11-14 11:16:46 UTC (rev 1223) +++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java 2008-11-17 09:39:40 UTC (rev 1227) @@ -1,278 +0,0 @@ -/* *##% ToPIA - Tools for Portable and Independent Architecture - * Copyright (C) 2004 - 2008 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>. ##%*/ - -/* * - * TopiaDAODelegator.java - * - * Created: 30 déc. 2005 22:28:48 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - -package org.codelutin.topia.persistence; - -import java.security.Permission; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import org.codelutin.topia.TopiaException; -import org.codelutin.topia.event.TopiaEntityListener; -import org.codelutin.topia.event.TopiaEntityVetoable; -import org.codelutin.topia.framework.TopiaContextImplementor; - - -/** - * Cette classe est utilisé par les DAO générés pour encapsuler un véritable - * DAO (Hibernate, FlatFile) - * On utilise donc le pattern (TODO retrouver le nom du pattern) qui permet - * de générer les classes sans ce soucier de quel DAO va etre utilisé - * a l'execution. - * - * @author poussin - * - */ - -public class TopiaDAODelegator<Entity extends TopiaEntity> implements TopiaDAO<Entity> { - - /** - * DAO reel sur lequel on peut s'appuyer pour faire les requetes - */ - protected TopiaDAO<Entity> parentDAO = null; - - /** - * A priori seul les enfants on besoin de le recuperer - */ - protected TopiaDAO<Entity> getParentDAO() { - return parentDAO; - } - /** - * Le setter est public car potentiellement le context qui le cree n'est - * pas dans le meme package, mais seul le context doit utiliser cette - * methode - */ - public void setParentDAO(TopiaDAO<Entity> v) { - this.parentDAO = v; - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#init(org.codelutin.topia.TopiaContextImpl, java.lang.Class) - */ - public void init(TopiaContextImplementor context, Class entityClass) throws TopiaException { - // rien a faire cette methode a ete appele sur le parentDAO - } - - /* (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#getEntityClass() - */ - public Class<Entity> getEntityClass() { - return getParentDAO().getEntityClass(); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#getContext() - */ - public TopiaContextImplementor getContext() { - return getParentDAO().getContext(); - } - - public void commitTransaction() throws TopiaException { - getParentDAO().commitTransaction(); - } - public void rollbackTransaction() throws TopiaException { - getParentDAO().rollbackTransaction(); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#create(java.lang.String, java.lang.Object, java.lang.Object...) - */ - public Entity create(Object... properties) throws TopiaException { - return getParentDAO().create(properties); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#create(java.util.Map) - */ - public Entity create(Map<String, Object> properties) throws TopiaException { - return getParentDAO().create(properties); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#update(Entity) - */ - public Entity update(Entity e) throws TopiaException { - return getParentDAO().update(e); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#delete(Entity) - */ - public void delete(Entity e) throws TopiaException { - getParentDAO().delete(e); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findByTopiaId(java.lang.Object) - */ - public Entity findByTopiaId(String k) throws TopiaException { - return getParentDAO().findByTopiaId(k); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findAll() - */ - public List<Entity> findAll() throws TopiaException { - return getParentDAO().findAll(); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#size() - */ - public int size() throws TopiaException { - return getParentDAO().size(); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.util.Map) - */ - public Entity findByPrimaryKey(Map<String, Object> keys) throws TopiaException { - return getParentDAO().findByPrimaryKey(keys); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.lang.Object...) - */ - public Entity findByPrimaryKey(Object... k) throws TopiaException { - return getParentDAO().findByPrimaryKey(k); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findByProperty(java.lang.String, java.lang.Object) - */ - public Entity findByProperty(String propertyName, Object value) - throws TopiaException { - return getParentDAO().findByProperty(propertyName, value); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findByProperties(java.lang.String, java.lang.Object, java.lang.Object...) - */ - public Entity findByProperties(String propertyName, Object value, - Object... others) throws TopiaException { - return getParentDAO().findByProperties(propertyName, value, others); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findByProperties(java.util.Map) - */ - public Entity findByProperties(Map<String, Object> properties) throws TopiaException { - return getParentDAO().findByProperties(properties); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findAllByProperty(java.lang.String, java.lang.Object) - */ - public List<Entity> findAllByProperty(String propertyName, Object value) - throws TopiaException { - return getParentDAO().findAllByProperty(propertyName, value); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.lang.String, java.lang.Object, java.lang.Object...) - */ - public List<Entity> findAllByProperties(String propertyName, Object value, - Object... others) throws TopiaException { - return getParentDAO().findAllByProperties(propertyName, value, others); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.util.Map) - */ - public List<Entity> findAllByProperties(Map<String, Object> properties) throws TopiaException { - return getParentDAO().findAllByProperties(properties); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map) - */ - public Entity findContainsProperties(Map<String, Collection> properties) throws TopiaException { - return getParentDAO().findContainsProperties(properties); - } - /* (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[]) - */ - public Entity findContainsProperties(String propertyName, Collection values, Object... others) throws TopiaException { - return getParentDAO().findContainsProperties(propertyName, values, others); - } - /* (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map) - */ - public List<Entity> findAllContainsProperties(Map<String, Collection> properties) throws TopiaException { - return getParentDAO().findAllContainsProperties(properties); - } - /* (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[]) - */ - public List<Entity> findAllContainsProperties(String propertyName, Collection values, Object... others) throws TopiaException { - return getParentDAO().findAllContainsProperties(propertyName, values, others); - } - - /* - * (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#addTopiaEntityListener(org.codelutin.topia.event.TopiaEntityListener) - */ - public void addTopiaEntityListener(TopiaEntityListener listener) { - getParentDAO().addTopiaEntityListener(listener); - } - - /* - * (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#addTopiaEntityVetoable(org.codelutin.topia.event.TopiaEntityVetoable) - */ - public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) { - getParentDAO().addTopiaEntityVetoable(vetoable); - } - - /* - * (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#removeTopiaEntityListener(org.codelutin.topia.event.TopiaEntityListener) - */ - public void removeTopiaEntityListener(TopiaEntityListener listener) { - getParentDAO().removeTopiaEntityListener(listener); - } - - /* - * (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#removeTopiaEntityVetoable(org.codelutin.topia.event.TopiaEntityVetoable) - */ - public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) { - getParentDAO().removeTopiaEntityVetoable(vetoable); - } - - /* - * (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#getRequestPermission(java.lang.String, int) - */ - public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException { - return getParentDAO().getRequestPermission(topiaId, actions); - } - -} //TopiaDAODelegator Copied: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java (from rev 1224, topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java) =================================================================== --- topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java (rev 0) +++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java 2008-11-17 09:39:40 UTC (rev 1227) @@ -0,0 +1,282 @@ +/* *##% ToPIA - Tools for Portable and Independent Architecture + * Copyright (C) 2004 - 2008 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>. ##%*/ + +/* * + * TopiaDAODelegator.java + * + * Created: 30 déc. 2005 22:28:48 + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ + +package org.codelutin.topia.persistence; + +import java.security.Permission; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.codelutin.topia.TopiaException; +import org.codelutin.topia.event.TopiaEntityListener; +import org.codelutin.topia.event.TopiaEntityVetoable; +import org.codelutin.topia.framework.TopiaContextImplementor; + + +/** + * Cette classe est utilisé par les DAO générés pour encapsuler un véritable + * DAO (Hibernate, FlatFile) + * On utilise donc le pattern (TODO retrouver le nom du pattern) qui permet + * de générer les classes sans ce soucier de quel DAO va etre utilisé + * a l'execution. + * + * @author poussin + * + */ + +public class TopiaDAODelegator<Entity extends TopiaEntity> implements TopiaDAO<Entity> { + + /** + * DAO reel sur lequel on peut s'appuyer pour faire les requetes + */ + protected TopiaDAO<Entity> parentDAO = null; + + /** + * A priori seul les enfants on besoin de le recuperer + */ + protected TopiaDAO<Entity> getParentDAO() { + return parentDAO; + } + /** + * Le setter est public car potentiellement le context qui le cree n'est + * pas dans le meme package, mais seul le context doit utiliser cette + * methode + */ + public void setParentDAO(TopiaDAO<Entity> v) { + this.parentDAO = v; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#init(org.codelutin.topia.TopiaContextImpl, java.lang.Class) + */ + public void init(TopiaContextImplementor context, Class entityClass) throws TopiaException { + // rien a faire cette methode a ete appele sur le parentDAO + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#getEntityClass() + */ + public Class<Entity> getEntityClass() { + return getParentDAO().getEntityClass(); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#getContext() + */ + public TopiaContextImplementor getContext() { + return getParentDAO().getContext(); + } + + public void commitTransaction() throws TopiaException { + getParentDAO().commitTransaction(); + } + public void rollbackTransaction() throws TopiaException { + getParentDAO().rollbackTransaction(); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#create(java.lang.String, java.lang.Object, java.lang.Object...) + */ + public Entity create(Object... properties) throws TopiaException { + return getParentDAO().create(properties); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#create(java.util.Map) + */ + public Entity create(Map<String, Object> properties) throws TopiaException { + return getParentDAO().create(properties); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#update(Entity) + */ + public Entity update(Entity e) throws TopiaException { + return getParentDAO().update(e); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#delete(Entity) + */ + public void delete(Entity e) throws TopiaException { + getParentDAO().delete(e); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findByTopiaId(java.lang.Object) + */ + public Entity findByTopiaId(String k) throws TopiaException { + return getParentDAO().findByTopiaId(k); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findAll() + */ + public List<Entity> findAll() throws TopiaException { + return getParentDAO().findAll(); + } + + public List<Entity> findAllWithOrder(String... propertyNames) throws TopiaException { + return getParentDAO().findAllWithOrder(propertyNames); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#size() + */ + public int size() throws TopiaException { + return getParentDAO().size(); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.util.Map) + */ + public Entity findByPrimaryKey(Map<String, Object> keys) throws TopiaException { + return getParentDAO().findByPrimaryKey(keys); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.lang.Object...) + */ + public Entity findByPrimaryKey(Object... k) throws TopiaException { + return getParentDAO().findByPrimaryKey(k); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findByProperty(java.lang.String, java.lang.Object) + */ + public Entity findByProperty(String propertyName, Object value) + throws TopiaException { + return getParentDAO().findByProperty(propertyName, value); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findByProperties(java.lang.String, java.lang.Object, java.lang.Object...) + */ + public Entity findByProperties(String propertyName, Object value, + Object... others) throws TopiaException { + return getParentDAO().findByProperties(propertyName, value, others); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findByProperties(java.util.Map) + */ + public Entity findByProperties(Map<String, Object> properties) throws TopiaException { + return getParentDAO().findByProperties(properties); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findAllByProperty(java.lang.String, java.lang.Object) + */ + public List<Entity> findAllByProperty(String propertyName, Object value) + throws TopiaException { + return getParentDAO().findAllByProperty(propertyName, value); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.lang.String, java.lang.Object, java.lang.Object...) + */ + public List<Entity> findAllByProperties(String propertyName, Object value, + Object... others) throws TopiaException { + return getParentDAO().findAllByProperties(propertyName, value, others); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.util.Map) + */ + public List<Entity> findAllByProperties(Map<String, Object> properties) throws TopiaException { + return getParentDAO().findAllByProperties(properties); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map) + */ + public Entity findContainsProperties(Map<String, Collection> properties) throws TopiaException { + return getParentDAO().findContainsProperties(properties); + } + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[]) + */ + public Entity findContainsProperties(String propertyName, Collection values, Object... others) throws TopiaException { + return getParentDAO().findContainsProperties(propertyName, values, others); + } + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map) + */ + public List<Entity> findAllContainsProperties(Map<String, Collection> properties) throws TopiaException { + return getParentDAO().findAllContainsProperties(properties); + } + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[]) + */ + public List<Entity> findAllContainsProperties(String propertyName, Collection values, Object... others) throws TopiaException { + return getParentDAO().findAllContainsProperties(propertyName, values, others); + } + + /* + * (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#addTopiaEntityListener(org.codelutin.topia.event.TopiaEntityListener) + */ + public void addTopiaEntityListener(TopiaEntityListener listener) { + getParentDAO().addTopiaEntityListener(listener); + } + + /* + * (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#addTopiaEntityVetoable(org.codelutin.topia.event.TopiaEntityVetoable) + */ + public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) { + getParentDAO().addTopiaEntityVetoable(vetoable); + } + + /* + * (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#removeTopiaEntityListener(org.codelutin.topia.event.TopiaEntityListener) + */ + public void removeTopiaEntityListener(TopiaEntityListener listener) { + getParentDAO().removeTopiaEntityListener(listener); + } + + /* + * (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#removeTopiaEntityVetoable(org.codelutin.topia.event.TopiaEntityVetoable) + */ + public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) { + getParentDAO().removeTopiaEntityVetoable(vetoable); + } + + /* + * (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#getRequestPermission(java.lang.String, int) + */ + public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException { + return getParentDAO().getRequestPermission(topiaId, actions); + } + +} //TopiaDAODelegator Deleted: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java 2008-11-14 11:16:46 UTC (rev 1223) +++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java 2008-11-17 09:39:40 UTC (rev 1227) @@ -1,73 +0,0 @@ -package org.codelutin.topia.persistence; - -import org.codelutin.topia.TopiaContext; -import org.codelutin.topia.TopiaException; -import org.codelutin.topia.framework.TopiaContextImplementor; - -import java.util.List; - -/** @author chemit */ -public class TopiaEntityEnumEntry<T extends TopiaEntity> implements java.io.Serializable { - - /** the contract class of the entity's type. */ - protected Class<T> contractClass; - - /** the concrete implementation class of the entity's type. */ - protected Class<T> implementationClass; - - private static final long serialVersionUID = 1L; - - public TopiaEntityEnumEntry(Class<T> contractClass) { - this.contractClass = contractClass; - } - - public Class<T> getContractClass() { - return contractClass; - } - - @SuppressWarnings({"unchecked"}) - public Class<T> getImplementationClass() { - if (implementationClass == null) { - try { - implementationClass = (Class<T>) Class.forName(contractClass.getName() + "Impl"); - } catch (ClassNotFoundException e) { - throw new IllegalArgumentException("could not find implementation for entity contract " + contractClass); - } - } - return implementationClass; - } - - public TopiaDAO<T> getDAO(TopiaContext ctxt) throws TopiaException { - TopiaContextImplementor ci = (TopiaContextImplementor) ctxt; - return ci.getDAO(contractClass); - } - - public T create(TopiaContext ctxt) throws TopiaException { - TopiaDAO<T> dao = getDAO(ctxt); - T newInstance = dao.create(); - // attach topia context to entity (to allow propertyChangeSupport for entity) - ((TopiaEntityAbstract) newInstance).setTopiaContext(ctxt); - return newInstance; - } - - public T update(T entity, TopiaContext ctxt) throws TopiaException { - TopiaDAO<T> dao = getDAO(ctxt); - return dao.update(entity); - } - - public void delete(T entity, TopiaContext ctxt) throws TopiaException { - TopiaDAO<T> dao = getDAO(ctxt); - dao.delete(entity); - } - - public List<T> findAll(TopiaContext ctxt) throws TopiaException { - TopiaDAO<T> dao = getDAO(ctxt); - return dao.findAll(); - } - - public T findByTopiaId(String topiaId, TopiaContext ctxt) throws TopiaException { - TopiaDAO<T> dao = getDAO(ctxt); - return dao.findByTopiaId(topiaId); - } - -} Copied: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java (from rev 1224, topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java) =================================================================== --- topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java (rev 0) +++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java 2008-11-17 09:39:40 UTC (rev 1227) @@ -0,0 +1,155 @@ +package org.codelutin.topia.persistence; + +import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.TopiaException; +import org.codelutin.topia.framework.TopiaContextImplementor; + +import java.util.Collection; +import java.util.List; +import java.util.Map; + +/** @author chemit */ +public class TopiaEntityEnumEntry<T extends TopiaEntity> implements java.io.Serializable { + + /** the contract class of the entity's type. */ + protected Class<T> contractClass; + + /** the concrete implementation class of the entity's type. */ + protected Class<T> implementationClass; + + private static final long serialVersionUID = 1L; + + public TopiaEntityEnumEntry(Class<T> contractClass) { + this.contractClass = contractClass; + } + + public Class<T> getContractClass() { + return contractClass; + } + + @SuppressWarnings({"unchecked"}) + public Class<T> getImplementationClass() { + if (implementationClass == null) { + try { + implementationClass = (Class<T>) Class.forName(contractClass.getName() + "Impl"); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException("could not find implementation for entity contract " + contractClass); + } + } + return implementationClass; + } + + public TopiaDAO<T> getDAO(TopiaContext ctxt) throws TopiaException { + TopiaContextImplementor ci = (TopiaContextImplementor) ctxt; + return ci.getDAO(contractClass); + } + + public T create(TopiaContext ctxt) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + T newInstance = dao.create(); + // attach topia context to entity (to allow propertyChangeSupport for entity) + ((TopiaEntityAbstract) newInstance).setTopiaContext(ctxt); + return newInstance; + } + + public T create(TopiaContext ctxt, Object... properties) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.create(properties); + } + + public T create(TopiaContext ctxt, Map<String, Object> properties) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.create(properties); + } + + public T update(T entity, TopiaContext ctxt) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.update(entity); + } + + public void delete(T entity, TopiaContext ctxt) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + dao.delete(entity); + } + + public int size(TopiaContext ctxt) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.size(); + } + + public List<T> findAll(TopiaContext ctxt) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.findAll(); + } + + public List<T> findAllWithOrder(TopiaContext ctxt,String... propertyNames) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.findAllWithOrder(propertyNames); + } + + public T findByTopiaId(String topiaId, TopiaContext ctxt) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.findByTopiaId(topiaId); + } + + public T findByPrimaryKey(TopiaContext ctxt, Map<String, Object> keys) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.findByPrimaryKey(keys); + } + + public T findByPrimaryKey(TopiaContext ctxt, Object... k) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.findByPrimaryKey(k); + } + + public T findByProperty(TopiaContext ctxt, String propertyName, Object value) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.findByProperty(propertyName, value); + } + + public T findByProperties(TopiaContext ctxt, String propertyName, Object value, Object... others) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.findByProperties(propertyName, value, others); + } + + public T findByProperties(TopiaContext ctxt, Map<String, Object> properties) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.findByProperties(properties); + } + + public List<T> findAllByProperty(TopiaContext ctxt, String propertyName, Object value) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.findAllByProperty(propertyName, value); + } + + public List<T> findAllByProperties(TopiaContext ctxt, String propertyName, Object value, Object... others) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.findAllByProperties(propertyName, value, others); + } + + public List<T> findAllByProperties(TopiaContext ctxt, Map<String, Object> properties) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.findAllByProperties(properties); + } + + public T findContainsProperties(TopiaContext ctxt, Map<String, Collection> properties) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.findContainsProperties(properties); + } + + public T findContainsProperties(TopiaContext ctxt, String propertyName, Collection values, Object... others) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.findContainsProperties(propertyName, values, others); + } + + public List<T> findAllContainsProperties(TopiaContext ctxt, Map<String, Collection> properties) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.findAllContainsProperties(properties); + } + + public List<T> findAllContainsProperties(TopiaContext ctxt, String propertyName, Collection values, Object... others) throws TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.findAllContainsProperties(propertyName, values, others); + } + +} Deleted: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java 2008-11-14 11:16:46 UTC (rev 1223) +++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java 2008-11-17 09:39:40 UTC (rev 1227) @@ -1,543 +0,0 @@ -/* *##% ToPIA - Tools for Portable and Independent Architecture - * Copyright (C) 2004 - 2008 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>. ##%*/ - -/******************************************************************************* - * TopiaDAOFlatFile.java - * - * Created: 30 déc. 2005 03:11:55 - * - * @author poussin - * - * @version $Revision$ - * - * Last update: $Date$ by : $Author$ - */ - -package org.codelutin.topia.persistence.flatfile; - -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileFilter; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Serializable; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Modifier; -import java.security.Permission; -import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import org.apache.commons.beanutils.BeanUtils; -import org.apache.commons.beanutils.PropertyUtils; -import org.apache.commons.collections.map.AbstractReferenceMap; -import org.apache.commons.collections.map.ReferenceMap; -import org.apache.commons.lang.ClassUtils; -import org.apache.commons.lang.ObjectUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.topia.TopiaException; -import org.codelutin.topia.framework.TopiaContextImplementor; -import org.codelutin.topia.framework.TopiaUtil; -import org.codelutin.topia.persistence.TopiaDAOAbstract; -import org.codelutin.topia.persistence.TopiaEntity; -import org.codelutin.util.FileUtil; -import org.hibernate.Criteria; -import org.hibernate.FlushMode; -import org.hibernate.criterion.Criterion; -import org.hibernate.criterion.Projection; - -/** - * <p> - * <b>ATTENTION:</b> Le rollback des transactions n'est pas du tout pris en - * compte. Et l'implantation n'est pas fait pour les supporter un jour. Il - * faudrait pour cela que le context préviennent les DAO, lors d'un - * commit/rollback. - * <p> - * <b>REMARQUE:</b> pour l'instant on ne sauve que les types que l'on sait - * convertir en chaine et inversement. Si on souhaite aller plus loin il - * faudrait plutot regarde du cote d'hibernate et customiser les objets - * ClassPersistence ou autre responsable de la sauvegarde des entités, - * sauvegarde qui pourrait avoir lieu dans un fichier texte, ldap, ... - * <p> - * Si on souhaite tout de meme ameliorer cette classe, elle utilise BeanUtils de - * commons-beanutils. Il est possible d'ajouter des convertisseurs par ce moyen. - * <p> - * Permet de sauver les entités dans des fichiers au lieu d'une base de données - * il est possible de configurer la sauvegarde de différent moyen. - * <dl> - * <dt>topia.dao.flatfile.properties.file - * <dd>indique le fichier de configuration a utiliser en plus de la - * configuration du context - * - * <dt>topia.dao.flatfile.directory - * <dd>indique le répertoire au sauver les entités - * - * <dt>topia.dao.flatfile.directory.<fqn-entity> - * <dd>permet de spécifier un répertoire différent pour une entity spécifique - * - * <dt>topia.dao.flatfile.mapping - * <dd>permet d'indique le mapping a utiliser pour les entités - * - * <dt>topia.dao.flatfile.mapping.<fqn-entity> - * <dd>permet d'indique un mapping différent pour entité - * </dl> - * - * <p> - * à la place flatfile il est possible de mettre le FQN du DAO utilisé par - * exemple org.codelutin.topia.persistence.flatfile.TopiaDAOFlatFile - * - * <p> - * Si directory est absent alors "." est utilisé - * - * <p> - * les mappings s'écrivent de la façon suivant: - * <li>ext=extension a ajouter au fichier contenant l'entity - * <li>key=attribute - * <li>body=attribute - * - * <p> - * Si key est absent alors on utilise le topiaId, key est utilisé comme nom de - * fichier de sauvegarde - * <p> - * Si body est absent alors on utilise un fichier de propriété pour sauver - * l'entity. Si body est présent seul cet attribut sera sauvé. - * - * <pre> - * topia.dao.flatfile.mapping.key=topiaId - * - * topia.dao.flatfile.mapping.fr.ifremer.isisfish.entities.Script.key=name - * topia.dao.flatfile.mapping.fr.ifremer.isisfish.entities.Script.body=script - * </pre> - * - * <pre> - * TODO: auto généré un id pour TopiaId si dans le mapping il n'y a pas de key - * TODO: Pour la version si presence d'un rep CVS on utilise la version - * du fichier a l'interieur de Entries comme valeur initial - * TODO: modifier le champs version lors d'un update - * TODO: permettre dans mapping.body de mettre une liste d'attribute dans ce cas - * on sauve toujours sous forme de propriétés mais que les champs demandés - * - * NOTE: autre idee - * - si on a un body avec un champs unique sauver les autres propriétés - * dans une fichier <id>.properties - * - peut-etre ameliorer le mapping pour pouvoir mapper une entite sur plusieurs - * fichiers - * - * </pre> - * - * @author poussin - * - */ -public class TopiaDAOFlatFile<Entity extends TopiaEntity> extends - TopiaDAOAbstract<Entity> { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(TopiaDAOFlatFile.class); - - final protected String DAO_CONFIG_1 = "topia.dao.flatfile"; - - final protected String DAO_CONFIG_2 = "topia.dao." + getClass().getName(); - - protected Properties config = null; - - protected File directory = null; - - protected String ext = null; - - protected EntityFileFilter filter = null; - - protected String key = null; - - protected String body = null; - - /** - * Cache sur les entities. - */ - @SuppressWarnings("unchecked") - protected Map<File, Entity> cache = (Map<File, Entity>) new ReferenceMap( - AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT); - - @Override - public void init(TopiaContextImplementor context, Class<Entity> entityClass) - throws TopiaException { - super.init(context, entityClass); - // on recherche le fichier par la propriete - // topia.dao.flatfile.properties.file - // puis topia.dao.fqnclass.properties.file - - String configFile = context.getConfig().getProperty( - DAO_CONFIG_1 + ".properties.file"); - config = TopiaUtil.getProperties(context.getConfig(), configFile); - log.debug("Use file " + configFile); - configFile = context.getConfig().getProperty( - DAO_CONFIG_2 + ".properties.file"); - config = TopiaUtil.getProperties(context.getConfig(), configFile); - log.debug("Use file " + configFile); - - String dirname = getProperty("directory." + entityClass.getName()); - if (dirname == null) { - dirname = getProperty("directory", "."); - } - directory = new File(dirname); - directory.mkdirs(); - - ext = getProperty("mapping." + entityClass.getName() + ".ext"); - if (ext == null) { - ext = getProperty("mapping.ext", ""); - } - filter = new EntityFileFilter(ext); - - key = getProperty("mapping." + entityClass.getName() + ".key"); - if (key == null) { - key = getProperty("mapping.key", "topiaId"); - } - - body = getProperty("mapping." + entityClass.getName() + ".body"); - if (body == null) { - body = getProperty("mapping.body"); - } - } - - protected String getProperty(String name) { - return getProperty(name, null); - } - - protected String getProperty(String name, String defaultValue) { - String result = config.getProperty(DAO_CONFIG_1 + "." + name, - defaultValue); - result = config.getProperty(DAO_CONFIG_2 + "." + name, result); - return result; - } - - /** - * Par defaut ne fait rien - */ - @Override - public void commitTransaction() throws TopiaException { - } - - /** - * Par defaut ne fait rien - */ - @Override - public void rollbackTransaction() throws TopiaException { - } - - /** - * Sauve l'entity dans le fichier - * - * @see org.codelutin.topia.TopiaDAO#update() - */ - public Entity update(Entity e) throws TopiaException { - getContext().getFiresSupport().fireOnPreUpdate(getContext(), e, new Object[]{}); - - // le topiaId contient le nom du fichier a partir duquel l'entity - // a ete chargé - try { - String oldId = (String)e.getTopiaId(); - String newId = (String) PropertyUtils.getProperty(e, key); - - // Si l'identifiant a changé alors il faut aussi changer le nom - // du fichier, on supprime donc l'ancien nom - if (ObjectUtils.equals(oldId, newId) == false) { - File f = new File(directory, getFilename(oldId)); - if (f.exists()) { - f.delete(); - } - e.setTopiaId(newId); - } - - File f = new File(directory, getFilename(newId)); - if (body != null) { - String bodyValue = BeanUtils.getProperty(e, body); - FileWriter out = new FileWriter(f); - out.append(bodyValue); - out.close(); - } else { - Properties prop = new Properties(); - Map<String, String> propMap = (Map<String, String>) BeanUtils - .describe(e); - - // remove transient field property - // we search field that match exactly get/set name only - Class clazz = e.getClass(); - for (Iterator<String> i = propMap.keySet().iterator(); i - .hasNext();) { - String propName = i.next(); - List<Class> classes = ClassUtils.getAllSuperclasses(clazz); - classes.add(0, clazz); - for (Class c : classes) { - try { - Field field = c.getDeclaredField(propName); - if (Modifier.isTransient(field.getModifiers())) { - i.remove(); - } - break; - } catch (Exception eee) { - if (log.isWarnEnabled()) { - log.trace("Unable to find field " + propName - + " on " + c.getName());// , eee); - } - } - - } - - } - - prop.putAll(propMap); - FileOutputStream out = new FileOutputStream(f); - prop.store(out, "flatfile topia persistence entity"); - out.close(); - } - - getContext().getFiresSupport().fireOnPostUpdate(getContext(), e, new Object[]{}); - - return e; - } catch (IllegalAccessException eee) { - throw new TopiaException("Impossible de sauver l'entity: " + e, eee); - } catch (InvocationTargetException eee) { - throw new TopiaException("Impossible de sauver l'entity: " + e, eee); - } catch (NoSuchMethodException eee) { - throw new TopiaException("Impossible de sauver l'entity: " + e, eee); - } catch (IOException eee) { - throw new TopiaException("Impossible de sauver l'entity: " + e, eee); - } - } - - /** - * Supprime le fichier contenant l'entity - * - * @see org.codelutin.topia.TopiaDAO#delete() - */ - public void delete(Entity e) throws TopiaException { - getContext().getFiresSupport().fireOnPreDelete(getContext(), e, new Object[]{}); - // le topiaId contient le nom du fichier a partir duquel l'entity - // a ete chargé - String oldId = e.getTopiaId().toString(); - File f = new File(directory, getFilename(oldId)); - cache.remove(f); - f.delete(); - - getContext().getFiresSupport().fireOnPostDelete(getContext(), e, new Object[]{}); - - } - - /** - * Recherche un fichier si dans mapping key est indiqué il est utilisé a la - * place du topiaId qui n'existe peut-etre pas - * - * @see org.codelutin.topia.TopiaDAO#findByTopiaId() - */ - @Override - public Entity findByTopiaId(String k) throws TopiaException { - String keyValue = (String) k; - File f = new File(directory, getFilename(keyValue)); - Entity result = findByFile(f); - return result; - } - - protected String getFilename(String id) { - String result = ext; - if (ext != null && !"".equals(ext)) { - result = "." + result; - } - result = id + result; - return result; - } - - protected Entity findByFile(File f) throws TopiaException { - long lastModified = f.lastModified(); - Entity e = cache.get(f); - getContext().getFiresSupport().fireOnPreLoad(getContext(), e, new Object[]{}); - // si on a pas encore l'entity ou que le fichier est plus recent - // il faut relire l'entité - if (e == null) { - // en fait il ne faut pas recharger s'il est plus recent - // sur le disque car on est dans une transaction, - // si on veut la nouvelle version il faut ouvrire une - // nouvelle transaction - // || e.getTopiaCreateDate().getTime() < lastModified) { - String keyValue = FileUtil.basename(f, "." + ext); - - if (e == null) { - e = instanciateNew(); - } - Properties prop = new Properties(); - // on met le topiaCreateDate a lastModified maintenant - // pour qu'il puisse etre ecrassé si on arrive a lire - // une meilleur information dans le fichier. - // FIXME: voir comment en Java recuperer la date de creation - // d'un fichier - prop.put("topiaCreateDate", new Date(lastModified)); - - try { - InputStream in = new BufferedInputStream(new FileInputStream(f)); - if (body == null) { - prop.load(in); - } else { - StringBuffer buffer = new StringBuffer(); - BufferedReader br = new BufferedReader( - new InputStreamReader(in)); - int c; - while ((c = br.read()) != -1) { - buffer.append((char) c); - } - prop.put(body, buffer.toString()); - } - - // on ecrase topiaId et la key maintenant car le nom - // du fichier doit toujours etre l'id de l'objet - prop.put(key, keyValue); - prop.put("topiaId", keyValue); - - BeanUtils.populate(e, prop); - } catch (IOException eee) { - throw new TopiaException( - "Impossible de lire l'entity du fichier: " + f, eee); - } catch (IllegalAccessException eee) { - throw new TopiaException( - "Impossible de mettre le contenu du fichier dans l'entity: " - + f, eee); - } catch (InvocationTargetException eee) { - throw new TopiaException( - "Impossible de mettre le contenu du fichier dans l'entity: " - + f, eee); - } - - // on le met en cache car on doit toujours retourner - // la meme instance au cours du temps - cache.put(f, e); - getContext().getFiresSupport().fireOnPostLoad(getContext(), e, new Object[]{}); - } - return e; - } - - /** - * Charge tous les objets présent. Si un objet est invalide, il n'est pas - * lu, un message WARN est affiché mais aucune exception n'est levé. - * - * @see org.codelutin.topia.persistence.TopiaDAOAbstract#findAll() - */ - @Override - public List<Entity> findAll() throws TopiaException { - List<Entity> result = new ArrayList<Entity>(); - - File[] entitiesFile = directory.listFiles(filter); - for (File f : entitiesFile) { - try { - Entity e = findByFile(f); - result.add(e); - } catch (TopiaException eee) { - if (log.isWarnEnabled()) { - log.warn(eee); - } - } - } - return result; - } - - /** - * Permet de filtrer les fichiers si une extension a ete defini dans le - * mapping - * - * @author poussin - * - */ - protected class EntityFileFilter implements FileFilter { - - protected String ext = null; - - public EntityFileFilter(String ext) { - this.ext = ext; - } - - /* - * (non-Javadoc) - * - * @see java.io.FileFilter#accept(java.io.File) - */ - public boolean accept(File pathname) { - boolean result; - if (ext == null || "".equals(ext)) { - return true; - } else { - String e = FileUtil.extension(pathname, "."); - result = e.equals(ext); - } - return result; - } - } - - /* (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#query(org.hibernate.criterion.Criterion) - */ - public Entity query(Criterion criterion) throws TopiaException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#queryAll(org.hibernate.criterion.Criterion) - */ - public List<Entity> queryAll(Criterion criterion) throws TopiaException { - // TODO Auto-generated method stub - return null; - } - - public Object query(Projection projection, Criterion criterion) throws TopiaException { - // TODO Auto-generated method stub - return null; - } - - public List queryAll(Projection projection, Criterion criterion) throws TopiaException { - // TODO Auto-generated method stub - return null; - } - - public Object project(Projection projection) throws TopiaException { - // TODO Auto-generated method stub - return null; - } - - public List projectAll(Projection projection) throws TopiaException { - // TODO Auto-generated method stub - return null; - } - - public Criteria createCriteria(FlushMode mode) throws TopiaException { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#getRequestPermission(java.lang.String, int) - */ - public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException { - return null; - } -} Copied: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java (from rev 1224, topia/trunk/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java) =================================================================== --- topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java (rev 0) +++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java 2008-11-17 09:39:40 UTC (rev 1227) @@ -0,0 +1,547 @@ +/* *##% ToPIA - Tools for Portable and Independent Architecture + * Copyright (C) 2004 - 2008 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>. ##%*/ + +/******************************************************************************* + * TopiaDAOFlatFile.java + * + * Created: 30 déc. 2005 03:11:55 + * + * @author poussin + * + * @version $Revision$ + * + * Last update: $Date$ by : $Author$ + */ + +package org.codelutin.topia.persistence.flatfile; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Serializable; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Modifier; +import java.security.Permission; +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.beanutils.PropertyUtils; +import org.apache.commons.collections.map.AbstractReferenceMap; +import org.apache.commons.collections.map.ReferenceMap; +import org.apache.commons.lang.ClassUtils; +import org.apache.commons.lang.ObjectUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.topia.TopiaException; +import org.codelutin.topia.framework.TopiaContextImplementor; +import org.codelutin.topia.framework.TopiaUtil; +import org.codelutin.topia.persistence.TopiaDAOAbstract; +import org.codelutin.topia.persistence.TopiaEntity; +import org.codelutin.util.FileUtil; +import org.hibernate.Criteria; +import org.hibernate.FlushMode; +import org.hibernate.criterion.Criterion; +import org.hibernate.criterion.Projection; + +/** + * <p> + * <b>ATTENTION:</b> Le rollback des transactions n'est pas du tout pris en + * compte. Et l'implantation n'est pas fait pour les supporter un jour. Il + * faudrait pour cela que le context préviennent les DAO, lors d'un + * commit/rollback. + * <p> + * <b>REMARQUE:</b> pour l'instant on ne sauve que les types que l'on sait + * convertir en chaine et inversement. Si on souhaite aller plus loin il + * faudrait plutot regarde du cote d'hibernate et customiser les objets + * ClassPersistence ou autre responsable de la sauvegarde des entités, + * sauvegarde qui pourrait avoir lieu dans un fichier texte, ldap, ... + * <p> + * Si on souhaite tout de meme ameliorer cette classe, elle utilise BeanUtils de + * commons-beanutils. Il est possible d'ajouter des convertisseurs par ce moyen. + * <p> + * Permet de sauver les entités dans des fichiers au lieu d'une base de données + * il est possible de configurer la sauvegarde de différent moyen. + * <dl> + * <dt>topia.dao.flatfile.properties.file + * <dd>indique le fichier de configuration a utiliser en plus de la + * configuration du context + * + * <dt>topia.dao.flatfile.directory + * <dd>indique le répertoire au sauver les entités + * + * <dt>topia.dao.flatfile.directory.<fqn-entity> + * <dd>permet de spécifier un répertoire différent pour une entity spécifique + * + * <dt>topia.dao.flatfile.mapping + * <dd>permet d'indique le mapping a utiliser pour les entités + * + * <dt>topia.dao.flatfile.mapping.<fqn-entity> + * <dd>permet d'indique un mapping différent pour entité + * </dl> + * + * <p> + * à la place flatfile il est possible de mettre le FQN du DAO utilisé par + * exemple org.codelutin.topia.persistence.flatfile.TopiaDAOFlatFile + * + * <p> + * Si directory est absent alors "." est utilisé + * + * <p> + * les mappings s'écrivent de la façon suivant: + * <li>ext=extension a ajouter au fichier contenant l'entity + * <li>key=attribute + * <li>body=attribute + * + * <p> + * Si key est absent alors on utilise le topiaId, key est utilisé comme nom de + * fichier de sauvegarde + * <p> + * Si body est absent alors on utilise un fichier de propriété pour sauver + * l'entity. Si body est présent seul cet attribut sera sauvé. + * + * <pre> + * topia.dao.flatfile.mapping.key=topiaId + * + * topia.dao.flatfile.mapping.fr.ifremer.isisfish.entities.Script.key=name + * topia.dao.flatfile.mapping.fr.ifremer.isisfish.entities.Script.body=script + * </pre> + * + * <pre> + * TODO: auto généré un id pour TopiaId si dans le mapping il n'y a pas de key + * TODO: Pour la version si presence d'un rep CVS on utilise la version + * du fichier a l'interieur de Entries comme valeur initial + * TODO: modifier le champs version lors d'un update + * TODO: permettre dans mapping.body de mettre une liste d'attribute dans ce cas + * on sauve toujours sous forme de propriétés mais que les champs demandés + * + * NOTE: autre idee + * - si on a un body avec un champs unique sauver les autres propriétés + * dans une fichier <id>.properties + * - peut-etre ameliorer le mapping pour pouvoir mapper une entite sur plusieurs + * fichiers + * + * </pre> + * + * @author poussin + * + */ +public class TopiaDAOFlatFile<Entity extends TopiaEntity> extends + TopiaDAOAbstract<Entity> { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(TopiaDAOFlatFile.class); + + final protected String DAO_CONFIG_1 = "topia.dao.flatfile"; + + final protected String DAO_CONFIG_2 = "topia.dao." + getClass().getName(); + + protected Properties config = null; + + protected File directory = null; + + protected String ext = null; + + protected EntityFileFilter filter = null; + + protected String key = null; + + protected String body = null; + + /** + * Cache sur les entities. + */ + @SuppressWarnings("unchecked") + protected Map<File, Entity> cache = (Map<File, Entity>) new ReferenceMap( + AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT); + + @Override + public void init(TopiaContextImplementor context, Class<Entity> entityClass) + throws TopiaException { + super.init(context, entityClass); + // on recherche le fichier par la propriete + // topia.dao.flatfile.properties.file + // puis topia.dao.fqnclass.properties.file + + String configFile = context.getConfig().getProperty( + DAO_CONFIG_1 + ".properties.file"); + config = TopiaUtil.getProperties(context.getConfig(), configFile); + log.debug("Use file " + configFile); + configFile = context.getConfig().getProperty( + DAO_CONFIG_2 + ".properties.file"); + config = TopiaUtil.getProperties(context.getConfig(), configFile); + log.debug("Use file " + configFile); + + String dirname = getProperty("directory." + entityClass.getName()); + if (dirname == null) { + dirname = getProperty("directory", "."); + } + directory = new File(dirname); + directory.mkdirs(); + + ext = getProperty("mapping." + entityClass.getName() + ".ext"); + if (ext == null) { + ext = getProperty("mapping.ext", ""); + } + filter = new EntityFileFilter(ext); + + key = getProperty("mapping." + entityClass.getName() + ".key"); + if (key == null) { + key = getProperty("mapping.key", "topiaId"); + } + + body = getProperty("mapping." + entityClass.getName() + ".body"); + if (body == null) { + body = getProperty("mapping.body"); + } + } + + protected String getProperty(String name) { + return getProperty(name, null); + } + + protected String getProperty(String name, String defaultValue) { + String result = config.getProperty(DAO_CONFIG_1 + "." + name, + defaultValue); + result = config.getProperty(DAO_CONFIG_2 + "." + name, result); + return result; + } + + /** + * Par defaut ne fait rien + */ + @Override + public void commitTransaction() throws TopiaException { + } + + /** + * Par defaut ne fait rien + */ + @Override + public void rollbackTransaction() throws TopiaException { + } + + /** + * Sauve l'entity dans le fichier + * + * @see org.codelutin.topia.persistence.TopiaDAO#update(org.codelutin.topia.persistence.TopiaEntity) + */ + public Entity update(Entity e) throws TopiaException { + getContext().getFiresSupport().fireOnPreUpdate(getContext(), e, new Object[]{}); + + // le topiaId contient le nom du fichier a partir duquel l'entity + // a ete chargé + try { + String oldId = (String)e.getTopiaId(); + String newId = (String) PropertyUtils.getProperty(e, key); + + // Si l'identifiant a changé alors il faut aussi changer le nom + // du fichier, on supprime donc l'ancien nom + if (ObjectUtils.equals(oldId, newId) == false) { + File f = new File(directory, getFilename(oldId)); + if (f.exists()) { + f.delete(); + } + e.setTopiaId(newId); + } + + File f = new File(directory, getFilename(newId)); + if (body != null) { + String bodyValue = BeanUtils.getProperty(e, body); + FileWriter out = new FileWriter(f); + out.append(bodyValue); + out.close(); + } else { + Properties prop = new Properties(); + Map<String, String> propMap = (Map<String, String>) BeanUtils + .describe(e); + + // remove transient field property + // we search field that match exactly get/set name only + Class clazz = e.getClass(); + for (Iterator<String> i = propMap.keySet().iterator(); i + .hasNext();) { + String propName = i.next(); + List<Class> classes = ClassUtils.getAllSuperclasses(clazz); + classes.add(0, clazz); + for (Class c : classes) { + try { + Field field = c.getDeclaredField(propName); + if (Modifier.isTransient(field.getModifiers())) { + i.remove(); + } + break; + } catch (Exception eee) { + if (log.isWarnEnabled()) { + log.trace("Unable to find field " + propName + + " on " + c.getName());// , eee); + } + } + + } + + } + + prop.putAll(propMap); + FileOutputStream out = new FileOutputStream(f); + prop.store(out, "flatfile topia persistence entity"); + out.close(); + } + + getContext().getFiresSupport().fireOnPostUpdate(getContext(), e, new Object[]{}); + + return e; + } catch (IllegalAccessException eee) { + throw new TopiaException("Impossible de sauver l'entity: " + e, eee); + } catch (InvocationTargetException eee) { + throw new TopiaException("Impossible de sauver l'entity: " + e, eee); + } catch (NoSuchMethodException eee) { + throw new TopiaException("Impossible de sauver l'entity: " + e, eee); + } catch (IOException eee) { + throw new TopiaException("Impossible de sauver l'entity: " + e, eee); + } + } + + /** + * Supprime le fichier contenant l'entity + * + * @see org.codelutin.topia.persistence.TopiaDAO#delete(org.codelutin.topia.persistence.TopiaEntity) + */ + public void delete(Entity e) throws TopiaException { + getContext().getFiresSupport().fireOnPreDelete(getContext(), e, new Object[]{}); + // le topiaId contient le nom du fichier a partir duquel l'entity + // a ete chargé + String oldId = e.getTopiaId().toString(); + File f = new File(directory, getFilename(oldId)); + cache.remove(f); + f.delete(); + + getContext().getFiresSupport().fireOnPostDelete(getContext(), e, new Object[]{}); + + } + + /** + * Recherche un fichier si dans mapping key est indiqué il est utilisé a la + * place du topiaId qui n'existe peut-etre pas + * + * @see org.codelutin.topia.persistence.TopiaDAO#findByTopiaId(String) + */ + @Override + public Entity findByTopiaId(String k) throws TopiaException { + String keyValue = (String) k; + File f = new File(directory, getFilename(keyValue)); + Entity result = findByFile(f); + return result; + } + + protected String getFilename(String id) { + String result = ext; + if (ext != null && !"".equals(ext)) { + result = "." + result; + } + result = id + result; + return result; + } + + protected Entity findByFile(File f) throws TopiaException { + long lastModified = f.lastModified(); + Entity e = cache.get(f); + getContext().getFiresSupport().fireOnPreLoad(getContext(), e, new Object[]{}); + // si on a pas encore l'entity ou que le fichier est plus recent + // il faut relire l'entité + if (e == null) { + // en fait il ne faut pas recharger s'il est plus recent + // sur le disque car on est dans une transaction, + // si on veut la nouvelle version il faut ouvrire une + // nouvelle transaction + // || e.getTopiaCreateDate().getTime() < lastModified) { + String keyValue = FileUtil.basename(f, "." + ext); + + if (e == null) { + e = instanciateNew(); + } + Properties prop = new Properties(); + // on met le topiaCreateDate a lastModified maintenant + // pour qu'il puisse etre ecrassé si on arrive a lire + // une meilleur information dans le fichier. + // FIXME: voir comment en Java recuperer la date de creation + // d'un fichier + prop.put("topiaCreateDate", new Date(lastModified)); + + try { + InputStream in = new BufferedInputStream(new FileInputStream(f)); + if (body == null) { + prop.load(in); + } else { + StringBuffer buffer = new StringBuffer(); + BufferedReader br = new BufferedReader( + new InputStreamReader(in)); + int c; + while ((c = br.read()) != -1) { + buffer.append((char) c); + } + prop.put(body, buffer.toString()); + } + + // on ecrase topiaId et la key maintenant car le nom + // du fichier doit toujours etre l'id de l'objet + prop.put(key, keyValue); + prop.put("topiaId", keyValue); + + BeanUtils.populate(e, prop); + } catch (IOException eee) { + throw new TopiaException( + "Impossible de lire l'entity du fichier: " + f, eee); + } catch (IllegalAccessException eee) { + throw new TopiaException( + "Impossible de mettre le contenu du fichier dans l'entity: " + + f, eee); + } catch (InvocationTargetException eee) { + throw new TopiaException( + "Impossible de mettre le contenu du fichier dans l'entity: " + + f, eee); + } + + // on le met en cache car on doit toujours retourner + // la meme instance au cours du temps + cache.put(f, e); + getContext().getFiresSupport().fireOnPostLoad(getContext(), e, new Object[]{}); + } + return e; + } + + /** + * Charge tous les objets présent. Si un objet est invalide, il n'est pas + * lu, un message WARN est affiché mais aucune exception n'est levé. + * + * @see org.codelutin.topia.persistence.TopiaDAOAbstract#findAll() + */ + @Override + public List<Entity> findAll() throws TopiaException { + List<Entity> result = new ArrayList<Entity>(); + + File[] entitiesFile = directory.listFiles(filter); + for (File f : entitiesFile) { + try { + Entity e = findByFile(f); + result.add(e); + } catch (TopiaException eee) { + if (log.isWarnEnabled()) { + log.warn(eee); + } + } + } + return result; + } + + public List<Entity> findAllWithOrder(String... propertyNames) throws TopiaException { + throw new IllegalStateException("findAllWithOrder method is not implemented by "+getClass()); + } + + /** + * Permet de filtrer les fichiers si une extension a ete defini dans le + * mapping + * + * @author poussin + * + */ + protected class EntityFileFilter implements FileFilter { + + protected String ext = null; + + public EntityFileFilter(String ext) { + this.ext = ext; + } + + /* + * (non-Javadoc) + * + * @see java.io.FileFilter#accept(java.io.File) + */ + public boolean accept(File pathname) { + boolean result; + if (ext == null || "".equals(ext)) { + return true; + } else { + String e = FileUtil.extension(pathname, "."); + result = e.equals(ext); + } + return result; + } + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#query(org.hibernate.criterion.Criterion) + */ + public Entity query(Criterion criterion) throws TopiaException { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#queryAll(org.hibernate.criterion.Criterion) + */ + public List<Entity> queryAll(Criterion criterion) throws TopiaException { + // TODO Auto-generated method stub + return null; + } + + public Object query(Projection projection, Criterion criterion) throws TopiaException { + // TODO Auto-generated method stub + return null; + } + + public List queryAll(Projection projection, Criterion criterion) throws TopiaException { + // TODO Auto-generated method stub + return null; + } + + public Object project(Projection projection) throws TopiaException { + // TODO Auto-generated method stub + return null; + } + + public List projectAll(Projection projection) throws TopiaException { + // TODO Auto-generated method stub + return null; + } + + public Criteria createCriteria(FlushMode mode) throws TopiaException { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#getRequestPermission(java.lang.String, int) + */ + public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException { + return null; + } +} Deleted: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java 2008-11-14 11:16:46 UTC (rev 1223) +++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java 2008-11-17 09:39:40 UTC (rev 1227) @@ -1,264 +0,0 @@ -/* *##% ToPIA - Tools for Portable and Independent Architecture - * Copyright (C) 2004 - 2008 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>. ##%*/ - -/******************************************************************************* - * TopiaDAOHibernate.java - * - * Created: 23 déc. 2005 18:34:01 - * - * @author poussin - * - * @version $Revision$ - * - * Last update: $Date$ by : $Author$ - */ - -package org.codelutin.topia.persistence.hibernate; - -import java.security.Permission; -import java.util.List; -import java.util.Map; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.topia.TopiaException; -import org.codelutin.topia.persistence.TopiaDAOAbstract; -import org.codelutin.topia.persistence.TopiaEntity; -import org.hibernate.Criteria; -import org.hibernate.FlushMode; -import org.hibernate.HibernateException; -import org.hibernate.Session; -import org.hibernate.criterion.Criterion; -import org.hibernate.criterion.Restrictions; - -/** - * Cette persistence accède à l'objet Session hibernate pour exécuter - * les différentes demandes de persistences. - * - * @author poussin - * - */ -// FIXME les Entity ne doivent pas forcement etendre TopiaEntity de cette -// facon on peut utiliser le framework sans la generation et sur des POJO -// existant. Cela implique de faire un peu attention au codage -public class TopiaDAOHibernate<Entity extends TopiaEntity> extends TopiaDAOAbstract<Entity> { - - private static Log log = LogFactory.getLog(TopiaDAOHibernate.class); - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#create() - */ - @Override - public Entity create(Map<String, Object> properties) throws TopiaException { - Entity result = super.create(properties); - // on fait un save maintenant, car puisqu'on a creer l'entity au - // travers du DAO, on s'attend a l'avoir a disposition tout de - // suite pour les requetes sans avoir a faire un update dessus - getSession().save(result); - getContext().getFiresSupport().warnOnCreateEntity(result); - return result; - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#update(Entity) - */ - public Entity update(Entity e) throws TopiaException { - try { - getSession().saveOrUpdate(e); - getContext().getFiresSupport().warnOnUpdateEntity(e); - return e; - } catch (HibernateException eee) { - throw new TopiaException(eee); - } - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#delete(Entity) - */ - public void delete(Entity e) throws TopiaException { - try { - getSession().delete(e); - getContext().getFiresSupport().warnOnDeleteEntity(e); - } catch (HibernateException eee) { - throw new TopiaException(eee); - } - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findByTopiaId() - */ - @Override - public Entity findByTopiaId(String k) throws TopiaException { - return query(Restrictions.idEq(k)); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findAll() - */ - @Override - public List<Entity> findAll() throws TopiaException { - try { - Criteria criteria = createCriteria(FlushMode.AUTO); - List<Entity> result = (List<Entity>)criteria.list(); - result = getContext().getFiresSupport().fireEntitiesLoad(context, result); - return result; - } catch (HibernateException eee) { - throw new TopiaException(eee); - } - } - - /** - * TODO implanter une facon plus rapide de recupere la size (count direct - * sur la base) - * (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#size() - */ - @Override - public int size() throws TopiaException { - int result = findAll().size(); - return result; - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findByProperties(java.util.Map) - */ - @Override - public Entity findByProperties(Map<String, Object> properties) - throws TopiaException { - return query(Restrictions.allEq(properties)); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.util.Map) - */ - public List<Entity> findAllByProperties(Map<String, Object> properties) - throws TopiaException { - return queryAll(Restrictions.allEq(properties)); - } - - /* (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#queryAll(org.hibernate.criterion.Criterion) - */ - private List<Entity> queryAll(Criterion criterion) throws TopiaException { - try { - Criteria criteria = createCriteria(FlushMode.AUTO); - criteria.add(criterion); - List<Entity> result = (List<Entity>)criteria.list(); - result = getContext().getFiresSupport().fireEntitiesLoad(context, result); - return result; - } catch (HibernateException eee) { - throw new TopiaException(eee); - } - } - - /* (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#query(org.hibernate.criterion.Criterion) - */ - private Entity query(Criterion criterion) throws TopiaException { - try { - Criteria criteria = createCriteria(FlushMode.AUTO); - criteria.add(criterion); - criteria.setMaxResults(1); - List<Entity> result = (List<Entity>)criteria.list(); - int sizeBefore = (result != null?result.size():0); - result = getContext().getFiresSupport().fireEntitiesLoad(context, result); - int sizeAfter = (result != null?result.size():0); - if (sizeAfter < sizeBefore) { - if (log.isDebugEnabled()) { - log.debug((sizeBefore - sizeAfter) + " element(s) removed. Filter entity: " + entityClass.getName() + " - criterion: " + criterion); - } - } - if (result != null && result.size() > 0) { - Entity elem = result.get(0); - return elem; - } - return null; - } catch (HibernateException eee) { - throw new TopiaException(eee); - } - } - -//FIXME : Commenté car impossible de trouver le bon Criterion - -// /* (non-Javadoc) -// * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map) -// */ -// public Entity findContainsProperties(Map<String, Collection> properties) throws TopiaException { -// try { -// Criteria criteria = createCriteria(FlushMode.AUTO); -// for (Entry<String, Collection> entry : properties.entrySet()) { -// for (Object value : entry.getValue()) { -// criteria.add(Restrictions.eq(entry.getKey(), value)); -// } -// } -// criteria.setMaxResults(1); -// List<Entity> results = (List<Entity>)criteria.list(); -// if (results.size() > 0) { -// return (Entity)results.get(0); -// } else { -// return null; -// } -// } catch (HibernateException eee) { -// throw new TopiaException(eee); -// } -// } -// -// /* (non-Javadoc) -// * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map) -// */ -// public List<Entity> findAllContainsProperties(Map<String, Collection> properties) throws TopiaException { -// try { -// Criteria criteria = createCriteria(FlushMode.AUTO); -// for (Entry<String, Collection> entry : properties.entrySet()) { -// for (Object value : entry.getValue()) { -// criteria.add(Restrictions.eq(entry.getKey(), value)); -// } -// } -// List<Entity> result = (List<Entity>)criteria.list(); -// return result; -// } catch (HibernateException eee) { -// throw new TopiaException(eee); -// } -// } - - /** - * Renvoie un Criteria créé avec l'entityClass - * @param mode le FlushMode du Criteria - * @return le Criteria nouvellement créé - */ - private Criteria createCriteria(FlushMode mode) throws TopiaException { - Criteria criteria = getSession().createCriteria(entityClass); - criteria.setFlushMode(mode); - return criteria; - } - - /** - * Renvoie la Session contenue dans le contexte - */ - private Session getSession() throws TopiaException { - return getContext().getHibernate(); - } - - /* - * (non-Javadoc) - * @see org.codelutin.topia.persistence.TopiaDAO#getRequestPermission(java.lang.String, int) - */ - public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException { - return null; - } - -} //TopiaDAOHibernate Copied: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java (from rev 1224, topia/trunk/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java) =================================================================== --- topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java (rev 0) +++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java 2008-11-17 09:39:40 UTC (rev 1227) @@ -0,0 +1,279 @@ +/* *##% ToPIA - Tools for Portable and Independent Architecture + * Copyright (C) 2004 - 2008 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>. ##%*/ + +/******************************************************************************* + * TopiaDAOHibernate.java + * + * Created: 23 déc. 2005 18:34:01 + * + * @author poussin + * + * @version $Revision$ + * + * Last update: $Date$ by : $Author$ + */ + +package org.codelutin.topia.persistence.hibernate; + +import java.security.Permission; +import java.util.List; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.topia.TopiaException; +import org.codelutin.topia.persistence.TopiaDAOAbstract; +import org.codelutin.topia.persistence.TopiaEntity; +import org.hibernate.Criteria; +import org.hibernate.FlushMode; +import org.hibernate.HibernateException; +import org.hibernate.Session; +import org.hibernate.criterion.Criterion; +import org.hibernate.criterion.Restrictions; +import org.hibernate.criterion.Order; + +/** + * Cette persistence accède à l'objet Session hibernate pour exécuter + * les différentes demandes de persistences. + * + * @author poussin + * + */ +// FIXME les Entity ne doivent pas forcement etendre TopiaEntity de cette +// facon on peut utiliser le framework sans la generation et sur des POJO +// existant. Cela implique de faire un peu attention au codage +public class TopiaDAOHibernate<Entity extends TopiaEntity> extends TopiaDAOAbstract<Entity> { + + private static Log log = LogFactory.getLog(TopiaDAOHibernate.class); + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#create() + */ + @Override + public Entity create(Map<String, Object> properties) throws TopiaException { + Entity result = super.create(properties); + // on fait un save maintenant, car puisqu'on a creer l'entity au + // travers du DAO, on s'attend a l'avoir a disposition tout de + // suite pour les requetes sans avoir a faire un update dessus + getSession().save(result); + getContext().getFiresSupport().warnOnCreateEntity(result); + return result; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#update(Entity) + */ + public Entity update(Entity e) throws TopiaException { + try { + getSession().saveOrUpdate(e); + getContext().getFiresSupport().warnOnUpdateEntity(e); + return e; + } catch (HibernateException eee) { + throw new TopiaException(eee); + } + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#delete(Entity) + */ + public void delete(Entity e) throws TopiaException { + try { + getSession().delete(e); + getContext().getFiresSupport().warnOnDeleteEntity(e); + } catch (HibernateException eee) { + throw new TopiaException(eee); + } + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findByTopiaId() + */ + @Override + public Entity findByTopiaId(String k) throws TopiaException { + return query(Restrictions.idEq(k)); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findAll() + */ + @Override + public List<Entity> findAll() throws TopiaException { + try { + Criteria criteria = createCriteria(FlushMode.AUTO); + List<Entity> result = (List<Entity>)criteria.list(); + result = getContext().getFiresSupport().fireEntitiesLoad(context, result); + return result; + } catch (HibernateException eee) { + throw new TopiaException(eee); + } + } + + public List<Entity> findAllWithOrder(String... propertyNames) throws TopiaException { + try { + Criteria criteria = createCriteria(FlushMode.AUTO); + for (String propertyName : propertyNames) { + criteria.addOrder(Order.asc(propertyName)); + } + List<Entity> result = (List<Entity>)criteria.list(); + result = getContext().getFiresSupport().fireEntitiesLoad(context, result); + return result; + } catch (HibernateException eee) { + throw new TopiaException(eee); + } + } + + /** + * TODO implanter une facon plus rapide de recupere la size (count direct + * sur la base) + * (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#size() + */ + @Override + public int size() throws TopiaException { + int result = findAll().size(); + return result; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findByProperties(java.util.Map) + */ + @Override + public Entity findByProperties(Map<String, Object> properties) + throws TopiaException { + return query(Restrictions.allEq(properties)); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.util.Map) + */ + public List<Entity> findAllByProperties(Map<String, Object> properties) + throws TopiaException { + return queryAll(Restrictions.allEq(properties)); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#queryAll(org.hibernate.criterion.Criterion) + */ + private List<Entity> queryAll(Criterion criterion) throws TopiaException { + try { + Criteria criteria = createCriteria(FlushMode.AUTO); + criteria.add(criterion); + List<Entity> result = (List<Entity>)criteria.list(); + result = getContext().getFiresSupport().fireEntitiesLoad(context, result); + return result; + } catch (HibernateException eee) { + throw new TopiaException(eee); + } + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#query(org.hibernate.criterion.Criterion) + */ + private Entity query(Criterion criterion) throws TopiaException { + try { + Criteria criteria = createCriteria(FlushMode.AUTO); + criteria.add(criterion); + criteria.setMaxResults(1); + List<Entity> result = (List<Entity>)criteria.list(); + int sizeBefore = (result != null?result.size():0); + result = getContext().getFiresSupport().fireEntitiesLoad(context, result); + int sizeAfter = (result != null?result.size():0); + if (sizeAfter < sizeBefore) { + if (log.isDebugEnabled()) { + log.debug((sizeBefore - sizeAfter) + " element(s) removed. Filter entity: " + entityClass.getName() + " - criterion: " + criterion); + } + } + if (result != null && result.size() > 0) { + Entity elem = result.get(0); + return elem; + } + return null; + } catch (HibernateException eee) { + throw new TopiaException(eee); + } + } + +//FIXME : Commenté car impossible de trouver le bon Criterion + +// /* (non-Javadoc) +// * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map) +// */ +// public Entity findContainsProperties(Map<String, Collection> properties) throws TopiaException { +// try { +// Criteria criteria = createCriteria(FlushMode.AUTO); +// for (Entry<String, Collection> entry : properties.entrySet()) { +// for (Object value : entry.getValue()) { +// criteria.add(Restrictions.eq(entry.getKey(), value)); +// } +// } +// criteria.setMaxResults(1); +// List<Entity> results = (List<Entity>)criteria.list(); +// if (results.size() > 0) { +// return (Entity)results.get(0); +// } else { +// return null; +// } +// } catch (HibernateException eee) { +// throw new TopiaException(eee); +// } +// } +// +// /* (non-Javadoc) +// * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map) +// */ +// public List<Entity> findAllContainsProperties(Map<String, Collection> properties) throws TopiaException { +// try { +// Criteria criteria = createCriteria(FlushMode.AUTO); +// for (Entry<String, Collection> entry : properties.entrySet()) { +// for (Object value : entry.getValue()) { +// criteria.add(Restrictions.eq(entry.getKey(), value)); +// } +// } +// List<Entity> result = (List<Entity>)criteria.list(); +// return result; +// } catch (HibernateException eee) { +// throw new TopiaException(eee); +// } +// } + + /** + * Renvoie un Criteria créé avec l'entityClass + * @param mode le FlushMode du Criteria + * @return le Criteria nouvellement créé + */ + private Criteria createCriteria(FlushMode mode) throws TopiaException { + Criteria criteria = getSession().createCriteria(entityClass); + criteria.setFlushMode(mode); + return criteria; + } + + /** + * Renvoie la Session contenue dans le contexte + */ + private Session getSession() throws TopiaException { + return getContext().getHibernate(); + } + + /* + * (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#getRequestPermission(java.lang.String, int) + */ + public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException { + return null; + } + +} //TopiaDAOHibernate