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
- 4806 discussions
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
r1283 - topia/trunk/topia-persistence/src/site/rst
by ruchaud@users.labs.libre-entreprise.org 19 Dec '08
by ruchaud@users.labs.libre-entreprise.org 19 Dec '08
19 Dec '08
Author: ruchaud
Date: 2008-12-19 13:23:10 +0000 (Fri, 19 Dec 2008)
New Revision: 1283
Added:
topia/trunk/topia-persistence/src/site/rst/howto.rst
Log:
Document pour la prise en main de Topia
Added: topia/trunk/topia-persistence/src/site/rst/howto.rst
===================================================================
--- topia/trunk/topia-persistence/src/site/rst/howto.rst (rev 0)
+++ topia/trunk/topia-persistence/src/site/rst/howto.rst 2008-12-19 13:23:10 UTC (rev 1283)
@@ -0,0 +1,244 @@
+How to
+======
+
+Ce document a pour objectif de prendre en main le framework Topia. Le document
+est constitué de 4 parties, la modèlisation, la génération, la configuration et
+l'utilisation.
+
+Modélisation
+------------
+
+La première étape constiste à réaliser le modèle UML soit avec Argouml
+(http://argouml.tigris.org) soit avec Poséidon (http://www.gentleware.com)
+
+Le stérotype «entity» sur les classes permet de préciser que la classe est
+persister par Topia. D'autre stérotypes (extern, service, ...) sont disponiples
+mais ne sont pas présenté.
+
+Le fichier de modélisation peut être compléter par un fichier de configuration
+nommé <nom fichier modélisation>.properties. Il contient des informations
+techniques propres au librairie utilisé par Topia.
+
+Exemple :
+
+# Précise comment est mappé un type
+# model.tagvalue.<type java>=<type base de donnée>
+model.tagvalue.java.lang.String=text
+
+# Précise le schema de la base de données par défaut
+# model.tagvalue.dbSchema=<nom schéma>
+model.tagvalue.dbSchema=test
+
+# Précise l'entête de l'ensemble des fichiers générés
+# model.tagvalue.copyright=<valeur>
+model.tagvalue.copyright=/* *##%\n Copyright (C) 2007 Code Lutin\n *##% */
+
+# Force le chargement d'un attribut
+# <nom paquetage>.<nom entité>.attribute.<nom attribut>.tagvalue.lazy=false
+org.codelutin.Person.attribute.association.tagvalue.lazy=false
+
+Génération
+----------
+
+La génération des fichiers Topia se font par l'utilisation d'un plugin maven.
+Le plugin est disponnible sur le repository maven de Code Lutin à l'adresse
+suivante http://lutinbuilder.labs.libre-entreprise.org/maven2.
+
+Configuration du plugin maven :
+
+<plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-generator-plugin</artifactId>
+ <version>0.63</version>
+ <executions>
+ <execution>
+ <phase>process-sources</phase>
+ <!--Configuration of model generator-->
+ <configuration>
+ <addCompileDirectory>true</addCompileDirectory>
+ <srcDirZuml>${maven.src.dir}/main/xmi</srcDirZuml>
+ <srcXmiDest>${maven.gen.dir}/xmi/</srcXmiDest>
+ <srcGenDest>${maven.gen.dir}/objectmodel/</srcGenDest>
+ <includes>**/*.objectmodel</includes>
+ <templates>org.codelutin.topia.generator.TopiaMetaGenerator</templates>
+ <destDirGen>${maven.gen.dir}/java</destDirGen>
+ <defaultPackage>org.codelutin</defaultPackage>
+ <extractedPackages>org.codelutin</extractedPackages>
+ </configuration>
+ <goals>
+ <goal>zargo2xmi</goal>
+ <goal>xmi2objectmodel</goal>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.codelutin.topia</groupId>
+ <artifactId>topia-persistence</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+</plugin>
+
+Le plugin utilise lutin generator avec les templates de génération de Topia, le
+fichier argouml ou poséidon doit se trouver dans le répertoire
+${maven.src.dir}/main/xmi. Les fichiers sont générés dans le répertoire
+${maven.gen.dir}/java. Il faut préciser au plugin les paquetages à traiter avec
+le defaultPackage et extractedPackages.
+
+Ajout dans des dépendances de Topia pour la compilation des fichiers générés :
+
+<dependency>
+ <groupId>org.codelutin.topia</groupId>
+ <artifactId>topia-persistence</artifactId>
+ <version>2.1.1</version>
+ <scope>compile</scope>
+</dependency>
+
+Pour une classe modélisé, nous retrouvons 6 fichiers :
+ * Une interface
+ * Une classe abstraite
+ * Une implantation
+ * Une configuration hibernate
+ * Un DAO abstrait
+ * Une implantation du DAO
+
+Une classe Helper est aussi générée, permettant l'accès à l'ensemble des DAO.
+
+Configuration
+-------------
+
+Un fichier contenant les informations de connexion à la base de données et de
+configuration de Topia doit être créé au niveau des ressources du projet.
+
+Exemple :
+
+# Permet la création, la modification, ou pas automatique de la base de données
+# [create | update | none]
+hibernate.hbm2ddl.auto=update
+
+# Affichage des requêtes dans la console
+# [true | false]
+hibernate.show_sql=false
+
+# Permet de préciser les classes à persister
+topia.persistence.classes=org.codelutin.Person, org.codelutin.Pet
+
+# Informations de connection :
+
+# Dialect à utiliser
+hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
+
+# Driver JDBC
+hibernate.connection.driver_class=org.postgresql.Driver
+
+# URL de connection
+hibernate.connection.url=jdbc:postgresql://localhost/mydb
+
+# Login de l'utilisateur qui se connecte
+hibernate.connection.username=user
+
+# Mot de passe de l'utilisateur
+hibernate.connection.password=xxxx
+
+Utilisation
+-----------
+
+Implantation des méthodes
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Si des méthodes ont été définis dans le modèle de données il faut créer
+l'implantation correspondante. Le paquetage doit porter le même nom que celui de
+la génération.
+
+Gestion des transactions
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+>>> Properties conf = Resource.getConfigProperties("/TopiaContext.properties");
+
+Permet de charger un fichier contenant les informations de connexion à la base
+et de configuration de Topia.
+
+>>> TopiaContext rootContext = TopiaContextFactory.getContext(conf);
+
+Récupère le context de départ pour la création de sous context pour la gestion
+des entités.
+
+>>> TopiaContext transaction = rootContext.beginTransaction();
+
+Création d'un sous context pour la gestion des entités.
+
+>>> transaction.commitTransaction();
+
+Validation de l'état du context, les modifications des entités sont reportées
+dans la base de données.
+
+>>> transaction.rollBackTransaction();
+
+Invalidation de l'état du context, les modifications des entités ne sont pas
+reportées dans la base de données.
+
+>>> transaction.closeContext();
+
+Relâche la connexion JDBC d'un sous context et de ses sous contexts sans
+validation de l'état des contexts.
+
+>>> rootContext.closeContext();
+
+Relâche l'ensemble des ressources (cache, pools, ...) et relâche la connexion
+JDBC des sous contexts avec validation de l'état des contexts.
+
+Manipulation des entités
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+>>> PersonDAO personDAO = <nom modele>Helper.getPersonDAO(transaction);
+
+Récupération d'un DAO pour accéder à une entité.
+
+>>> Person person = personDAO.findByTopiaId(id);
+
+Les méthodes find permettent de récupérer une ou plusieurs selon différents
+critères.
+
+>>> person.setName("tutu");
+
+Manipulation de l'entité par les getters et setters.
+
+>>> Person person = personDAO.create();
+
+Création d'une entité. Si vous utilisez l'instanciation classique java avec le
+new, l'entité n'est pas persistée.
+
+>>> personDAO.update(person);
+
+Modification d'un entité.
+
+>>> personDAO.delete(person);
+
+Suppression d'une entité.
+
+Exemple
+~~~~~~~
+
+Properties conf = Resource.getConfigProperties("/TopiaContext.properties");
+TopiaContext rootContext = TopiaContextFactory.getContext(conf);
+
+TopiaContext transaction = rootContext.beginTransaction();
+PersonDAO personDAO = ModelHelper.getPersonDAO(transaction);
+
+Person person = personDAO.create();
+person.set...(...);
+person.set...(...);
+personDAO.update(person);
+
+person.get...(...);
+person.get...(...);
+
+personDAO.delete(person);
+
+transaction.commitTransaction();
+transaction.closeContext();
+
+rootContext.closeContext();
1
0
r1282 - in topia/trunk/topia-persistence/src/main/java/org/codelutin/topia: event framework persistence persistence/hibernate
by chatellier@users.labs.libre-entreprise.org 17 Dec '08
by chatellier@users.labs.libre-entreprise.org 17 Dec '08
17 Dec '08
Author: chatellier
Date: 2008-12-17 13:08:56 +0000 (Wed, 17 Dec 2008)
New Revision: 1282
Modified:
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaEntitiesVetoable.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaContextImplementor.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaEntity.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaId.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/hibernate/FlatFilePersister.java
Log:
Fix javadoc
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaEntitiesVetoable.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaEntitiesVetoable.java 2008-12-17 11:20:34 UTC (rev 1281)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaEntitiesVetoable.java 2008-12-17 13:08:56 UTC (rev 1282)
@@ -30,6 +30,6 @@
*/
public interface TopiaEntitiesVetoable extends EventListener {
- public <E extends TopiaEntity> List<E> load(TopiaEntitiesEvent event);
+ public <E extends TopiaEntity> List<E> load(TopiaEntitiesEvent<E> event);
}
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaContextImplementor.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaContextImplementor.java 2008-12-17 11:20:34 UTC (rev 1281)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaContextImplementor.java 2008-12-17 13:08:56 UTC (rev 1282)
@@ -93,7 +93,7 @@
*
* @param <E>
* @param entityClass
- * @return
+ * @return a doa
* @throws TopiaException
*/
public <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass)
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java 2008-12-17 11:20:34 UTC (rev 1281)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java 2008-12-17 13:08:56 UTC (rev 1282)
@@ -37,8 +37,6 @@
import org.codelutin.topia.TopiaException;
import org.codelutin.topia.event.TopiaEntityListener;
import org.codelutin.topia.event.TopiaEntityVetoable;
-import org.codelutin.topia.event.TopiaTransactionListener;
-import org.codelutin.topia.event.TopiaTransactionVetoable;
import org.codelutin.topia.framework.TopiaContextImplementor;
/**
@@ -50,16 +48,18 @@
/**
* When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just
- * after
+ * after.
*
- * @param entityClass
+ * @param context context
+ * @param entityClass entity class
+ * @throws TopiaException
*/
public void init(TopiaContextImplementor context, Class<Entity> entityClass)
throws TopiaException;
/**
* Return class of entity managed by this DAO
- * @return
+ * @return entity managed by this DAO
*/
public abstract Class<Entity> getEntityClass();
@@ -69,14 +69,21 @@
public abstract TopiaContextImplementor getContext();
/**
- * appelé lorsque le context a eu un commit de fait
+ * Appelé lorsque le context a eu un commit de fait.
+ *
* TODO il faudrait peut-etre plutot faire un commit a deux phase
* car plusieurs type de persistence peuvent etre melangé, et il
* serait bien que si l'une echoué les autres echoue aussi.
+ *
+ * @throws TopiaException
*/
public void commitTransaction() throws TopiaException;
- /** appelé lorsque le context a eu un commit de fait */
+ /**
+ * Appelé lorsque le context a eu un rollback de fait.
+ *
+ * @throws TopiaException
+ */
public void rollbackTransaction() throws TopiaException;
/**
@@ -122,7 +129,7 @@
/**
* TODO modifier l'implantation pour faire un simple count sur la base
*
- * @return
+ * @return la taille de ?
* @throws TopiaException
*/
public abstract int size() throws TopiaException;
@@ -132,7 +139,7 @@
* cle naturelle est une entre de la map passe en argument.
*
* @param keys la liste des champs de la cle naturelle avec leur valeur
- * @return
+ * @return l'entite trouvé
* @throws TopiaException
*/
public abstract Entity findByPrimaryKey(Map<String, Object> keys)
@@ -144,7 +151,7 @@
* dans l'ordre de declaration dans le fichier de mapping
*
* @param k l'objet cle naturelle de la classe
- * @return
+ * @return l'entité trouvé
* @throws TopiaException
*/
public abstract Entity findByPrimaryKey(Object... k) throws TopiaException;
@@ -158,7 +165,7 @@
* @param value
* @param others les autres proprietes doivent aller par 2 propertyName,
* value
- * @return
+ * @return l'entité trouvé
* @throws TopiaException
*/
public abstract Entity findByProperties(String propertyName, Object value,
@@ -176,7 +183,7 @@
* @param value
* @param others les autres proprietes doivent aller par 2 propertyName,
* value
- * @return
+ * @return l'entité trouvé
* @throws TopiaException
*/
public abstract List<Entity> findAllByProperties(String propertyName,
@@ -191,6 +198,10 @@
/**
* Cherche et renvoie la première entité trouvée dont les propriétés en clé
* de Map contiennent toutes les valeurs de la Collection.
+ *
+ * @param properties
+ * @return l'entité trouvé
+ * @throws TopiaException
*/
public abstract Entity findContainsProperties(
Map<String, Collection> properties) throws TopiaException;
@@ -198,6 +209,12 @@
/**
* Cherche et renvoie la première entité trouvée dont la propriété
* propertyName contient values, ainsi de suite avec others.
+ *
+ * @param propertyName
+ * @param values
+ * @param others
+ * @return l'entité trouvé
+ * @throws TopiaException
*/
public abstract Entity findContainsProperties(String propertyName,
Collection values, Object... others) throws TopiaException;
@@ -205,6 +222,10 @@
/**
* Cherche et renvoie la première entité trouvée dont les propriétés en clé
* de Map contiennent toutes les valeurs de la Collection.
+ *
+ * @param properties
+ * @return l'entité trouvé
+ * @throws TopiaException
*/
public abstract List<Entity> findAllContainsProperties(
Map<String, Collection> properties) throws TopiaException;
@@ -212,14 +233,23 @@
/**
* Cherche et renvoie toutes les entités trouvées dont la propriété
* propertyName contient values, ainsi de suite avec others.
+ *
+ * @param propertyName
+ * @param values
+ * @param others
+ * @return l'entité trouvé
+ * @throws TopiaException
*/
public abstract List<Entity> findAllContainsProperties(String propertyName,
Collection values, Object... others) throws TopiaException;
/**
- * Retourne les permissions a verifier pour l'acces a l'entite pour le service Taas
+ * Retourne les permissions a verifier pour l'acces a l'entite pour le service Taas.
+ *
* @param topiaId topiaId d'une entite
+ * @param actions
* @return la liste des permissions
+ * @throws TopiaException
*/
public List<Permission> getRequestPermission(String topiaId, int actions)
throws TopiaException;
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaEntity.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaEntity.java 2008-12-17 11:20:34 UTC (rev 1281)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaEntity.java 2008-12-17 13:08:56 UTC (rev 1282)
@@ -60,7 +60,7 @@
public Date getTopiaCreateDate();
/**
- * @param topiaCreateTime The topiaCreateTime to set.
+ * @param topiaCreatedate the topiaCreateTime to set.
*/
public void setTopiaCreateDate(Date topiaCreatedate);
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaId.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaId.java 2008-12-17 11:20:34 UTC (rev 1281)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaId.java 2008-12-17 13:08:56 UTC (rev 1282)
@@ -73,6 +73,9 @@
/**
* Cree un topiaId pour une certaine classe
+ *
+ * @param clazz
+ * @return a generated topiaId
*/
public static String create(Class clazz) {
if (!clazz.isInterface()) {
@@ -88,9 +91,12 @@
}
/**
- * Extrait la classe du topiaId
- * @throws ClassNotFoundException
- */
+ * Extrait la classe du topiaId.
+ *
+ * @param topiaId
+ * @return class
+ * @throws TopiaNotFoundException
+ */
public static Class getClassName(String topiaId)
throws TopiaNotFoundException {
String classname = getClassNameAsString(topiaId);
@@ -105,10 +111,10 @@
/**
* Return class name id topiaId is id, and empty string if topiaId is
- * not an id
+ * not an id.
*
* @param topiaId
- * @return
+ * @return class name
*/
public static String getClassNameAsString(String topiaId) {
String result = "";
@@ -122,7 +128,10 @@
/**
* Verifie si l'id passé en paramètre est bien un Id topia, c-a-d si la
* forme est bien classname#timemillis#random et si le classname est
- * celui d'une classe valide, c-a-d que le systeme arrive a trouver
+ * celui d'une classe valide, c-a-d que le systeme arrive a trouver.
+ *
+ * @param topiaId
+ * @return is valid topiaId
*/
public static boolean isValidId(String topiaId) {
try {
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/hibernate/FlatFilePersister.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/hibernate/FlatFilePersister.java 2008-12-17 11:20:34 UTC (rev 1281)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/hibernate/FlatFilePersister.java 2008-12-17 13:08:56 UTC (rev 1282)
@@ -506,7 +506,6 @@
}
/**
- * @see EntityPersister#getCache()
*/
public CacheConcurrencyStrategy getCache() {
return null;
1
0
r1281 - topia/trunk/topia-ui/src/main/java/org/codelutin/topia/generator
by chatellier@users.labs.libre-entreprise.org 17 Dec '08
by chatellier@users.labs.libre-entreprise.org 17 Dec '08
17 Dec '08
Author: chatellier
Date: 2008-12-17 11:20:34 +0000 (Wed, 17 Dec 2008)
New Revision: 1281
Modified:
topia/trunk/topia-ui/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java
Log:
Correction de la javadoc
Modified: topia/trunk/topia-ui/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java
===================================================================
--- topia/trunk/topia-ui/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java 2008-12-17 11:17:45 UTC (rev 1280)
+++ topia/trunk/topia-ui/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java 2008-12-17 11:20:34 UTC (rev 1281)
@@ -367,7 +367,7 @@
* ContactListPage -> clp
*
* @param name
- * @return
+ * @return hashed state name
*/
protected String getHashStateName(String name) {
1
0
r1280 - in topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service: . servers
by chatellier@users.labs.libre-entreprise.org 17 Dec '08
by chatellier@users.labs.libre-entreprise.org 17 Dec '08
17 Dec '08
Author: chatellier
Date: 2008-12-17 11:17:45 +0000 (Wed, 17 Dec 2008)
New Revision: 1280
Modified:
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationService.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationServiceAbstract.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaServiceServerAbstract.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/servers/RemoteClassLoader.java
Log:
Correction de la javadoc
Modified: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationService.java
===================================================================
--- topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationService.java 2008-12-17 11:01:34 UTC (rev 1279)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationService.java 2008-12-17 11:17:45 UTC (rev 1280)
@@ -44,7 +44,6 @@
/**
* Detruit le service
- * @param context
*/
public void destroy();
}
Modified: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationServiceAbstract.java
===================================================================
--- topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationServiceAbstract.java 2008-12-17 11:01:34 UTC (rev 1279)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationServiceAbstract.java 2008-12-17 11:17:45 UTC (rev 1280)
@@ -45,8 +45,6 @@
/**
* Detruit le service
- *
- * @param context
*/
public void destroy() {
}
Modified: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaServiceServerAbstract.java
===================================================================
--- topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaServiceServerAbstract.java 2008-12-17 11:01:34 UTC (rev 1279)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaServiceServerAbstract.java 2008-12-17 11:17:45 UTC (rev 1280)
@@ -47,12 +47,8 @@
/**
* Disptach
*
- * @param className
- * la classe
- * @param methodName
- * le nom de la methode
- * @param args
- * les arguments
+ * @param method la methode
+ * @param args les arguments
* @return le resultat de l'appel
*/
protected Object invoke(Method method, Object[] args) {
Modified: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/servers/RemoteClassLoader.java
===================================================================
--- topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/servers/RemoteClassLoader.java 2008-12-17 11:01:34 UTC (rev 1279)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/servers/RemoteClassLoader.java 2008-12-17 11:17:45 UTC (rev 1280)
@@ -74,9 +74,6 @@
/**
* Constructeur
- *
- * @param clazz
- * la classes a convertir
*/
protected RemoteClassLoader() {
}
1
0
r1279 - topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework
by chatellier@users.labs.libre-entreprise.org 17 Dec '08
by chatellier@users.labs.libre-entreprise.org 17 Dec '08
17 Dec '08
Author: chatellier
Date: 2008-12-17 11:01:34 +0000 (Wed, 17 Dec 2008)
New Revision: 1279
Modified:
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaContextImpl.java
Log:
Add child context into child after hibernate initilialisation.
Replace hibernate deprecated code.
Replace some warningazed code.
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaContextImpl.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaContextImpl.java 2008-12-15 09:46:19 UTC (rev 1278)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaContextImpl.java 2008-12-17 11:01:34 UTC (rev 1279)
@@ -41,7 +41,6 @@
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Enumeration;
@@ -259,12 +258,14 @@
public Map<String, TopiaService> getServices() {
TopiaContextImplementor parent = getParentContext();
+
+ Map<String, TopiaService> result = null;
if (parent != null) {
- return parent.getServices();
+ result = parent.getServices();
} else {
- return services;
+ result = services;
}
-
+ return result;
}
protected boolean serviceEnabled(String name) {
@@ -533,12 +534,12 @@
TOPIA_PERSISTENCE_CLASSES, "");
for (TopiaService service : getAllServices()) {
- Class[] persistenceClasses = service
+ Class<?>[] persistenceClasses = service
.getPersistenceClasses();
// certains service n'ont pas de classe persistantes
if (persistenceClasses != null) {
- for (Class clazz : persistenceClasses) {
+ for (Class<?> clazz : persistenceClasses) {
hibernateConfiguration.addClass(clazz);
}
}
@@ -548,7 +549,7 @@
for (String classname : classes) {
classname = classname.trim();
if (!"".equals(classname)) {
- Class clazz;
+ Class<?> clazz;
try {
clazz = Class.forName(classname);
} catch (ClassNotFoundException eee) {
@@ -602,7 +603,7 @@
+ " doute oublié d'ajouter son mapping");
}
- TopiaDAO<E> result = (TopiaDAO<E>) daoCache.get(entityClass);
+ TopiaDAO<E> result = daoCache.get(entityClass);
if (result == null) {
// recherche du type de DAO a instancier pour cette entity
String defaultDAOClassname = getConfig().getProperty(
@@ -659,13 +660,12 @@
checkClosed("Ce contexte a ete ferme, impossible de commencer une transaction");
TopiaContextImpl result = new TopiaContextImpl(this);
- addChildContext(result);
SessionFactory factory = getHibernateFactory();
result.hibernate = factory.openSession();
// new TopiaInterceptor(result));
// on ne synchronise jamais les données avec la base tant que
// l'utilisateur n'a pas fait de commit du context
- result.hibernate.setFlushMode(FlushMode.NEVER);
+ result.hibernate.setFlushMode(FlushMode.MANUAL);
// 20060926 poussin ajouter pour voir si ca regle les problemes de deadlock h2
// Conclusion, il faut bien ouvrir une transaction maintenant, sinon
@@ -674,7 +674,12 @@
// de lock sur les tables.
result.hibernate.beginTransaction();
+ // 20081217 : add child AFTER hibernate session is opened
+ addChildContext(result);
+
+ // fire event
getFiresSupport().fireOnBeginTransaction(result);
+
return result;
}
@@ -739,7 +744,7 @@
// it's very important to change the session after rollback
// otherwize there are many error during next Entity's modification
hibernate = getHibernateFactory().openSession();
- hibernate.setFlushMode(FlushMode.NEVER);
+ hibernate.setFlushMode(FlushMode.MANUAL);
hibernate.beginTransaction();
1
0
15 Dec '08
Author: chatellier
Date: 2008-12-15 09:46:19 +0000 (Mon, 15 Dec 2008)
New Revision: 1278
Modified:
topia/trunk/topia-persistence/pom.xml
Log:
Add ehcache (performance api)
Modified: topia/trunk/topia-persistence/pom.xml
===================================================================
--- topia/trunk/topia-persistence/pom.xml 2008-12-15 03:17:13 UTC (rev 1277)
+++ topia/trunk/topia-persistence/pom.xml 2008-12-15 09:46:19 UTC (rev 1278)
@@ -42,6 +42,12 @@
<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>
1
0
r1277 - topia/trunk topia/trunk/topia-persistence topia/trunk/topia-soa topia/trunk/topia-ui topia-service/trunk
by tchemit@users.labs.libre-entreprise.org 15 Dec '08
by tchemit@users.labs.libre-entreprise.org 15 Dec '08
15 Dec '08
Author: tchemit
Date: 2008-12-15 03:17:13 +0000 (Mon, 15 Dec 2008)
New Revision: 1277
Modified:
topia-service/trunk/pom.xml
topia/trunk/pom.xml
topia/trunk/topia-persistence/pom.xml
topia/trunk/topia-soa/pom.xml
topia/trunk/topia-ui/pom.xml
Log:
push back scm generic values
Modified: topia/trunk/pom.xml
===================================================================
--- topia/trunk/pom.xml 2008-12-15 03:05:07 UTC (rev 1276)
+++ topia/trunk/pom.xml 2008-12-15 03:17:13 UTC (rev 1277)
@@ -119,9 +119,9 @@
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
<scm>
- <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia/trunk</connection>
- <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/topia/topia/trunk</developerConnection>
- <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia/trunk/?ro…</url>
+ <connection>${maven.scm.connection}</connection>
+ <developerConnection>${maven.scm.developerConnection}</developerConnection>
+ <url>${maven.scm.url}</url>
</scm>
</project>
Modified: topia/trunk/topia-persistence/pom.xml
===================================================================
--- topia/trunk/topia-persistence/pom.xml 2008-12-15 03:05:07 UTC (rev 1276)
+++ topia/trunk/topia-persistence/pom.xml 2008-12-15 03:17:13 UTC (rev 1277)
@@ -93,9 +93,9 @@
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
<scm>
- <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia/trunk/topia-persistence</connection>
- <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/topia/topia/trunk/topia-persistence</developerConnection>
- <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia/trunk/top…</url>
+ <connection>${maven.scm.connection.child}</connection>
+ <developerConnection>${maven.scm.developerConnection.child}</developerConnection>
+ <url>${maven.scm.url.child}</url>
</scm>
Modified: topia/trunk/topia-soa/pom.xml
===================================================================
--- topia/trunk/topia-soa/pom.xml 2008-12-15 03:05:07 UTC (rev 1276)
+++ topia/trunk/topia-soa/pom.xml 2008-12-15 03:17:13 UTC (rev 1277)
@@ -115,9 +115,9 @@
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
<scm>
- <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia/trunk/topia-soa</connection>
- <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/topia/topia/trunk/topia-soa</developerConnection>
- <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia/trunk/top…</url>
+ <connection>${maven.scm.connection.child}</connection>
+ <developerConnection>${maven.scm.developerConnection.child}</developerConnection>
+ <url>${maven.scm.url.child}</url>
</scm>
</project>
Modified: topia/trunk/topia-ui/pom.xml
===================================================================
--- topia/trunk/topia-ui/pom.xml 2008-12-15 03:05:07 UTC (rev 1276)
+++ topia/trunk/topia-ui/pom.xml 2008-12-15 03:17:13 UTC (rev 1277)
@@ -66,9 +66,9 @@
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
<scm>
- <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia/trunk/topia-ui</connection>
- <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/topia/topia/trunk/topia-ui</developerConnection>
- <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia/trunk/top…</url>
+ <connection>${maven.scm.connection.child}</connection>
+ <developerConnection>${maven.scm.developerConnection.child}</developerConnection>
+ <url>${maven.scm.url.child}</url>
</scm>
</project>
Modified: topia-service/trunk/pom.xml
===================================================================
--- topia-service/trunk/pom.xml 2008-12-15 03:05:07 UTC (rev 1276)
+++ topia-service/trunk/pom.xml 2008-12-15 03:17:13 UTC (rev 1277)
@@ -167,9 +167,9 @@
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
<scm>
- <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia-service/trunk</connection>
- <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/topia/topia-service/trunk</developerConnection>
- <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia-service/t…</url>
+ <connection>${maven.scm.connection}</connection>
+ <developerConnection>${maven.scm.developerConnection}</developerConnection>
+ <url>${maven.scm.url}</url>
</scm>
</project>
1
0