Topia-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
January 2009
- 5 participants
- 54 discussions
r1287 - in topia/tags: . 2.1.2 2.1.2/topia-persistence 2.1.2/topia-persistence/src/main/java/org/codelutin/topia/generator 2.1.2/topia-persistence/src/main/java/org/codelutin/topia/persistence/util 2.1.2/topia-soa 2.1.2/topia-ui
by tchemit@users.labs.libre-entreprise.org 07 Jan '09
by tchemit@users.labs.libre-entreprise.org 07 Jan '09
07 Jan '09
Author: tchemit
Date: 2009-01-07 08:35:25 +0000 (Wed, 07 Jan 2009)
New Revision: 1287
Added:
topia/tags/2.1.2/
topia/tags/2.1.2/pom.xml
topia/tags/2.1.2/topia-persistence/changelog.txt
topia/tags/2.1.2/topia-persistence/pom.xml
topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java
topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java
topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/BeanPropertyLoador.java
topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Loador.java
topia/tags/2.1.2/topia-soa/pom.xml
topia/tags/2.1.2/topia-ui/pom.xml
Removed:
topia/tags/2.1.2/pom.xml
topia/tags/2.1.2/topia-persistence/changelog.txt
topia/tags/2.1.2/topia-persistence/pom.xml
topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java
topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java
topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/BeanPropertyLoador.java
topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Loador.java
topia/tags/2.1.2/topia-soa/pom.xml
topia/tags/2.1.2/topia-ui/pom.xml
Log:
[maven-release-plugin] copy for tag 2.1.2
Copied: topia/tags/2.1.2 (from rev 1284, topia/trunk)
Deleted: topia/tags/2.1.2/pom.xml
===================================================================
--- topia/trunk/pom.xml 2009-01-05 08:40:44 UTC (rev 1284)
+++ topia/tags/2.1.2/pom.xml 2009-01-07 08:35:25 UTC (rev 1287)
@@ -1,127 +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.2</version>
- </parent>
-
- <artifactId>topia</artifactId>
- <version>2.1.2-SNAPSHOT</version>
-
- <modules>
- <module>topia-persistence</module>
- <module>topia-soa</module>
- <module>topia-ui</module>
- </modules>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>lutingenerator</artifactId>
- <version>${generator.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>lutinutil</artifactId>
- <version>${lutinutil.version}</version>
- <scope>compile</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
- <!-- ************************************************************* -->
- <!-- *** Project Information ************************************* -->
- <!-- ************************************************************* -->
- <name>ToPIA - Tools for Portable and Independent Architecture</name>
- <description>Framework de persistance et de distribution d'application.</description>
- <inceptionYear>2004</inceptionYear>
-
- <!-- ************************************************************* -->
- <!-- *** Build Settings ****************************************** -->
- <!-- ************************************************************* -->
-
- <packaging>pom</packaging>
-
- <properties>
- <!-- id du projet du labs -->
- <labs.id>21</labs.id>
-
- <!-- nom du projet sur le labs -->
- <labs.project>topia</labs.project>
-
- <!-- Ignore failure test for now -->
- <maven.test.testFailureIgnore>true</maven.test.testFailureIgnore>
-
- <!-- generator version -->
- <generator.version>0.63</generator.version>
-
- <!-- processor version -->
- <processor.version>0.16</processor.version>
-
- <!-- lutinutil version -->
- <lutinutil.version>1.0</lutinutil.version>
-
- </properties>
-
- <build>
- <defaultGoal>install</defaultGoal>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-processor-plugin</artifactId>
- <version>${processor.version}</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>
- </plugins>
- </pluginManagement>
-
- <plugins>
-
- <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.1.2/pom.xml (from rev 1286, topia/trunk/pom.xml)
===================================================================
--- topia/tags/2.1.2/pom.xml (rev 0)
+++ topia/tags/2.1.2/pom.xml 2009-01-07 08:35:25 UTC (rev 1287)
@@ -0,0 +1,127 @@
+<?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.2</version>
+ </parent>
+
+ <artifactId>topia</artifactId>
+ <version>2.1.2</version>
+
+ <modules>
+ <module>topia-persistence</module>
+ <module>topia-soa</module>
+ <module>topia-ui</module>
+ </modules>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutingenerator</artifactId>
+ <version>${generator.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutinutil</artifactId>
+ <version>${lutinutil.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
+ <name>ToPIA - Tools for Portable and Independent Architecture</name>
+ <description>Framework de persistance et de distribution d'application.</description>
+ <inceptionYear>2004</inceptionYear>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
+
+ <packaging>pom</packaging>
+
+ <properties>
+ <!-- id du projet du labs -->
+ <labs.id>21</labs.id>
+
+ <!-- nom du projet sur le labs -->
+ <labs.project>topia</labs.project>
+
+ <!-- Ignore failure test for now -->
+ <maven.test.testFailureIgnore>true</maven.test.testFailureIgnore>
+
+ <!-- generator version -->
+ <generator.version>0.63</generator.version>
+
+ <!-- processor version -->
+ <processor.version>0.16</processor.version>
+
+ <!-- lutinutil version -->
+ <lutinutil.version>1.0</lutinutil.version>
+
+ </properties>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-processor-plugin</artifactId>
+ <version>${processor.version}</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>
+ </plugins>
+ </pluginManagement>
+
+ <plugins>
+
+ <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.1.2</connection>
+ <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.1.2</developerConnection>
+ <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia/tags/2.1.…</url>
+ </scm>
+
+</project>
Deleted: topia/tags/2.1.2/topia-persistence/changelog.txt
===================================================================
--- topia/trunk/topia-persistence/changelog.txt 2009-01-05 08:40:44 UTC (rev 1284)
+++ topia/tags/2.1.2/topia-persistence/changelog.txt 2009-01-07 08:35:25 UTC (rev 1287)
@@ -1,14 +0,0 @@
-2.1.2 ??? 200901??
-* 20090104 [chemit] - utilisation foreach dans les générateurs
- - ajout de méthode getXXXByTopiaId pour les attributs à multiplicité dans les entités (interface et abstract)
- - fix generic dans les méthodes générées
- - ajout d'un tagValue i18n pour générer dans les entités abstraites les chaines i18n
- - ajout d'un paquetage org.codelutin.topia.persistence.util avec du code utile :) (javadoc a faire...)
-
-2.1.1 chemit 20081215
-* 20081215 [chemit] - new release for isis-fish :)
-* 20081212 [chemit] - add a InterfaceGenerator to generate simple with no stereotype interfaces.
-
-2.1.0 chemit 20081210
-* 20081205 [chemit] - improve poms, use lutinproject 3.2
- - add some usefull methods in TopiaUtil to help with regex on topiaId expression
\ No newline at end of file
Copied: topia/tags/2.1.2/topia-persistence/changelog.txt (from rev 1285, topia/trunk/topia-persistence/changelog.txt)
===================================================================
--- topia/tags/2.1.2/topia-persistence/changelog.txt (rev 0)
+++ topia/tags/2.1.2/topia-persistence/changelog.txt 2009-01-07 08:35:25 UTC (rev 1287)
@@ -0,0 +1,21 @@
+2.1.2 ??? 200901??
+* 20090106 [chemit] - amélioration du générateur de mapping hibernate :
+ - génération des clefs metier dans le mapping hibernate via la tag value naturalId
+ - mise en constantes des tagValues utiliser dans le génératuer du mapping hibernate
+ - ajout du tagValue notNull pour le mapping hibernate
+ - changement du tagValue order-by en orderBy car sinon on récupère order au lieu de order-by
+ - ajout de la méthode obtainProgperties sur la classe Loador pour recuperer la map des propriétés à binder
+ (car pour les clef métiers on doit les ajouter à la création sinon hibernate pleure...)
+* 20090104 [chemit] - utilisation foreach dans les générateurs
+ - ajout de méthode getXXXByTopiaId pour les attributs à multiplicité dans les entités (interface et abstract)
+ - fix generic dans les méthodes générées
+ - ajout d'un tagValue i18n pour générer dans les entités abstraites les chaines i18n
+ - ajout d'un paquetage org.codelutin.topia.persistence.util avec du code utile :) (javadoc a faire...)
+
+2.1.1 chemit 20081215
+* 20081215 [chemit] - new release for isis-fish :)
+* 20081212 [chemit] - add a InterfaceGenerator to generate simple with no stereotype interfaces.
+
+2.1.0 chemit 20081210
+* 20081205 [chemit] - improve poms, use lutinproject 3.2
+ - add some usefull methods in TopiaUtil to help with regex on topiaId expression
\ No newline at end of file
Deleted: topia/tags/2.1.2/topia-persistence/pom.xml
===================================================================
--- topia/trunk/topia-persistence/pom.xml 2009-01-05 08:40:44 UTC (rev 1284)
+++ topia/tags/2.1.2/topia-persistence/pom.xml 2009-01-07 08:35:25 UTC (rev 1287)
@@ -1,108 +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>topia</artifactId>
- <version>2.1.2-SNAPSHOT</version>
- </parent>
-
- <groupId>org.codelutin.topia</groupId>
- <artifactId>topia-persistence</artifactId>
-
- <dependencies>
-
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>lutinutil</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>lutingenerator</artifactId>
- </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>org.hibernate</groupId>
- <artifactId>hibernate-ehcache</artifactId>
- <version>3.3.1.GA</version>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>javassist</groupId>
- <artifactId>javassist</artifactId>
- <version>3.4.GA</version>
- <scope>runtime</scope>
- </dependency>
- <!-- hibernate-core only include api, need core -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.5.2</version>
- <scope>runtime</scope>
- </dependency>
-
- <!-- BD H2 for testing -->
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <version>1.1.104</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <!-- ************************************************************* -->
- <!-- *** Project Information ************************************* -->
- <!-- ************************************************************* -->
-
- <name>ToPIA - Persistence</name>
- <description>Hibernate based persistence module</description>
-
- <!-- ************************************************************* -->
- <!-- *** Build Settings ****************************************** -->
- <!-- ************************************************************* -->
-
- <packaging>jar</packaging>
-
- <build>
- <defaultGoal>install</defaultGoal>
- <plugins>
-
- <plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-processor-plugin</artifactId>
- </plugin>
-
- </plugins>
- </build>
-
- <!-- ************************************************************* -->
- <!-- *** Build Environment ************************************** -->
- <!-- ************************************************************* -->
- <scm>
- <connection>${maven.scm.connection.child}</connection>
- <developerConnection>${maven.scm.developerConnection.child}</developerConnection>
- <url>${maven.scm.url.child}</url>
- </scm>
-
-
-</project>
Copied: topia/tags/2.1.2/topia-persistence/pom.xml (from rev 1286, topia/trunk/topia-persistence/pom.xml)
===================================================================
--- topia/tags/2.1.2/topia-persistence/pom.xml (rev 0)
+++ topia/tags/2.1.2/topia-persistence/pom.xml 2009-01-07 08:35:25 UTC (rev 1287)
@@ -0,0 +1,108 @@
+<?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>topia</artifactId>
+ <version>2.1.2</version>
+ </parent>
+
+ <groupId>org.codelutin.topia</groupId>
+ <artifactId>topia-persistence</artifactId>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutinutil</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutingenerator</artifactId>
+ </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>org.hibernate</groupId>
+ <artifactId>hibernate-ehcache</artifactId>
+ <version>3.3.1.GA</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
+ <version>3.4.GA</version>
+ <scope>runtime</scope>
+ </dependency>
+ <!-- hibernate-core only include api, need core -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.5.2</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <!-- BD H2 for testing -->
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>1.1.104</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
+
+ <name>ToPIA - Persistence</name>
+ <description>Hibernate based persistence module</description>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
+
+ <packaging>jar</packaging>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-processor-plugin</artifactId>
+ </plugin>
+
+ </plugins>
+ </build>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Environment ************************************** -->
+ <!-- ************************************************************* -->
+ <scm>
+ <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.1.2/topia-persistence</connection>
+ <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.1.2/topia-persistence</developerConnection>
+ <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia/tags/2.1.…</url>
+ </scm>
+
+
+</project>
Deleted: topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java 2009-01-05 08:40:44 UTC (rev 1284)
+++ topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java 2009-01-07 08:35:25 UTC (rev 1287)
@@ -1,447 +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>. ##%*/
-
-/* *
-* EntityHibernateMappingGenerator.java
-*
-* Created: 12 déc. 2005
-*
-* @author Arnaud Thimel <thimel(a)codelutin.com>
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-* Mise a jour: $Date$
-* par : $Author$
-*/
-
-package org.codelutin.topia.generator;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.HashMap;
-import java.util.Map;
-
-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.Util;
-import org.codelutin.generator.models.object.ObjectModelAssociationClass;
-import org.codelutin.generator.models.object.ObjectModelAttribute;
-import org.codelutin.generator.models.object.ObjectModelClass;
-
-import static org.codelutin.topia.generator.GeneratorUtil.notEmpty;
-import static org.codelutin.topia.generator.GeneratorUtil.STEREOTYPE_ENTITY;
-import static org.codelutin.topia.generator.GeneratorUtil.TAG_ACCESS;
-import static org.codelutin.topia.generator.GeneratorUtil.PERSISTENCE_TYPE_HIBERNATE;
-import static org.codelutin.topia.generator.GeneratorUtil.hasUnidirectionalRelationOnAbstractType;
-
-/**
- * FIXME mettre les attributs node="..." sur tous les attributs
- * @author poussin
- *
- */
-public class EntityHibernateMappingGenerator extends ObjectModelGenerator {
-
- /**
- * Logger for this class
- */
- private static final Log log = LogFactory
- .getLog(EntityHibernateMappingGenerator.class);
-
- private Map<String, String[]> columnNamesMap = new HashMap<String, String[]>();
-
- public EntityHibernateMappingGenerator() {
- super();
- }
-
- public EntityHibernateMappingGenerator(Generator parent) {
- super(parent);
- }
-
- @Override
- public String getFilenameForClass(ObjectModelClass clazz) {
- String DOName = GeneratorUtil.getDOType(clazz, model);
- return DOName.replace('.', File.separatorChar) + ".hbm.xml";
- }
-
- @Override
- public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException {
- String persistenceType = GeneratorUtil.getPersistenceType(clazz);
- if (!clazz.hasStereotype(STEREOTYPE_ENTITY) && PERSISTENCE_TYPE_HIBERNATE.equals(persistenceType)) {
- return;
- }
-/*{<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-<hibernate-mapping default-access="field" auto-import="true" package="<%=clazz.getPackageName()%>">
-}*/
- boolean haveSuper = clazz.getSuperclasses().size() > 0;
-
- if (haveSuper) {
- ObjectModelClass superClass = clazz.getSuperclasses().iterator().next();
- String superClassname = superClass.getQualifiedName();
- if (log.isDebugEnabled()) {log.debug("superClass for " + clazz.getQualifiedName() + " is " + superClassname);}
-/*{ <union-subclass }*/
-/*{name="<%=GeneratorUtil.getDOType(clazz, model)%>" }*/
-/*{extends="<%=GeneratorUtil.getDOType(superClassname, model)%>" }*/
-/*{table="<%=GeneratorUtil.getDBName(clazz)%>" }*/
- String schema = GeneratorUtil.getSchemaName(clazz, model);
- if (schema != null) {
-/*{schema="<%=schema%>" }*/
- }
-/*{node="<%=GeneratorUtil.getDOType(clazz, model)%>" }*/
-/*{abstract="<%=(clazz.isAbstract()?"true":"false")%>" }*/
- //On précise au proxy de quelle interface hérite l'objet
-/*{proxy="<%=clazz.getQualifiedName()%>" }*/
-/*{>
- <!--key column="topiaId"/-->
-}*/
- } else {
-/*{ <class }*/
-/*{name="<%=GeneratorUtil.getDOType(clazz, model)%>" }*/
-/*{table="<%=GeneratorUtil.getDBName(clazz)%>" }*/
- String schema = GeneratorUtil.getSchemaName(clazz, model);
- if (schema != null) {
-/*{schema="<%=schema%>" }*/
- }
-/*{node="<%=GeneratorUtil.getDOType(clazz, model)%>" }*/
-/*{abstract="<%=(clazz.isAbstract()?"true":"false")%>" }*/
- //On précise au proxy de quelle interface hérite l'objet
-/*{proxy="<%=clazz.getQualifiedName()%>" }*/
-/*{>
- <id name="topiaId" type="string" length="255" node="@topiaId"/>
- <version name="topiaVersion" type="long" node="@topiaVersion"/>
- <property name="topiaCreateDate" type="date" node="@topiaCreateDate"/>
-}*/
- }
-
- for (Object o : clazz.getAttributes()) {
- ObjectModelAttribute attr = (ObjectModelAttribute) o;
- ObjectModelAttribute reverse = attr.getReverseAttribute();
-
- // pour les asso quoi qu'il arrive il faut les lier des 2 cotes
- // pour pouvoir supprimer en cascade l'asso lors de la suppression
- // d'un des cotes
- if (attr.isNavigable()
- || hasUnidirectionalRelationOnAbstractType(reverse, model)
- || attr.hasAssociationClass()) {
- if (!Util.isNMultiplicity(attr)) {
- if (attr.getClassifier() != null && attr.getClassifier().hasStereotype(STEREOTYPE_ENTITY)) {
- if (Util.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) {
- generateHibernateManyToOne(output, attr);
- } else {
- generateHibernateOneToOne(output, attr);
- }
- } else {
- generateHibernateProperty(output, attr);
- }
- } else {
- if (attr.getClassifier() != null && attr.getClassifier().hasStereotype(STEREOTYPE_ENTITY)) {
- if (Util.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) {
- generateHibernateManyToMany(output, attr);
- } else {
- generateHibernateOneToMany(output, attr);
- }
- } else {
- generateHibernateMany(output, attr);
- }
- }
- }
- }
-
- //Attributs pour les classes d'association
- if (clazz instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assoc = (ObjectModelAssociationClass)clazz;
- for (Object o : assoc.getParticipantsAttributes()) {
- ObjectModelAttribute attr = (ObjectModelAttribute) o;
- if (attr != null) {
-
-// Note(poussin) pour moi quoi qu'il arrive sur la classe d'association il faut
-// un many-to-one, sinon on a des problemes.
-// if ((!attr.getReverseAttribute().isNavigable()) || !Util.isNMultiplicity(attr.getReverseAttribute())) {
-// / *{ <one-to-one name="<%=getName(attr, true)%>" class="<%=getType(attr, true)%>"<%=(GeneratorUtil.notEmpty(attr.getTagValue(GeneratorUtil.TAG_LENGTH))?(" length=\"" + attr.getTagValue(GeneratorUtil.TAG_LENGTH) + "\""):"")%><%=(attr.isComposite()?" cascade=\"delete\"":"")%>/>
-// } */
-// } else {
-
-/*{ <many-to-one name="<%=getName(attr, true)%>" class="<%=getType(attr, true)%>" column="<%=GeneratorUtil.getDBName(attr)%>" node="<%=getName(attr, true)%>/@topiaId" embed-xml="false"/>
-}*/
-// }
- //Ne sert plus grâce à l'utilisation de la navigabilité
-// if (!attr.getReverseAttribute().isNavigable()) {
-// String type = GeneratorUtil.getDOType(((ObjectModelClassifier)attr.getDeclaringElement()).getQualifiedName(), model);
-// String name = Util.toLowerCaseFirstLetter(attr.getDeclaringElement().getName());
-// if (log.isTraceEnabled()) {log.trace("reverse: " + type + " " + name);}
-// if (!Util.isNMultiplicity(attr)) {
-//{<!-- <one-to-one name="<%=name%>" class="<%=type%>"/>
-//}
-// } else {
-//{ <many-to-one name="<%=name%>" class="<%=type%>" column="<%=name.toLowerCase()%>"/> -->
-//}
-// }
-// }
- }
- }
- }
-
- if (haveSuper) {
-/*{ </union-subclass>
-}*/
- } else {
-/*{ </class>
-}*/
- }
-/*{</hibernate-mapping>
-}*/
- }
-
- protected String getName(ObjectModelAttribute attr) {
- return getName(attr, false);
- }
-
- protected String getName(ObjectModelAttribute attr, boolean isAssoc) {
- String result = Util.toLowerCaseFirstLetter(attr.getName());
- if (attr.hasAssociationClass() && !isAssoc) {
- result = GeneratorUtil.getAssocAttrName(attr);
- }
- return result;
- }
-
- protected String getType(ObjectModelAttribute attr) {
- return getType(attr, false);
- }
-
- protected String getType(ObjectModelAttribute attr, boolean isAssoc) {
- String type = attr.getType();
- if (GeneratorUtil.notEmpty(model.getTagValue(type))) {
- String typeString = model.getTagValue(type);
- int bracketIndex = typeString.indexOf('(');
- if (bracketIndex != -1) {
- type = typeString.substring(0, bracketIndex);
- int bracketEndIndex = typeString.indexOf(')', bracketIndex + 1);
- String colmunList;
- if (bracketEndIndex != -1) {
- colmunList = typeString.substring(bracketIndex + 1, bracketEndIndex);
- } else {
- colmunList = typeString.substring(bracketIndex);
- }
- columnNamesMap.put(type, colmunList.split(","));
- } else {
- type = typeString;
- }
- }
- if (attr.hasAssociationClass() && !isAssoc) {
- type = attr.getAssociationClass().getQualifiedName();
- }
- return GeneratorUtil.getDOType(type, model);
- }
-
- protected void generateHibernateProperty(Writer output, ObjectModelAttribute attr) throws IOException {
- String type = getType(attr);
- if (type.trim().endsWith("[]")) {
- type = type.trim().substring(0, type.trim().length()-2);
-/*{ <primitive-array name="<%=getName(attr)%>" table="<%=GeneratorUtil.getDBName(attr.getDeclaringElement()) + "_" + getName(attr)%>" }*/
- String accessField = attr.getTagValue(TAG_ACCESS);
- if (notEmpty(accessField)) {
-/*{access="<%=accessField%>" }*/
- } else {
-/*{access="field" }*/
- }
- String schema = GeneratorUtil.getSchemaName(attr, model);
- if (schema != null) {
-/*{schema="<%=schema%>" }*/
- }
- if (attr.isIndexed()) {
-/*{index="<%=GeneratorUtil.getDBName(attr.getDeclaringElement()) + "_" + getName(attr)%>_idx" }*/
- }
-/*{>
- <key column="<%=GeneratorUtil.getDBName(attr.getDeclaringElement())%>"/>
- <list-index column="<%=getName(attr)%>_idx"/>
- <element type="<%=type%>"/>
- </primitive-array>
-}*/
- } else {
-/*{ <property name="<%=getName(attr)%>" type="<%=type%>" }*/
- String accessField = attr.getTagValue(TAG_ACCESS);
- if (notEmpty(accessField)) {
-/*{access="<%=accessField%>" }*/
- } else {
-/*{access="field" }*/
- }
- if (attr.isIndexed()) {
-/*{index="<%=GeneratorUtil.getDBName(attr.getDeclaringElement()) + "_" + getName(attr)%>_idx" }*/
- }
- String[] columnNames = this.columnNamesMap.get(type);
- if (columnNames == null || columnNames.length == 0) {
-/*{column="<%=GeneratorUtil.getDBName(attr)%>"<%=(GeneratorUtil.notEmpty(attr.getTagValue(GeneratorUtil.TAG_LENGTH))?(" length=\"" + attr.getTagValue(GeneratorUtil.TAG_LENGTH) + "\""):"")%> node="<%=getName(attr)%>"/>
-}*/
- } else {
-/*{>
-}*/
- for (String columnName : columnNames) {
- columnName = columnName.trim();
-/*{ <column name="<%=getName(attr) + "_" + columnName%>"/>
-}*/
- }
-/*{ </property>
-}*/
- }
- }
- }
-
- protected void generateHibernateOneToOne(Writer output, ObjectModelAttribute attr) throws IOException {
- generateHibernateManyToOne(output, attr, true);
-// boolean accessField = hasUnidirectionalRelationOnAbstractType(attr.getReverseAttribute(), model);
-/// *{ <one-to-one name="<%=getName(attr)%>" class="<%=getType(attr)%>"<%=(GeneratorUtil.notEmpty(attr.getTagValue(GeneratorUtil.TAG_LENGTH))?(" length=\"" + attr.getTagValue(GeneratorUtil.TAG_LENGTH) + "\""):"")%><%=((attr.isComposite() || attr.hasAssociationClass())?" cascade=\"delete\"":"")%><%=((accessField)?" access=\"field\"":"")%> node="<%=getName(attr)%>/@topiaId" embed-xml="false"/>
-//} */
- }
-
- protected void generateHibernateOneToMany(Writer output, ObjectModelAttribute attr) throws IOException {
- boolean needsIndex = attr.isIndexed();
- boolean isInverse = attr.getReverseAttribute().isNavigable();
- isInverse |= hasUnidirectionalRelationOnAbstractType(attr, model);
- String orderBy = attr.getTagValue("order-by");
- if (orderBy == null) {
- orderBy = "";
- } else {
- orderBy = "order-by=\"" + orderBy + "\"";
- }
-
- String cascade = "";
- if (attr.isComposite() || attr.hasAssociationClass()) {
- cascade += "cascade=\"all,delete-orphan\"";
- }
-
- String lazy = "lazy=\"";
- if (attr.getTagValue("lazy") != null){
- lazy += attr.getTagValue("lazy");
- }
- else {
- lazy += "true";
- }
- lazy += "\"";
-
- String fetch = "";
- if (attr.getTagValue("fetch") != null){
- fetch = "fetch=\"" + attr.getTagValue("fetch") + "\"";
- }
-
- String collType = GeneratorUtil.getNMultiplicityHibernateType(attr);
- if (!needsIndex) {
-/*{ <<%=collType%> name="<%=getName(attr)%>" <%=orderBy%> <%=((!isInverse)?"":"inverse=\"true\"")%> <%=fetch%> <%=lazy%> <%=cascade%> node="<%=getName(attr)%>" embed-xml="true">
- <key column="<%=GeneratorUtil.getReverseDBName(attr)%>"/>
- <one-to-many class="<%=getType(attr)%>" node="topiaId" embed-xml="false"/>
- </<%=collType%>>
-}*/
- }else {
-/*{ <<%=collType%> name="<%=getName(attr)%>"<%=((!isInverse)?"":" inverse=\"true\"")%> <%=lazy%> <%=cascade%> node="<%=getName(attr)%>" embed-xml="false">
- <key column="<%=GeneratorUtil.getReverseDBName(attr)%>"/>
- <list-index column="<%=GeneratorUtil.getReverseDBName(attr)%>_idx"/>
- <one-to-many class="<%=getType(attr)%>" node="topiaId" embed-xml="false"/>
- </<%=collType%>>
-}*/
- }
- }
-
- protected void generateHibernateMany(Writer output, ObjectModelAttribute attr) throws IOException {
- boolean needsIndex = attr.isIndexed();
- String collType = GeneratorUtil.getNMultiplicityHibernateType(attr);
- String lazy = "";
- if (attr.getTagValue("lazy") != null) {
- lazy = "lazy=\"" + attr.getTagValue("lazy") + "\"";
- }
-
-/*{ <<%=collType%> name="<%=getName(attr)%>" node="<%=getName(attr)%>" embed-xml="true" <%=lazy%>>
- <key column="OWNER"/>
-}*/
- if (needsIndex) {
-/*{ <list-index/>
-}*/
- }
-/*{ <element type="<%=getType(attr)%>" column="<%=GeneratorUtil.getDBName(attr)%>" node="id"/>
- </<%=collType%>>
-}*/
- }
-
- protected void generateHibernateManyToOne(Writer output, ObjectModelAttribute attr) throws IOException {
- generateHibernateManyToOne(output, attr, false);
- }
-
- protected void generateHibernateManyToOne(Writer output, ObjectModelAttribute attr, boolean isUnique) throws IOException {
-/*{ <many-to-one name="<%=getName(attr)%>" class="<%=getType(attr)%>" column="<%=GeneratorUtil.getDBName(attr)%>"}*/
- if (attr.isComposite() || attr.hasAssociationClass()) {
-/*{ cascade="delete"}*/
- }
- // Pour le test suivant, on verifie d'abord que l'attribut a un reverse.
- // S'il n'en a pas, cela signifie qu'il ne s'agit pas d'un entite
- // (au sens stereotype entity), donc a donc pas besoin de faire un access=field.
- if (attr.getReverseAttribute() != null && hasUnidirectionalRelationOnAbstractType(attr.getReverseAttribute(), model)) {
-/*{ access="field"}*/
- }
- if (isUnique) {
-/*{ unique="true"}*/
- }
-/*{ node="<%=getName(attr)%>/@topiaId" embed-xml="false"}*/
-
- // vérifier si le tag lazy est defini par defaut dans le fichier de proprietes
- if (attr.getTagValue("lazy") != null){
-/*{ lazy="<%=attr.getTagValue("lazy")%>"}*/
- }
-/*{/>
-}*/
- }
-
- protected void generateHibernateManyToMany(Writer output, ObjectModelAttribute attr) throws IOException {
- // On ne met le inverse="true" uniquement pour un seul coté de la relation.
- // Dans le cas contraire, les modifications dans la relation ne seront
- // pas sauvegardées. Ceci n'est vrai que si les deux coté sont navigable
- boolean isInverse = attr.isNavigable() && attr.getReverseAttribute().isNavigable();
- //isInverse |= !Util.isFirstAttribute(attr);
- //isInverse = false; // 20070117 poussin: pour du many, jamais de inverse
- isInverse &= Util.isFirstAttribute(attr);
-
- boolean needsIndex = attr.isIndexed();
- String cascade = "";
- if (attr.isComposite() || attr.hasAssociationClass()) {
- cascade += "cascade=\"delete,delete-orphan\"";
- }
- cascade += "";
-
- String lazy = "lazy=\"";
- if (attr.getTagValue("lazy") != null){
- lazy += attr.getTagValue("lazy");
- }
- else {
- lazy += "true";
- }
- lazy += "\"";
- String collType = GeneratorUtil.getNMultiplicityHibernateType(attr);
-
-/*{ <<%=collType%> name="<%=getName(attr)%>" table="<%=GeneratorUtil.getManyToManyTableName(attr)%>" <%=(isInverse?"inverse=\"true\" ":"")%> <%=lazy%> <%=cascade%> node="<%=getName(attr)%>" embed-xml="true">
- <key column="<%=GeneratorUtil.getReverseDBName(attr)%>"/>
-}*/
- if (needsIndex) {
-/*{ <list-index column="<%=GeneratorUtil.getReverseDBName(attr)%>_idx"/>
-}*/
- }
-/*{ <many-to-many class="<%=getType(attr)%>" column="<%=GeneratorUtil.getDBName(attr)%>" node="topiaId"/>
- </<%=collType%>>
-}*/
- }
-
-} //EntityHibernateMappingGenerator
Copied: topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java (from rev 1285, topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java)
===================================================================
--- topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java (rev 0)
+++ topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java 2009-01-07 08:35:25 UTC (rev 1287)
@@ -0,0 +1,486 @@
+/* *##% 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>. ##%*/
+
+/* *
+* EntityHibernateMappingGenerator.java
+*
+* Created: 12 déc. 2005
+*
+* @author Arnaud Thimel <thimel(a)codelutin.com>
+* @version $Revision$
+*
+* Mise a jour: $Date$
+* par : $Author$
+* Mise a jour: $Date$
+* par : $Author$
+*/
+
+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.Util;
+import org.codelutin.generator.models.object.ObjectModelAssociationClass;
+import org.codelutin.generator.models.object.ObjectModelAttribute;
+import org.codelutin.generator.models.object.ObjectModelClass;
+import static org.codelutin.topia.generator.GeneratorUtil.PERSISTENCE_TYPE_HIBERNATE;
+import static org.codelutin.topia.generator.GeneratorUtil.STEREOTYPE_ENTITY;
+import static org.codelutin.topia.generator.GeneratorUtil.TAG_ACCESS;
+import static org.codelutin.topia.generator.GeneratorUtil.hasUnidirectionalRelationOnAbstractType;
+import static org.codelutin.topia.generator.GeneratorUtil.notEmpty;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * FIXME mettre les attributs node="..." sur tous les attributs
+ * @author poussin
+ *
+ */
+public class EntityHibernateMappingGenerator extends ObjectModelGenerator {
+
+ /**
+ * Logger for this class
+ */
+ private static final Log log = LogFactory
+ .getLog(EntityHibernateMappingGenerator.class);
+
+ private Map<String, String[]> columnNamesMap = new HashMap<String, String[]>();
+
+ public EntityHibernateMappingGenerator() {
+ super();
+ }
+
+ public EntityHibernateMappingGenerator(Generator parent) {
+ super(parent);
+ }
+
+ @Override
+ public String getFilenameForClass(ObjectModelClass clazz) {
+ String DOName = GeneratorUtil.getDOType(clazz, model);
+ return DOName.replace('.', File.separatorChar) + ".hbm.xml";
+ }
+
+ @Override
+ public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException {
+ String persistenceType = GeneratorUtil.getPersistenceType(clazz);
+ if (!clazz.hasStereotype(STEREOTYPE_ENTITY) && PERSISTENCE_TYPE_HIBERNATE.equals(persistenceType)) {
+ return;
+ }
+/*{<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping default-access="field" auto-import="true" package="<%=clazz.getPackageName()%>">
+}*/
+ boolean haveSuper = clazz.getSuperclasses().size() > 0;
+ List<ObjectModelAttribute> noneNaturalAttributes = new ArrayList<ObjectModelAttribute >();
+ if (haveSuper) {
+ ObjectModelClass superClass = clazz.getSuperclasses().iterator().next();
+ String superClassname = superClass.getQualifiedName();
+ if (log.isDebugEnabled()) {log.debug("superClass for " + clazz.getQualifiedName() + " is " + superClassname);}
+/*{ <union-subclass }*/
+/*{name="<%=GeneratorUtil.getDOType(clazz, model)%>" }*/
+/*{extends="<%=GeneratorUtil.getDOType(superClassname, model)%>" }*/
+/*{table="<%=GeneratorUtil.getDBName(clazz)%>" }*/
+ String schema = GeneratorUtil.getSchemaName(clazz, model);
+ if (schema != null) {
+/*{schema="<%=schema%>" }*/
+ }
+/*{node="<%=GeneratorUtil.getDOType(clazz, model)%>" }*/
+/*{abstract="<%=(clazz.isAbstract()?"true":"false")%>" }*/
+ //On précise au proxy de quelle interface hérite l'objet
+/*{proxy="<%=clazz.getQualifiedName()%>" }*/
+/*{>
+ <!--key column="topiaId"/-->
+}*/
+ } else {
+/*{ <class }*/
+/*{name="<%=GeneratorUtil.getDOType(clazz, model)%>" }*/
+/*{table="<%=GeneratorUtil.getDBName(clazz)%>" }*/
+ String schema = GeneratorUtil.getSchemaName(clazz, model);
+ if (schema != null) {
+/*{schema="<%=schema%>" }*/
+ }
+/*{node="<%=GeneratorUtil.getDOType(clazz, model)%>" }*/
+/*{abstract="<%=(clazz.isAbstract()?"true":"false")%>" }*/
+ //On précise au proxy de quelle interface hérite l'objet
+/*{proxy="<%=clazz.getQualifiedName()%>" }*/
+/*{>
+ <id name="topiaId" type="string" length="255" node="@topiaId"/>
+}*/
+ List<String> attributes = GeneratorUtil.getNaturalId(clazz);
+ if (log.isDebugEnabled()) {
+ log.debug("natural-id for class "+clazz.getName()+" : "+attributes);
+ }
+
+ if (attributes.isEmpty()) {
+ // pas de clef metiers sur la classe
+ noneNaturalAttributes.addAll(clazz.getAttributes());
+ } else {
+ // une clef métier sur la classe a ete detectee
+ List<ObjectModelAttribute> naturalAttributes = new ArrayList<ObjectModelAttribute >(attributes.size());
+ for (ObjectModelAttribute attr : clazz.getAttributes()) {
+ if (attributes.contains(attr.getName())) {
+ naturalAttributes.add(attr);
+ } else {
+ noneNaturalAttributes.add(attr);
+ }
+ }
+/*{ <natural-id>
+}*/
+ generateAttributes(output, clazz, naturalAttributes," ");
+/*{ </natural-id>
+}*/
+ }
+
+/*{ <version name="topiaVersion" type="long" node="@topiaVersion"/>
+ <property name="topiaCreateDate" type="date" node="@topiaCreateDate"/>
+}*/
+ }
+ generateAttributes(output, clazz, noneNaturalAttributes,"");
+
+ if (haveSuper) {
+/*{ </union-subclass>
+}*/
+ } else {
+/*{ </class>
+}*/
+ }
+/*{</hibernate-mapping>
+}*/
+ }
+
+ protected void generateAttributes(Writer output, ObjectModelClass clazz, List<ObjectModelAttribute> attributes,String prefix) throws IOException {
+ for (ObjectModelAttribute attr : attributes) {
+ ObjectModelAttribute reverse = attr.getReverseAttribute();
+
+ // pour les asso quoi qu'il arrive il faut les lier des 2 cotes
+ // pour pouvoir supprimer en cascade l'asso lors de la suppression
+ // d'un des cotes
+ if (attr.isNavigable()
+ || hasUnidirectionalRelationOnAbstractType(reverse, model)
+ || attr.hasAssociationClass()) {
+ if (!Util.isNMultiplicity(attr)) {
+ if (attr.getClassifier() != null && attr.getClassifier().hasStereotype(STEREOTYPE_ENTITY)) {
+ if (Util.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) {
+ generateHibernateManyToOne(output, attr, prefix);
+ } else {
+ generateHibernateOneToOne(output, attr, prefix);
+ }
+ } else {
+ generateHibernateProperty(output, attr, prefix);
+ }
+ } else {
+ if (attr.getClassifier() != null && attr.getClassifier().hasStereotype(STEREOTYPE_ENTITY)) {
+ if (Util.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) {
+ generateHibernateManyToMany(output, attr, prefix);
+ } else {
+ generateHibernateOneToMany(output, attr, prefix);
+ }
+ } else {
+ generateHibernateMany(output, attr, prefix);
+ }
+ }
+ }
+ }
+
+ //Attributs pour les classes d'association
+ if (clazz instanceof ObjectModelAssociationClass) {
+ ObjectModelAssociationClass assoc = (ObjectModelAssociationClass)clazz;
+ for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) {
+ if (attr != null) {
+
+// Note(poussin) pour moi quoi qu'il arrive sur la classe d'association il faut
+// un many-to-one, sinon on a des problemes.
+// if ((!attr.getReverseAttribute().isNavigable()) || !Util.isNMultiplicity(attr.getReverseAttribute())) {
+// / *{ <one-to-one name="<%=getName(attr, true)%>" class="<%=getType(attr, true)%>"<%=(GeneratorUtil.notEmpty(attr.getTagValue(GeneratorUtil.TAG_LENGTH))?(" length=\"" + attr.getTagValue(GeneratorUtil.TAG_LENGTH) + "\""):"")%><%=(attr.isComposite()?" cascade=\"delete\"":"")%>/>
+// } */
+// } else {
+ String notNull = attr.getTagValue(GeneratorUtil.TAG_NOT_NULL);
+ if (notNull!=null) {
+ notNull = "not-null=\""+notNull.trim()+"\"";
+ }
+/*{<%=prefix%> <many-to-one name="<%=getName(attr, true)%>" class="<%=getType(attr, true)%>" column="<%=GeneratorUtil.getDBName(attr)%>" node="<%=getName(attr, true)%>/@topiaId" embed-xml="false" <%=notNull%> />
+}*/
+// }
+ //Ne sert plus grâce à l'utilisation de la navigabilité
+// if (!attr.getReverseAttribute().isNavigable()) {
+// String type = GeneratorUtil.getDOType(((ObjectModelClassifier)attr.getDeclaringElement()).getQualifiedName(), model);
+// String name = Util.toLowerCaseFirstLetter(attr.getDeclaringElement().getName());
+// if (log.isTraceEnabled()) {log.trace("reverse: " + type + " " + name);}
+// if (!Util.isNMultiplicity(attr)) {
+//{<!-- <one-to-one name="<%=name%>" class="<%=type%>"/>
+//}
+// } else {
+//{ <many-to-one name="<%=name%>" class="<%=type%>" column="<%=name.toLowerCase()%>"/> -->
+//}
+// }
+// }
+ }
+ }
+ }
+
+ }
+ protected String getName(ObjectModelAttribute attr) {
+ return getName(attr, false);
+ }
+
+ protected String getName(ObjectModelAttribute attr, boolean isAssoc) {
+ String result = Util.toLowerCaseFirstLetter(attr.getName());
+ if (attr.hasAssociationClass() && !isAssoc) {
+ result = GeneratorUtil.getAssocAttrName(attr);
+ }
+ return result;
+ }
+
+ protected String getType(ObjectModelAttribute attr) {
+ return getType(attr, false);
+ }
+
+ protected String getType(ObjectModelAttribute attr, boolean isAssoc) {
+ String type = attr.getType();
+ if (GeneratorUtil.notEmpty(model.getTagValue(type))) {
+ String typeString = model.getTagValue(type);
+ int bracketIndex = typeString.indexOf('(');
+ if (bracketIndex != -1) {
+ type = typeString.substring(0, bracketIndex);
+ int bracketEndIndex = typeString.indexOf(')', bracketIndex + 1);
+ String colmunList;
+ if (bracketEndIndex != -1) {
+ colmunList = typeString.substring(bracketIndex + 1, bracketEndIndex);
+ } else {
+ colmunList = typeString.substring(bracketIndex);
+ }
+ columnNamesMap.put(type, colmunList.split(","));
+ } else {
+ type = typeString;
+ }
+ }
+ if (attr.hasAssociationClass() && !isAssoc) {
+ type = attr.getAssociationClass().getQualifiedName();
+ }
+ return GeneratorUtil.getDOType(type, model);
+ }
+
+ protected void generateHibernateProperty(Writer output, ObjectModelAttribute attr, String prefix) throws IOException {
+ String type = getType(attr);
+ if (type.trim().endsWith("[]")) {
+ type = type.trim().substring(0, type.trim().length()-2);
+/*{<%=prefix%> <primitive-array name="<%=getName(attr)%>" table="<%=GeneratorUtil.getDBName(attr.getDeclaringElement()) + "_" + getName(attr)%>" }*/
+ String accessField = attr.getTagValue(TAG_ACCESS);
+ if (notEmpty(accessField)) {
+/*{access="<%=accessField%>" }*/
+ } else {
+/*{access="field" }*/
+ }
+ String schema = GeneratorUtil.getSchemaName(attr, model);
+ if (schema != null) {
+/*{schema="<%=schema%>" }*/
+ }
+ if (attr.isIndexed()) {
+/*{index="<%=GeneratorUtil.getDBName(attr.getDeclaringElement()) + "_" + getName(attr)%>_idx" }*/
+ }
+/*{>
+<%=prefix%> <key column="<%=GeneratorUtil.getDBName(attr.getDeclaringElement())%>"/>
+<%=prefix%> <list-index column="<%=getName(attr)%>_idx"/>
+<%=prefix%> <element type="<%=type%>"/>
+<%=prefix%> </primitive-array>
+}*/
+ } else {
+/*{<%=prefix%> <property name="<%=getName(attr)%>" type="<%=type%>" }*/
+ String accessField = attr.getTagValue(TAG_ACCESS);
+ if (notEmpty(accessField)) {
+/*{access="<%=accessField%>" }*/
+ } else {
+/*{access="field" }*/
+ }
+ if (attr.isIndexed()) {
+/*{index="<%=GeneratorUtil.getDBName(attr.getDeclaringElement()) + "_" + getName(attr)%>_idx" }*/
+ }
+ String notNull = attr.getTagValue(GeneratorUtil.TAG_NOT_NULL);
+ if (notNull != null) {
+/*{ not-null="<%=notNull.trim()%>" }*/
+ }
+ String[] columnNames = this.columnNamesMap.get(type);
+ if (columnNames == null || columnNames.length == 0) {
+/*{column="<%=GeneratorUtil.getDBName(attr)%>"<%=(GeneratorUtil.notEmpty(attr.getTagValue(GeneratorUtil.TAG_LENGTH))?(" length=\"" + attr.getTagValue(GeneratorUtil.TAG_LENGTH) + "\""):"")%> node="<%=getName(attr)%>"/>
+}*/
+ } else {
+/*{>
+}*/
+ for (String columnName : columnNames) {
+ columnName = columnName.trim();
+/*{<%=prefix%> <column name="<%=getName(attr) + "_" + columnName%>"/>
+}*/
+ }
+/*{<%=prefix%> </property>
+}*/
+ }
+ }
+ }
+
+ protected void generateHibernateOneToOne(Writer output, ObjectModelAttribute attr, String prefix) throws IOException {
+ generateHibernateManyToOne(output, attr, true, prefix);
+// boolean accessField = hasUnidirectionalRelationOnAbstractType(attr.getReverseAttribute(), model);
+/// *{ <one-to-one name="<%=getName(attr)%>" class="<%=getType(attr)%>"<%=(GeneratorUtil.notEmpty(attr.getTagValue(GeneratorUtil.TAG_LENGTH))?(" length=\"" + attr.getTagValue(GeneratorUtil.TAG_LENGTH) + "\""):"")%><%=((attr.isComposite() || attr.hasAssociationClass())?" cascade=\"delete\"":"")%><%=((accessField)?" access=\"field\"":"")%> node="<%=getName(attr)%>/@topiaId" embed-xml="false"/>
+//} */
+ }
+
+ protected void generateHibernateOneToMany(Writer output, ObjectModelAttribute attr, String prefix) throws IOException {
+ boolean needsIndex = attr.isIndexed();
+ boolean isInverse = attr.getReverseAttribute().isNavigable();
+ isInverse |= hasUnidirectionalRelationOnAbstractType(attr, model);
+ String orderBy = attr.getTagValue(GeneratorUtil.TAG_ORDER_BY);
+ if (orderBy == null) {
+ orderBy = "";
+ } else {
+ orderBy = "order-by=\"" + orderBy + "\"";
+ }
+
+ String cascade = "";
+ if (attr.isComposite() || attr.hasAssociationClass()) {
+ cascade += "cascade=\"all,delete-orphan\"";
+ }
+
+ String lazy = "lazy=\"";
+ if (attr.getTagValue(GeneratorUtil.TAG_LAZY) != null){
+ lazy += attr.getTagValue(GeneratorUtil.TAG_LAZY);
+ }
+ else {
+ lazy += "true";
+ }
+ lazy += "\"";
+
+ String fetch = "";
+ if (attr.getTagValue(GeneratorUtil.TAG_FETCH) != null){
+ fetch = "fetch=\"" + attr.getTagValue(GeneratorUtil.TAG_FETCH) + "\"";
+ }
+
+ String collType = GeneratorUtil.getNMultiplicityHibernateType(attr);
+ if (!needsIndex) {
+/*{<%=prefix%> <<%=collType%> name="<%=getName(attr)%>" <%=orderBy%> <%=((!isInverse)?"":"inverse=\"true\"")%> <%=fetch%> <%=lazy%> <%=cascade%> node="<%=getName(attr)%>" embed-xml="true">
+<%=prefix%> <key column="<%=GeneratorUtil.getReverseDBName(attr)%>"/>
+<%=prefix%> <one-to-many class="<%=getType(attr)%>" node="topiaId" embed-xml="false"/>
+<%=prefix%> </<%=collType%>>
+}*/
+ }else {
+/*{<%=prefix%> <<%=collType%> name="<%=getName(attr)%>"<%=((!isInverse)?"":" inverse=\"true\"")%> <%=lazy%> <%=cascade%> node="<%=getName(attr)%>" embed-xml="false">
+<%=prefix%> <key column="<%=GeneratorUtil.getReverseDBName(attr)%>"/>
+<%=prefix%> <list-index column="<%=GeneratorUtil.getReverseDBName(attr)%>_idx"/>
+<%=prefix%> <one-to-many class="<%=getType(attr)%>" node="topiaId" embed-xml="false"/>
+<%=prefix%> </<%=collType%>>
+}*/
+ }
+ }
+
+ protected void generateHibernateMany(Writer output, ObjectModelAttribute attr, String prefix) throws IOException {
+ boolean needsIndex = attr.isIndexed();
+ String collType = GeneratorUtil.getNMultiplicityHibernateType(attr);
+ String lazy = "";
+ if (attr.getTagValue(GeneratorUtil.TAG_LAZY) != null) {
+ lazy = "lazy=\"" + attr.getTagValue(GeneratorUtil.TAG_LAZY) + "\"";
+ }
+
+/*{<%=prefix%> <<%=collType%> name="<%=getName(attr)%>" node="<%=getName(attr)%>" embed-xml="true" <%=lazy%>>
+<%=prefix%> <key column="OWNER"/>
+}*/
+ if (needsIndex) {
+/*{<%=prefix%> <list-index/>
+}*/
+ }
+/*{<%=prefix%> <element type="<%=getType(attr)%>" column="<%=GeneratorUtil.getDBName(attr)%>" node="id"/>
+<%=prefix%> </<%=collType%>>
+}*/
+ }
+
+ protected void generateHibernateManyToOne(Writer output, ObjectModelAttribute attr, String prefix) throws IOException {
+ generateHibernateManyToOne(output, attr, false, prefix);
+ }
+
+ protected void generateHibernateManyToOne(Writer output, ObjectModelAttribute attr, boolean isUnique, String prefix) throws IOException {
+/*{<%=prefix%> <many-to-one name="<%=getName(attr)%>" class="<%=getType(attr)%>" column="<%=GeneratorUtil.getDBName(attr)%>"}*/
+ if (attr.isComposite() || attr.hasAssociationClass()) {
+/*{ cascade="delete"}*/
+ }
+ // Pour le test suivant, on verifie d'abord que l'attribut a un reverse.
+ // S'il n'en a pas, cela signifie qu'il ne s'agit pas d'un entite
+ // (au sens stereotype entity), donc a donc pas besoin de faire un access=field.
+ if (attr.getReverseAttribute() != null && hasUnidirectionalRelationOnAbstractType(attr.getReverseAttribute(), model)) {
+/*{ access="field"}*/
+ }
+ if (isUnique) {
+/*{ unique="true"}*/
+ }
+/*{ node="<%=getName(attr)%>/@topiaId" embed-xml="false"}*/
+
+ // vérifier si le tag lazy est defini par defaut dans le fichier de proprietes
+ if (attr.getTagValue("lazy") != null){
+/*{ lazy="<%=attr.getTagValue("lazy")%>"}*/
+ }
+ String notNull = attr.getTagValue(GeneratorUtil.TAG_NOT_NULL);
+ if (notNull != null) {
+/*{ not-null="<%=notNull.trim()%>"}*/
+ }
+/*{/>
+}*/
+ }
+
+ protected void generateHibernateManyToMany(Writer output, ObjectModelAttribute attr, String prefix) throws IOException {
+ // On ne met le inverse="true" uniquement pour un seul coté de la relation.
+ // Dans le cas contraire, les modifications dans la relation ne seront
+ // pas sauvegardées. Ceci n'est vrai que si les deux coté sont navigable
+ boolean isInverse = attr.isNavigable() && attr.getReverseAttribute().isNavigable();
+ //isInverse |= !Util.isFirstAttribute(attr);
+ //isInverse = false; // 20070117 poussin: pour du many, jamais de inverse
+ isInverse &= Util.isFirstAttribute(attr);
+
+ boolean needsIndex = attr.isIndexed();
+ String cascade = "";
+ if (attr.isComposite() || attr.hasAssociationClass()) {
+ cascade += "cascade=\"delete,delete-orphan\"";
+ }
+ cascade += "";
+
+ String lazy = "lazy=\"";
+ if (attr.getTagValue("lazy") != null){
+ lazy += attr.getTagValue("lazy");
+ }
+ else {
+ lazy += "true";
+ }
+ lazy += "\"";
+ String collType = GeneratorUtil.getNMultiplicityHibernateType(attr);
+
+/*{<%=prefix%> <<%=collType%> name="<%=getName(attr)%>" table="<%=GeneratorUtil.getManyToManyTableName(attr)%>" <%=(isInverse?"inverse=\"true\" ":"")%> <%=lazy%> <%=cascade%> node="<%=getName(attr)%>" embed-xml="true">
+<%=prefix%> <key column="<%=GeneratorUtil.getReverseDBName(attr)%>"/>
+}*/
+ if (needsIndex) {
+/*{<%=prefix%> <list-index column="<%=GeneratorUtil.getReverseDBName(attr)%>_idx"/>
+}*/
+ }
+/*{<%=prefix%> <many-to-many class="<%=getType(attr)%>" column="<%=GeneratorUtil.getDBName(attr)%>" node="topiaId"/>
+<%=prefix%> </<%=collType%>>
+}*/
+ }
+
+} //EntityHibernateMappingGenerator
Deleted: topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java 2009-01-05 08:40:44 UTC (rev 1284)
+++ topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java 2009-01-07 08:35:25 UTC (rev 1287)
@@ -1,601 +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>. ##%*/
-
-/*******************************************************************************
- * GeneratorUtil.java
- *
- * Created: 13 déc. 2005
- *
- * @author Arnaud Thimel <thimel(a)codelutin.com>
- *
- * @version $Revision$
- *
- * Mise a jour: $Date$ par : $Author$
- */
-
-package org.codelutin.topia.generator;
-
-import org.apache.commons.lang.StringUtils;
-import org.codelutin.generator.Generator;
-import org.codelutin.generator.Util;
-import org.codelutin.generator.models.Model;
-import org.codelutin.generator.models.object.ObjectModel;
-import org.codelutin.generator.models.object.ObjectModelAttribute;
-import org.codelutin.generator.models.object.ObjectModelClass;
-import org.codelutin.generator.models.object.ObjectModelElement;
-import org.codelutin.generator.models.object.ObjectModelInterface;
-import org.codelutin.generator.models.object.ObjectModelOperation;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-/** Classe regroupant divers méthodes utiles pour la génération des entités */
-public class GeneratorUtil extends Util {
-
- /** Stéréotype pour les interfaces devant être générées sous forme de facades */
- public final static String STEREOTYPE_FACADE = "facade";
-
- /** Stéréotype pour les objets devant être générées sous forme d'entités */
- public static final String STEREOTYPE_ENTITY = "entity";
-
- /** Stéréotype pour les objets devant être générées sous forme de DTO */
- public static final String STEREOTYPE_DTO = "dto";
-
- /**
- * Stéréotype pour les interfaces devant être générées sous forme de
- * services
- */
- public static final String STEREOTYPE_SERVICE = "service";
-
- /** Stéréotype pour les interfaces devant être générées sous forme de DAO */
- public static final String STEREOTYPE_DAO = "dao";
-
- /** Stéréotype pour les attributs à indexer en base */
- public static final String STEREOTYPE_INDEXED = "indexed";
-
- /** Stéréotype pour les collections avec unicité */
- public static final String STEREOTYPE_UNIQUE = "unique";
-
- /** Stéréotype pour les attributs étant des clés primaires */
- public static final String STEREOTYPE_PRIMARYKAY = "primaryKey";
-
- /** Tag pour le type de persistence */
- public static final String TAG_PERSISTENCE_TYPE = "persistenceType";
-
- /** Tag pour le nom du champ / entité en BD */
- public static final String TAG_DB_NAME = "dbName";
-
- /** Tag pour le nom du schema en BD */
- public static final String TAG_SCHEMA_NAME = "dbSchema";
-
- /** Tag pour la taille du champ en BD */
- public static final String TAG_LENGTH = "length";
-
- /** Tag pour ajouter une annotation à un champ */
- public static final String TAG_ANNOTATION = "annotation";
-
- /** Tag pour ajouter specifier le copyright d'un fichier */
- public static final String TAG_COPYRIGHT = "copyright";
-
- /** Tag pour specfier le type d'acces a un champ */
- public static final String TAG_ACCESS = "access";
-
- /** Tag pour specfier si on doit générer i18n */
- public static final String TAG_I18N_PREFIX = "i18n";
-
- /** Type de persistence Hibernate */
- public static final String PERSISTENCE_TYPE_HIBERNATE = "hibernate";
-
- /** Type de persistence LDAP */
- public static final String PERSISTENCE_TYPE_LDAP = "ldap";
-
- /** Type de persistence par défaut (si aucun précisé) */
- public static final String PERSISTENCE_TYPE_DEFAULT = PERSISTENCE_TYPE_HIBERNATE;
-
- /** Propriété des générateurs indiquant le package par défaut */
- public static final String PROPERTY_DEFAULT_PACKAGE = "defaultPackage";
-
- /** Le package par défaut si aucun n'est spécifié */
- public static final String DEFAULT_PACKAGE = "org.codelutin.malo";
-
- /**
- * Renvoie le package par défaut pour le générateur donné
- *
- * @param generator le générateur donné
- * @return le package par défaut du générator donné
- */
- public static String getDefaultPackage(Generator generator) {
- String packageName = generator.getProperty(PROPERTY_DEFAULT_PACKAGE);
- if (packageName == null || "".equals(packageName)) {
- packageName = DEFAULT_PACKAGE;
- }
- return packageName;
- }
-
- /**
- * Indique si l'élément spécifié dispose de documentation
- *
- * @param element l'élément à tester
- * @return true s'il y a documentation, false sinon
- */
- public static boolean hasDocumentation(ObjectModelElement element) {
- return notEmpty(element.getDocumentation());
- }
-
- /**
- * Indique si la chaine de caratère n'est pas vide (null ou "")
- *
- * @param s la chaine de caractères à tester
- * @return true si <code>s</code> n'est pas vide
- */
- public static boolean notEmpty(String s) {
- return (s != null && !"".equals(s));
- }
-
- /**
- * Renvoie l'interface DAO associée à la classe passée en paramètre
- *
- * @param clazz la classe à tester
- * @param model le modele utilisé
- * @return l'interface trouvée ou null sinon
- */
- public static ObjectModelInterface getDAOInterface(ObjectModelClass clazz,
- ObjectModel model) {
- for (Object o : model.getInterfaces()) {
- ObjectModelInterface daoInterface = (ObjectModelInterface) o;
- if (daoInterface.getName().equals(clazz.getName() + "DAO")) {
- if (daoInterface.hasStereotype(STEREOTYPE_DAO)) {
- return daoInterface;
- }
- }
- }
- return null;
- }
-
- /**
- * Renvoie le type de persistence pour l'élément donné. Si aucun n'est
- * trouvé, le type par défaut est utilisé
- *
- * @param element l'élément à tester
- * @return le type de persitence pour l'élément donné.
- */
- public static String getPersistenceType(ObjectModelElement element) {
- String tag = element.getTagValue(TAG_PERSISTENCE_TYPE);
- if (tag == null) {
- tag = PERSISTENCE_TYPE_DEFAULT;
- }
- return tag;
- }
-
- public static String getReverseDBName(ObjectModelAttribute attr) {
- if (attr.getReverseAttribute() != null) {
- return getDBName(attr.getReverseAttribute());
- } else {
- return getDBName(attr) + "_id";
- }
- }
-
- /**
- * Renvoie le nom BD de l'élement passé en paramètre. Elle se base sur le
- * tag associé si il existe, sinon sur le nom de l'élément
- *
- * @param element l'élément à tester
- * @return le nom de table
- */
- public static String getDBName(ObjectModelElement element) {
- if (element == null) {
- return null;
- }
- if (notEmpty(element.getTagValue(TAG_DB_NAME))) {
- return element.getTagValue(TAG_DB_NAME);
- }
- return toLowerCaseFirstLetter(element.getName());
- }
-
- /**
- * Cherche et renvoie le schema a utiliser sur cet element, sinon sur le model.
- *
- * @param element l'élément à tester
- * @param model le modele utilisé
- * @return le nom du schema ou null
- */
- public static String getSchemaName(ObjectModelElement element,
- ObjectModel model) {
- return findTagValue(TAG_SCHEMA_NAME, element, model);
- }
-
- /**
- * Cherche et renvoie le prefixe i18n à utiliser sur cet element, sinon sur le model.
- *
- * @param element l'élément à tester
- * @param model le modele utilisé
- * @return le prefix i18n ou <code>null</code> si non spécifié
- */
- public static String getI18nPrefix(ObjectModelElement element,
- ObjectModel model) {
- return findTagValue(TAG_I18N_PREFIX, element, model);
- }
-
- /**
- * Cherches et renvoie le copyright a utiliser sur le model.
- *
- * @param model le modele utilisé
- * @return le texte du copyright ou null
- */
- public static String getCopyright(Model model) {
- return findTagValue(TAG_COPYRIGHT, null, model);
- }
-
- /**
- * Cherches et renvoie la valeur du tagvalue indique sur cet element,
- * sinon sur le model.
- *
- * @param tagName le nom du tag
- * @param element l'élément à tester
- * @param model le modele utilisé
- * @return la valeur du tagValue ou null
- */
- public static String findTagValue(String tagName,
- ObjectModelElement element, Model model) {
- if (element == null) {
- if (model != null) {
- if (notEmpty(model.getTagValue(tagName))) {
- return model.getTagValue(tagName);
- }
- }
- return null;
- }
- if (notEmpty(element.getTagValue(tagName))) {
- return element.getTagValue(tagName);
- }
- //On va chercher sur l'element declarant
- return findTagValue(tagName, element.getDeclaringElement(), model);
- }
-
- public static <Type extends ObjectModelElement> Collection<Type> getElementsWithStereotype(
- Collection<Type> elements, String... stereotypes) {
- Collection<Type> result = new ArrayList<Type>();
- for (Type element : elements) {
- if (hasStereotypes(element, stereotypes)) {
- result.add(element);
- }
- }
- return result;
- }
-
- public static boolean hasStereotypes(ObjectModelElement element,
- String... stereotypes) {
- for (String stereotype : stereotypes) {
- if (!element.hasStereotype(stereotype)) {
- return false;
- }
- }
- return true;
- }
-
- public static String getPrimaryKeyAttributesListDeclaration(
- ObjectModelClass clazz, boolean includeName) {
- String attributes = "";
- for (ObjectModelAttribute attr : getElementsWithStereotype(clazz
- .getAttributes(), STEREOTYPE_PRIMARYKAY)) {
- attributes += attr.getType();
- if (includeName) {
- attributes += " " + attr.getName();
- }
- attributes += ", ";
- }
- if (attributes.length() > 0) {
- attributes = attributes.substring(0, attributes.length() - 2);
- }
- return attributes;
- }
-
- public static String capitalize(String s) {
- return StringUtils.capitalize(s);
- }
-
- public static boolean isAssociationClassDoublon(ObjectModelAttribute attr) {
- return (attr.getReverseAttribute() != null)
- && (attr.getDeclaringElement().equals(attr
- .getReverseAttribute().getDeclaringElement()))
- && (!Util.isFirstAttribute(attr));
- }
-
- /**
- * Renvoie le nom de l'attribut de classe d'association en fonction des cas:
- * Si l'attribut porte le même nom que le type (extrémité inverse de
- * l'association), on lui ajoute le nom de la classe d'association
- *
- * @param attr l'attribut a traiter
- * @return le nom de l'attribut de classe d'association
- */
- public static String getAssocAttrName(ObjectModelAttribute attr) {
- String typeName = attr.getType().substring(
- attr.getType().lastIndexOf(".") + 1);
- String result = attr.getName();
- if (attr.getName().equalsIgnoreCase(typeName)) {
- result += GeneratorUtil.capitalize(attr.getAssociationClass()
- .getName());
- }
- return result;
- }
-
- public static String getDOType(ObjectModelElement elem, ObjectModel model) {
- String type = elem.getName();
- if (elem instanceof ObjectModelAttribute) {
- type = ((ObjectModelAttribute) elem).getType();
- }
- if (elem instanceof ObjectModelClass) {
- type = ((ObjectModelClass) elem).getQualifiedName();
- }
- return getDOType(type, model);
- }
-
- public static String getDOType(String type, ObjectModel model) {
- if (!model.hasClass(type)) {
- return type;
- }
- ObjectModelClass clazz = model.getClass(type);
- if (clazz.hasStereotype(STEREOTYPE_ENTITY)) {
- if (shouldBeAbstract(clazz)) {
- type += "Abstract";
- } else {
- type += "Impl";
- }
- }
- return type;
- }
-
- private static Set<String> numberTypes = new HashSet<String>();
-
- static {
- numberTypes.add("byte");
- numberTypes.add("java.lang.Byte");
- numberTypes.add("short");
- numberTypes.add("java.lang.Short");
- numberTypes.add("int");
- numberTypes.add("java.lang.Integer");
- numberTypes.add("long");
- numberTypes.add("java.lang.Long");
- numberTypes.add("float");
- numberTypes.add("java.lang.Float");
- numberTypes.add("double");
- numberTypes.add("java.lang.Double");
- }
-
- public static boolean isNumericType(ObjectModelAttribute attr) {
- return numberTypes.contains(attr.getType());
- }
-
- private static Set<String> textTypes = new HashSet<String>();
-
- static {
- textTypes.add("char");
- textTypes.add("java.lang.Char");
- textTypes.add("java.lang.String");
- }
-
- public static boolean isTextType(ObjectModelAttribute attr) {
- return textTypes.contains(attr.getType());
- }
-
- public static boolean isDateType(ObjectModelAttribute attr) {
- return "java.util.Date".equals(attr.getType());
- }
-
- public static boolean isBooleanType(ObjectModelAttribute attr) {
- return ("boolean".equals(attr.getType()) || "java.lang.Boolean"
- .equals(attr.getType()));
- }
-
- /**
- * Indique si la classe specifiee n'a aucune ou que des methodes abstraites
- *
- * @param clazz l'instance de ObjectModelClass
- * @return true si la classe n'a que des operations abstraite ou aucune
- * operation
- */
- public static boolean hasNothingOrAbstractMethods(ObjectModelClass clazz) {
- boolean result = true;
- Iterator operations = clazz.getOperations().iterator();
- while (result && operations.hasNext()) {
- ObjectModelOperation op = (ObjectModelOperation) operations.next();
- result = op.isAbstract();
- }
- return result;
- }
-
- /**
- * Indique si la classe specifiee devrait etre abstraite
- *
- * @param clazz l'instance de ObjectModelClass
- * @return true dans ce cas, false sinon
- */
- public static boolean shouldBeAbstract(ObjectModelClass clazz) {
- return clazz != null
- && (clazz.isAbstract() && hasNothingOrAbstractMethods(clazz));
- }
-
- /**
- * <p>
- * Cette méthode permet de détecter si
- * - l'attribut représente une relation 1-n
- * - cette relation est unidirectionnelle
- * - le type de l'attribut représente un entité
- * - cette entité a des sous-classes dans le modèle
- * <p/>
- * Ce cas correspond à une incompatibilité d'Hibernate qui nous oblige a
- * adopter un comportement particulier.
- * </p>
- *
- * @param attr l'attribut a tester
- * @param model le model
- * @return true si et seulement si il s'agit bien de ce type de relation
- */
- public static boolean hasUnidirectionalRelationOnAbstractType(
- ObjectModelAttribute attr, ObjectModel model) {
- ObjectModelAttribute reverse = attr.getReverseAttribute();
- //relation 1-n
- if (reverse != null && isNMultiplicity(attr)
- && !isNMultiplicity(reverse)) {
- //Pas de navigabilité
- if (!reverse.isNavigable()) {
- //Il s'agit d'une entity
- ObjectModelClass clazz = model.getClass(attr.getType());
- if (clazz != null && clazz.hasStereotype(STEREOTYPE_ENTITY)) {
- //Cette classe a des sous-classes dans le modèle
- for (ObjectModelClass subClass : model.getClasses()) {
- if (subClass.getSuperclasses().contains(clazz)) {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
-
- /**
- * Renvoie le nom unique de table pour une relation ManyToMany en fonction
- * de l'attribut <code>attr</code>
- * <p/>
- * Plusieurs cas de figure:
- * <li>
- *
- * @param attr l'attribut servant de base au calcul du nom
- * @return le nom de la table
- */
- public static String getManyToManyTableName(ObjectModelAttribute attr) {
- String result;
-
- if (attr.hasAssociationClass()) {
- result = GeneratorUtil.getDBName(attr.getAssociationClass());
- } else {
- String name = attr.getName();
- String revers = attr.getReverseAttributeName();
-
- if (name.compareToIgnoreCase(revers) < 0) {
- result = name + "_" + revers;
- } else {
- result = revers + "_" + name;
- }
- }
- // String result;
- // if (!Util.isFirstAttribute(attr)) {
- // result = attr.getDeclaringElement().getName() + "_" + attr.getReverseAttribute().getDeclaringElement().getName();
- // } else {
- // result = attr.getReverseAttribute().getDeclaringElement().getName() + "_" + attr.getDeclaringElement().getName();
- // }
- return result.toLowerCase();
- }
-
- /**
- * Renvoie le type d'interface à utiliser en fonction de l'attribut
- *
- * @param attr l'attribut a traiter
- * @return String
- */
- public static String getNMultiplicityInterfaceType(ObjectModelAttribute attr) {
- if (attr.hasStereotype(STEREOTYPE_UNIQUE)) {
- return Set.class.getName();
- } else if (attr.isIndexed() || attr.isOrdered()) {
- return List.class.getName();
- }
- return Collection.class.getName();
- }
-
- /**
- * Renvoie le type d'objet (instance) à utiliser en fonction de l'attribut
- *
- * @param attr l'attribut a traiter
- * @return String
- */
- public static String getNMultiplicityObjectType(ObjectModelAttribute attr) {
- if (attr.hasStereotype(STEREOTYPE_UNIQUE)) {
- return HashSet.class.getName();
- } else if (attr.isIndexed() || attr.isOrdered()) {
- //On considère qu'on ne sait pas traiter vraiment l'attribut "ordered"
- // puisqu'on va conserver l'ordre d'insertion, et non un ordre en
- // fonction d'un élément donné. Donc on renvoi une ArrayList
- return ArrayList.class.getName();
- }
- LinkedList.class.getName();
- return ArrayList.class.getName();
- }
-
- /**
- * Renvoie le type d'interface à utiliser en fonction de l'attribut
- *
- * @param attr l'attribut a traiter
- * @return String
- */
- public static String getNMultiplicityHibernateType(ObjectModelAttribute attr) {
- if (attr.hasStereotype(STEREOTYPE_UNIQUE)) {
- return "set";
- } else if (attr.isIndexed()) {
- return "list";
- }
- //attr.isOrdered() - On génère le ordered en bag
- return "bag";
- }
-
- /**
- * Obtain the list of entities classes with the possibility to sort the result.
- *
- * @param model the current model to scan
- * @param sort flag to allow sort the result
- * @return the list of filtred classes by their stereotype
- */
- public static List<ObjectModelClass> getEntityClasses(ObjectModel model,
- boolean sort) {
- return getClassesByStereotype(STEREOTYPE_ENTITY, model, sort);
- }
-
- /**
- * Obtain the list of classes for a given stereotype with the possibility to sort the result.
- *
- * @param stereotype filter stereotype
- * @param model the current model to scan
- * @param sort flag to allow sort the result
- * @return the list of filtred classes by their stereotype
- */
- public static List<ObjectModelClass> getClassesByStereotype(
- String stereotype, ObjectModel model, boolean sort) {
- List<ObjectModelClass> classes = new ArrayList<ObjectModelClass>();
- for (ObjectModelClass clazz : model.getClasses()) {
- if (clazz.hasStereotype(stereotype)) {
- classes.add(clazz);
- }
- }
- if (sort && !classes.isEmpty()) {
- java.util.Collections.sort(classes,
- new java.util.Comparator<ObjectModelClass>() {
- public int compare(ObjectModelClass o1,
- ObjectModelClass o2) {
- return o1.getQualifiedName().compareTo(
- o2.getQualifiedName());
- }
- });
- }
- return classes;
- }
-} // GeneratorUtil
Copied: topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java (from rev 1285, topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java)
===================================================================
--- topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java (rev 0)
+++ topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java 2009-01-07 08:35:25 UTC (rev 1287)
@@ -0,0 +1,635 @@
+/* *##% 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>. ##%*/
+
+/*******************************************************************************
+ * GeneratorUtil.java
+ *
+ * Created: 13 déc. 2005
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ *
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$ par : $Author$
+ */
+
+package org.codelutin.topia.generator;
+
+import org.apache.commons.lang.StringUtils;
+import org.codelutin.generator.Generator;
+import org.codelutin.generator.Util;
+import org.codelutin.generator.models.Model;
+import org.codelutin.generator.models.object.ObjectModel;
+import org.codelutin.generator.models.object.ObjectModelAttribute;
+import org.codelutin.generator.models.object.ObjectModelClass;
+import org.codelutin.generator.models.object.ObjectModelElement;
+import org.codelutin.generator.models.object.ObjectModelInterface;
+import org.codelutin.generator.models.object.ObjectModelOperation;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+/** Classe regroupant divers méthodes utiles pour la génération des entités */
+public class GeneratorUtil extends Util {
+
+ /** Stéréotype pour les interfaces devant être générées sous forme de facades */
+ public final static String STEREOTYPE_FACADE = "facade";
+
+ /** Stéréotype pour les objets devant être générées sous forme d'entités */
+ public static final String STEREOTYPE_ENTITY = "entity";
+
+ /** Stéréotype pour les objets devant être générées sous forme de DTO */
+ public static final String STEREOTYPE_DTO = "dto";
+
+ /**
+ * Stéréotype pour les interfaces devant être générées sous forme de
+ * services
+ */
+ public static final String STEREOTYPE_SERVICE = "service";
+
+ /** Stéréotype pour les interfaces devant être générées sous forme de DAO */
+ public static final String STEREOTYPE_DAO = "dao";
+
+ /** Stéréotype pour les attributs à indexer en base */
+ public static final String STEREOTYPE_INDEXED = "indexed";
+
+ /** Stéréotype pour les collections avec unicité */
+ public static final String STEREOTYPE_UNIQUE = "unique";
+
+ /** Stéréotype pour les attributs étant des clés primaires */
+ public static final String STEREOTYPE_PRIMARYKAY = "primaryKey";
+
+ /** Tag pour le type de persistence */
+ public static final String TAG_PERSISTENCE_TYPE = "persistenceType";
+
+ /** Tag pour le nom du champ / entité en BD */
+ public static final String TAG_DB_NAME = "dbName";
+
+ /** Tag pour le nom du schema en BD */
+ public static final String TAG_SCHEMA_NAME = "dbSchema";
+
+ /** Tag pour la taille du champ en BD */
+ public static final String TAG_LENGTH = "length";
+
+ /** Tag pour ajouter une annotation à un champ */
+ public static final String TAG_ANNOTATION = "annotation";
+
+ /** Tag pour ajouter specifier le copyright d'un fichier */
+ public static final String TAG_COPYRIGHT = "copyright";
+
+ /** Tag pour specfier le type d'acces a un champ */
+ public static final String TAG_ACCESS = "access";
+
+ /** Tag pour specfier si on doit générer i18n */
+ public static final String TAG_I18N_PREFIX = "i18n";
+
+ /** Tag pour ajouter un attribut dans une clef métier */
+ public static final String TAG_NATURAL_ID = "naturalId";
+
+ /** Tag pour spécifier la caractèrelazy d'une association multiple */
+ public static final String TAG_LAZY = "lazy";
+
+ /** Tag pour spécifier la caractère fetch d'une association multiple */
+ public static final String TAG_FETCH = "fetch";
+
+ /** Tag pour spécifier la caractère order-by d'une association multiple */
+ public static final String TAG_ORDER_BY = "orderBy";
+
+ /** Tag pour spécifier la caractère not-null d'un attribut */
+ public static final String TAG_NOT_NULL = "notNull";
+
+ /** Type de persistence Hibernate */
+ public static final String PERSISTENCE_TYPE_HIBERNATE = "hibernate";
+
+ /** Type de persistence LDAP */
+ public static final String PERSISTENCE_TYPE_LDAP = "ldap";
+
+ /** Type de persistence par défaut (si aucun précisé) */
+ public static final String PERSISTENCE_TYPE_DEFAULT = PERSISTENCE_TYPE_HIBERNATE;
+
+ /** Propriété des générateurs indiquant le package par défaut */
+ public static final String PROPERTY_DEFAULT_PACKAGE = "defaultPackage";
+
+ /** Le package par défaut si aucun n'est spécifié */
+ public static final String DEFAULT_PACKAGE = "org.codelutin.malo";
+
+ /**
+ * Renvoie le package par défaut pour le générateur donné
+ *
+ * @param generator le générateur donné
+ * @return le package par défaut du générator donné
+ */
+ public static String getDefaultPackage(Generator generator) {
+ String packageName = generator.getProperty(PROPERTY_DEFAULT_PACKAGE);
+ if (packageName == null || "".equals(packageName)) {
+ packageName = DEFAULT_PACKAGE;
+ }
+ return packageName;
+ }
+
+ /**
+ * Indique si l'élément spécifié dispose de documentation
+ *
+ * @param element l'élément à tester
+ * @return true s'il y a documentation, false sinon
+ */
+ public static boolean hasDocumentation(ObjectModelElement element) {
+ return notEmpty(element.getDocumentation());
+ }
+
+ /**
+ * Indique si la chaine de caratère n'est pas vide (null ou "")
+ *
+ * @param s la chaine de caractères à tester
+ * @return true si <code>s</code> n'est pas vide
+ */
+ public static boolean notEmpty(String s) {
+ return (s != null && !"".equals(s));
+ }
+
+ /**
+ * Renvoie l'interface DAO associée à la classe passée en paramètre
+ *
+ * @param clazz la classe à tester
+ * @param model le modele utilisé
+ * @return l'interface trouvée ou null sinon
+ */
+ public static ObjectModelInterface getDAOInterface(ObjectModelClass clazz,
+ ObjectModel model) {
+ for (Object o : model.getInterfaces()) {
+ ObjectModelInterface daoInterface = (ObjectModelInterface) o;
+ if (daoInterface.getName().equals(clazz.getName() + "DAO")) {
+ if (daoInterface.hasStereotype(STEREOTYPE_DAO)) {
+ return daoInterface;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Renvoie le type de persistence pour l'élément donné. Si aucun n'est
+ * trouvé, le type par défaut est utilisé
+ *
+ * @param element l'élément à tester
+ * @return le type de persitence pour l'élément donné.
+ */
+ public static String getPersistenceType(ObjectModelElement element) {
+ String tag = element.getTagValue(TAG_PERSISTENCE_TYPE);
+ if (tag == null) {
+ tag = PERSISTENCE_TYPE_DEFAULT;
+ }
+ return tag;
+ }
+
+ public static String getReverseDBName(ObjectModelAttribute attr) {
+ if (attr.getReverseAttribute() != null) {
+ return getDBName(attr.getReverseAttribute());
+ } else {
+ return getDBName(attr) + "_id";
+ }
+ }
+
+ /**
+ * Renvoie le nom BD de l'élement passé en paramètre. Elle se base sur le
+ * tag associé si il existe, sinon sur le nom de l'élément
+ *
+ * @param element l'élément à tester
+ * @return le nom de table
+ */
+ public static String getDBName(ObjectModelElement element) {
+ if (element == null) {
+ return null;
+ }
+ if (notEmpty(element.getTagValue(TAG_DB_NAME))) {
+ return element.getTagValue(TAG_DB_NAME);
+ }
+ return toLowerCaseFirstLetter(element.getName());
+ }
+
+ /**
+ * Cherche et renvoie le schema a utiliser sur cet element, sinon sur le model.
+ *
+ * @param element l'élément à tester
+ * @param model le modele utilisé
+ * @return le nom du schema ou null
+ */
+ public static String getSchemaName(ObjectModelElement element,
+ ObjectModel model) {
+ return findTagValue(TAG_SCHEMA_NAME, element, model);
+ }
+
+ /**
+ * Cherche et renvoie le prefixe i18n à utiliser sur cet element, sinon sur le model.
+ *
+ * @param element l'élément à tester
+ * @param model le modele utilisé
+ * @return le prefix i18n ou <code>null</code> si non spécifié
+ */
+ public static String getI18nPrefix(ObjectModelElement element,
+ ObjectModel model) {
+ return findTagValue(TAG_I18N_PREFIX, element, model);
+ }
+
+ /**
+ * Cherche et renvoie la liste des attributs constituant la clef metier d'une classe.
+ *
+ * @param clazz la classe à tester
+ * @return la liste des attributs de la clef métier ou null si pas de clef métier.
+ */
+ public static List<String> getNaturalId(ObjectModelClass clazz) {
+
+ String value = clazz.getTagValue(TAG_NATURAL_ID);
+ if (value == null || value.trim().isEmpty()) {
+ return java.util.Collections.emptyList();
+ }
+ List<String> result = new ArrayList<String>();
+ for (String attribute : value.split(",")) {
+ result.add(attribute.trim());
+ }
+ return result;
+ }
+
+ /**
+ * Cherches et renvoie le copyright a utiliser sur le model.
+ *
+ * @param model le modele utilisé
+ * @return le texte du copyright ou null
+ */
+ public static String getCopyright(Model model) {
+ return findTagValue(TAG_COPYRIGHT, null, model);
+ }
+
+ /**
+ * Cherches et renvoie la valeur du tagvalue indique sur cet element,
+ * sinon sur le model.
+ *
+ * @param tagName le nom du tag
+ * @param element l'élément à tester
+ * @param model le modele utilisé
+ * @return la valeur du tagValue ou null
+ */
+ public static String findTagValue(String tagName,
+ ObjectModelElement element, Model model) {
+ if (element == null) {
+ if (model != null) {
+ if (notEmpty(model.getTagValue(tagName))) {
+ return model.getTagValue(tagName);
+ }
+ }
+ return null;
+ }
+ if (notEmpty(element.getTagValue(tagName))) {
+ return element.getTagValue(tagName);
+ }
+ //On va chercher sur l'element declarant
+ return findTagValue(tagName, element.getDeclaringElement(), model);
+ }
+
+ public static <Type extends ObjectModelElement> Collection<Type> getElementsWithStereotype(
+ Collection<Type> elements, String... stereotypes) {
+ Collection<Type> result = new ArrayList<Type>();
+ for (Type element : elements) {
+ if (hasStereotypes(element, stereotypes)) {
+ result.add(element);
+ }
+ }
+ return result;
+ }
+
+ public static boolean hasStereotypes(ObjectModelElement element,
+ String... stereotypes) {
+ for (String stereotype : stereotypes) {
+ if (!element.hasStereotype(stereotype)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static String getPrimaryKeyAttributesListDeclaration(
+ ObjectModelClass clazz, boolean includeName) {
+ String attributes = "";
+ for (ObjectModelAttribute attr : getElementsWithStereotype(clazz
+ .getAttributes(), STEREOTYPE_PRIMARYKAY)) {
+ attributes += attr.getType();
+ if (includeName) {
+ attributes += " " + attr.getName();
+ }
+ attributes += ", ";
+ }
+ if (attributes.length() > 0) {
+ attributes = attributes.substring(0, attributes.length() - 2);
+ }
+ return attributes;
+ }
+
+ public static String capitalize(String s) {
+ return StringUtils.capitalize(s);
+ }
+
+ public static boolean isAssociationClassDoublon(ObjectModelAttribute attr) {
+ return (attr.getReverseAttribute() != null)
+ && (attr.getDeclaringElement().equals(attr
+ .getReverseAttribute().getDeclaringElement()))
+ && (!Util.isFirstAttribute(attr));
+ }
+
+ /**
+ * Renvoie le nom de l'attribut de classe d'association en fonction des cas:
+ * Si l'attribut porte le même nom que le type (extrémité inverse de
+ * l'association), on lui ajoute le nom de la classe d'association
+ *
+ * @param attr l'attribut a traiter
+ * @return le nom de l'attribut de classe d'association
+ */
+ public static String getAssocAttrName(ObjectModelAttribute attr) {
+ String typeName = attr.getType().substring(
+ attr.getType().lastIndexOf(".") + 1);
+ String result = attr.getName();
+ if (attr.getName().equalsIgnoreCase(typeName)) {
+ result += GeneratorUtil.capitalize(attr.getAssociationClass()
+ .getName());
+ }
+ return result;
+ }
+
+ public static String getDOType(ObjectModelElement elem, ObjectModel model) {
+ String type = elem.getName();
+ if (elem instanceof ObjectModelAttribute) {
+ type = ((ObjectModelAttribute) elem).getType();
+ }
+ if (elem instanceof ObjectModelClass) {
+ type = ((ObjectModelClass) elem).getQualifiedName();
+ }
+ return getDOType(type, model);
+ }
+
+ public static String getDOType(String type, ObjectModel model) {
+ if (!model.hasClass(type)) {
+ return type;
+ }
+ ObjectModelClass clazz = model.getClass(type);
+ if (clazz.hasStereotype(STEREOTYPE_ENTITY)) {
+ if (shouldBeAbstract(clazz)) {
+ type += "Abstract";
+ } else {
+ type += "Impl";
+ }
+ }
+ return type;
+ }
+
+ private static Set<String> numberTypes = new HashSet<String>();
+
+ static {
+ numberTypes.add("byte");
+ numberTypes.add("java.lang.Byte");
+ numberTypes.add("short");
+ numberTypes.add("java.lang.Short");
+ numberTypes.add("int");
+ numberTypes.add("java.lang.Integer");
+ numberTypes.add("long");
+ numberTypes.add("java.lang.Long");
+ numberTypes.add("float");
+ numberTypes.add("java.lang.Float");
+ numberTypes.add("double");
+ numberTypes.add("java.lang.Double");
+ }
+
+ public static boolean isNumericType(ObjectModelAttribute attr) {
+ return numberTypes.contains(attr.getType());
+ }
+
+ private static Set<String> textTypes = new HashSet<String>();
+
+ static {
+ textTypes.add("char");
+ textTypes.add("java.lang.Char");
+ textTypes.add("java.lang.String");
+ }
+
+ public static boolean isTextType(ObjectModelAttribute attr) {
+ return textTypes.contains(attr.getType());
+ }
+
+ public static boolean isDateType(ObjectModelAttribute attr) {
+ return "java.util.Date".equals(attr.getType());
+ }
+
+ public static boolean isBooleanType(ObjectModelAttribute attr) {
+ return ("boolean".equals(attr.getType()) || "java.lang.Boolean"
+ .equals(attr.getType()));
+ }
+
+ /**
+ * Indique si la classe specifiee n'a aucune ou que des methodes abstraites
+ *
+ * @param clazz l'instance de ObjectModelClass
+ * @return true si la classe n'a que des operations abstraite ou aucune
+ * operation
+ */
+ public static boolean hasNothingOrAbstractMethods(ObjectModelClass clazz) {
+ boolean result = true;
+ Iterator operations = clazz.getOperations().iterator();
+ while (result && operations.hasNext()) {
+ ObjectModelOperation op = (ObjectModelOperation) operations.next();
+ result = op.isAbstract();
+ }
+ return result;
+ }
+
+ /**
+ * Indique si la classe specifiee devrait etre abstraite
+ *
+ * @param clazz l'instance de ObjectModelClass
+ * @return true dans ce cas, false sinon
+ */
+ public static boolean shouldBeAbstract(ObjectModelClass clazz) {
+ return clazz != null
+ && (clazz.isAbstract() && hasNothingOrAbstractMethods(clazz));
+ }
+
+ /**
+ * <p>
+ * Cette méthode permet de détecter si
+ * - l'attribut représente une relation 1-n
+ * - cette relation est unidirectionnelle
+ * - le type de l'attribut représente un entité
+ * - cette entité a des sous-classes dans le modèle
+ * <p/>
+ * Ce cas correspond à une incompatibilité d'Hibernate qui nous oblige a
+ * adopter un comportement particulier.
+ * </p>
+ *
+ * @param attr l'attribut a tester
+ * @param model le model
+ * @return true si et seulement si il s'agit bien de ce type de relation
+ */
+ public static boolean hasUnidirectionalRelationOnAbstractType(
+ ObjectModelAttribute attr, ObjectModel model) {
+ ObjectModelAttribute reverse = attr.getReverseAttribute();
+ //relation 1-n
+ if (reverse != null && isNMultiplicity(attr)
+ && !isNMultiplicity(reverse)) {
+ //Pas de navigabilité
+ if (!reverse.isNavigable()) {
+ //Il s'agit d'une entity
+ ObjectModelClass clazz = model.getClass(attr.getType());
+ if (clazz != null && clazz.hasStereotype(STEREOTYPE_ENTITY)) {
+ //Cette classe a des sous-classes dans le modèle
+ for (ObjectModelClass subClass : model.getClasses()) {
+ if (subClass.getSuperclasses().contains(clazz)) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Renvoie le nom unique de table pour une relation ManyToMany en fonction
+ * de l'attribut <code>attr</code>
+ * <p/>
+ * Plusieurs cas de figure:
+ * <li>
+ *
+ * @param attr l'attribut servant de base au calcul du nom
+ * @return le nom de la table
+ */
+ public static String getManyToManyTableName(ObjectModelAttribute attr) {
+ String result;
+
+ if (attr.hasAssociationClass()) {
+ result = GeneratorUtil.getDBName(attr.getAssociationClass());
+ } else {
+ String name = attr.getName();
+ String revers = attr.getReverseAttributeName();
+
+ if (name.compareToIgnoreCase(revers) < 0) {
+ result = name + "_" + revers;
+ } else {
+ result = revers + "_" + name;
+ }
+ }
+ // String result;
+ // if (!Util.isFirstAttribute(attr)) {
+ // result = attr.getDeclaringElement().getName() + "_" + attr.getReverseAttribute().getDeclaringElement().getName();
+ // } else {
+ // result = attr.getReverseAttribute().getDeclaringElement().getName() + "_" + attr.getDeclaringElement().getName();
+ // }
+ return result.toLowerCase();
+ }
+
+ /**
+ * Renvoie le type d'interface à utiliser en fonction de l'attribut
+ *
+ * @param attr l'attribut a traiter
+ * @return String
+ */
+ public static String getNMultiplicityInterfaceType(ObjectModelAttribute attr) {
+ if (attr.hasStereotype(STEREOTYPE_UNIQUE)) {
+ return Set.class.getName();
+ } else if (attr.isIndexed() || attr.isOrdered()) {
+ return List.class.getName();
+ }
+ return Collection.class.getName();
+ }
+
+ /**
+ * Renvoie le type d'objet (instance) à utiliser en fonction de l'attribut
+ *
+ * @param attr l'attribut a traiter
+ * @return String
+ */
+ public static String getNMultiplicityObjectType(ObjectModelAttribute attr) {
+ if (attr.hasStereotype(STEREOTYPE_UNIQUE)) {
+ return HashSet.class.getName();
+ } else if (attr.isIndexed() || attr.isOrdered()) {
+ //On considère qu'on ne sait pas traiter vraiment l'attribut "ordered"
+ // puisqu'on va conserver l'ordre d'insertion, et non un ordre en
+ // fonction d'un élément donné. Donc on renvoi une ArrayList
+ return ArrayList.class.getName();
+ }
+ LinkedList.class.getName();
+ return ArrayList.class.getName();
+ }
+
+ /**
+ * Renvoie le type d'interface à utiliser en fonction de l'attribut
+ *
+ * @param attr l'attribut a traiter
+ * @return String
+ */
+ public static String getNMultiplicityHibernateType(ObjectModelAttribute attr) {
+ if (attr.hasStereotype(STEREOTYPE_UNIQUE)) {
+ return "set";
+ } else if (attr.isIndexed()) {
+ return "list";
+ }
+ //attr.isOrdered() - On génère le ordered en bag
+ return "bag";
+ }
+
+ /**
+ * Obtain the list of entities classes with the possibility to sort the result.
+ *
+ * @param model the current model to scan
+ * @param sort flag to allow sort the result
+ * @return the list of filtred classes by their stereotype
+ */
+ public static List<ObjectModelClass> getEntityClasses(ObjectModel model,
+ boolean sort) {
+ return getClassesByStereotype(STEREOTYPE_ENTITY, model, sort);
+ }
+
+ /**
+ * Obtain the list of classes for a given stereotype with the possibility to sort the result.
+ *
+ * @param stereotype filter stereotype
+ * @param model the current model to scan
+ * @param sort flag to allow sort the result
+ * @return the list of filtred classes by their stereotype
+ */
+ public static List<ObjectModelClass> getClassesByStereotype(
+ String stereotype, ObjectModel model, boolean sort) {
+ List<ObjectModelClass> classes = new ArrayList<ObjectModelClass>();
+ for (ObjectModelClass clazz : model.getClasses()) {
+ if (clazz.hasStereotype(stereotype)) {
+ classes.add(clazz);
+ }
+ }
+ if (sort && !classes.isEmpty()) {
+ java.util.Collections.sort(classes,
+ new java.util.Comparator<ObjectModelClass>() {
+ public int compare(ObjectModelClass o1,
+ ObjectModelClass o2) {
+ return o1.getQualifiedName().compareTo(
+ o2.getQualifiedName());
+ }
+ });
+ }
+ return classes;
+ }
+} // GeneratorUtil
Deleted: topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/BeanPropertyLoador.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/BeanPropertyLoador.java 2009-01-05 08:40:44 UTC (rev 1284)
+++ topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/BeanPropertyLoador.java 2009-01-07 08:35:25 UTC (rev 1287)
@@ -1,154 +0,0 @@
-package org.codelutin.topia.persistence.util;
-
-import org.apache.commons.beanutils.MethodUtils;
-
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Arrays;
-import java.util.List;
-
-/** @author chemit */
-public class BeanPropertyLoador<E> implements Loador<E> {
-
- public static <E> BeanPropertyLoador<E> newLoador(Class<E> klass, String... properties) {
- return new BeanPropertyLoador<E>(klass, properties);
- }
-
- private static final long serialVersionUID = 1L;
-
- protected static final Integer ZERO = 0;
- protected static final Float ZEROF = 0f;
- protected static final Long ZEROL = 0l;
- protected static final Double ZEROD = 0.;
- protected static final Byte ZEROB = 0;
-
- protected List<String> properties;
- protected transient PropertyDescriptor[] descriptors;
- protected Class<E> klass;
-
- protected BeanPropertyLoador(Class<E> klass, String... properties) {
- this.properties = java.util.Collections.unmodifiableList(Arrays.asList(properties));
- this.klass = klass;
- }
-
- public List<String> getProperties() {
- return properties;
- }
-
- public PropertyDescriptor[] getDescriptors() {
- if (descriptors == null) {
- try {
- descriptors = new PropertyDescriptor[properties.size()];
- for (PropertyDescriptor propertydescriptor : Introspector.getBeanInfo(klass).getPropertyDescriptors()) {
- int index = properties.indexOf(propertydescriptor.getName());
- if (index != -1) {
- descriptors[index] = propertydescriptor;
- }
- }
- } catch (IntrospectionException e) {
- throw new RuntimeException(e);
- }
- }
- return descriptors;
- }
-
- @Override
- public void load(E from, E dst, boolean tech) {
- if (from == null) {
- // reset all fields
- for (PropertyDescriptor descriptor : getDescriptors()) {
- Object read = getNullValue(descriptor.getPropertyType());
- setProperty(dst, descriptor, read);
- }
- } else {
- // set all fields from
- for (PropertyDescriptor descriptor : getDescriptors()) {
- try {
- Object value = descriptor.getReadMethod().invoke(from);
- setProperty(dst, descriptor, value);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- }
- }
- }
-
- protected void setProperty(E dst, PropertyDescriptor descriptor, Object value) {
- try {
- descriptor.getWriteMethod().invoke(dst, value);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- protected static Object getNullValue(Class<?> type) {
- if (type.isPrimitive()) {
- type = MethodUtils.getPrimitiveWrapper(type);
- if (Boolean.class.isAssignableFrom(type)) {
- return Boolean.FALSE;
- }
- if (Integer.class.isAssignableFrom(type)) {
- return ZERO;
- }
- if (Float.class.isAssignableFrom(type)) {
- return ZEROF;
- }
- if (Long.class.isAssignableFrom(type)) {
- return ZEROL;
- }
- if (Double.class.isAssignableFrom(type)) {
- return ZEROD;
- }
- if (Byte.class.isAssignableFrom(type)) {
- return ZEROB;
- }
- }
- return null;
- }
-
- public static boolean isNullValue(Object value) {
- if (value == null) {
- return true;
- }
- Class<?> type = value.getClass();
- if (type.isPrimitive()) {
- type = MethodUtils.getPrimitiveWrapper(type);
- }
- if (Boolean.class.isAssignableFrom(type)) {
- return Boolean.FALSE.equals(value);
- }
- if (Integer.class.isAssignableFrom(type)) {
- return ZERO.equals(value);
- }
- if (Float.class.isAssignableFrom(type)) {
- return ZEROF.equals(value);
- }
- if (Long.class.isAssignableFrom(type)) {
- return ZEROL.equals(value);
- }
- if (Double.class.isAssignableFrom(type)) {
- return ZEROD.equals(value);
- }
- return Byte.class.isAssignableFrom(type) && ZEROB.equals(value);
- }
-
- protected void checkProperties() {
- PropertyDescriptor[] descriptors = getDescriptors();
- for (int i = 0; i < descriptors.length; i++) {
- PropertyDescriptor descriptor = descriptors[i];
- if (descriptor == null) {
- throw new IllegalStateException("could not find descriptor for property " + properties.get(i) + " on " + klass);
- }
- if (descriptor.getReadMethod() == null) {
- throw new IllegalStateException("property " + properties.get(i) + " is not readable on " + klass);
- }
- if (descriptor.getWriteMethod() == null) {
- throw new IllegalStateException("property " + properties.get(i) + " is not writable on " + klass);
- }
- }
- }
-}
Copied: topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/BeanPropertyLoador.java (from rev 1285, topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/BeanPropertyLoador.java)
===================================================================
--- topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/BeanPropertyLoador.java (rev 0)
+++ topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/BeanPropertyLoador.java 2009-01-07 08:35:25 UTC (rev 1287)
@@ -0,0 +1,178 @@
+package org.codelutin.topia.persistence.util;
+
+import org.apache.commons.beanutils.MethodUtils;
+
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/** @author chemit */
+public class BeanPropertyLoador<E> implements Loador<E> {
+
+ public static <E> BeanPropertyLoador<E> newLoador(Class<E> klass, String... properties) {
+ return new BeanPropertyLoador<E>(klass, properties);
+ }
+
+ private static final long serialVersionUID = 1L;
+
+ protected static final Integer ZERO = 0;
+ protected static final Float ZEROF = 0f;
+ protected static final Long ZEROL = 0l;
+ protected static final Double ZEROD = 0.;
+ protected static final Byte ZEROB = 0;
+
+ protected List<String> properties;
+ protected transient PropertyDescriptor[] descriptors;
+ protected Class<E> klass;
+
+ protected BeanPropertyLoador(Class<E> klass, String... properties) {
+ this.properties = java.util.Collections.unmodifiableList(Arrays.asList(properties));
+ this.klass = klass;
+ }
+
+ public List<String> getProperties() {
+ return properties;
+ }
+
+ public PropertyDescriptor[] getDescriptors() {
+ if (descriptors == null) {
+ try {
+ descriptors = new PropertyDescriptor[properties.size()];
+ for (PropertyDescriptor propertydescriptor : Introspector.getBeanInfo(klass).getPropertyDescriptors()) {
+ int index = properties.indexOf(propertydescriptor.getName());
+ if (index != -1) {
+ descriptors[index] = propertydescriptor;
+ }
+ }
+ } catch (IntrospectionException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return descriptors;
+ }
+
+ public Map<String, Object> obtainProgperties(E from) {
+ if (from == null) {
+ return java.util.Collections.emptyMap();
+ }
+ Map<String, Object> result = new HashMap<String, Object>();
+ for (PropertyDescriptor descriptor : getDescriptors()) {
+ Object read = null;
+ try {
+ read = descriptor.getReadMethod().invoke(from);
+ if (read != null) {
+ result.put(descriptor.getName(), read);
+ }
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+ return result;
+ }
+
+ @Override
+ public void load(E from, E dst, boolean tech) {
+ if (from == null) {
+ // reset all fields
+ for (PropertyDescriptor descriptor : getDescriptors()) {
+ Object read = getNullValue(descriptor.getPropertyType());
+ setProperty(dst, descriptor, read);
+ }
+ } else {
+ // set all fields from
+ for (PropertyDescriptor descriptor : getDescriptors()) {
+ try {
+ Object value = descriptor.getReadMethod().invoke(from);
+ setProperty(dst, descriptor, value);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ }
+
+ protected void setProperty(E dst, PropertyDescriptor descriptor, Object value) {
+ try {
+ descriptor.getWriteMethod().invoke(dst, value);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected static Object getNullValue(Class<?> type) {
+ if (type.isPrimitive()) {
+ type = MethodUtils.getPrimitiveWrapper(type);
+ if (Boolean.class.isAssignableFrom(type)) {
+ return Boolean.FALSE;
+ }
+ if (Integer.class.isAssignableFrom(type)) {
+ return ZERO;
+ }
+ if (Float.class.isAssignableFrom(type)) {
+ return ZEROF;
+ }
+ if (Long.class.isAssignableFrom(type)) {
+ return ZEROL;
+ }
+ if (Double.class.isAssignableFrom(type)) {
+ return ZEROD;
+ }
+ if (Byte.class.isAssignableFrom(type)) {
+ return ZEROB;
+ }
+ }
+ return null;
+ }
+
+ public static boolean isNullValue(Object value) {
+ if (value == null) {
+ return true;
+ }
+ Class<?> type = value.getClass();
+ if (type.isPrimitive()) {
+ type = MethodUtils.getPrimitiveWrapper(type);
+ }
+ if (Boolean.class.isAssignableFrom(type)) {
+ return Boolean.FALSE.equals(value);
+ }
+ if (Integer.class.isAssignableFrom(type)) {
+ return ZERO.equals(value);
+ }
+ if (Float.class.isAssignableFrom(type)) {
+ return ZEROF.equals(value);
+ }
+ if (Long.class.isAssignableFrom(type)) {
+ return ZEROL.equals(value);
+ }
+ if (Double.class.isAssignableFrom(type)) {
+ return ZEROD.equals(value);
+ }
+ return Byte.class.isAssignableFrom(type) && ZEROB.equals(value);
+ }
+
+ protected void checkProperties() {
+ PropertyDescriptor[] descriptors = getDescriptors();
+ for (int i = 0; i < descriptors.length; i++) {
+ PropertyDescriptor descriptor = descriptors[i];
+ if (descriptor == null) {
+ throw new IllegalStateException("could not find descriptor for property " + properties.get(i) + " on " + klass);
+ }
+ if (descriptor.getReadMethod() == null) {
+ throw new IllegalStateException("property " + properties.get(i) + " is not readable on " + klass);
+ }
+ if (descriptor.getWriteMethod() == null) {
+ throw new IllegalStateException("property " + properties.get(i) + " is not writable on " + klass);
+ }
+ }
+ }
+}
Deleted: topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Loador.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Loador.java 2009-01-05 08:40:44 UTC (rev 1284)
+++ topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Loador.java 2009-01-07 08:35:25 UTC (rev 1287)
@@ -1,7 +0,0 @@
-package org.codelutin.topia.persistence.util;
-
-/** @author chemit */
-public interface Loador<E> extends java.io.Serializable {
-
- void load(E from, E dst, boolean tech);
-}
Copied: topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Loador.java (from rev 1285, topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Loador.java)
===================================================================
--- topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Loador.java (rev 0)
+++ topia/tags/2.1.2/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Loador.java 2009-01-07 08:35:25 UTC (rev 1287)
@@ -0,0 +1,11 @@
+package org.codelutin.topia.persistence.util;
+
+import java.util.Map;
+
+/** @author chemit */
+public interface Loador<E> extends java.io.Serializable {
+
+ Map<String, Object> obtainProgperties(E from);
+
+ void load(E from, E dst, boolean tech);
+}
Deleted: topia/tags/2.1.2/topia-soa/pom.xml
===================================================================
--- topia/trunk/topia-soa/pom.xml 2009-01-05 08:40:44 UTC (rev 1284)
+++ topia/tags/2.1.2/topia-soa/pom.xml 2009-01-07 08:35:25 UTC (rev 1287)
@@ -1,123 +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>topia</artifactId>
- <version>2.1.2-SNAPSHOT</version>
- </parent>
-
- <groupId>org.codelutin.topia</groupId>
- <artifactId>topia-soa</artifactId>
-
- <dependencies>
-
- <dependency>
- <groupId>org.codelutin.topia</groupId>
- <artifactId>topia-persistence</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>lutinutil</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>lutingenerator</artifactId>
- </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>
- <scope>test</scope>
- </dependency>
-
- <!-- Dependencies for class generation -->
- <dependency>
- <groupId>asm</groupId>
- <artifactId>asm</artifactId>
- <version>1.5.3</version>
- <scope>compile</scope>
- </dependency>
- </dependencies>
-
- <!-- ************************************************************* -->
- <!-- *** Project Information ************************************* -->
- <!-- ************************************************************* -->
-
- <name>ToPIA - SOA</name>
- <description>Service Oriented Architecture module</description>
-
- <!-- ************************************************************* -->
- <!-- *** Build Settings ****************************************** -->
- <!-- ************************************************************* -->
-
- <packaging>jar</packaging>
-
- <build>
- <defaultGoal>install</defaultGoal>
- <plugins>
-
- <plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-processor-plugin</artifactId>
- </plugin>
-
- </plugins>
- </build>
-
- <!-- ************************************************************* -->
- <!-- *** Build Environment ************************************** -->
- <!-- ************************************************************* -->
- <scm>
- <connection>${maven.scm.connection.child}</connection>
- <developerConnection>${maven.scm.developerConnection.child}</developerConnection>
- <url>${maven.scm.url.child}</url>
- </scm>
-
-</project>
Copied: topia/tags/2.1.2/topia-soa/pom.xml (from rev 1286, topia/trunk/topia-soa/pom.xml)
===================================================================
--- topia/tags/2.1.2/topia-soa/pom.xml (rev 0)
+++ topia/tags/2.1.2/topia-soa/pom.xml 2009-01-07 08:35:25 UTC (rev 1287)
@@ -0,0 +1,123 @@
+<?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>topia</artifactId>
+ <version>2.1.2</version>
+ </parent>
+
+ <groupId>org.codelutin.topia</groupId>
+ <artifactId>topia-soa</artifactId>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.codelutin.topia</groupId>
+ <artifactId>topia-persistence</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutinutil</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutingenerator</artifactId>
+ </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>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- Dependencies for class generation -->
+ <dependency>
+ <groupId>asm</groupId>
+ <artifactId>asm</artifactId>
+ <version>1.5.3</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
+
+ <name>ToPIA - SOA</name>
+ <description>Service Oriented Architecture module</description>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
+
+ <packaging>jar</packaging>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-processor-plugin</artifactId>
+ </plugin>
+
+ </plugins>
+ </build>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Environment ************************************** -->
+ <!-- ************************************************************* -->
+ <scm>
+ <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.1.2/topia-soa</connection>
+ <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.1.2/topia-soa</developerConnection>
+ <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia/tags/2.1.…</url>
+ </scm>
+
+</project>
Deleted: topia/tags/2.1.2/topia-ui/pom.xml
===================================================================
--- topia/trunk/topia-ui/pom.xml 2009-01-05 08:40:44 UTC (rev 1284)
+++ topia/tags/2.1.2/topia-ui/pom.xml 2009-01-07 08:35:25 UTC (rev 1287)
@@ -1,74 +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>topia</artifactId>
- <version>2.1.2-SNAPSHOT</version>
- </parent>
-
- <groupId>org.codelutin.topia</groupId>
- <artifactId>topia-ui</artifactId>
-
- <dependencies>
-
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>lutinutil</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>lutingenerator</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tapestry</groupId>
- <artifactId>tapestry-core</artifactId>
- <version>5.0.7</version>
- <scope>compile</scope>
- </dependency>
-
- </dependencies>
-
- <!-- ************************************************************* -->
- <!-- *** Project Information ************************************* -->
- <!-- ************************************************************* -->
-
- <name>ToPIA - UI</name>
- <description>User interface module</description>
-
- <!-- ************************************************************* -->
- <!-- *** Build Settings ****************************************** -->
- <!-- ************************************************************* -->
-
- <packaging>jar</packaging>
-
- <build>
- <defaultGoal>install</defaultGoal>
- <plugins>
-
- <plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-processor-plugin</artifactId>
- </plugin>
-
- </plugins>
- </build>
-
- <!-- ************************************************************* -->
- <!-- *** Build Environment ************************************** -->
- <!-- ************************************************************* -->
- <scm>
- <connection>${maven.scm.connection.child}</connection>
- <developerConnection>${maven.scm.developerConnection.child}</developerConnection>
- <url>${maven.scm.url.child}</url>
- </scm>
-
-</project>
Copied: topia/tags/2.1.2/topia-ui/pom.xml (from rev 1286, topia/trunk/topia-ui/pom.xml)
===================================================================
--- topia/tags/2.1.2/topia-ui/pom.xml (rev 0)
+++ topia/tags/2.1.2/topia-ui/pom.xml 2009-01-07 08:35:25 UTC (rev 1287)
@@ -0,0 +1,74 @@
+<?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>topia</artifactId>
+ <version>2.1.2</version>
+ </parent>
+
+ <groupId>org.codelutin.topia</groupId>
+ <artifactId>topia-ui</artifactId>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutinutil</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutingenerator</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tapestry</groupId>
+ <artifactId>tapestry-core</artifactId>
+ <version>5.0.7</version>
+ <scope>compile</scope>
+ </dependency>
+
+ </dependencies>
+
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
+
+ <name>ToPIA - UI</name>
+ <description>User interface module</description>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
+
+ <packaging>jar</packaging>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-processor-plugin</artifactId>
+ </plugin>
+
+ </plugins>
+ </build>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Environment ************************************** -->
+ <!-- ************************************************************* -->
+ <scm>
+ <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.1.2/topia-ui</connection>
+ <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.1.2/topia-ui</developerConnection>
+ <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia/tags/2.1.…</url>
+ </scm>
+
+</project>
1
0
r1286 - in topia/trunk: . topia-persistence topia-soa topia-ui
by tchemit@users.labs.libre-entreprise.org 07 Jan '09
by tchemit@users.labs.libre-entreprise.org 07 Jan '09
07 Jan '09
Author: tchemit
Date: 2009-01-07 08:35:21 +0000 (Wed, 07 Jan 2009)
New Revision: 1286
Modified:
topia/trunk/pom.xml
topia/trunk/topia-persistence/pom.xml
topia/trunk/topia-soa/pom.xml
topia/trunk/topia-ui/pom.xml
Log:
[maven-release-plugin] prepare release 2.1.2
Modified: topia/trunk/pom.xml
===================================================================
--- topia/trunk/pom.xml 2009-01-07 08:11:19 UTC (rev 1285)
+++ topia/trunk/pom.xml 2009-01-07 08:35:21 UTC (rev 1286)
@@ -13,7 +13,7 @@
</parent>
<artifactId>topia</artifactId>
- <version>2.1.2-SNAPSHOT</version>
+ <version>2.1.2</version>
<modules>
<module>topia-persistence</module>
@@ -119,9 +119,9 @@
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
<scm>
- <connection>${maven.scm.connection}</connection>
- <developerConnection>${maven.scm.developerConnection}</developerConnection>
- <url>${maven.scm.url}</url>
+ <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.1.2</connection>
+ <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.1.2</developerConnection>
+ <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia/tags/2.1.…</url>
</scm>
</project>
Modified: topia/trunk/topia-persistence/pom.xml
===================================================================
--- topia/trunk/topia-persistence/pom.xml 2009-01-07 08:11:19 UTC (rev 1285)
+++ topia/trunk/topia-persistence/pom.xml 2009-01-07 08:35:21 UTC (rev 1286)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.codelutin</groupId>
<artifactId>topia</artifactId>
- <version>2.1.2-SNAPSHOT</version>
+ <version>2.1.2</version>
</parent>
<groupId>org.codelutin.topia</groupId>
@@ -99,9 +99,9 @@
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
<scm>
- <connection>${maven.scm.connection.child}</connection>
- <developerConnection>${maven.scm.developerConnection.child}</developerConnection>
- <url>${maven.scm.url.child}</url>
+ <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.1.2/topia-persistence</connection>
+ <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.1.2/topia-persistence</developerConnection>
+ <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia/tags/2.1.…</url>
</scm>
Modified: topia/trunk/topia-soa/pom.xml
===================================================================
--- topia/trunk/topia-soa/pom.xml 2009-01-07 08:11:19 UTC (rev 1285)
+++ topia/trunk/topia-soa/pom.xml 2009-01-07 08:35:21 UTC (rev 1286)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.codelutin</groupId>
<artifactId>topia</artifactId>
- <version>2.1.2-SNAPSHOT</version>
+ <version>2.1.2</version>
</parent>
<groupId>org.codelutin.topia</groupId>
@@ -115,9 +115,9 @@
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
<scm>
- <connection>${maven.scm.connection.child}</connection>
- <developerConnection>${maven.scm.developerConnection.child}</developerConnection>
- <url>${maven.scm.url.child}</url>
+ <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.1.2/topia-soa</connection>
+ <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.1.2/topia-soa</developerConnection>
+ <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia/tags/2.1.…</url>
</scm>
</project>
Modified: topia/trunk/topia-ui/pom.xml
===================================================================
--- topia/trunk/topia-ui/pom.xml 2009-01-07 08:11:19 UTC (rev 1285)
+++ topia/trunk/topia-ui/pom.xml 2009-01-07 08:35:21 UTC (rev 1286)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.codelutin</groupId>
<artifactId>topia</artifactId>
- <version>2.1.2-SNAPSHOT</version>
+ <version>2.1.2</version>
</parent>
<groupId>org.codelutin.topia</groupId>
@@ -66,9 +66,9 @@
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
<scm>
- <connection>${maven.scm.connection.child}</connection>
- <developerConnection>${maven.scm.developerConnection.child}</developerConnection>
- <url>${maven.scm.url.child}</url>
+ <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.1.2/topia-ui</connection>
+ <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.1.2/topia-ui</developerConnection>
+ <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia/tags/2.1.…</url>
</scm>
</project>
1
0
r1285 - in topia/trunk/topia-persistence: . src/main/java/org/codelutin/topia/generator src/main/java/org/codelutin/topia/persistence/util
by tchemit@users.labs.libre-entreprise.org 07 Jan '09
by tchemit@users.labs.libre-entreprise.org 07 Jan '09
07 Jan '09
Author: tchemit
Date: 2009-01-07 08:11:19 +0000 (Wed, 07 Jan 2009)
New Revision: 1285
Modified:
topia/trunk/topia-persistence/changelog.txt
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/BeanPropertyLoador.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Loador.java
Log:
- am?\195?\169lioration du g?\195?\169n?\195?\169rateur de mapping hibernate :
- g?\195?\169n?\195?\169ration des clefs metier dans le mapping hibernate via la tag value naturalId
- mise en constantes des tagValues utiliser dans le g?\195?\169n?\195?\169ratuer du mapping hibernate
- ajout du tagValue notNull pour le mapping hibernate
- changement du tagValue order-by en orderBy car sinon on r?\195?\169cup?\195?\168re order au lieu de order-by
- ajout de la m?\195?\169thode obtainProgperties sur la classe Loador pour recuperer la map des propri?\195?\169t?\195?\169s ?\195?\160 binder (car pour les clef m?\195?\169tiers on doit les ajouter ?\195?\160 la cr?\195?\169ation sinon hibernate pleure...)
Modified: topia/trunk/topia-persistence/changelog.txt
===================================================================
--- topia/trunk/topia-persistence/changelog.txt 2009-01-05 08:40:44 UTC (rev 1284)
+++ topia/trunk/topia-persistence/changelog.txt 2009-01-07 08:11:19 UTC (rev 1285)
@@ -1,4 +1,11 @@
2.1.2 ??? 200901??
+* 20090106 [chemit] - amélioration du générateur de mapping hibernate :
+ - génération des clefs metier dans le mapping hibernate via la tag value naturalId
+ - mise en constantes des tagValues utiliser dans le génératuer du mapping hibernate
+ - ajout du tagValue notNull pour le mapping hibernate
+ - changement du tagValue order-by en orderBy car sinon on récupère order au lieu de order-by
+ - ajout de la méthode obtainProgperties sur la classe Loador pour recuperer la map des propriétés à binder
+ (car pour les clef métiers on doit les ajouter à la création sinon hibernate pleure...)
* 20090104 [chemit] - utilisation foreach dans les générateurs
- ajout de méthode getXXXByTopiaId pour les attributs à multiplicité dans les entités (interface et abstract)
- fix generic dans les méthodes générées
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java 2009-01-05 08:40:44 UTC (rev 1284)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java 2009-01-07 08:11:19 UTC (rev 1285)
@@ -31,12 +31,6 @@
package org.codelutin.topia.generator;
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.HashMap;
-import java.util.Map;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codelutin.generator.Generator;
@@ -45,13 +39,20 @@
import org.codelutin.generator.models.object.ObjectModelAssociationClass;
import org.codelutin.generator.models.object.ObjectModelAttribute;
import org.codelutin.generator.models.object.ObjectModelClass;
-
-import static org.codelutin.topia.generator.GeneratorUtil.notEmpty;
+import static org.codelutin.topia.generator.GeneratorUtil.PERSISTENCE_TYPE_HIBERNATE;
import static org.codelutin.topia.generator.GeneratorUtil.STEREOTYPE_ENTITY;
import static org.codelutin.topia.generator.GeneratorUtil.TAG_ACCESS;
-import static org.codelutin.topia.generator.GeneratorUtil.PERSISTENCE_TYPE_HIBERNATE;
import static org.codelutin.topia.generator.GeneratorUtil.hasUnidirectionalRelationOnAbstractType;
+import static org.codelutin.topia.generator.GeneratorUtil.notEmpty;
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
/**
* FIXME mettre les attributs node="..." sur tous les attributs
* @author poussin
@@ -92,7 +93,7 @@
<hibernate-mapping default-access="field" auto-import="true" package="<%=clazz.getPackageName()%>">
}*/
boolean haveSuper = clazz.getSuperclasses().size() > 0;
-
+ List<ObjectModelAttribute> noneNaturalAttributes = new ArrayList<ObjectModelAttribute >();
if (haveSuper) {
ObjectModelClass superClass = clazz.getSuperclasses().iterator().next();
String superClassname = superClass.getQualifiedName();
@@ -111,7 +112,7 @@
/*{proxy="<%=clazz.getQualifiedName()%>" }*/
/*{>
<!--key column="topiaId"/-->
-}*/
+}*/
} else {
/*{ <class }*/
/*{name="<%=GeneratorUtil.getDOType(clazz, model)%>" }*/
@@ -126,13 +127,51 @@
/*{proxy="<%=clazz.getQualifiedName()%>" }*/
/*{>
<id name="topiaId" type="string" length="255" node="@topiaId"/>
- <version name="topiaVersion" type="long" node="@topiaVersion"/>
+}*/
+ List<String> attributes = GeneratorUtil.getNaturalId(clazz);
+ if (log.isDebugEnabled()) {
+ log.debug("natural-id for class "+clazz.getName()+" : "+attributes);
+ }
+
+ if (attributes.isEmpty()) {
+ // pas de clef metiers sur la classe
+ noneNaturalAttributes.addAll(clazz.getAttributes());
+ } else {
+ // une clef métier sur la classe a ete detectee
+ List<ObjectModelAttribute> naturalAttributes = new ArrayList<ObjectModelAttribute >(attributes.size());
+ for (ObjectModelAttribute attr : clazz.getAttributes()) {
+ if (attributes.contains(attr.getName())) {
+ naturalAttributes.add(attr);
+ } else {
+ noneNaturalAttributes.add(attr);
+ }
+ }
+/*{ <natural-id>
+}*/
+ generateAttributes(output, clazz, naturalAttributes," ");
+/*{ </natural-id>
+}*/
+ }
+
+/*{ <version name="topiaVersion" type="long" node="@topiaVersion"/>
<property name="topiaCreateDate" type="date" node="@topiaCreateDate"/>
}*/
}
+ generateAttributes(output, clazz, noneNaturalAttributes,"");
- for (Object o : clazz.getAttributes()) {
- ObjectModelAttribute attr = (ObjectModelAttribute) o;
+ if (haveSuper) {
+/*{ </union-subclass>
+}*/
+ } else {
+/*{ </class>
+}*/
+ }
+/*{</hibernate-mapping>
+}*/
+ }
+
+ protected void generateAttributes(Writer output, ObjectModelClass clazz, List<ObjectModelAttribute> attributes,String prefix) throws IOException {
+ for (ObjectModelAttribute attr : attributes) {
ObjectModelAttribute reverse = attr.getReverseAttribute();
// pour les asso quoi qu'il arrive il faut les lier des 2 cotes
@@ -144,22 +183,22 @@
if (!Util.isNMultiplicity(attr)) {
if (attr.getClassifier() != null && attr.getClassifier().hasStereotype(STEREOTYPE_ENTITY)) {
if (Util.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) {
- generateHibernateManyToOne(output, attr);
+ generateHibernateManyToOne(output, attr, prefix);
} else {
- generateHibernateOneToOne(output, attr);
+ generateHibernateOneToOne(output, attr, prefix);
}
} else {
- generateHibernateProperty(output, attr);
+ generateHibernateProperty(output, attr, prefix);
}
} else {
if (attr.getClassifier() != null && attr.getClassifier().hasStereotype(STEREOTYPE_ENTITY)) {
if (Util.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) {
- generateHibernateManyToMany(output, attr);
+ generateHibernateManyToMany(output, attr, prefix);
} else {
- generateHibernateOneToMany(output, attr);
+ generateHibernateOneToMany(output, attr, prefix);
}
} else {
- generateHibernateMany(output, attr);
+ generateHibernateMany(output, attr, prefix);
}
}
}
@@ -168,18 +207,20 @@
//Attributs pour les classes d'association
if (clazz instanceof ObjectModelAssociationClass) {
ObjectModelAssociationClass assoc = (ObjectModelAssociationClass)clazz;
- for (Object o : assoc.getParticipantsAttributes()) {
- ObjectModelAttribute attr = (ObjectModelAttribute) o;
+ for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) {
if (attr != null) {
// Note(poussin) pour moi quoi qu'il arrive sur la classe d'association il faut
-// un many-to-one, sinon on a des problemes.
+// un many-to-one, sinon on a des problemes.
// if ((!attr.getReverseAttribute().isNavigable()) || !Util.isNMultiplicity(attr.getReverseAttribute())) {
// / *{ <one-to-one name="<%=getName(attr, true)%>" class="<%=getType(attr, true)%>"<%=(GeneratorUtil.notEmpty(attr.getTagValue(GeneratorUtil.TAG_LENGTH))?(" length=\"" + attr.getTagValue(GeneratorUtil.TAG_LENGTH) + "\""):"")%><%=(attr.isComposite()?" cascade=\"delete\"":"")%>/>
// } */
// } else {
-
-/*{ <many-to-one name="<%=getName(attr, true)%>" class="<%=getType(attr, true)%>" column="<%=GeneratorUtil.getDBName(attr)%>" node="<%=getName(attr, true)%>/@topiaId" embed-xml="false"/>
+ String notNull = attr.getTagValue(GeneratorUtil.TAG_NOT_NULL);
+ if (notNull!=null) {
+ notNull = "not-null=\""+notNull.trim()+"\"";
+ }
+/*{<%=prefix%> <many-to-one name="<%=getName(attr, true)%>" class="<%=getType(attr, true)%>" column="<%=GeneratorUtil.getDBName(attr)%>" node="<%=getName(attr, true)%>/@topiaId" embed-xml="false" <%=notNull%> />
}*/
// }
//Ne sert plus grâce à l'utilisation de la navigabilité
@@ -199,17 +240,7 @@
}
}
- if (haveSuper) {
-/*{ </union-subclass>
-}*/
- } else {
-/*{ </class>
-}*/
- }
-/*{</hibernate-mapping>
-}*/
}
-
protected String getName(ObjectModelAttribute attr) {
return getName(attr, false);
}
@@ -251,11 +282,11 @@
return GeneratorUtil.getDOType(type, model);
}
- protected void generateHibernateProperty(Writer output, ObjectModelAttribute attr) throws IOException {
+ protected void generateHibernateProperty(Writer output, ObjectModelAttribute attr, String prefix) throws IOException {
String type = getType(attr);
if (type.trim().endsWith("[]")) {
type = type.trim().substring(0, type.trim().length()-2);
-/*{ <primitive-array name="<%=getName(attr)%>" table="<%=GeneratorUtil.getDBName(attr.getDeclaringElement()) + "_" + getName(attr)%>" }*/
+/*{<%=prefix%> <primitive-array name="<%=getName(attr)%>" table="<%=GeneratorUtil.getDBName(attr.getDeclaringElement()) + "_" + getName(attr)%>" }*/
String accessField = attr.getTagValue(TAG_ACCESS);
if (notEmpty(accessField)) {
/*{access="<%=accessField%>" }*/
@@ -270,13 +301,13 @@
/*{index="<%=GeneratorUtil.getDBName(attr.getDeclaringElement()) + "_" + getName(attr)%>_idx" }*/
}
/*{>
- <key column="<%=GeneratorUtil.getDBName(attr.getDeclaringElement())%>"/>
- <list-index column="<%=getName(attr)%>_idx"/>
- <element type="<%=type%>"/>
- </primitive-array>
+<%=prefix%> <key column="<%=GeneratorUtil.getDBName(attr.getDeclaringElement())%>"/>
+<%=prefix%> <list-index column="<%=getName(attr)%>_idx"/>
+<%=prefix%> <element type="<%=type%>"/>
+<%=prefix%> </primitive-array>
}*/
} else {
-/*{ <property name="<%=getName(attr)%>" type="<%=type%>" }*/
+/*{<%=prefix%> <property name="<%=getName(attr)%>" type="<%=type%>" }*/
String accessField = attr.getTagValue(TAG_ACCESS);
if (notEmpty(accessField)) {
/*{access="<%=accessField%>" }*/
@@ -286,6 +317,10 @@
if (attr.isIndexed()) {
/*{index="<%=GeneratorUtil.getDBName(attr.getDeclaringElement()) + "_" + getName(attr)%>_idx" }*/
}
+ String notNull = attr.getTagValue(GeneratorUtil.TAG_NOT_NULL);
+ if (notNull != null) {
+/*{ not-null="<%=notNull.trim()%>" }*/
+ }
String[] columnNames = this.columnNamesMap.get(type);
if (columnNames == null || columnNames.length == 0) {
/*{column="<%=GeneratorUtil.getDBName(attr)%>"<%=(GeneratorUtil.notEmpty(attr.getTagValue(GeneratorUtil.TAG_LENGTH))?(" length=\"" + attr.getTagValue(GeneratorUtil.TAG_LENGTH) + "\""):"")%> node="<%=getName(attr)%>"/>
@@ -295,27 +330,27 @@
}*/
for (String columnName : columnNames) {
columnName = columnName.trim();
-/*{ <column name="<%=getName(attr) + "_" + columnName%>"/>
+/*{<%=prefix%> <column name="<%=getName(attr) + "_" + columnName%>"/>
}*/
}
-/*{ </property>
+/*{<%=prefix%> </property>
}*/
}
}
}
- protected void generateHibernateOneToOne(Writer output, ObjectModelAttribute attr) throws IOException {
- generateHibernateManyToOne(output, attr, true);
+ protected void generateHibernateOneToOne(Writer output, ObjectModelAttribute attr, String prefix) throws IOException {
+ generateHibernateManyToOne(output, attr, true, prefix);
// boolean accessField = hasUnidirectionalRelationOnAbstractType(attr.getReverseAttribute(), model);
/// *{ <one-to-one name="<%=getName(attr)%>" class="<%=getType(attr)%>"<%=(GeneratorUtil.notEmpty(attr.getTagValue(GeneratorUtil.TAG_LENGTH))?(" length=\"" + attr.getTagValue(GeneratorUtil.TAG_LENGTH) + "\""):"")%><%=((attr.isComposite() || attr.hasAssociationClass())?" cascade=\"delete\"":"")%><%=((accessField)?" access=\"field\"":"")%> node="<%=getName(attr)%>/@topiaId" embed-xml="false"/>
//} */
}
- protected void generateHibernateOneToMany(Writer output, ObjectModelAttribute attr) throws IOException {
+ protected void generateHibernateOneToMany(Writer output, ObjectModelAttribute attr, String prefix) throws IOException {
boolean needsIndex = attr.isIndexed();
boolean isInverse = attr.getReverseAttribute().isNavigable();
isInverse |= hasUnidirectionalRelationOnAbstractType(attr, model);
- String orderBy = attr.getTagValue("order-by");
+ String orderBy = attr.getTagValue(GeneratorUtil.TAG_ORDER_BY);
if (orderBy == null) {
orderBy = "";
} else {
@@ -328,8 +363,8 @@
}
String lazy = "lazy=\"";
- if (attr.getTagValue("lazy") != null){
- lazy += attr.getTagValue("lazy");
+ if (attr.getTagValue(GeneratorUtil.TAG_LAZY) != null){
+ lazy += attr.getTagValue(GeneratorUtil.TAG_LAZY);
}
else {
lazy += "true";
@@ -337,53 +372,53 @@
lazy += "\"";
String fetch = "";
- if (attr.getTagValue("fetch") != null){
- fetch = "fetch=\"" + attr.getTagValue("fetch") + "\"";
+ if (attr.getTagValue(GeneratorUtil.TAG_FETCH) != null){
+ fetch = "fetch=\"" + attr.getTagValue(GeneratorUtil.TAG_FETCH) + "\"";
}
-
+
String collType = GeneratorUtil.getNMultiplicityHibernateType(attr);
if (!needsIndex) {
-/*{ <<%=collType%> name="<%=getName(attr)%>" <%=orderBy%> <%=((!isInverse)?"":"inverse=\"true\"")%> <%=fetch%> <%=lazy%> <%=cascade%> node="<%=getName(attr)%>" embed-xml="true">
- <key column="<%=GeneratorUtil.getReverseDBName(attr)%>"/>
- <one-to-many class="<%=getType(attr)%>" node="topiaId" embed-xml="false"/>
- </<%=collType%>>
+/*{<%=prefix%> <<%=collType%> name="<%=getName(attr)%>" <%=orderBy%> <%=((!isInverse)?"":"inverse=\"true\"")%> <%=fetch%> <%=lazy%> <%=cascade%> node="<%=getName(attr)%>" embed-xml="true">
+<%=prefix%> <key column="<%=GeneratorUtil.getReverseDBName(attr)%>"/>
+<%=prefix%> <one-to-many class="<%=getType(attr)%>" node="topiaId" embed-xml="false"/>
+<%=prefix%> </<%=collType%>>
}*/
}else {
-/*{ <<%=collType%> name="<%=getName(attr)%>"<%=((!isInverse)?"":" inverse=\"true\"")%> <%=lazy%> <%=cascade%> node="<%=getName(attr)%>" embed-xml="false">
- <key column="<%=GeneratorUtil.getReverseDBName(attr)%>"/>
- <list-index column="<%=GeneratorUtil.getReverseDBName(attr)%>_idx"/>
- <one-to-many class="<%=getType(attr)%>" node="topiaId" embed-xml="false"/>
- </<%=collType%>>
+/*{<%=prefix%> <<%=collType%> name="<%=getName(attr)%>"<%=((!isInverse)?"":" inverse=\"true\"")%> <%=lazy%> <%=cascade%> node="<%=getName(attr)%>" embed-xml="false">
+<%=prefix%> <key column="<%=GeneratorUtil.getReverseDBName(attr)%>"/>
+<%=prefix%> <list-index column="<%=GeneratorUtil.getReverseDBName(attr)%>_idx"/>
+<%=prefix%> <one-to-many class="<%=getType(attr)%>" node="topiaId" embed-xml="false"/>
+<%=prefix%> </<%=collType%>>
}*/
}
}
- protected void generateHibernateMany(Writer output, ObjectModelAttribute attr) throws IOException {
+ protected void generateHibernateMany(Writer output, ObjectModelAttribute attr, String prefix) throws IOException {
boolean needsIndex = attr.isIndexed();
String collType = GeneratorUtil.getNMultiplicityHibernateType(attr);
String lazy = "";
- if (attr.getTagValue("lazy") != null) {
- lazy = "lazy=\"" + attr.getTagValue("lazy") + "\"";
+ if (attr.getTagValue(GeneratorUtil.TAG_LAZY) != null) {
+ lazy = "lazy=\"" + attr.getTagValue(GeneratorUtil.TAG_LAZY) + "\"";
}
-
-/*{ <<%=collType%> name="<%=getName(attr)%>" node="<%=getName(attr)%>" embed-xml="true" <%=lazy%>>
- <key column="OWNER"/>
+
+/*{<%=prefix%> <<%=collType%> name="<%=getName(attr)%>" node="<%=getName(attr)%>" embed-xml="true" <%=lazy%>>
+<%=prefix%> <key column="OWNER"/>
}*/
if (needsIndex) {
-/*{ <list-index/>
+/*{<%=prefix%> <list-index/>
}*/
}
-/*{ <element type="<%=getType(attr)%>" column="<%=GeneratorUtil.getDBName(attr)%>" node="id"/>
- </<%=collType%>>
+/*{<%=prefix%> <element type="<%=getType(attr)%>" column="<%=GeneratorUtil.getDBName(attr)%>" node="id"/>
+<%=prefix%> </<%=collType%>>
}*/
}
- protected void generateHibernateManyToOne(Writer output, ObjectModelAttribute attr) throws IOException {
- generateHibernateManyToOne(output, attr, false);
+ protected void generateHibernateManyToOne(Writer output, ObjectModelAttribute attr, String prefix) throws IOException {
+ generateHibernateManyToOne(output, attr, false, prefix);
}
- protected void generateHibernateManyToOne(Writer output, ObjectModelAttribute attr, boolean isUnique) throws IOException {
-/*{ <many-to-one name="<%=getName(attr)%>" class="<%=getType(attr)%>" column="<%=GeneratorUtil.getDBName(attr)%>"}*/
+ protected void generateHibernateManyToOne(Writer output, ObjectModelAttribute attr, boolean isUnique, String prefix) throws IOException {
+/*{<%=prefix%> <many-to-one name="<%=getName(attr)%>" class="<%=getType(attr)%>" column="<%=GeneratorUtil.getDBName(attr)%>"}*/
if (attr.isComposite() || attr.hasAssociationClass()) {
/*{ cascade="delete"}*/
}
@@ -397,16 +432,20 @@
/*{ unique="true"}*/
}
/*{ node="<%=getName(attr)%>/@topiaId" embed-xml="false"}*/
-
+
// vérifier si le tag lazy est defini par defaut dans le fichier de proprietes
if (attr.getTagValue("lazy") != null){
-/*{ lazy="<%=attr.getTagValue("lazy")%>"}*/
+/*{ lazy="<%=attr.getTagValue("lazy")%>"}*/
}
+ String notNull = attr.getTagValue(GeneratorUtil.TAG_NOT_NULL);
+ if (notNull != null) {
+/*{ not-null="<%=notNull.trim()%>"}*/
+ }
/*{/>
}*/
}
- protected void generateHibernateManyToMany(Writer output, ObjectModelAttribute attr) throws IOException {
+ protected void generateHibernateManyToMany(Writer output, ObjectModelAttribute attr, String prefix) throws IOException {
// On ne met le inverse="true" uniquement pour un seul coté de la relation.
// Dans le cas contraire, les modifications dans la relation ne seront
// pas sauvegardées. Ceci n'est vrai que si les deux coté sont navigable
@@ -414,7 +453,7 @@
//isInverse |= !Util.isFirstAttribute(attr);
//isInverse = false; // 20070117 poussin: pour du many, jamais de inverse
isInverse &= Util.isFirstAttribute(attr);
-
+
boolean needsIndex = attr.isIndexed();
String cascade = "";
if (attr.isComposite() || attr.hasAssociationClass()) {
@@ -432,15 +471,15 @@
lazy += "\"";
String collType = GeneratorUtil.getNMultiplicityHibernateType(attr);
-/*{ <<%=collType%> name="<%=getName(attr)%>" table="<%=GeneratorUtil.getManyToManyTableName(attr)%>" <%=(isInverse?"inverse=\"true\" ":"")%> <%=lazy%> <%=cascade%> node="<%=getName(attr)%>" embed-xml="true">
- <key column="<%=GeneratorUtil.getReverseDBName(attr)%>"/>
+/*{<%=prefix%> <<%=collType%> name="<%=getName(attr)%>" table="<%=GeneratorUtil.getManyToManyTableName(attr)%>" <%=(isInverse?"inverse=\"true\" ":"")%> <%=lazy%> <%=cascade%> node="<%=getName(attr)%>" embed-xml="true">
+<%=prefix%> <key column="<%=GeneratorUtil.getReverseDBName(attr)%>"/>
}*/
if (needsIndex) {
-/*{ <list-index column="<%=GeneratorUtil.getReverseDBName(attr)%>_idx"/>
+/*{<%=prefix%> <list-index column="<%=GeneratorUtil.getReverseDBName(attr)%>_idx"/>
}*/
}
-/*{ <many-to-many class="<%=getType(attr)%>" column="<%=GeneratorUtil.getDBName(attr)%>" node="topiaId"/>
- </<%=collType%>>
+/*{<%=prefix%> <many-to-many class="<%=getType(attr)%>" column="<%=GeneratorUtil.getDBName(attr)%>" node="topiaId"/>
+<%=prefix%> </<%=collType%>>
}*/
}
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java 2009-01-05 08:40:44 UTC (rev 1284)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java 2009-01-07 08:11:19 UTC (rev 1285)
@@ -102,6 +102,21 @@
/** Tag pour specfier si on doit générer i18n */
public static final String TAG_I18N_PREFIX = "i18n";
+ /** Tag pour ajouter un attribut dans une clef métier */
+ public static final String TAG_NATURAL_ID = "naturalId";
+
+ /** Tag pour spécifier la caractèrelazy d'une association multiple */
+ public static final String TAG_LAZY = "lazy";
+
+ /** Tag pour spécifier la caractère fetch d'une association multiple */
+ public static final String TAG_FETCH = "fetch";
+
+ /** Tag pour spécifier la caractère order-by d'une association multiple */
+ public static final String TAG_ORDER_BY = "orderBy";
+
+ /** Tag pour spécifier la caractère not-null d'un attribut */
+ public static final String TAG_NOT_NULL = "notNull";
+
/** Type de persistence Hibernate */
public static final String PERSISTENCE_TYPE_HIBERNATE = "hibernate";
@@ -134,7 +149,7 @@
/**
* Indique si l'élément spécifié dispose de documentation
*
- * @param element l'élément à tester
+ * @param element l'élément à tester
* @return true s'il y a documentation, false sinon
*/
public static boolean hasDocumentation(ObjectModelElement element) {
@@ -159,7 +174,7 @@
* @return l'interface trouvée ou null sinon
*/
public static ObjectModelInterface getDAOInterface(ObjectModelClass clazz,
- ObjectModel model) {
+ ObjectModel model) {
for (Object o : model.getInterfaces()) {
ObjectModelInterface daoInterface = (ObjectModelInterface) o;
if (daoInterface.getName().equals(clazz.getName() + "DAO")) {
@@ -215,11 +230,11 @@
* Cherche et renvoie le schema a utiliser sur cet element, sinon sur le model.
*
* @param element l'élément à tester
- * @param model le modele utilisé
+ * @param model le modele utilisé
* @return le nom du schema ou null
*/
public static String getSchemaName(ObjectModelElement element,
- ObjectModel model) {
+ ObjectModel model) {
return findTagValue(TAG_SCHEMA_NAME, element, model);
}
@@ -227,15 +242,34 @@
* Cherche et renvoie le prefixe i18n à utiliser sur cet element, sinon sur le model.
*
* @param element l'élément à tester
- * @param model le modele utilisé
+ * @param model le modele utilisé
* @return le prefix i18n ou <code>null</code> si non spécifié
*/
public static String getI18nPrefix(ObjectModelElement element,
- ObjectModel model) {
+ ObjectModel model) {
return findTagValue(TAG_I18N_PREFIX, element, model);
}
/**
+ * Cherche et renvoie la liste des attributs constituant la clef metier d'une classe.
+ *
+ * @param clazz la classe à tester
+ * @return la liste des attributs de la clef métier ou null si pas de clef métier.
+ */
+ public static List<String> getNaturalId(ObjectModelClass clazz) {
+
+ String value = clazz.getTagValue(TAG_NATURAL_ID);
+ if (value == null || value.trim().isEmpty()) {
+ return java.util.Collections.emptyList();
+ }
+ List<String> result = new ArrayList<String>();
+ for (String attribute : value.split(",")) {
+ result.add(attribute.trim());
+ }
+ return result;
+ }
+
+ /**
* Cherches et renvoie le copyright a utiliser sur le model.
*
* @param model le modele utilisé
@@ -251,11 +285,11 @@
*
* @param tagName le nom du tag
* @param element l'élément à tester
- * @param model le modele utilisé
+ * @param model le modele utilisé
* @return la valeur du tagValue ou null
*/
public static String findTagValue(String tagName,
- ObjectModelElement element, Model model) {
+ ObjectModelElement element, Model model) {
if (element == null) {
if (model != null) {
if (notEmpty(model.getTagValue(tagName))) {
@@ -283,7 +317,7 @@
}
public static boolean hasStereotypes(ObjectModelElement element,
- String... stereotypes) {
+ String... stereotypes) {
for (String stereotype : stereotypes) {
if (!element.hasStereotype(stereotype)) {
return false;
@@ -316,7 +350,7 @@
public static boolean isAssociationClassDoublon(ObjectModelAttribute attr) {
return (attr.getReverseAttribute() != null)
&& (attr.getDeclaringElement().equals(attr
- .getReverseAttribute().getDeclaringElement()))
+ .getReverseAttribute().getDeclaringElement()))
&& (!Util.isFirstAttribute(attr));
}
@@ -566,7 +600,7 @@
* @return the list of filtred classes by their stereotype
*/
public static List<ObjectModelClass> getEntityClasses(ObjectModel model,
- boolean sort) {
+ boolean sort) {
return getClassesByStereotype(STEREOTYPE_ENTITY, model, sort);
}
@@ -590,7 +624,7 @@
java.util.Collections.sort(classes,
new java.util.Comparator<ObjectModelClass>() {
public int compare(ObjectModelClass o1,
- ObjectModelClass o2) {
+ ObjectModelClass o2) {
return o1.getQualifiedName().compareTo(
o2.getQualifiedName());
}
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/BeanPropertyLoador.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/BeanPropertyLoador.java 2009-01-05 08:40:44 UTC (rev 1284)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/BeanPropertyLoador.java 2009-01-07 08:11:19 UTC (rev 1285)
@@ -7,7 +7,9 @@
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/** @author chemit */
public class BeanPropertyLoador<E> implements Loador<E> {
@@ -54,6 +56,28 @@
return descriptors;
}
+ public Map<String, Object> obtainProgperties(E from) {
+ if (from == null) {
+ return java.util.Collections.emptyMap();
+ }
+ Map<String, Object> result = new HashMap<String, Object>();
+ for (PropertyDescriptor descriptor : getDescriptors()) {
+ Object read = null;
+ try {
+ read = descriptor.getReadMethod().invoke(from);
+ if (read != null) {
+ result.put(descriptor.getName(), read);
+ }
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+ return result;
+ }
+
@Override
public void load(E from, E dst, boolean tech) {
if (from == null) {
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Loador.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Loador.java 2009-01-05 08:40:44 UTC (rev 1284)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Loador.java 2009-01-07 08:11:19 UTC (rev 1285)
@@ -1,7 +1,11 @@
package org.codelutin.topia.persistence.util;
+import java.util.Map;
+
/** @author chemit */
public interface Loador<E> extends java.io.Serializable {
+ Map<String, Object> obtainProgperties(E from);
+
void load(E from, E dst, boolean tech);
}
1
0
r1284 - in topia/trunk/topia-persistence: . src/main/java/org/codelutin/topia/generator src/main/java/org/codelutin/topia/persistence src/main/java/org/codelutin/topia/persistence/util
by tchemit@users.labs.libre-entreprise.org 05 Jan '09
by tchemit@users.labs.libre-entreprise.org 05 Jan '09
05 Jan '09
Author: tchemit
Date: 2009-01-05 08:40:44 +0000 (Mon, 05 Jan 2009)
New Revision: 1284
Added:
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/BeanPropertyLoador.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Creator.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/DBMapping.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Deletor.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/EntityListUpdator.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/EntityLoador.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Gettor.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/ListUpdator.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Loador.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/TopiaEntityHelper.java
Modified:
topia/trunk/topia-persistence/changelog.txt
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java
Log:
- utilisation foreach dans les g?\195?\169n?\195?\169rateurs
- ajout de m?\195?\169thode getXXXByTopiaId pour les attributs ?\195?\160 multiplicit?\195?\169 dans les entit?\195?\169s (interface et abstract)
- fix generic dans les m?\195?\169thodes g?\195?\169n?\195?\169r?\195?\169es
- ajout d'un tagValue i18n pour g?\195?\169n?\195?\169rer dans les entit?\195?\169s abstraites les chaines i18n
- ajout d'un paquetage org.codelutin.topia.persistence.util avec du code utile :) (javadoc a faire...)
Modified: topia/trunk/topia-persistence/changelog.txt
===================================================================
--- topia/trunk/topia-persistence/changelog.txt 2008-12-19 13:23:10 UTC (rev 1283)
+++ topia/trunk/topia-persistence/changelog.txt 2009-01-05 08:40:44 UTC (rev 1284)
@@ -1,3 +1,10 @@
+2.1.2 ??? 200901??
+* 20090104 [chemit] - utilisation foreach dans les générateurs
+ - ajout de méthode getXXXByTopiaId pour les attributs à multiplicité dans les entités (interface et abstract)
+ - fix generic dans les méthodes générées
+ - ajout d'un tagValue i18n pour générer dans les entités abstraites les chaines i18n
+ - ajout d'un paquetage org.codelutin.topia.persistence.util avec du code utile :) (javadoc a faire...)
+
2.1.1 chemit 20081215
* 20081215 [chemit] - new release for isis-fish :)
* 20081212 [chemit] - add a InterfaceGenerator to generate simple with no stereotype interfaces.
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java 2008-12-19 13:23:10 UTC (rev 1283)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java 2009-01-05 08:40:44 UTC (rev 1284)
@@ -29,15 +29,6 @@
package org.codelutin.topia.generator;
-import static org.codelutin.topia.generator.GeneratorUtil.TAG_ANNOTATION;
-import static org.codelutin.topia.generator.GeneratorUtil.hasUnidirectionalRelationOnAbstractType;
-import static org.codelutin.topia.generator.GeneratorUtil.shouldBeAbstract;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Iterator;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codelutin.generator.Generator;
@@ -47,8 +38,16 @@
import org.codelutin.generator.models.object.ObjectModelAttribute;
import org.codelutin.generator.models.object.ObjectModelClass;
import org.codelutin.generator.models.object.ObjectModelClassifier;
+import static org.codelutin.topia.generator.GeneratorUtil.TAG_ANNOTATION;
+import static org.codelutin.topia.generator.GeneratorUtil.hasUnidirectionalRelationOnAbstractType;
+import static org.codelutin.topia.generator.GeneratorUtil.shouldBeAbstract;
import org.codelutin.topia.persistence.TopiaEntityAbstract;
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Iterator;
+
/**
* Generateur d'entites abstraites. Il s'agit de l'implatation par defaut d'une
* entite. Les classes generees sont surchargees par un XXXImpl lorsque l'entite
@@ -56,9 +55,7 @@
*/
public class EntityAbstractGenerator extends ObjectModelGenerator {
- /**
- * Logger for this class
- */
+ /** Logger for this class */
private static final Log log = LogFactory
.getLog(EntityAbstractGenerator.class);
@@ -99,8 +96,8 @@
* Implantation POJO pour l'entité <%=Util.capitalize(clazz.getName())%>.
}*/
{
-String dbName = clazz.getTagValue(GeneratorUtil.TAG_DB_NAME);
- if (dbName!=null) {
+ String dbName = clazz.getTagValue(GeneratorUtil.TAG_DB_NAME);
+ if (dbName != null) {
/*{ *
* <p>Nom de l'entité en BD : <%=dbName%>.</p>
}*/
@@ -109,14 +106,14 @@
/*{ *)
public abstract class <%=clazz.getName()%>Abstract extends }*/
String extendClass = "";
- for (Iterator i=clazz.getSuperclasses().iterator(); i.hasNext();) {
- ObjectModelClassifier parent = (ObjectModelClassifier)i.next();
+ for (Iterator i = clazz.getSuperclasses().iterator(); i.hasNext();) {
+ ObjectModelClassifier parent = (ObjectModelClassifier) i.next();
extendClass += parent.getQualifiedName();
//Si une des classes parentes définies des méthodes abstraites, son
// impl ne sera pas créé
boolean abstractParent = false;
if (parent instanceof ObjectModelClass) {
- abstractParent = shouldBeAbstract((ObjectModelClass)parent);
+ abstractParent = shouldBeAbstract((ObjectModelClass) parent);
}
if (parent.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) {
if (abstractParent) {
@@ -145,7 +142,7 @@
}
for (ObjectModelAttribute attr : clazz.getAttributes()) {
ObjectModelAttribute reverse = attr.getReverseAttribute();
-
+
// pour les asso quoi qu'il arrive il faut les lier des 2 cotes
// pour pouvoir supprimer en cascade l'asso lors de la suppression
// d'un des cotes
@@ -202,9 +199,8 @@
//Déclaration des attributs d'une classe d'associations
if (clazz instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assoc = (ObjectModelAssociationClass)clazz;
- for (Iterator i = assoc.getParticipantsAttributes().iterator(); i.hasNext(); ) {
- ObjectModelAttribute attr = (ObjectModelAttribute) i.next();
+ ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) clazz;
+ for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) {
if (attr != null) {
/*{ <%=attr.getVisibility()%> <%=attr.getType()%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>;
@@ -228,15 +224,14 @@
}
}*/
-
+
/*{
public List<TopiaEntity> getAggregate() throws TopiaException {
List<TopiaEntity> tmp = new ArrayList<TopiaEntity>();
// pour tous les attributs rechecher les composites et les class d'asso
// on les ajoute dans tmp
-}*/
- for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) {
- ObjectModelAttribute attr = (ObjectModelAttribute)it.next();
+}*/
+ for (ObjectModelAttribute attr : clazz.getAttributes()) {
if (attr.referenceClassifier() && attr.getClassifier().hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) {
if (attr.isAggregate()) {
if (Util.isNMultiplicity(attr)) {
@@ -246,7 +241,7 @@
} else {
/*{
tmp.add(get<%=Util.capitalize(attr.getName())%>());
-}*/
+}*/
}
}
}
@@ -264,15 +259,14 @@
}
}*/
-
+
/*{
public List<TopiaEntity> getComposite() throws TopiaException {
List<TopiaEntity> tmp = new ArrayList<TopiaEntity>();
// pour tous les attributs rechecher les composites et les class d'asso
// on les ajoute dans tmp
-}*/
- for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) {
- ObjectModelAttribute attr = (ObjectModelAttribute)it.next();
+}*/
+ for (ObjectModelAttribute attr : clazz.getAttributes()) {
ObjectModelAttribute reverse = attr.getReverseAttribute();
if (attr.referenceClassifier() && attr.getClassifier().hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) {
if (attr.isComposite()) {
@@ -283,7 +277,7 @@
} else {
/*{
tmp.add(get<%=Util.capitalize(attr.getName())%>());
-}*/
+}*/
}
} else if (attr.hasAssociationClass()) {
String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
@@ -308,7 +302,7 @@
tmp.addAll(((TopiaContextImplementor)getTopiaContext())
.getDAO(<%=attr.getAssociationClass().getQualifiedName()%>.class)
.findAllByProperties("<%=reverse.getName()%>", this));
-}*/
+}*/
}
}
}
@@ -329,10 +323,9 @@
}*/
- for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) {
- ObjectModelAttribute attr = (ObjectModelAttribute)it.next();
+ for (ObjectModelAttribute attr : clazz.getAttributes()) {
ObjectModelAttribute reverse = attr.getReverseAttribute();
-
+
if (!(attr.isNavigable()
|| hasUnidirectionalRelationOnAbstractType(reverse, model))) {
continue;
@@ -362,7 +355,9 @@
}*/
} else {
String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
- if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); }
+ if (log.isTraceEnabled()) {
+ log.trace("assocAttrName: " + assocAttrName);
+ }
/*{ /* (non-Javadoc)
* @see <%=clazz.getQualifiedName()%>#set<%=Util.capitalize(assocAttrName)%>(<%=attr.getAssociationClass().getQualifiedName()%>)
*)
@@ -425,6 +420,13 @@
}
/* (non-Javadoc)
+ * @see <%=clazz.getQualifiedName()%>#get<%=Util.capitalize(attr.getName())%>ByTopiaId(String)
+ *)
+ public <%=attr.getType()%> get<%=Util.capitalize(attr.getName())%>ByTopiaId(String topiaId) {
+ return org.codelutin.topia.persistence.util.TopiaEntityHelper.getEntityByTopiaId(<%=attr.getName()%>, topiaId);
+ }
+
+ /* (non-Javadoc)
* @see <%=clazz.getQualifiedName()%>#set<%=Util.capitalize(attr.getName())%>(<%=collectionInterface%><<%=attr.getType()%>>)
*)
public void set<%=Util.capitalize(attr.getName())%>(<%=collectionInterface%><<%=attr.getType()%>> values) {
@@ -466,7 +468,7 @@
}*/
if (reverse != null && (reverse.isNavigable() ||
hasUnidirectionalRelationOnAbstractType(attr, model))) {
-
+
/*{ for (<%=attr.getType()%> item : this.<%=attr.getName()%>) {
}*/
if (!Util.isNMultiplicity(reverse)) {
@@ -478,8 +480,8 @@
}
/*{ }
}*/
- }
-/*{ <%=collectionInterface%> _oldValue = new <%=collectionObject%>(this.<%=attr.getName()%>);
+ }
+/*{ <%=collectionInterface%><<%=attr.getType()%>> _oldValue = new <%=collectionObject%><<%=attr.getType()%>>(this.<%=attr.getName()%>);
fireOnPreWrite("<%=attr.getName()%>", _oldValue, this.<%=attr.getName()%>);
this.<%=attr.getName()%>.clear();
fireOnPostWrite("<%=attr.getName()%>", _oldValue, this.<%=attr.getName()%>);
@@ -488,7 +490,9 @@
}*/
} else {
String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
- if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); }
+ if (log.isTraceEnabled()) {
+ log.trace("assocAttrName: " + assocAttrName);
+ }
/*{ /* (non-Javadoc)
* @see <%=clazz.getQualifiedName()%>#add<%=Util.capitalize(assocAttrName)%>(<%=attr.getAssociationClass().getQualifiedName()%>)
*)
@@ -508,6 +512,13 @@
}
/* (non-Javadoc)
+ * @see <%=clazz.getQualifiedName()%>#get<%=Util.capitalize(attr.getName())%>ByTopiaId(String)
+ *)
+ public <%=attr.getType()%> get<%=Util.capitalize(attr.getName())%>ByTopiaId(String topiaId) {
+ return org.codelutin.topia.persistence.util.TopiaEntityHelper.getEntityByTopiaId(<%=attr.getName()%>, topiaId);
+ }
+
+ /* (non-Javadoc)
* @see <%=clazz.getQualifiedName()%>#addAll<%=Util.capitalize(assocAttrName)%>(<%=collectionInterface%><<%=attr.getAssociationClass().getQualifiedName()%>>()
*)
public void addAll<%=Util.capitalize(assocAttrName)%>(<%=collectionInterface%><<%=attr.getAssociationClass().getQualifiedName()%>> values) {
@@ -564,7 +575,7 @@
}
}*/
}
-/*{ <%=collectionInterface%> _oldValue = new <%=collectionObject%>(this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%>);
+/*{ <%=collectionInterface%><<%=attr.getType()%>> _oldValue = new <%=collectionObject%><<%=attr.getType()%>>(this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%>);
fireOnPreWrite("<%=Util.toLowerCaseFirstLetter(assocAttrName)%>", _oldValue, null);
this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%>.clear();
fireOnPostWrite("<%=Util.toLowerCaseFirstLetter(assocAttrName)%>", _oldValue, null);
@@ -593,7 +604,9 @@
}*/
} else {
String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
- if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); }
+ if (log.isTraceEnabled()) {
+ log.trace("assocAttrName: " + assocAttrName);
+ }
/*{ /* (non-Javadoc)
* @see <%=clazz.getQualifiedName()%>#get<%=Util.capitalize(assocAttrName)%>()
*)
@@ -633,13 +646,12 @@
//Méthodes d'accès aux attributs d'une classe d'associations
if (clazz instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assoc = (ObjectModelAssociationClass)clazz;
- for (Iterator i = assoc.getParticipantsAttributes().iterator(); i.hasNext(); ) {
- ObjectModelAttribute attr = (ObjectModelAttribute) i.next();
- if (attr != null) {
- String type = attr.getType();
- String name = attr.getName();
- generateAssociationAccessors(output, name, type);
+ ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) clazz;
+ for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) {
+ if (attr != null) {
+ String type = attr.getType();
+ String name = attr.getName();
+ generateAssociationAccessors(output, name, type);
// //Ne sert plus à rien normalement avec la navigabilité
// ObjectModelAttribute reverse = attr.getReverseAttribute();
// if (reverse == null) {
@@ -647,7 +659,7 @@
// name = attr.getDeclaringElement().getName();
// generateAssociationAccessors(output, name, type);
// }
- }
+ }
}
}
@@ -657,8 +669,7 @@
public String toString() {
String result = new ToStringBuilder(this).
}*/
- for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) {
- ObjectModelAttribute attr = (ObjectModelAttribute)it.next();
+ for (ObjectModelAttribute attr : clazz.getAttributes()) {
//FIXME possibilité de boucles (non directes)
ObjectModelClass attrEntity = null;
if (model.hasClass(attr.getType())) {
@@ -674,7 +685,13 @@
/*{ toString();
return result;
}
-
+}*/
+ String i18nPrefix = GeneratorUtil.getI18nPrefix(clazz, model);
+ if (i18nPrefix != null) {
+ // generate i18n prefix
+ generateI18n(output, i18nPrefix, clazz);
+ }
+/*{
} //<%=clazz.getName()%>Abstract
}*/
}
@@ -700,4 +717,21 @@
}*/
}
+ private void generateI18n(Writer output, String i18nPrefix, ObjectModelClass clazz) throws IOException {
+/*{
+ static {
+}*/
+ StringBuilder buffer = new StringBuilder();
+ addI18n(buffer, i18nPrefix, java.beans.Introspector.decapitalize(clazz.getName()));
+ for (ObjectModelAttribute attr : clazz.getAttributes()) {
+ addI18n(buffer, i18nPrefix, java.beans.Introspector.decapitalize(attr.getName()));
+ }
+/*{<%=buffer.toString()%>}
+}*/
+ }
+
+ private void addI18n(StringBuilder buffer, String i18nPrefix, String suffix) {
+ buffer.append(" org.codelutin.i18n.I18n.n_(\"").append(i18nPrefix).append(suffix).append("\");\n");
+ }
+
} //EntityAbstractGenerator
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java 2008-12-19 13:23:10 UTC (rev 1283)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java 2009-01-05 08:40:44 UTC (rev 1284)
@@ -367,6 +367,15 @@
public <%=collectionInterface%><<%=attr.getType()%>> get<%=Util.capitalize(attr.getName())%>();
/**
+ * Recupère l'attribut <%=attr.getName()%> à partir de son topiaId.
+ *
+ * @param topiaId le topia id de l'entité recherchée
+ *
+ * @return l'attribut recherché, ou <code>null</code> s'il n'existe pas.
+ *)
+ public <%=attr.getType()%> get<%=Util.capitalize(attr.getName())%>ByTopiaId(String topiaId);
+
+ /**
* @return Le nombre d'éléments de la collection <%=attr.getName()%>.
*)
public int size<%=Util.capitalize(attr.getName())%>();
@@ -383,6 +392,15 @@
public <%=collectionInterface%><<%=attr.getAssociationClass().getQualifiedName()%>> get<%=Util.capitalize(assocAttrName)%>();
/**
+ * Recupère l'attribut <%=attr.getName()%> à partir de son topiaId.
+ *
+ * @param topiaId le topia id de l'attribut recherchée
+ *
+ * @return l'attribut recherché, ou <code>null</code> s'il n'existe pas.
+ *)
+ public <%=attr.getType()%> get<%=Util.capitalize(attr.getName())%>ByTopiaId(String topiaId);
+
+ /**
* @return L'attribut <%=attr.getAssociationClass().getName()%> associé à la valeur <code>value</code> de l'attribut <%=attr.getName()%>.
*)
public <%=attr.getAssociationClass().getQualifiedName()%> get<%=Util.capitalize(assocAttrName)%>(<%=attr.getType()%> value);
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java 2008-12-19 13:23:10 UTC (rev 1283)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java 2009-01-05 08:40:44 UTC (rev 1284)
@@ -99,6 +99,9 @@
/** Tag pour specfier le type d'acces a un champ */
public static final String TAG_ACCESS = "access";
+ /** Tag pour specfier si on doit générer i18n */
+ public static final String TAG_I18N_PREFIX = "i18n";
+
/** Type de persistence Hibernate */
public static final String PERSISTENCE_TYPE_HIBERNATE = "hibernate";
@@ -209,7 +212,7 @@
}
/**
- * Cherches et renvoie le schema a utiliser sur cet element, sinon sur le model.
+ * Cherche et renvoie le schema a utiliser sur cet element, sinon sur le model.
*
* @param element l'élément à tester
* @param model le modele utilisé
@@ -221,6 +224,18 @@
}
/**
+ * Cherche et renvoie le prefixe i18n à utiliser sur cet element, sinon sur le model.
+ *
+ * @param element l'élément à tester
+ * @param model le modele utilisé
+ * @return le prefix i18n ou <code>null</code> si non spécifié
+ */
+ public static String getI18nPrefix(ObjectModelElement element,
+ ObjectModel model) {
+ return findTagValue(TAG_I18N_PREFIX, element, model);
+ }
+
+ /**
* Cherches et renvoie le copyright a utiliser sur le model.
*
* @param model le modele utilisé
Added: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/BeanPropertyLoador.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/BeanPropertyLoador.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/BeanPropertyLoador.java 2009-01-05 08:40:44 UTC (rev 1284)
@@ -0,0 +1,154 @@
+package org.codelutin.topia.persistence.util;
+
+import org.apache.commons.beanutils.MethodUtils;
+
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import java.util.List;
+
+/** @author chemit */
+public class BeanPropertyLoador<E> implements Loador<E> {
+
+ public static <E> BeanPropertyLoador<E> newLoador(Class<E> klass, String... properties) {
+ return new BeanPropertyLoador<E>(klass, properties);
+ }
+
+ private static final long serialVersionUID = 1L;
+
+ protected static final Integer ZERO = 0;
+ protected static final Float ZEROF = 0f;
+ protected static final Long ZEROL = 0l;
+ protected static final Double ZEROD = 0.;
+ protected static final Byte ZEROB = 0;
+
+ protected List<String> properties;
+ protected transient PropertyDescriptor[] descriptors;
+ protected Class<E> klass;
+
+ protected BeanPropertyLoador(Class<E> klass, String... properties) {
+ this.properties = java.util.Collections.unmodifiableList(Arrays.asList(properties));
+ this.klass = klass;
+ }
+
+ public List<String> getProperties() {
+ return properties;
+ }
+
+ public PropertyDescriptor[] getDescriptors() {
+ if (descriptors == null) {
+ try {
+ descriptors = new PropertyDescriptor[properties.size()];
+ for (PropertyDescriptor propertydescriptor : Introspector.getBeanInfo(klass).getPropertyDescriptors()) {
+ int index = properties.indexOf(propertydescriptor.getName());
+ if (index != -1) {
+ descriptors[index] = propertydescriptor;
+ }
+ }
+ } catch (IntrospectionException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return descriptors;
+ }
+
+ @Override
+ public void load(E from, E dst, boolean tech) {
+ if (from == null) {
+ // reset all fields
+ for (PropertyDescriptor descriptor : getDescriptors()) {
+ Object read = getNullValue(descriptor.getPropertyType());
+ setProperty(dst, descriptor, read);
+ }
+ } else {
+ // set all fields from
+ for (PropertyDescriptor descriptor : getDescriptors()) {
+ try {
+ Object value = descriptor.getReadMethod().invoke(from);
+ setProperty(dst, descriptor, value);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ }
+
+ protected void setProperty(E dst, PropertyDescriptor descriptor, Object value) {
+ try {
+ descriptor.getWriteMethod().invoke(dst, value);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected static Object getNullValue(Class<?> type) {
+ if (type.isPrimitive()) {
+ type = MethodUtils.getPrimitiveWrapper(type);
+ if (Boolean.class.isAssignableFrom(type)) {
+ return Boolean.FALSE;
+ }
+ if (Integer.class.isAssignableFrom(type)) {
+ return ZERO;
+ }
+ if (Float.class.isAssignableFrom(type)) {
+ return ZEROF;
+ }
+ if (Long.class.isAssignableFrom(type)) {
+ return ZEROL;
+ }
+ if (Double.class.isAssignableFrom(type)) {
+ return ZEROD;
+ }
+ if (Byte.class.isAssignableFrom(type)) {
+ return ZEROB;
+ }
+ }
+ return null;
+ }
+
+ public static boolean isNullValue(Object value) {
+ if (value == null) {
+ return true;
+ }
+ Class<?> type = value.getClass();
+ if (type.isPrimitive()) {
+ type = MethodUtils.getPrimitiveWrapper(type);
+ }
+ if (Boolean.class.isAssignableFrom(type)) {
+ return Boolean.FALSE.equals(value);
+ }
+ if (Integer.class.isAssignableFrom(type)) {
+ return ZERO.equals(value);
+ }
+ if (Float.class.isAssignableFrom(type)) {
+ return ZEROF.equals(value);
+ }
+ if (Long.class.isAssignableFrom(type)) {
+ return ZEROL.equals(value);
+ }
+ if (Double.class.isAssignableFrom(type)) {
+ return ZEROD.equals(value);
+ }
+ return Byte.class.isAssignableFrom(type) && ZEROB.equals(value);
+ }
+
+ protected void checkProperties() {
+ PropertyDescriptor[] descriptors = getDescriptors();
+ for (int i = 0; i < descriptors.length; i++) {
+ PropertyDescriptor descriptor = descriptors[i];
+ if (descriptor == null) {
+ throw new IllegalStateException("could not find descriptor for property " + properties.get(i) + " on " + klass);
+ }
+ if (descriptor.getReadMethod() == null) {
+ throw new IllegalStateException("property " + properties.get(i) + " is not readable on " + klass);
+ }
+ if (descriptor.getWriteMethod() == null) {
+ throw new IllegalStateException("property " + properties.get(i) + " is not writable on " + klass);
+ }
+ }
+ }
+}
Added: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Creator.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Creator.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Creator.java 2009-01-05 08:40:44 UTC (rev 1284)
@@ -0,0 +1,8 @@
+package org.codelutin.topia.persistence.util;
+
+import org.codelutin.topia.TopiaException;
+
+/** @author chemit */
+public interface Creator<P, E> {
+ E create(DBMapping mapping, P parent, E from) throws TopiaException;
+}
Added: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/DBMapping.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/DBMapping.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/DBMapping.java 2009-01-05 08:40:44 UTC (rev 1284)
@@ -0,0 +1,425 @@
+package org.codelutin.topia.persistence.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.topia.TopiaContext;
+import org.codelutin.topia.TopiaException;
+import org.codelutin.topia.framework.TopiaContextImpl;
+import org.codelutin.topia.persistence.TopiaEntity;
+import org.hibernate.SQLQuery;
+import org.hibernate.jdbc.Work;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigInteger;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Une classe qui permet d'obtenir les mapping de noms entre les entités et les objets de la base.
+ * <p/>
+ * On retrouve aussi ici des méthodes utils pour executer du code sql sur la base (notamment la gestion des séquences).
+ *
+ * @author chemit
+ */
+public abstract class DBMapping {
+
+ /** log */
+ protected static final Log log = LogFactory.getLog(DBMapping.class);
+
+ protected static final String CLASS_PATTERN = "(.+)\\.class\\.tagvalue\\.dbName";
+
+ protected static final String DBNAME_ATTRIBUTE_PATTERN = "(.+).attribute.(\\w+)\\.tagvalue\\.dbName";
+
+ protected static final String SEQUENCE_ATTRIBUTE_PATTERN = "(.+).attribute.(\\w+)\\.tagvalue\\.sequence";
+
+ protected static final String CREATE_SEQUENCE_FORMAT = "create sequence %1$s%2$s_%3$s_sequence start (select max(%3$s) from %1$s%2$s);";
+
+ protected static final String UPDATE_SEQUENCE_FORMAT = "alter sequence %1$s%2$s_%3$s_sequence restart with (select max(%3$s) from %1$s%2$s);";
+
+ protected static final String CURRENT_VALUE_SEQUENCE_FORMAT = "select %1$s%2$s_%3$s_sequence.currval";
+
+ protected static final String NEXT_VALUE_SEQUENCE_FORMAT = "select %1$s%2$s_%3$s_sequence.nextval";
+
+ protected static final String SCHEMA_FORMAT = "model.tagvalue.dbSchema";
+
+ protected static final String DOT = ".";
+
+ protected Map<String, String> mappingBeanToDb;
+
+ protected Map<String, Class<? extends TopiaEntity>> sequences;
+
+ protected String schema;
+
+ protected abstract Class<? extends TopiaEntity> getContractClass(Class<? extends TopiaEntity> entityClass) throws TopiaException;
+
+ public DBMapping(String propertyFile, String path) throws IOException {
+ mappingBeanToDb = new java.util.TreeMap<String, String>();
+ sequences = new java.util.TreeMap<String, Class<? extends TopiaEntity>>();
+
+ if (propertyFile == null) {
+ propertyFile = path;
+ }
+
+ InputStream stream = getClass().getResourceAsStream(propertyFile);
+ if (stream == null) {
+ throw new IllegalStateException("no tagsvalues defined (did not find the resource : " + propertyFile + ")");
+ }
+
+ Properties props = new Properties();
+
+ try {
+
+ props.load(stream);
+
+ initMapping(props);
+
+ } finally {
+ props.clear();
+ stream.close();
+ }
+ }
+
+ public void init(TopiaContext ctxt, boolean doCreate, boolean doUpdate) throws TopiaException {
+ if (sequences.isEmpty()) {
+ // no sequence registed
+ return;
+ }
+ String firstSequenceKey = sequences.keySet().iterator().next();
+ TopiaContext newContext = ctxt.beginTransaction();
+ boolean exists = existSequence(firstSequenceKey, newContext);
+
+ if (!exists) {
+ if (!doCreate) {
+ // not exists and do not create
+ return;
+ }
+ createSequences(newContext);
+ } else {
+ if (doUpdate) {
+ updateSequences(newContext);
+ }
+ }
+ newContext.commitTransaction();
+ newContext.closeContext();
+ }
+
+ public void createSequences(TopiaContext ctxt) throws TopiaException {
+ if (log.isInfoEnabled()) {
+ log.info("start create db sequences...");
+ }
+ for (String sequenceKey : sequences.keySet()) {
+ createSequence(sequenceKey, ctxt, false);
+ }
+ }
+
+ public void updateSequences(TopiaContext ctxt) throws TopiaException {
+ if (log.isInfoEnabled()) {
+ log.info("start update db sequences...");
+ }
+ for (String sequenceKey : sequences.keySet()) {
+ updateSequence(sequenceKey, ctxt, false);
+ }
+ }
+
+ public boolean existSequence(String sequenceKey, TopiaContext ctxt) throws TopiaException {
+ return existSequence(sequenceKey, ctxt, true);
+ }
+
+ public void createSequence(String sequenceKey, TopiaContext ctxt) throws TopiaException {
+ createSequence(sequenceKey, ctxt, true);
+ }
+
+ public void updateSequence(String sequenceKey, TopiaContext ctxt) throws TopiaException {
+ updateSequence(sequenceKey, ctxt, true);
+ }
+
+ public BigInteger getCurrentValueFromSequence(String sequenceKey, TopiaContext ctxt) throws TopiaException {
+ return getCurrentValueFromSequence(sequenceKey, ctxt, true);
+ }
+
+ public BigInteger getNextValueFromSequence(String sequenceKey, TopiaContext ctxt) throws TopiaException {
+ return getNextValueFromSequence(sequenceKey, ctxt, true);
+ }
+
+ public boolean existSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaContext ctxt) throws TopiaException {
+ String sequenceKey = checkSequence(entityClass, propertyName);
+ return existSequence(sequenceKey, ctxt, false);
+ }
+
+ public void createSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaContext ctxt) throws TopiaException {
+ String sequenceKey = checkSequence(entityClass, propertyName);
+ createSequence(sequenceKey, ctxt, false);
+ }
+
+ public void updateSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaContext ctxt) throws TopiaException {
+ String sequenceKey = checkSequence(entityClass, propertyName);
+ updateSequence(sequenceKey, ctxt, false);
+ }
+
+ public BigInteger getCurrentValueFromSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaContext ctxt) throws TopiaException {
+ String sequenceKey = checkSequence(entityClass, propertyName);
+ return getCurrentValueFromSequence(sequenceKey, ctxt, false);
+ }
+
+ public BigInteger getNextValueFromSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaContext ctxt) throws TopiaException {
+ String sequenceKey = checkSequence(entityClass, propertyName);
+ return getNextValueFromSequence(sequenceKey, ctxt, false);
+ }
+
+ public Iterator<String> getSequenceKeysIterator() {
+ return sequences.keySet().iterator();
+ }
+
+ public boolean existSequence(String sequenceKey, TopiaContext ctxt, boolean check) throws TopiaException {
+ if (check) {
+ checkSequence(sequenceKey);
+ }
+ try {
+ getCurrentValueFromSequence(sequenceKey, ctxt, false);
+
+ } catch (TopiaException e) {
+ // the sequence's name does not exist in database, so it is a grammer exception
+ if (e.getCause() != null && e.getCause().getClass() == org.hibernate.exception.SQLGrammarException.class) {
+ return false;
+ }
+ throw e;
+ }
+ return true;
+ }
+
+ public void createSequence(String sequenceKey, TopiaContext ctxt, boolean check) throws TopiaException {
+ if (check) {
+ checkSequence(sequenceKey);
+ }
+ final String sql = getSequenceSQL(CREATE_SEQUENCE_FORMAT, sequenceKey);
+ doSQLWork(ctxt, sql);
+ BigInteger currentValue = getNextValueFromSequence(sequenceKey, ctxt, false);
+
+ if (log.isDebugEnabled()) {
+ log.debug(sequenceKey + " currentValue " + currentValue.intValue());
+ }
+ }
+
+ public void updateSequence(String sequenceKey, TopiaContext ctxt, boolean check) throws TopiaException {
+ if (check) {
+ checkSequence(sequenceKey);
+ }
+ final String sql = getSequenceSQL(UPDATE_SEQUENCE_FORMAT, sequenceKey);
+ doSQLWork(ctxt, sql);
+ BigInteger currentValue = getNextValueFromSequence(sequenceKey, ctxt, false);
+ if (log.isDebugEnabled()) {
+ log.debug(sequenceKey + " currentValue " + currentValue.intValue());
+ }
+ }
+
+ public BigInteger getCurrentValueFromSequence(String sequenceKey, TopiaContext ctxt, boolean check) throws TopiaException {
+ if (check) {
+ checkSequence(sequenceKey);
+ }
+ String sql = getSequenceSQL(CURRENT_VALUE_SEQUENCE_FORMAT, sequenceKey);
+ TopiaContext newCtxt = ctxt.beginTransaction();
+ BigInteger bigInteger = getBigInteger(newCtxt, sql, BigInteger.ZERO);
+ newCtxt.closeContext();
+ return bigInteger;
+ }
+
+ public BigInteger getNextValueFromSequence(String sequenceKey, TopiaContext ctxt, boolean check) throws TopiaException {
+ if (check) {
+ checkSequence(sequenceKey);
+ }
+ String sql = getSequenceSQL(NEXT_VALUE_SEQUENCE_FORMAT, sequenceKey);
+ return getBigInteger(ctxt, sql, BigInteger.ZERO);
+ }
+
+ /**
+ * @param entityClass the seek entity class
+ * @param property the name of the property to translate
+ * @return the DB name for the given property
+ * @throws org.codelutin.topia.TopiaException
+ * if any db pb
+ */
+ protected String getDBProperty(Class<? extends TopiaEntity> entityClass, String property) throws TopiaException {
+ Class<? extends TopiaEntity> contractClass = getContractClass(entityClass);
+ String key = contractClass.getName() + DOT + property;
+
+ String colName = mappingBeanToDb.get(key);
+ if (colName == null) {
+ colName = property;
+ }
+ return colName;
+ }
+
+ /**
+ * @param entityClass the seek entity class
+ * @return the DB name for the given property
+ * @throws org.codelutin.topia.TopiaException
+ * if any db pb
+ */
+ protected String getDBTable(Class<? extends TopiaEntity> entityClass) throws TopiaException {
+ Class<? extends TopiaEntity> contractClass = getContractClass(entityClass);
+ String key = contractClass.getName();
+ String colName = mappingBeanToDb.get(key);
+
+ if (colName == null) {
+ colName = contractClass.getSimpleName().toLowerCase();
+ }
+ return colName;
+ }
+
+ protected String getSequenceSQL(String pattern, Class<? extends TopiaEntity> entityClass, String propertyName) throws TopiaException {
+ String dbTable = getDBTable(entityClass);
+ String dbPropertyName = getDBProperty(entityClass, propertyName);
+ String sql = String.format(pattern, schema, dbTable, dbPropertyName);
+ if (log.isTraceEnabled()) {
+ log.trace("sql : " + sql);
+ }
+ return sql;
+ }
+
+ protected String getSequenceSQL(String pattern, String sequenceKey) throws TopiaException {
+ Class<? extends TopiaEntity> entityClass = sequences.get(sequenceKey);
+ String dbTable = getDBTable(entityClass);
+ String propertyName = getSequencePropertyName(sequenceKey);
+ String dbPropertyName = getDBProperty(entityClass, propertyName);
+ String sql = String.format(pattern, schema, dbTable, dbPropertyName);
+ if (log.isTraceEnabled()) {
+ log.trace("sql : " + sql);
+ }
+ return sql;
+ }
+
+ protected BigInteger getBigInteger(TopiaContext ctxt, String sql, BigInteger defaultSize) throws TopiaException {
+ BigInteger size = defaultSize;
+ if (ctxt != null) {
+ try {
+ SQLQuery query = ((TopiaContextImpl) ctxt).getHibernate().createSQLQuery(sql);
+ size = (BigInteger) query.list().get(0);
+ } catch (org.hibernate.exception.SQLGrammarException e) {
+ // could not obtain sequence
+ throw new TopiaException(e);
+ }
+ }
+ return size;
+ }
+
+ protected void doSQLWork(TopiaContext ctxt, final String sql) throws TopiaException {
+ if (ctxt != null) {
+ //ctxt.beginTransaction();
+ ((TopiaContextImpl) ctxt).getHibernate().doWork(new Work() {
+ public void execute(Connection connection) throws SQLException {
+ if (log.isDebugEnabled()) {
+ log.debug(sql);
+ }
+ Statement stmt = connection.createStatement();
+ stmt.execute(sql);
+ }
+ });
+ //ctxt.commitTransaction();
+ }
+ }
+
+ protected String getSequencePropertyName(String sequenceKey) {
+ int dotIndex = sequenceKey.lastIndexOf(DOT);
+ return sequenceKey.substring(dotIndex + 1);
+ }
+
+ protected String checkSequence(Class<? extends TopiaEntity> entityClass, String propertyName) throws IllegalArgumentException, TopiaException {
+ Class<? extends TopiaEntity> contractClass = getContractClass(entityClass);
+ String sequenceKey = contractClass.getName() + DOT + propertyName;
+ if (!sequences.containsKey(sequenceKey)) {
+ throw new IllegalArgumentException("could not find the sequence " + sequenceKey);
+ }
+ return sequenceKey;
+ }
+
+ protected String checkSequence(String sequenceKey) throws IllegalArgumentException, TopiaException {
+ if (!sequences.containsKey(sequenceKey)) {
+ throw new IllegalArgumentException("could not find the sequence " + sequenceKey);
+ }
+ return sequenceKey;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected void initMapping(Properties props) throws IOException {
+
+ if (props.containsKey(SCHEMA_FORMAT)) {
+ schema = props.getProperty(SCHEMA_FORMAT) + DOT;
+ } else {
+ schema = "";
+ }
+
+ Pattern classPattern = Pattern.compile(CLASS_PATTERN);
+
+ Pattern dbNameAttributePattern = Pattern.compile(DBNAME_ATTRIBUTE_PATTERN);
+
+ Pattern sequenceAttributePattern = Pattern.compile(SEQUENCE_ATTRIBUTE_PATTERN);
+
+ for (Entry<Object, Object> entry : props.entrySet()) {
+ String key = String.valueOf(entry.getKey());
+ String value = String.valueOf(entry.getValue());
+ Matcher matcher;
+
+ matcher = dbNameAttributePattern.matcher(key);
+ if (matcher.matches()) {
+ // find a attribute property
+ String clazz = matcher.group(1);
+ String attribute = matcher.group(2);
+ mappingBeanToDb.put(clazz + "." + attribute, value);
+
+ continue;
+ }
+ matcher = classPattern.matcher(key);
+ if (matcher.matches()) {
+ // find a class property
+ String clazz = matcher.group(1);
+ mappingBeanToDb.put(clazz, value);
+ continue;
+ }
+ matcher = sequenceAttributePattern.matcher(key);
+ if (matcher.matches()) {
+ // find a attribute property
+ String clazz = matcher.group(1);
+ String attribute = matcher.group(2);
+ try {
+ boolean useSequence = Boolean.valueOf(value);
+ if (useSequence) {
+ Class<?> value1 = Class.forName(clazz);
+ if (TopiaEntity.class.isAssignableFrom(value1)) {
+ sequences.put(clazz + "." + attribute, (Class<? extends TopiaEntity>) value1);
+ } else {
+ log.warn("can not create a sequence on a non TopiaEntity class " + clazz);
+ }
+
+ }
+ } catch (Exception e) {
+ log.warn("could not convert sequence value for entry " + key+" for reason "+e.getMessage());
+ }
+
+ }
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ close();
+ }
+
+ public void close() {
+ if (mappingBeanToDb != null) {
+ mappingBeanToDb.clear();
+ }
+ if (sequences != null) {
+ sequences.clear();
+ }
+ }
+
+}
Added: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Deletor.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Deletor.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Deletor.java 2009-01-05 08:40:44 UTC (rev 1284)
@@ -0,0 +1,6 @@
+package org.codelutin.topia.persistence.util;
+
+/** @author chemit */
+public interface Deletor<P, E> {
+ void delete(P parent, E from);
+}
Added: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/EntityListUpdator.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/EntityListUpdator.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/EntityListUpdator.java 2009-01-05 08:40:44 UTC (rev 1284)
@@ -0,0 +1,90 @@
+package org.codelutin.topia.persistence.util;
+
+import org.apache.commons.beanutils.PropertyUtilsBean;
+import org.apache.commons.lang.StringUtils;
+import org.codelutin.topia.TopiaException;
+import org.codelutin.topia.persistence.TopiaEntity;
+
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collection;
+
+/** @author chemit */
+public class EntityListUpdator<P extends TopiaEntity, E extends TopiaEntity> implements ListUpdator<P, E> {
+
+ public static <P extends TopiaEntity, E extends TopiaEntity> EntityListUpdator<P, E> newEntityListUpdator(Class<P> parentClass, Class<E> childClass, String propertyName) {
+ return new EntityListUpdator<P, E>(parentClass, childClass, propertyName);
+ }
+
+ protected String propertyName;
+
+ protected PropertyDescriptor descriptor;
+ protected Method getMethod;
+ protected Method addMethod;
+ protected Method removeMethod;
+
+ protected EntityListUpdator(Class<P> parentClass, Class<E> childClass, String propertyName) {
+ this.propertyName = propertyName;
+
+ for (PropertyDescriptor propertyDescriptor : new PropertyUtilsBean().getPropertyDescriptors(parentClass)) {
+ if (propertyDescriptor.getName().equals(propertyName)) {
+ descriptor = propertyDescriptor;
+ }
+ }
+ String cap = StringUtils.capitalize(propertyName);
+ try {
+ getMethod = parentClass.getMethod("get" + cap + "ByTopiaId", String.class);
+ addMethod = parentClass.getMethod("add" + cap, childClass);
+ removeMethod = parentClass.getMethod("remove" + cap, childClass);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public E getChild(P parent, String topiaId) {
+ return EntityListUpdator.<E>invokeWithResult(getMethod, parent, topiaId);
+ }
+
+ @Override
+ public Collection<E> getChilds(P parent) {
+ return EntityListUpdator.invokeWithResult(descriptor.getReadMethod(), parent);
+ }
+
+ @Override
+ public void setChilds(P parent, Collection<E> childs) {
+ invoke(descriptor.getWriteMethod(), parent, childs);
+ }
+
+ @Override
+ public void addToList(P parent, E bean) throws TopiaException {
+ invoke(addMethod, parent, bean);
+ }
+
+ @Override
+ public void removeFromList(P parent, E bean) throws TopiaException {
+ invoke(removeMethod, parent, bean);
+ }
+
+ protected static void invoke(Method m, Object bean, Object... args) {
+ try {
+ m.invoke(bean, args);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected static <V> V invokeWithResult(Method m, Object bean, Object... args) {
+ try {
+ return (V) m.invoke(bean, args);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
Added: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/EntityLoador.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/EntityLoador.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/EntityLoador.java 2009-01-05 08:40:44 UTC (rev 1284)
@@ -0,0 +1,37 @@
+package org.codelutin.topia.persistence.util;
+
+import org.codelutin.topia.persistence.TopiaEntity;
+
+/** @author chemit */
+public class EntityLoador<E extends TopiaEntity> extends BeanPropertyLoador<E> {
+ private static final long serialVersionUID = 1L;
+
+ protected E empty;
+
+ public static <E extends TopiaEntity> EntityLoador<E> newEntityLoador(Class<E> klass, E empty, String... properties) {
+ return new EntityLoador<E>(klass, empty, properties);
+ }
+
+ public static <E extends TopiaEntity> EntityLoador<E> newEntityLoador(Class<E> klass, String... properties) {
+ return newEntityLoador(klass, null, properties);
+ }
+
+
+ @Override
+ public void load(E from, E dst, boolean tech) {
+ if (from == null) {
+ from = empty;
+ }
+ if (tech) {
+ TopiaEntityHelper.bindTechnical(from, dst);
+ }
+ super.load(from, dst, tech);
+ }
+
+ protected EntityLoador(Class<E> klass, E empty, String... properties) {
+ super(klass, properties);
+ this.empty = empty;
+ // check properties
+ checkProperties();
+ }
+}
\ No newline at end of file
Added: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Gettor.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Gettor.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Gettor.java 2009-01-05 08:40:44 UTC (rev 1284)
@@ -0,0 +1,6 @@
+package org.codelutin.topia.persistence.util;
+
+/** @author chemit */
+public interface Gettor<P, E> {
+ E get(P parent, String topiaId);
+}
Added: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/ListUpdator.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/ListUpdator.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/ListUpdator.java 2009-01-05 08:40:44 UTC (rev 1284)
@@ -0,0 +1,19 @@
+package org.codelutin.topia.persistence.util;
+
+import org.codelutin.topia.TopiaException;
+
+import java.util.Collection;
+
+/** @author chemit */
+public interface ListUpdator<P, E> {
+
+ E getChild(P parent, String topiaId);
+
+ Collection<E> getChilds(P parent);
+
+ void setChilds(P parent, Collection<E> childs);
+
+ void addToList(P parent, E bean) throws TopiaException;
+
+ void removeFromList(P parent, E bean) throws TopiaException;
+}
Added: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Loador.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Loador.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/Loador.java 2009-01-05 08:40:44 UTC (rev 1284)
@@ -0,0 +1,7 @@
+package org.codelutin.topia.persistence.util;
+
+/** @author chemit */
+public interface Loador<E> extends java.io.Serializable {
+
+ void load(E from, E dst, boolean tech);
+}
Added: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/TopiaEntityHelper.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/TopiaEntityHelper.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/TopiaEntityHelper.java 2009-01-05 08:40:44 UTC (rev 1284)
@@ -0,0 +1,215 @@
+package org.codelutin.topia.persistence.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+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.util.IOUtils;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.util.Collection;
+
+/**
+ * Une classe avec des méthodes utiles sur les entités.
+ *
+ * @author chemit
+ */
+public class TopiaEntityHelper {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ private static final Log log = LogFactory.getLog(TopiaEntityHelper.class);
+
+ /**
+ * Bind les valeurs techniques depuis une entitée vers une autre.
+ *
+ * @param from l'entité source
+ * @param dst l'entité destination
+ */
+ public static void bindTechnical(TopiaEntity from, TopiaEntity dst) {
+ if (from == null) {
+ dst.setTopiaId(null);
+ dst.setTopiaVersion(0);
+ dst.setTopiaCreateDate(null);
+ } else {
+ dst.setTopiaId(from.getTopiaId());
+ dst.setTopiaVersion(from.getTopiaVersion());
+ dst.setTopiaCreateDate(from.getTopiaCreateDate());
+ }
+ }
+
+ /**
+ * Récupère une entité qui doit exister à partir de son id.
+ * <p/>
+ * Si l'entité n'existe pas, on déclanche une exception {@link IllegalArgumentException}.
+ *
+ * @param dao la dao pour récupérer la valeur
+ * @param topiaId l'id de l'entité recherchée
+ * @param <E> le type de l'entité
+ * @return l'entité recherché
+ * @throws TopiaException pour tout pb lors de la récupération de l'entité
+ * @throws IllegalArgumentException si l'entité n'existe pas.
+ */
+ public static <E extends TopiaEntity> E getExistingEntity(TopiaDAO<E> dao, String topiaId) throws TopiaException, IllegalArgumentException {
+ E entity = dao.findByTopiaId(topiaId);
+ if (entity == null) {
+ throw new IllegalArgumentException("could not find entity with topiaId " + topiaId);
+ }
+ return entity;
+ }
+
+ /**
+ * Récupère une entité dans une liste d'entité.
+ *
+ * @param entities la liste des entités à scanner
+ * @param topiaId l'id de l'entité recherchée
+ * @param <E> le type de l'entité
+ * @return l'entité trouvée, ou <code<null</code< si elle n'est pas trouvée.
+ */
+ public static <E extends TopiaEntity> E getEntityByTopiaId(Collection<E> entities, String topiaId) {
+ if (entities != null) {
+ for (E e : entities) {
+ if (topiaId.equals(e.getTopiaId())) {
+ return e;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Teste si une entité possède un topiaId.
+ *
+ * @param paramName le nom du paramètre à afficher en casd'erreur
+ * @param bean l'entité à tester
+ * @param <E> le type de l'entité
+ * @throws IllegalStateException si l'entité n'a pas de topiaId
+ * @throws NullPointerException si l'entité est null
+ */
+ public static <E extends TopiaEntity> void checkNotNullAndExistingEntity(String paramName, E bean) throws IllegalStateException, NullPointerException {
+ if (bean == null) {
+ throw new NullPointerException(paramName + " can not be null");
+ }
+ if (bean.getTopiaId() == null) {
+ // can not create bean here
+ throw new IllegalStateException("can not create " + bean.getClass() + " here...");
+ }
+ }
+
+ /**
+ * Teste si une entité ne possède pas un topiaId.
+ *
+ * @param paramName le nom de paramètre à afficher en cas d'erreur
+ * @param bean l'entité à tester
+ * @param <E> le type del'entité
+ * @throws NullPointerException si l'entité est nulle
+ * @throws IllegalStateException si l'entité possède un topiaId.
+ */
+ public static <E extends TopiaEntity> void checkNotNullAndNoneExistingEntity(String paramName, E bean) throws NullPointerException, IllegalStateException {
+ if (bean == null) {
+ throw new NullPointerException(paramName + " can not be null");
+ }
+ if (bean.getTopiaId() != null) {
+ // can not create bean here
+ throw new IllegalStateException("can not update " + bean.getClass() + " here...");
+ }
+ }
+
+ /**
+ * Create a new database from a sql dump locating in a gzip file.
+ *
+ * @param dbDirectory the directory where to create the db
+ * @param topiaContext the topiaContext to use to create the databse
+ * @param resource the url of the sql dump gzip file to use
+ * @throws TopiaException if any pb while creating db
+ * @throws IOException if any io exception
+ * @throws NullPointerException if parameters are null
+ */
+ public static void createDBFromSQL(File dbDirectory, TopiaContext topiaContext, URI resource) throws IOException, TopiaException, NullPointerException {
+ if (dbDirectory == null) {
+ throw new NullPointerException("dbDirectory can not be null");
+ }
+ if (topiaContext == null) {
+ throw new NullPointerException("topiaContext can not be null");
+ }
+ if (resource == null) {
+ throw new NullPointerException("resource can not be null");
+ }
+
+ File databaseDump;
+ if (resource.isOpaque()) {
+
+ ByteArrayOutputStream output = IOUtils.readBytesFrom(resource.toURL().openStream(), 8048);
+ File tempFile = File.createTempFile("topiaDumpDatabase", ".sql.gz");
+
+ output.writeTo(new FileOutputStream(tempFile));
+
+ tempFile.deleteOnExit();
+ databaseDump = tempFile;
+
+ } else {
+
+ databaseDump = new File(resource);
+ }
+
+ if (!dbDirectory.exists()) {
+ if (!dbDirectory.mkdirs()) {
+ throw new IOException("could not create directory " + dbDirectory);
+ }
+ }
+
+ log.info("create database from [" + databaseDump + "] at [" + dbDirectory + "]");
+
+ TopiaContext ctxt = topiaContext.beginTransaction();
+
+ try {
+ ctxt.restore(databaseDump);
+ ctxt.commitTransaction();
+ } catch (TopiaException e) {
+ ctxt.rollbackTransaction();
+ throw e;
+ } finally {
+ ctxt.closeContext();
+ }
+ }
+
+ /**
+ * Save the given database to a gzip file.
+ *
+ * @param gzipFile the file where to store db
+ * @param topiaContext the topiaContext of the db to store
+ * @throws TopiaException if any pb while saving db
+ * @throws NullPointerException if parameters are null
+ * @throws IOException if could not create gzipFile container directory
+ */
+ public static void saveDB(File gzipFile, TopiaContext topiaContext) throws TopiaException, IOException, NullPointerException {
+ if (gzipFile == null) {
+ throw new NullPointerException("gzipFile can not be null");
+ }
+ if (topiaContext == null) {
+ throw new NullPointerException("topiaContext can not be null");
+ }
+ if (!gzipFile.getParentFile().exists()) {
+ if (!gzipFile.getParentFile().mkdirs()) {
+ throw new IOException("could not create directory " + gzipFile.getParentFile());
+ }
+ }
+ log.info("store database to [" + gzipFile + "]");
+
+ TopiaContext ctxt = null;
+
+ try {
+ ctxt = topiaContext.beginTransaction();
+ ctxt.backup(gzipFile, true);
+ } finally {
+ if (ctxt != null) {
+ ctxt.closeContext();
+ }
+ }
+ }
+}
1
0