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
May 2010
- 4 participants
- 68 discussions
r1945 - trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util
by tchemit@users.nuiton.org 09 May '10
by tchemit@users.nuiton.org 09 May '10
09 May '10
Author: tchemit
Date: 2010-05-09 22:30:29 +0200 (Sun, 09 May 2010)
New Revision: 1945
Url: http://nuiton.org/repositories/revision/topia/1945
Log:
open Creator api (expose topiacontext)
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Creator.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Creator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Creator.java 2010-05-09 12:35:08 UTC (rev 1944)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Creator.java 2010-05-09 20:30:29 UTC (rev 1945)
@@ -25,6 +25,7 @@
package org.nuiton.topia.persistence.util;
+import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
/**
@@ -43,13 +44,14 @@
* <p/>
* The given <code>from</code> entity should not have already been created in
* database ? it should only be here to prepare the creation of the entity.
- *
+ * <p/>
* TODO Review this explanation :)
*
+ * @param tx the current available transaction
* @param parent the parent of the entity
* @param from the entity to create
- * @return the really created entity in database
+ * @return the really created entity in database
* @throws TopiaException if any db problem.
*/
- E create(P parent, E from) throws TopiaException;
+ E create(TopiaContext tx, P parent, E from) throws TopiaException;
}
1
0
Author: tchemit
Date: 2010-05-09 14:35:08 +0200 (Sun, 09 May 2010)
New Revision: 1944
Url: http://nuiton.org/repositories/revision/topia/1944
Log:
Utilisation de mavenpom4redmine 2.1.4
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-05-09 12:30:59 UTC (rev 1943)
+++ trunk/pom.xml 2010-05-09 12:35:08 UTC (rev 1944)
@@ -33,7 +33,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>2.1.3</version>
+ <version>2.1.4</version>
</parent>
<artifactId>topia</artifactId>
1
0
09 May '10
Author: tchemit
Date: 2010-05-09 14:30:59 +0200 (Sun, 09 May 2010)
New Revision: 1943
Url: http://nuiton.org/repositories/revision/topia/1943
Log:
prepare use of mavenpom 1.2.4
Modified:
trunk/pom.xml
trunk/topia-persistence/pom.xml
trunk/topia-persistence/src/main/java/org/nuiton/topia/event/package-info.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/package-info.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/package-info.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/package-info.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/package-info.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-05-08 18:50:02 UTC (rev 1942)
+++ trunk/pom.xml 2010-05-09 12:30:59 UTC (rev 1943)
@@ -230,7 +230,6 @@
<i18n.version>1.2.2</i18n.version>
<xmlrpc.version>3.1.2</xmlrpc.version>
<hibernate.version>3.3.2.GA</hibernate.version>
-
</properties>
<build>
Modified: trunk/topia-persistence/pom.xml
===================================================================
--- trunk/topia-persistence/pom.xml 2010-05-08 18:50:02 UTC (rev 1942)
+++ trunk/topia-persistence/pom.xml 2010-05-09 12:30:59 UTC (rev 1943)
@@ -293,6 +293,45 @@
</reporting>
</profile>
+
+ <profile>
+ <id>run-its</id>
+ <activation>
+ <property>
+ <name>performRelease</name>
+ <value>true</value>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <configuration>
+ <pomIncludes>
+ <pomInclude>copyVersionFiles/anomalie163/pom.xml</pomInclude>
+ <!--<pomInclude>**/pom.xml</pomInclude>-->
+ </pomIncludes>
+ <postBuildHookScript>verify</postBuildHookScript>
+ <localRepositoryPath>${basedir}/target/local-repo</localRepositoryPath>
+ <settingsFile>src/it/settings.xml</settingsFile>
+ <cloneProjectsTo>${project.build.directory}/its</cloneProjectsTo>
+ <!--<debug>true</debug>-->
+ </configuration>
+ <executions>
+ <execution>
+ <id>integration-test</id>
+ <goals>
+ <goal>install</goal>
+ <goal>run</goal>
+ </goals>
+ <phase>integration-test</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
</profiles>
</project>
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/event/package-info.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/event/package-info.java 2010-05-08 18:50:02 UTC (rev 1942)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/event/package-info.java 2010-05-09 12:30:59 UTC (rev 1943)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
/**
* Events used for topia services.
* TODO-fdesbois-20100507 : Need more javadoc.
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/package-info.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/package-info.java 2010-05-08 18:50:02 UTC (rev 1942)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/package-info.java 2010-05-09 12:30:59 UTC (rev 1943)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
/**
* Contains two interfaces, one {@link TopiaContextImplementor}for internal
* manipulations of {@link TopiaContext} and one {@link TopiaService}for topia
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/package-info.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/package-info.java 2010-05-08 18:50:02 UTC (rev 1942)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/package-info.java 2010-05-09 12:30:59 UTC (rev 1943)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
/**
* TODO-FD20100507 : Need update this javadoc for ToPIA 2.4
*
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/package-info.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/package-info.java 2010-05-08 18:50:02 UTC (rev 1942)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/package-info.java 2010-05-09 12:30:59 UTC (rev 1943)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
/**
* TODO-FD20100507 : Need update this javadoc for ToPIA 2.4
*
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/package-info.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/package-info.java 2010-05-08 18:50:02 UTC (rev 1942)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/package-info.java 2010-05-09 12:30:59 UTC (rev 1943)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
/**
* This package contains interfaces and abstract classes for entities and daos.
* <p />
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java 2010-05-08 18:50:02 UTC (rev 1942)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java 2010-05-09 12:30:59 UTC (rev 1943)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
package org.nuiton.topia;
import org.apache.commons.logging.Log;
1
0
r1942 - trunk/topia-persistence/src/main/java/org/nuiton/topia
by fdesbois@users.nuiton.org 08 May '10
by fdesbois@users.nuiton.org 08 May '10
08 May '10
Author: fdesbois
Date: 2010-05-08 20:50:02 +0200 (Sat, 08 May 2010)
New Revision: 1942
Url: http://nuiton.org/repositories/revision/topia/1942
Log:
Add test for TopiaContextFactory, optimize also some code
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java 2010-05-08 18:46:01 UTC (rev 1941)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java 2010-05-08 18:50:02 UTC (rev 1942)
@@ -71,9 +71,9 @@
for (Entry<Properties, TopiaContextImpl> e : contextCache.entrySet()) {
// Useless test : will never happened that e.getValue() is null,
// not allowed for {@link AbstractReferenceMap#SOFT}.
- if (e.getValue() != null) {
+// if (e.getValue() != null) {
result.add(e.getKey().getProperty("hibernate.connection.url"));
- }
+// }
}
return result;
}
1
0
r1941 - in trunk/topia-persistence/src: main/java/org/nuiton/topia main/java/org/nuiton/topia/framework test/java/org/nuiton/topia
by fdesbois@users.nuiton.org 08 May '10
by fdesbois@users.nuiton.org 08 May '10
08 May '10
Author: fdesbois
Date: 2010-05-08 20:46:01 +0200 (Sat, 08 May 2010)
New Revision: 1941
Url: http://nuiton.org/repositories/revision/topia/1941
Log:
Add test for TopiaContextFactory, optimize also some code
Added:
trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java 2010-05-08 16:05:12 UTC (rev 1940)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java 2010-05-08 18:46:01 UTC (rev 1941)
@@ -25,20 +25,23 @@
package org.nuiton.topia;
+import org.apache.commons.collections.map.AbstractReferenceMap;
+import org.apache.commons.collections.map.ReferenceMap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.framework.TopiaContextImpl;
+import org.nuiton.topia.framework.TopiaUtil;
+
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Properties;
-import java.util.Map.Entry;
-import org.apache.commons.collections.map.AbstractReferenceMap;
-import org.apache.commons.collections.map.ReferenceMap;
-import org.nuiton.topia.framework.TopiaContextImpl;
-import org.nuiton.topia.framework.TopiaUtil;
-
/**
* TODO-FD20100507 : Need javadoc + translate the one on methods.
- *
+ * <p/>
* Created: 3 janv. 2006 21:19:37
*
* @author poussin <poussin(a)codelutin.com>
@@ -47,24 +50,27 @@
*/
public class TopiaContextFactory {
- static final private String DEFAULT_CONFIG_PROPERTIES =
+ private static final Log log = LogFactory.getLog(TopiaContextFactory.class);
+
+ private static final String DEFAULT_CONFIG_PROPERTIES =
"TopiaContextImpl.properties";
- /**
- * Cache contenant tous les contexts deja créé.
- */
- static protected Map<Properties, TopiaContextImpl> contextCache =
+ /** Cache contenant tous les contexts deja créé. */
+ protected static Map<Properties, TopiaContextImpl> contextCache =
new ReferenceMap(AbstractReferenceMap.HARD,
- AbstractReferenceMap.SOFT);
+ AbstractReferenceMap.SOFT);
/**
- * Permet de connaitre la liste des contexts encore en memoire, utile
- * pour du debuggage
+ * Permet de connaitre la liste des contexts encore en memoire, utile pour
+ * du debuggage.
+ *
* @return la liste des urls de connexion
*/
- static public List<String> getContextOpened() {
+ public static List<String> getContextOpened() {
List<String> result = new ArrayList<String>();
for (Entry<Properties, TopiaContextImpl> e : contextCache.entrySet()) {
+ // Useless test : will never happened that e.getValue() is null,
+ // not allowed for {@link AbstractReferenceMap#SOFT}.
if (e.getValue() != null) {
result.add(e.getKey().getProperty("hibernate.connection.url"));
}
@@ -77,27 +83,40 @@
*
* @param context closed
*/
- static public void removeContext(TopiaContext context) {
- Properties key = null;
- for (Entry<Properties, TopiaContextImpl> e : contextCache.entrySet()) {
- if (e.getValue() == context) {
- key = e.getKey();
- break;
+ public static void removeContext(TopiaContext context) {
+// Properties key = null;
+// for (Entry<Properties, TopiaContextImpl> e : contextCache.entrySet()) {
+// if (e.getValue() == context) {
+// key = e.getKey();
+// break;
+// }
+// }
+// if (key != null) {
+// contextCache.remove(key);
+// }
+
+ // Replaced by more powerful algorithm using iterator to remove context
+
+ Iterator<TopiaContextImpl> it = contextCache.values().iterator();
+
+ boolean removed = false;
+ while (it.hasNext() && !removed) {
+ TopiaContextImpl curr = it.next();
+ if (curr == context) {
+ it.remove();
+ removed = true;
}
}
- if (key != null) {
- contextCache.remove(key);
- }
}
/**
* Utilise par defaut le fichier de propriete TopiaContextImpl.properties
- *
+ *
* @return the context using the default configuration file
* @throws TopiaNotFoundException Si le fichier de configuration par defaut
- * n'est pas retrouvé.
+ * n'est pas retrouvé.
*/
- static public TopiaContext getContext() throws TopiaNotFoundException {
+ public static TopiaContext getContext() throws TopiaNotFoundException {
Properties config = TopiaUtil.getProperties(DEFAULT_CONFIG_PROPERTIES);
TopiaContext result = getContext(config);
return result;
@@ -108,12 +127,12 @@
* fois le meme objet config, on obtient la meme instance de
* TopiaContextImpl. Si le context qui devrait etre retourné est ferme,
* alors un nouveau est creer et retourné.
- *
+ *
* @param config the configuration of the context
* @return Un TopiaContext ouvert
* @throws TopiaNotFoundException if any pb
*/
- static public TopiaContext getContext(Properties config)
+ public static TopiaContext getContext(Properties config)
throws TopiaNotFoundException {
// Put all properties from a hierarchy in the current properties object.
// Resolve problem with hibernate which used iterator to get properties
@@ -123,9 +142,15 @@
config.setProperty(key, config.getProperty(key));
}
TopiaContextImpl result = contextCache.get(config);
- if (result == null || result.isClosed()) {
+ // useless test, context is automatically removed from Factory when closed
+ if (result == null/* || result.isClosed()*/) {
result = new TopiaContextImpl(config);
+ if (log.isDebugEnabled()) {
+ log.debug("instantiate new topiaContext : " + result);
+ }
contextCache.put((Properties) config.clone(), result);
+ } else if (log.isDebugEnabled()) {
+ log.debug("topiaContext found : " + result);
}
return result;
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2010-05-08 16:05:12 UTC (rev 1940)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2010-05-08 18:46:01 UTC (rev 1941)
@@ -813,7 +813,7 @@
hibernateFactory.close();
closed = true;
TopiaContextFactory.removeContext(this);
- log.debug("TopiaContext finalized");
+ log.debug("TopiaContext removed");
}
}
}
Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java 2010-05-08 18:46:01 UTC (rev 1941)
@@ -0,0 +1,156 @@
+package org.nuiton.topia;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.nuiton.topia.framework.TopiaContextImpl;
+
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * Created: 8 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class TopiaContextFactoryTest {
+
+ private static final Log log =
+ LogFactory.getLog(TopiaContextFactoryTest.class);
+
+ protected Properties properties;
+
+ @Before
+ public void setUp() throws Exception {
+ properties = new Properties();
+ properties.setProperty("prop1", "value1");
+ properties.setProperty("prop2", "value2");
+ TopiaContextFactory.contextCache.clear();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testGetContextOpened() throws Exception {
+ log.info("## testGetContextOpened");
+
+ /** PREPARE DATA **/
+ String databaseName = "h2data-testGetContextByPropertie";
+ String url = "jdbc:h2:file:target/surefire-data/" + databaseName;
+ properties.setProperty("hibernate.connection.url", url);
+
+ TopiaContextImpl test = new TopiaContextImpl(properties);
+ TopiaContextFactory.contextCache.put(properties, test);
+
+ /** EXEC METHOD **/
+ List<String> result = TopiaContextFactory.getContextOpened();
+ Assert.assertEquals(1, result.size());
+ Assert.assertEquals(url, result.get(0));
+ }
+
+ @Test
+ public void testRemoveContext() throws Exception {
+ log.info("## testRemoveContext");
+
+ /** PREPARE DATA **/
+ TopiaContextImpl test = new TopiaContextImpl(properties);
+ TopiaContextFactory.contextCache.put(properties, test);
+
+ /** EXEC METHOD **/
+ TopiaContextFactory.removeContext(test);
+ Assert.assertEquals(0, TopiaContextFactory.contextCache.size());
+ }
+
+ //@Test
+ public void testGetContext() throws Exception {
+ // TODO-fdesbois-20100508 : only used TopiaUtil.getProperties, need tests for this method
+ }
+
+ @Test
+ public void testGetContextByProperties() throws Exception {
+ log.info("## testGetContextByProperties");
+
+ /** PREPARE DATA **/
+ Properties propertiesParent = new Properties(properties);
+ propertiesParent.setProperty("prop3", "value3");
+
+ Properties propertiesAll = new Properties();
+ propertiesAll.setProperty("prop1", "value1");
+ propertiesAll.setProperty("prop2", "value2");
+ propertiesAll.setProperty("prop3", "value3");
+
+ /** EXEC METHOD **/
+
+ log.info("test 0 : add null properties");
+ try {
+ TopiaContextFactory.getContext(null);
+ } catch (Exception eee) {
+ Assert.assertEquals(NullPointerException.class, eee.getClass());
+ }
+
+ log.info("test 1 : add new properties, will instantiate a new" +
+ " TopiaContext");
+ TopiaContext test1 = TopiaContextFactory.getContext(propertiesParent);
+ Assert.assertNotNull(test1);
+ Assert.assertEquals(1, TopiaContextFactory.contextCache.size());
+
+ log.info("test 2 : with same properties, will retrieve existing" +
+ " TopiaContext");
+ TopiaContext test2 = TopiaContextFactory.getContext(propertiesParent);
+ Assert.assertEquals(test1, test2);
+ Assert.assertEquals(1, TopiaContextFactory.contextCache.size());
+
+ log.info("test 3 : use other properties, will instantiate a different" +
+ "TopiaContext");
+ TopiaContext test3 = TopiaContextFactory.getContext(properties);
+ log.debug("cache size : " + TopiaContextFactory.contextCache.size());
+ log.debug("result : " + test1);
+ log.debug("result3 : " + test3);
+ Assert.assertNotSame(test1, test3);
+ Assert.assertEquals(2, TopiaContextFactory.contextCache.size());
+
+ log.info("test 4 : use other properties but equivalent to existing " +
+ "TopiaContext");
+ // Test flating of properties
+ TopiaContext test4 = TopiaContextFactory.getContext(propertiesAll);
+ Assert.assertEquals(test1, test4);
+ Assert.assertEquals(2, TopiaContextFactory.contextCache.size());
+
+ log.info("test5a : reinstantiate new TopiaContext after one is closed.");
+ // TEST
+ // Strange behavior the closed flag of context stay true if
+ // hibernateFactory is not loaded from real properties
+// test1.closeContext();
+// Assert.assertTrue(test1.isClosed());
+
+ // Add properties for Hibernate to have real opened topiaContext
+ String databaseName = "h2data-testGetContextByPropertie";
+ properties.setProperty("hibernate.connection.username", "sa");
+ properties.setProperty("hibernate.connection.password", "");
+ properties.setProperty("hibernate.connection.driver_class", "org.h2.Driver");
+ properties.setProperty("hibernate.connection.url",
+ "jdbc:h2:file:target/surefire-data/" + databaseName);
+
+
+ TopiaContext test5 = TopiaContextFactory.getContext(properties);
+ Assert.assertNotSame(test1, test5);
+ Assert.assertEquals(3, TopiaContextFactory.contextCache.size());
+
+ log.info("test5b : beginTransaction to properly close the context");
+ test5.beginTransaction();
+
+ test5.closeContext();
+
+ TopiaContext result = TopiaContextFactory.getContext(properties);
+ Assert.assertNotSame(test5, result);
+ Assert.assertEquals(3, TopiaContextFactory.contextCache.size());
+
+
+ }
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
1
0
r1940 - trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence
by fdesbois@users.nuiton.org 08 May '10
by fdesbois@users.nuiton.org 08 May '10
08 May '10
Author: fdesbois
Date: 2010-05-08 18:05:12 +0200 (Sat, 08 May 2010)
New Revision: 1940
Url: http://nuiton.org/repositories/revision/topia/1940
Log:
Clean headers + add some javadoc
Added:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/package-info.java
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DepthEntityVisitor.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HorizontalEntityVisitor.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/SearchFields.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityEnum.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DepthEntityVisitor.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DepthEntityVisitor.java 2010-05-08 11:11:15 UTC (rev 1939)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DepthEntityVisitor.java 2010-05-08 16:05:12 UTC (rev 1940)
@@ -35,11 +35,9 @@
/**
* Parcourt du graphe d'entité en profondeur.
*
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
+ * @author chatellier <chatellier(a)codelutin.com>
+ * @author tchemit <tchemit(a)codelutin.com>
+ * @version $Id$
*/
public class DepthEntityVisitor implements EntityVisitor {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HorizontalEntityVisitor.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HorizontalEntityVisitor.java 2010-05-08 11:11:15 UTC (rev 1939)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HorizontalEntityVisitor.java 2010-05-08 16:05:12 UTC (rev 1940)
@@ -36,11 +36,9 @@
/**
* Parcourt en largeur du modele et délegation à un autre visiteur.
*
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
+ * @author chatellier <chatellier(a)codelutin.com>
+ * @author tchemit <tchemit(a)codelutin.com>
+ * @version $Id$
*/
public class HorizontalEntityVisitor implements EntityVisitor {
@@ -121,7 +119,7 @@
// here, must revisit all remembered entities
List<TopiaEntity> currentEntities =
new ArrayList<TopiaEntity>(toVisitEntities);
- // TODO verify if clearing here is enough
+ // TODO-chatellier-20091221 : verify if clearing here is enough
toVisitEntities.clear();
for (TopiaEntity currentEntity : currentEntities) {
try {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/SearchFields.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/SearchFields.java 2010-05-08 11:11:15 UTC (rev 1939)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/SearchFields.java 2010-05-08 16:05:12 UTC (rev 1940)
@@ -44,6 +44,9 @@
import java.lang.annotation.Target;
/**
+ *
+ * TODO-fdesbois-20100508 : javadoc : where is it used for ? which service use it ?
+ *
* Ces annotations permettent de savoir quels sont les champs sur lesquels
* la recherche pourra s'effectuer.
*/
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2010-05-08 11:11:15 UTC (rev 1939)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2010-05-08 16:05:12 UTC (rev 1940)
@@ -61,6 +61,7 @@
* DAOAbstractTransformer} for abstract implementation and {@link
* DAOImplTransformer} for final implementation class.
*
+ * TODO-fdesbois-20100508 : Need translation of javadoc.
*
* @author poussin <poussin(a)codelutin.com>
* @author fdesbois <fdesbois(a)codelutin.com>
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2010-05-08 11:11:15 UTC (rev 1939)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2010-05-08 16:05:12 UTC (rev 1940)
@@ -37,49 +37,50 @@
package org.nuiton.topia.persistence;
-import java.io.Serializable;
-import java.lang.reflect.InvocationTargetException;
-import java.security.Permission;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.FlushMode;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.metadata.ClassMetadata;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.event.TopiaEntityListener;
import org.nuiton.topia.event.TopiaEntityVetoable;
import org.nuiton.topia.framework.TopiaContextImplementor;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.criterion.Criterion;
-import org.hibernate.criterion.Restrictions;
-import org.hibernate.metadata.ClassMetadata;
import org.nuiton.topia.framework.TopiaQuery;
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.security.Permission;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
/**
- * Cette classe permet d'avoir un ensemble de méthode implantée de façon
+ * TODO-fdesbois-20100508 : Need translation of javadoc.
+ * <p/>
+ * Cette classe permet d'avoir un ensemble de méthode implantée de façon
* standard et plus spécifiquement pour Hibernate.
+ * <p/>
+ * Certains accès à Hibernate sont tout de même fait ici, car on a pris le choix
+ * de se baser entièrement sur hibernate pour la persistence, et il est ainsi
+ * possible d'accèder au meta information hibernate sur les classes lorque l'on
+ * en a besoin.
*
- * Certains accès à Hibernate sont tout de même fait ici, car on a pris le
- * choix de se baser entièrement sur hibernate pour la persistence, et il
- * est ainsi possible d'accèder au meta information hibernate sur les classes
- * lorque l'on en a besoin.
- *
+ * @author poussin <poussin(a)codelutin.com>
+ * @version $Id$
* @param <E> le type de l'entite
- * @author poussin <poussin(a)codelutin.com>
- *
*/
public class TopiaDAOImpl<E extends TopiaEntity> implements
TopiaDAO<E> { // TopiaDAOImpl
+
/** to use log facility, just put in your code: log.info(\"...\"); */
private static Log log = LogFactory.getLog(TopiaDAOImpl.class);
@@ -95,6 +96,7 @@
/**
* Retourne l'id de l'entity
+ *
* @param e l'entity
* @return l'id de l'entity ou null si pas trouvé
* @throws TopiaException Si une erreur survient durant la recherche
@@ -126,6 +128,7 @@
/**
* Retourne l'id de l'entity representer comme une map
+ *
* @param map l'entity en representation map
* @return l'id de l'entity ou null si pas trouvé
* @throws TopiaException Si une erreur survient durant la recherche
@@ -252,8 +255,9 @@
}
/**
- * Callback method when context was commit.
- * By default, the method does nothing
+ * Callback method when context was commit. By default, the method does
+ * nothing
+ *
* @throws TopiaException
*/
@Override
@@ -261,8 +265,9 @@
}
/**
- * Callback method when context was rollback.
- * By default, the method does nothing
+ * Callback method when context was rollback. By default, the method does
+ * nothing
+ *
* @throws TopiaException
*/
@Override
@@ -360,7 +365,7 @@
@Override
public E findByProperties(String propertyName, Object value,
- Object... others) throws TopiaException {
+ Object... others) throws TopiaException {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(propertyName, value);
Object name = null;
@@ -387,7 +392,7 @@
@Override
public List<E> findAllByProperties(String propertyName, Object value,
- Object... others) throws TopiaException {
+ Object... others) throws TopiaException {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(propertyName, value);
Object name = null;
@@ -419,13 +424,13 @@
E result = null;
if (!results.isEmpty()) {
result = results.get(0);
- }
+ }
return result;
}
@Override
public E findContainsProperties(String propertyName,
- Collection<?> values, Object... others) throws TopiaException {
+ Collection<?> values, Object... others) throws TopiaException {
Map<String, Collection<?>> properties = new HashMap<String, Collection<?>>();
properties.put(propertyName, values);
Object name = null;
@@ -451,19 +456,18 @@
}
/**
- * Find all entities with a specific rule :
- * When the entity have a Collection type property, you want to find all
- * entites where some values are contained in the collection type property.
- * Example entity parameter : private Collection<Date> historicalDates;
- * You want some dates to be contained in historicalDates.
- * Collection<Date> myDates...
- * myDates.add(date1) ...
- * Map<String, Collection> properties = new HashMap<String,Collection>();
- * properties.put("historicalDates",myDates);
+ * Find all entities with a specific rule : When the entity have a
+ * Collection type property, you want to find all entites where some values
+ * are contained in the collection type property. Example entity parameter :
+ * private Collection<Date> historicalDates; You want some dates to be
+ * contained in historicalDates. Collection<Date> myDates...
+ * myDates.add(date1) ... Map<String, Collection> properties = new
+ * HashMap<String,Collection>(); properties.put("historicalDates",myDates);
* findAllContainsProperties(properties);
+ *
* @param properties
* @return the list of entities corresponding to the request
- * @throws TopiaException if any pb
+ * @throws TopiaException if any pb
*/
@Override
public List<E> findAllContainsProperties(Map<String,
@@ -521,7 +525,7 @@
@Override
public List<E> findAllContainsProperties(String propertyName,
- Collection<?> values, Object... others) throws TopiaException {
+ Collection<?> values, Object... others) throws TopiaException {
Map<String, Collection<?>> properties = new HashMap<String, Collection<?>>();
properties.put(propertyName, values);
Object name = null;
@@ -580,12 +584,12 @@
@Override
public void addTopiaEntityListener(TopiaEntityListener listener) {
- getContext().addTopiaEntityListener(entityClass,listener);
+ getContext().addTopiaEntityListener(entityClass, listener);
}
@Override
public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- getContext().addTopiaEntityVetoable(entityClass,vetoable);
+ getContext().addTopiaEntityVetoable(entityClass, vetoable);
}
@Override
@@ -619,9 +623,9 @@
}
/**
- * Cette methode appelle fireVetoableCreate et fireOnCreated
- * Si vous la surchargé, faites attention a appeler le super
- * ou a appeler vous aussi ces deux methodes.
+ * Cette methode appelle fireVetoableCreate et fireOnCreated Si vous la
+ * surchargé, faites attention a appeler le super ou a appeler vous aussi
+ * ces deux methodes.
*/
@Override
public E create(Map<String, Object> properties) throws TopiaException {
@@ -732,7 +736,7 @@
throws TopiaException {
return query.executeToEntityMap(context, getEntityClass(), keyName,
keyClass);
- }
+ }
@Override
public List<E> findAllWithOrder(String... propertyNames)
@@ -758,9 +762,8 @@
}
/**
- * Count number of existing entities using
- * {@link TopiaQuery#executeCount(TopiaContext) }
- * FIXME-FD20091224 change type to int like in 2.2.2 version
+ * Count number of existing entities using {@link TopiaQuery#executeCount(TopiaContext)
+ * } FIXME-FD20091224 change type to int like in 2.2.2 version
*
* @return a long for the number of entities in database
*/
@@ -874,6 +877,7 @@
/**
* TODO-TC20100225 Should this method deprecated (it is never used ?)
* Renvoie un Criteria créé avec l'entityClass
+ *
* @param mode le FlushMode du Criteria
* @return le Criteria nouvellement créé
* @throws TopiaException if any pb
@@ -886,6 +890,7 @@
/**
* Renvoie la Session contenue dans le contexte
+ *
* @return hibernate session
* @throws TopiaException if any pb
*/
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2010-05-08 11:11:15 UTC (rev 1939)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2010-05-08 16:05:12 UTC (rev 1940)
@@ -58,6 +58,7 @@
* d'entité si cela ne pose pas d'autre probleme (heritage entre ces entités).
*
* @author poussin <poussin(a)codelutin.com>
+ * @ version $Id$
*/
public abstract class TopiaEntityAbstract implements TopiaEntity, Serializable {
@@ -189,7 +190,7 @@
*/
@Override
public int hashCode() {
- Date date = getTopiaCreateDate();
+ Date date = getCreateDate();
//TC-20100220 : il se peut que la date de creation soit nulle
// lorsque l'entite est utilise comme objet d'edition d'un formulaire
// par exemple...
@@ -208,16 +209,14 @@
if (this == obj) {
return true;
}
- //TC-20100220 : test farfeulu :)
- //if (obj instanceof TopiaEntity == false) {
if (!(obj instanceof TopiaEntity)) {
return false;
}
TopiaEntity other = (TopiaEntity) obj;
- if (getTopiaId() == null || other.getId() == null) {
+ if (getId() == null || other.getId() == null) {
return false;
}
- boolean result = getTopiaId().equals(other.getId());
+ boolean result = getId().equals(other.getId());
return result;
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityEnum.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityEnum.java 2010-05-08 11:11:15 UTC (rev 1939)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityEnum.java 2010-05-08 16:05:12 UTC (rev 1940)
@@ -43,6 +43,7 @@
* - a method to accept any TopiaEntity class for this entity description
*
* @author tchemit <chemit(a)codelutin.com>
+ * @version $Id$
* @since 2.2.0
*/
public interface TopiaEntityEnum {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java 2010-05-08 11:11:15 UTC (rev 1939)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java 2010-05-08 16:05:12 UTC (rev 1940)
@@ -38,16 +38,23 @@
package org.nuiton.topia.persistence;
+import org.nuiton.topia.TopiaNotFoundException;
+
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
-import org.nuiton.topia.TopiaNotFoundException;
-
/**
-* Classe representant un Id, utilisable par JDO. Cette classe contient aussi un
-* ensemble de methode static utile pour la manipulation des topiaId
-*/
+ * TODO-fdesbois-20100508 : Need translation of javadoc.
+ *
+ * Classe representant un Id, utilisable par JDO. Cette classe contient aussi un ensemble de methode
+ * static utile pour la manipulation des topiaId
+ *
+ * @author poussin <poussing(a)codelutin.com>
+ * @author tchemit <tchemit(a)codelutin.com>
+ * @author chatellier <chatellier(a)codelutin.com>
+ * @version $Id$
+ */
public class TopiaId implements Serializable { // TopiaId
/** */
@@ -84,11 +91,11 @@
}
/**
- * Cree un topiaId pour une certaine classe
- *
- * @param clazz
+ * Cree un topiaId pour une certaine classe
+ *
+ * @param clazz
* @return a generated topiaId
- */
+ */
public static String create(Class clazz) {
if (!clazz.isInterface()) {
throw new IllegalArgumentException(
@@ -104,10 +111,10 @@
/**
* Extrait la classe du topiaId.
- *
- * @param topiaId
+ *
+ * @param topiaId
* @return class
- * @throws TopiaNotFoundException
+ * @throws TopiaNotFoundException
*/
public static Class getClassName(String topiaId)
throws TopiaNotFoundException {
@@ -122,9 +129,9 @@
}
/**
- * Return class name id topiaId is id, and empty string if topiaId is
- * not an id.
- *
+ * Return class name id topiaId is id, and empty string if topiaId is not an
+ * id.
+ *
* @param topiaId
* @return class name
*/
@@ -138,13 +145,13 @@
}
/**
- * 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.
- *
- * @param topiaId
+ * 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.
+ *
+ * @param topiaId
* @return is valid topiaId
- */
+ */
public static boolean isValidId(String topiaId) {
try {
if (topiaId.matches(".*?#[0-9]+#[0-9.]+")) {
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/package-info.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/package-info.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/package-info.java 2010-05-08 16:05:12 UTC (rev 1940)
@@ -0,0 +1,13 @@
+/**
+ * This package contains interfaces and abstract classes for entities and daos.
+ * <p />
+ * For daos : {@link TopiaDAO} as interface and {@link TopiaDAImpl} as
+ * implementation.
+ * <p />
+ * For entities : {@link TopiaEntity} as interface and {@link
+ * TopiaEntityAbstract} as abstract class inherited by generated entities for
+ * final applications. Generation is done using transformers from {@code
+ * org.nuiton.topia.generator} package.
+ *
+ */
+package org.nuiton.topia.persistence;
\ No newline at end of file
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/package-info.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
1
0
r1939 - in trunk/topia-persistence/src: main/java/org/nuiton/topia/generator test/java/org/nuiton/topiatest/deletetest test/resources
by fdesbois@users.nuiton.org 08 May '10
by fdesbois@users.nuiton.org 08 May '10
08 May '10
Author: fdesbois
Date: 2010-05-08 13:11:15 +0200 (Sat, 08 May 2010)
New Revision: 1939
Url: http://nuiton.org/repositories/revision/topia/1939
Log:
Test for Evo #580 : problem with inheritance.
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java
trunk/topia-persistence/src/test/resources/log4j.properties
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java 2010-05-07 20:50:21 UTC (rev 1938)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java 2010-05-08 11:11:15 UTC (rev 1939)
@@ -33,6 +33,7 @@
import org.nuiton.eugene.models.object.*;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaContextImplementor;
+import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaDAOImpl;
import org.nuiton.topia.persistence.TopiaEntity;
@@ -294,7 +295,7 @@
PROP_DEFAULT_PACKAGE) + '.' + modelName +
"DAOHelper.getImplementationClass";
for (ObjectModelAttribute attr : clazz.getAttributes()) {
- String attrType = attr.getType();
+ String attrType = GeneratorUtil.getSimpleName(attr.getType());
String reverseAttrName = attr.getReverseAttributeName();
ObjectModelAttribute reverse = attr.getReverseAttribute();
if (!attr.hasAssociationClass() && reverse != null && reverse.isNavigable()
@@ -306,7 +307,33 @@
String attrClassifierDBName = TopiaGeneratorUtil.getDBName(attr.getClassifier());
String attrJoinTableName = TopiaGeneratorUtil.getManyToManyTableName(attr);
String attrReverseDBName = TopiaGeneratorUtil.getReverseDBName(attr);
+
//FIXME_-FC-20100413 Use a TopiaQuery (use HQLin elements)
+// // Add DAOHelper
+// String daoHelper = modelName + "DAOHelper";
+// String daoHelperFQN = getOutputProperties().
+// getProperty(PROP_DEFAULT_PACKAGE) + '.' + daoHelper;
+// addImport(result, daoHelperFQN);
+//
+// // Add import for TopiaQuery
+// addImport(result, TopiaQuery.class);
+//
+// // Entity DAO and reversePropertyName
+// String entityDAO = attrType + "DAO";
+// String reverseAttrNameProperty =
+// attrType + "." + getConstantName(reverseAttrName);
+//
+//
+// <%=entityDAO%> dao = <%=daoHelper%>.get<%=entityDAO%>(getContext());
+// TopiaQuery query = dao.createQuery("B").
+// addFrom(entity.getClass(), "A").
+// add("A", entity).
+// addInElements("A", "B." + <%=reverseAttrNameProperty%>);
+//
+// System.out.println("Query : " + query);
+// List<<%=attrType%>> list = dao.findAllByQuery(query);
+
+
body.append(""
/*{
{
@@ -316,6 +343,7 @@
"where main.topiaid=secondary.<%=attrDBName%>" +
" and secondary.<%=attrReverseDBName%>='" + entity.getTopiaId() + "'")
.addEntity("main", <%=providerFQN%>(<%=attrType%>.class)).list();
+
for (<%=attrType%> item : list) {
item.remove<%=StringUtils.capitalize(reverseAttrName)%>(entity);
}
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java 2010-05-07 20:50:21 UTC (rev 1938)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java 2010-05-08 11:11:15 UTC (rev 1939)
@@ -191,7 +191,7 @@
log.debug("ADD CONTACT TO PERSONNE");
personne.addContacts(contact);
transaction.commitTransaction();
- assertEquals(personne.getContacts().size(),1);
+ assertEquals(1, personne.getContacts().size());
log.debug("CONTACT ADDED !");
log.debug("DELETE PERSONNE");
@@ -201,7 +201,7 @@
assertNull(res);
log.debug("ENTITY PERSONNE DELETED !");
- assertEquals(contact.getParty2().size(),0);
+ assertEquals(0, contact.getParty2().size());
log.debug("DELETE CONTACT");
contactDAO.delete(contact);
Modified: trunk/topia-persistence/src/test/resources/log4j.properties
===================================================================
--- trunk/topia-persistence/src/test/resources/log4j.properties 2010-05-07 20:50:21 UTC (rev 1938)
+++ trunk/topia-persistence/src/test/resources/log4j.properties 2010-05-08 11:11:15 UTC (rev 1939)
@@ -8,4 +8,5 @@
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n
# package level
log4j.logger.org.nuiton.topia=INFO
+#log4j.logger.org.nuiton.topiatest=DEBUG
log4j.logger.org.nuiton.topia.persistence.util=INFO
1
0
Author: fdesbois
Date: 2010-05-07 22:50:21 +0200 (Fri, 07 May 2010)
New Revision: 1938
Url: http://nuiton.org/repositories/revision/topia/1938
Log:
- Evo #578 : start put deprecated methods for entities and daos.
- Add javadoc for TopiaEntity and TopiaDAO
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/EntityVisitor.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityRef.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/ExportXMLVisitor.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/EntityOperatorTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityBinderTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityRefTester.java
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/ManualMigrationEngine.java
trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachAssociation.java
trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachLink.java
trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractReplicationEngineTest.java
trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/ReplicationEngineTest.java
trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java
trunk/topia-service-security/src/main/java/org/nuiton/topia/security/TopiaSecurityServiceImpl.java
trunk/topia-service-security/src/main/java/org/nuiton/topia/security/jaas/TopiaLoginModule.java
trunk/topia-service-security/src/main/java/org/nuiton/topia/security/util/TopiaSecurityFactoryFilter.java
trunk/topia-service-security/src/main/java/org/nuiton/topia/security/util/TopiaSecurityUtil.java
trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/TaasService.java
trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/event/TaasEntityVetoable.java
trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/event/TaasEntityVetoableRequestPermission.java
trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/jaas/TaasLoginModule.java
trunk/topia-service-security/src/test/java/org/nuiton/topia/security/TopiaSecurityTest.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -710,6 +710,7 @@
try {
for (TopiaDAO<? extends TopiaEntity> dao : daoCache.values()) {
+ // TODO-fdesbois-20100507 : need to be removed for 2.5 version
dao.commitTransaction();
}
Transaction tx = hibernate.getTransaction();
@@ -754,6 +755,7 @@
"rollback"));
try {
for (TopiaDAO<? extends TopiaEntity> dao : daoCache.values()) {
+ // TODO-fdesbois-20100507 : need to be removed for 2.5 version
dao.rollbackTransaction();
}
Transaction tx = hibernate.getTransaction();
@@ -922,8 +924,8 @@
/**
* Execute HQL operation on data (Update, Delete)
*
- * @param hql
- * @param args
+ * @param hql HQL query
+ * @param args arguments for query
* @return The number of entities updated or deleted.
* @throws TopiaException
*/
@@ -956,7 +958,7 @@
"topia.persistence.error.unsupported.operation.on.closed.context",
"add"));
- String id = e.getTopiaId();
+ String id = e.getId();
Class<TopiaEntity> entityClass = TopiaId.getClassName(id);
TopiaDAO<TopiaEntity> dao = getDAO(entityClass);
dao.update(e);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -1004,7 +1004,7 @@
TopiaContext transaction, Class<E> entityClass)
throws TopiaException, ClassCastException {
return executeToEntityMap(transaction, entityClass,
- TopiaEntity.TOPIA_ID, String.class);
+ TopiaEntity.ID, String.class);
}
/**
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -68,7 +68,7 @@
* Logger
*/
private static final Log log = LogFactory.getLog(TopiaGeneratorUtil.class);
-
+
/**
* Stéréotype pour les interfaces devant être générées sous forme de facades
*/
@@ -404,31 +404,6 @@
* 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.
- * @deprecated since 2.3.0 use
- * {@link #getNaturalIdAttributes(ObjectModelClass) } instead
- * this usage is not allowed, prefer put tagvalue.naturalId on each
- * entity attribute needed
- */
- @Deprecated
- public static List<String> getNaturalId(ObjectModelClass clazz) {
- String value = clazz.getTagValue(TAG_NATURAL_ID);
- if (value == null || value.trim().isEmpty()) {
- return Collections.emptyList();
- }
- List<String> result = new ArrayList<String>();
- for (String attribute : value.split(",")) {
- result.add(attribute.trim());
- }
- return result;
- }
-
- /**
- * 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
*/
public static List<ObjectModelAttribute> getNaturalIdAttributes(
@@ -802,12 +777,6 @@
result = revers + '_' + name;
}
}
- // String result;
- // if (!Util.isFirstAttribute(attr)) {
- // result = attr.getDeclaringElement().getName() + "_" + attr.getReverseAttribute().getDeclaringElement().getName();
- // } else {
- // result = attr.getReverseAttribute().getDeclaringElement().getName() + "_" + attr.getDeclaringElement().getName();
- // }
return result.toLowerCase();
}
@@ -971,29 +940,6 @@
}
/**
- *
- * @param fqn fqn to parse
- * @return the simple name of fqn
- * @deprecated since 2.0.2 : already in GeneratorUtil
- */
- @Deprecated
- public static String getSimpleName(String fqn) {
- return GeneratorUtil.getSimpleName(fqn);
-// int lasIndex = fqn.lastIndexOf(".");
-// if (lasIndex == 1) {
-// // primitive type
-// return fqn;
-// }
-// return fqn.substring(lasIndex + 1);
- /*if (lasIndex == aClass.getPackageName().length()) {
- // same package
- return fqn.substring(lasIndex + 1);
- }
-
- return fqn;*/
- }
-
- /**
* Obtain the list of fqn of object involed in the given class.
*
* @param aClass the class to inspect
@@ -1116,39 +1062,6 @@
return result;
}
- /**
- * Convertit un nom de variable en nom de constante.
- *
- * @param variableName le nom de variable a convertir
- * @return le nom de la constante à partir du nom de la variable
- * @deprecated since 2.3, prefer use the
- * {@link org.nuiton.eugene.java.ConstantsManagerExtension}. Will be removed
- * in version 3.
- */
- @Deprecated
- public static String convertVariableNameToConstantName(String variableName) {
- //TODO Faire des tests pour savoir si variableName est non null et valide
- //TODO Ameliorer l'algo pour tenir compte des caractères non alpha
- //TODO pour le moment cela convient, donc...
- StringBuilder buffer = new StringBuilder();
- boolean lastCarIsUp = false;
- for (int i = 0, j = variableName.length(); i < j; i++) {
- char c = variableName.charAt(i);
- boolean carIsUp = Character.isUpperCase(c);
- if (i > 0 && !lastCarIsUp && carIsUp) {
- // ajout d'un _
- buffer.append('_');
- }
- if (carIsUp) {
- buffer.append(c);
- } else {
- buffer.append(Character.toUpperCase(c));
- }
- lastCarIsUp = carIsUp;
- }
- return buffer.toString();
- }
-
public static Map<ObjectModelClass, Set<ObjectModelClass>>
searchDirectUsages(ObjectModel model) {
List<ObjectModelClass> allEntities;
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/EntityVisitor.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/EntityVisitor.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/EntityVisitor.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -31,10 +31,7 @@
* Created: 28 janv. 2009 18:10:34
*
* @author poussin <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
+ * @version $Id$
*/
public interface EntityVisitor {
@@ -97,7 +94,7 @@
/**
* Reset all states of the visitor.
*
- * TODO called by who ? what is it for ?
+ * TODO-chatellier-20091221 : need explanations : called by who ? what is it for ?
*/
void clear();
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -36,131 +36,155 @@
*/
package org.nuiton.topia.persistence;
-import java.security.Permission;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.event.TopiaEntityListener;
import org.nuiton.topia.event.TopiaEntityVetoable;
import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.generator.DAOAbstractTransformer;
+import org.nuiton.topia.generator.DAOImplTransformer;
+import org.nuiton.topia.generator.DAOTransformer;
+import java.security.Permission;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
/**
+ * TopiaDAO is used to manipulate entities corresponding to {@code E} type :
+ * create, delete, update or find entities using properties of {@link
+ * TopiaQuery}.
+ * <p />
+ * This interface is implemented by {@link TopiaDAOImpl} overriden by generation
+ * from {@link DAOTransformer} for specific entity interface, {@link
+ * DAOAbstractTransformer} for abstract implementation and {@link
+ * DAOImplTransformer} for final implementation class.
+ *
+ *
* @author poussin <poussin(a)codelutin.com>
- *
- * @param <Entity>
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ * @param <E> the entity type linked with the dao
*/
-public interface TopiaDAO<Entity extends TopiaEntity> {
+public interface TopiaDAO<E extends TopiaEntity> {
/**
* When TopiaContextImpl create the TopiaDAOHibernate, it must call this
* method just after.
- *
- * @param context context
+ *
+ * @param context context
* @param entityClass entity class
- * @throws TopiaException if any pb while init
+ * @throws TopiaException if any pb while init
*/
- void init(TopiaContextImplementor context, Class<Entity> entityClass)
+ void init(TopiaContextImplementor context, Class<E> entityClass)
throws TopiaException;
/**
* Create a new instance of managed entity.
- *
+ *
* @return new entity instance
+ * @throws TopiaException if any pb while creating the entitie
* @since 2.3.1
- * @throws TopiaException if any pb while creating the entitie
*/
- Entity newInstance() throws TopiaException;
+ E newInstance() throws TopiaException;
/**
* Return class of entity managed by this DAO.
- *
+ *
* @return entity managed by this DAO
*/
- Class<Entity> getEntityClass();
+ Class<E> getEntityClass();
/**
* Return context used by this DAO.
- *
+ *
* @return Returns the context.
*/
TopiaContextImplementor getContext();
/**
* Appelé lorsque le context a eu un commit de fait.
- *
- * TODO il faudrait peut-etre plutot faire un commit a deux phase
- * car plusieurs type de persistence peuvent etre melangé, et il
- * serait bien que si l'une echoué les autres echoue aussi.
- *
+ * <p/>
+ * 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 if any pb while commit
+ * @deprecated since 2.4 do nothing in dao implementation generated, not
+ * well placed
*/
+ @Deprecated
void commitTransaction() throws TopiaException;
/**
* Appelé lorsque le context a eu un rollback de fait.
- *
+ *
* @throws TopiaException if any pb while rollback
+ * @deprecated since 2.4 do nothing in dao implementation generated, not
+ * well placed
*/
+ @Deprecated
void rollbackTransaction() throws TopiaException;
/**
* Construit une nouvelle instance de l'objet géré par ce DAO
- * @param properties la liste des propriétés que doit avoir l'objet créé
- * les arguments vont par paire (propertyName, value)
+ *
+ * @param properties la liste des propriétés que doit avoir l'objet créé les
+ * arguments vont par paire (propertyName, value)
* @return un nouvel objet
- * @throws TopiaException si un problème est rencontré durant l'instanciation
+ * @throws TopiaException si un problème est rencontré durant
+ * l'instanciation
* @throws IllegalArgumentException Si le nombre on le type des arguments
- * n'est pas bon ou que le type ou le nom d'une propriété est fausse
+ * n'est pas bon ou que le type ou le nom
+ * d'une propriété est fausse
*/
- Entity create(Object... properties) throws TopiaException;
+ E create(Object... properties) throws TopiaException;
/**
* Construit une nouvelle instance de l'objet géré par ce DAO
+ *
* @param properties la liste des propriétés que doit avoir l'objet créé
* @return un nouvel objet
- * @throws TopiaException si un problème est rencontré durant l'instanciation
+ * @throws TopiaException si un problème est rencontré durant
+ * l'instanciation
* @throws IllegalArgumentException Si le nombre on le type des arguments
- * n'est pas bon ou que le type ou le nom d'une propriété est fausse
+ * n'est pas bon ou que le type ou le nom
+ * d'une propriété est fausse
*/
- Entity create(Map<String, Object> properties) throws TopiaException;
+ E create(Map<String, Object> properties) throws TopiaException;
/**
* Permet de sauver un object instancié sans le DAO.
- *
+ *
* @param e l'entité instanciée à sauver
* @return l'entité avec son topiaID valorisé
* @throws TopiaException if any pb while creating datas
- *
* @since 2.3.1
*/
- Entity create(Entity e) throws TopiaException;
-
+ E create(E e) throws TopiaException;
+
/**
- * Permet d'ajouter ou de mettre a jour un objet. Cela permet d'ajouter
- * par exemple un objet provenant d'un autre context mais du meme type
- * de DAO.
+ * Permet d'ajouter ou de mettre a jour un objet. Cela permet d'ajouter par
+ * exemple un objet provenant d'un autre context mais du meme type de DAO.
*
* @param e l'entite a ajouter ou mettre a jour
* @return l'entity passé en paramètre.
* @throws TopiaException if any pb while updating datas
*/
- Entity update(Entity e) throws TopiaException;
+ E update(E e) throws TopiaException;
/**
* Permet de supprimer une entite.
- *
+ *
* @param e l'entite a supprimer
* @throws TopiaException if any pb while deleting datas
*/
- void delete(Entity e) throws TopiaException;
+ void delete(E e) throws TopiaException;
- Entity findByTopiaId(String k) throws TopiaException;
+ E findByTopiaId(String k) throws TopiaException;
- List<Entity> findAll() throws TopiaException;
+ List<E> findAll() throws TopiaException;
/**
* Recuperation de tous les ids en base pour le type d'entite du dao.
@@ -170,20 +194,20 @@
*/
List<String> findAllIds() throws TopiaException;
- List<Entity> findAllWithOrder(String... propertyNames)
+ List<E> findAllWithOrder(String... propertyNames)
throws TopiaException;
/**
* Compte le nombre d'entites en base
- *
+ *
* @return le nombre total d'entites existantes
* @throws TopiaException if any pb while getting datas
*/
long size() throws TopiaException;
/**
- * Crée une requete basé sur l'entité lié au DAO.
- * Résultat attendu : "FROM Entity"
+ * Crée une requete basé sur l'entité lié au DAO. Résultat attendu : "FROM
+ * E"
*
* @return une nouvelle TopiaQuery vide. (uniquement avec le From sur le
* type d'entité)
@@ -193,10 +217,11 @@
/**
* Crée une requête basé sur l'entité lié au DAO et lui assigne un alias
* valable dans la requête..
+ * <p/>
+ * Résultat attendu : "FROM E AS entityAlias"
*
- * Résultat attendu : "FROM Entity AS entityAlias"
- *
- * @param entityAlias alias permettant de manipuler l'entité dans la requête
+ * @param entityAlias alias permettant de manipuler l'entité dans la
+ * requête
* @return une nouvelle TopiaQuery
*/
TopiaQuery createQuery(String entityAlias);
@@ -206,12 +231,12 @@
* entité correspondant à la requête.
*
* @param query la requête
- * @return l'entité correspondant à la recherche ou null si aucune entité
- * n'a été trouvée
+ * @return l'entité correspondant à la recherche ou null si aucune entité
+ * n'a été trouvée
* @throws TopiaException if any pb while getting datas
* @see TopiaQuery#executeToEntity(TopiaContext, Class)
*/
- Entity findByQuery(TopiaQuery query) throws TopiaException;
+ E findByQuery(TopiaQuery query) throws TopiaException;
/**
* Execute une requête basé sur l'entité du DAO. Permet de récupérer une
@@ -222,178 +247,190 @@
* @throws TopiaException if any pb while getting datas
* @see TopiaQuery#executeToEntityList(TopiaContext, Class)
*/
- List<Entity> findAllByQuery(TopiaQuery query) throws TopiaException;
+ List<E> findAllByQuery(TopiaQuery query) throws TopiaException;
/**
- * Execute une requête basé sur l'entité du DAO. Permet de récupérer une
- * map d'entités correspondant à la requête. La clé de la map étant le
- * topiaId de l'entité.
+ * Execute une requête basé sur l'entité du DAO. Permet de récupérer une map
+ * d'entités correspondant à la requête. La clé de la map étant le topiaId
+ * de l'entité.
*
* @param query la requête
* @return la map d'entités correspondant à la recherche
* @throws TopiaException if any pb while getting datas
* @see TopiaQuery#executeToEntityMap(TopiaContext, Class)
*/
- Map<String, Entity> findAllMappedByQuery(TopiaQuery query) throws TopiaException;
+ Map<String, E> findAllMappedByQuery(TopiaQuery query) throws TopiaException;
/**
- * Execute une requête basé sur l'entité du DAO. Permet de récupérer une
- * map d'entités correspondant à la requête. Le type et le nom de la
- * propriété utilisé comme clé de la map doit être passé en argument.
+ * Execute une requête basé sur l'entité du DAO. Permet de récupérer une map
+ * d'entités correspondant à la requête. Le type et le nom de la propriété
+ * utilisé comme clé de la map doit être passé en argument.
*
- * @param <K> type de la clé de la map
- * @param query la requête
- * @param keyName nom de la propriété de l'entité utilisée comme clé
+ * @param <K> type de la clé de la map
+ * @param query la requête
+ * @param keyName nom de la propriété de l'entité utilisée comme clé
* @param keyClass type de la propriété de l'entité utilisée comme clé
* @return la map d'entités correspondant à la recherche
* @throws TopiaException if any pb while getting datas
* @see TopiaQuery#executeToEntityMap(TopiaContext, Class)
*/
- <K> Map<K, Entity> findAllMappedByQuery(TopiaQuery query,
- String keyName, Class<K> keyClass) throws TopiaException;
+ <K> Map<K, E> findAllMappedByQuery(TopiaQuery query,
+ String keyName, Class<K> keyClass) throws TopiaException;
/**
* Recherche la classe en utilisant la cle naturelle, chaque champs de la
* cle naturelle est une entre de la map passe en argument.
- *
+ *
* @param keys la liste des champs de la cle naturelle avec leur valeur
* @return l'entite trouvé
* @throws TopiaException if any pb while getting datas
*/
- Entity findByPrimaryKey(Map<String, Object> keys) throws TopiaException;
+ E findByPrimaryKey(Map<String, Object> keys) throws TopiaException;
/**
* Recherche la classe en utilisant la cle naturelle, si la cle naturelle
* est composé de plusieurs champs alors les arguments passés doivent être
* dans l'ordre de declaration dans le fichier de mapping
- *
+ *
* @param k l'objet cle naturelle de la classe
* @return l'entité trouvé
* @throws TopiaException if any pb while getting datas
*/
- Entity findByPrimaryKey(Object... k) throws TopiaException;
+ E findByPrimaryKey(Object... k) throws TopiaException;
- Entity findByProperty(String propertyName, Object value)
+ E findByProperty(String propertyName, Object value)
throws TopiaException;
/**
- *
* @param propertyName le nom de la propriété
- * @param value la valeur à tester
- * @param others les autres proprietes doivent aller par 2 propertyName,
- * value
+ * @param value la valeur à tester
+ * @param others les autres proprietes doivent aller par 2
+ * propertyName, value
* @return l'entité trouvé
* @throws TopiaException if any pb while getting datas
*/
- Entity findByProperties(String propertyName, Object value,
- Object... others) throws TopiaException;
+ E findByProperties(String propertyName, Object value,
+ Object... others) throws TopiaException;
- Entity findByProperties(Map<String, Object> properties) throws TopiaException;
+ E findByProperties(Map<String, Object> properties) throws TopiaException;
- List<Entity> findAllByProperty(String propertyName, Object value)
+ List<E> findAllByProperty(String propertyName, Object value)
throws TopiaException;
/**
- *
* @param propertyName le nom de la propriété
- * @param value la valeur à tester
- * @param others les autres proprietes doivent aller par 2 propertyName,
- * value
+ * @param value la valeur à tester
+ * @param others les autres proprietes doivent aller par 2
+ * propertyName, value
* @return l'entité trouvé
* @throws TopiaException if any pb while getting datas
*/
- List<Entity> findAllByProperties(String propertyName, Object value,
- Object... others) throws TopiaException;
+ List<E> findAllByProperties(String propertyName, Object value,
+ Object... others) throws TopiaException;
- List<Entity> findAllByProperties(Map<String, Object> properties)
+ List<E> findAllByProperties(Map<String, Object> properties)
throws TopiaException;
/*
* Find Contains
*/
+
/**
* Cherche et renvoie la première entité trouvée dont les propriétés en clé
* de Map contiennent toutes les valeurs de la Collection.
- *
+ *
* @param properties les proprietes a utiliser
* @return l'entité trouvé
* @throws TopiaException if any pb while getting datas
+ * @deprecated since 2.4 strange method, not very useful, use {@link
+ * TopiaQuery} instead
*/
- Entity findContainsProperties(Map<String, Collection<?>> properties) throws
+ @Deprecated
+ E findContainsProperties(Map<String, Collection<?>> properties) throws
TopiaException;
/**
* Cherche et renvoie la première entité trouvée dont la propriété
* propertyName contient values, ainsi de suite avec others.
- *
- * @param propertyName le nom de la propriété
- * @param values les premières valeurs à tester
- * @param others les secondes valeurs ) tester
+ *
+ * @param propertyName le nom de la propriété
+ * @param values les premières valeurs à tester
+ * @param others les secondes valeurs ) tester
* @return l'entité trouvé
* @throws TopiaException if any pb while getting datas
+ * @deprecated since 2.4 strange method, not very useful, use {@link
+ * TopiaQuery} instead
*/
- Entity findContainsProperties(String propertyName, Collection<?> values,
- Object... others) throws TopiaException;
+ @Deprecated
+ E findContainsProperties(String propertyName, Collection<?> values,
+ Object... others) throws TopiaException;
/**
* Cherche et renvoie la première entité trouvée dont les propriétés en clé
* de Map contiennent toutes les valeurs de la Collection.
- *
+ *
* @param properties les propriétés à tester
* @return l'entité trouvé
* @throws TopiaException if any pb while getting datas
+ * @deprecated since 2.4 strange method, not very useful, use {@link
+ * TopiaQuery} instead
*/
- List<Entity> findAllContainsProperties(Map<String, Collection<?>> properties)
+ @Deprecated
+ List<E> findAllContainsProperties(Map<String, Collection<?>> properties)
throws TopiaException;
/**
* Cherche et renvoie toutes les entités trouvées dont la propriété
* propertyName contient values, ainsi de suite avec others.
- *
+ *
* @param propertyName the name of the property
- * @param values les premières valeurs à tester
- * @param others les secondes valeurs à tester
+ * @param values les premières valeurs à tester
+ * @param others les secondes valeurs à tester
* @return l'entité trouvé
* @throws TopiaException if any pb while getting datas
+ * @deprecated since 2.4 strange method, not very useful, use {@link
+ * TopiaQuery} instead
*/
- List<Entity> findAllContainsProperties(String propertyName,
- Collection<?> values, Object... others) throws TopiaException;
+ @Deprecated
+ List<E> findAllContainsProperties(String propertyName,
+ Collection<?> values, Object... others)
+ throws TopiaException;
/**
* Find usages of the given {@code entity} in the entities of the given
* {@code type}.
*
- * @param type the type of entity to search
+ * @param type the type of entity to search
* @param entity the entity
- * @param <U> tthe type of entity to search
+ * @param <U> tthe type of entity to search
* @return the list of entities of the given type which uses the given
* entity
* @throws TopiaException if any problem while getting data
* @since 2.3.0
*/
- <U extends TopiaEntity> List<U> findUsages(Class<U> type, Entity entity)
+ <U extends TopiaEntity> List<U> findUsages(Class<U> type, E entity)
throws TopiaException;
/**
* Find all usages of the given {@code entity}.
- *
+ *
* @param entity the entity
* @return the dictionnary of usages of the given entities (keys are entity
- * usage container, values are the list of this type of entity to use the
- * given entity).
+ * usage container, values are the list of this type of entity to
+ * use the given entity).
* @throws TopiaException if any pb while getting data
* @since 2.3.0
*/
- Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> findAllUsages(Entity entity)
+ Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> findAllUsages(E entity)
throws TopiaException;
-
+
/**
* Retourne les permissions a verifier pour l'acces a l'entite pour le
* service Taas.
- *
+ *
* @param topiaId topiaId d'une entite
- * @param actions encoded actions
+ * @param actions encoded actions
* @return la liste des permissions
* @throws TopiaException if any pb while getting datas
*/
@@ -401,11 +438,13 @@
throws TopiaException;
/* Adders */
+
void addTopiaEntityListener(TopiaEntityListener listener);
void addTopiaEntityVetoable(TopiaEntityVetoable vetoable);
/* Removers */
+
void removeTopiaEntityListener(TopiaEntityListener listener);
void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -578,91 +578,6 @@
throw new UnsupportedOperationException();
}
- //TODO-TC20100225 Says since when it is deprecated (via javadoc annotations
- //TODO-TC20100225 + tells what to use instead)
- @Deprecated
- private Criterion computeCriterions(Object... values) {
- if (values == null) {
- return null;
- }
- Criterion criterion = null;
- for (Object value : values) {
- criterion = or(criterion, computeCriterion(value));
- }
- return criterion;
- }
-
- //TODO-TC20100225 Says since when it is deprecated (via javadoc annotations
- //TODO-TC20100225 + tells what to use instead)
- @Deprecated
- private Criterion computeCriterion(Object value) {
- Criterion criterion = null;
- SearchFields fields = entityClass.getAnnotation(SearchFields.class);
- String textValue = "%" + value + '%';
- //textFields
- String[] textFields = fields.txtFields();
- for (String propName : textFields) {
- criterion = or(criterion, Restrictions.like(propName, textValue));
- }
- //numFields
- boolean isNumber = value instanceof Number;
- if (value instanceof String) {
- try {
- Double.parseDouble((String) value);
- isNumber = true;
- } catch (NumberFormatException nfe) {
- isNumber = false;
- }
-
- }
- if (isNumber) {
- String[] numFields = fields.numFields();
- for (String propName : numFields) {
- criterion = or(criterion, Restrictions.sqlRestriction(propName
- + " like '" + textValue + '\''));
- }
- }
- //boolFields
- boolean isBoolean = value instanceof Boolean;
- if (value instanceof String) {
- isBoolean |= "true".equalsIgnoreCase((String) value) || "false"
- .equalsIgnoreCase((String) value);
- }
- if (isBoolean) {
- Boolean booleanValue;
- if (value instanceof String) {
- booleanValue = Boolean.valueOf((String) value);
- } else {
- booleanValue = (Boolean) value;
- }
- String[] boolFields = fields.numFields();
- for (String propName : boolFields) {
- criterion = or(criterion, Restrictions.eq(propName,
- booleanValue));
- }
- }
- //timeFields
- String[] timeFields = fields.dateFields();
- for (String propName : timeFields) {
- criterion = or(criterion, Restrictions.sqlRestriction(propName
- + " like '" + textValue + '\''));
- }
- return criterion;
- }
-
- //TODO-TC20100225 Says since when it is deprecated (via javadoc annotations
- //TODO-TC20100225 + tells what to use instead)
- @Deprecated
- private Criterion or(Criterion crit1, Criterion crit2) {
- if (crit1 == null) {
- return crit2;
- }
- if (crit2 == null) {
- return crit1;
- }
- return Restrictions.or(crit1, crit2);
- }
-
@Override
public void addTopiaEntityListener(TopiaEntityListener listener) {
getContext().addTopiaEntityListener(entityClass,listener);
@@ -737,6 +652,7 @@
throw new IllegalArgumentException(
"Can't put properties on new Object", eee);
}
+ // TODO-fdesbois-20100507 : need to be removed for 2.5 version
result.postCreate();
// on fait un save maintenant, car puisqu'on a creer l'entity au
@@ -770,29 +686,18 @@
@Override
public E findByTopiaId(String k) throws TopiaException {
- return findByQuery(createQuery().add(TopiaEntity.TOPIA_ID, k));
+ return findByQuery(createQuery().add(TopiaEntity.ID, k));
//return query(Restrictions.idEq(k));
}
@Override
public List<E> findAll() throws TopiaException {
-// try {
-// Criteria criteria = createCriteria(FlushMode.AUTO);
-// List<E> result = (List<E>) criteria.list();
-// result = getContext().getFiresSupport().fireEntitiesLoad(context,
-// result);
-// return result;
-// } catch (HibernateException eee) {
-// throw new TopiaException(eee);
-// }
return findAllByQuery(createQuery());
}
@Override
public List<String> findAllIds() throws TopiaException {
- //List<String> find = context.find("select src.topiaId from " + entityClass.getSimpleName() + "Impl src");
- //return find;
- return createQuery().setSelect(TopiaEntity.TOPIA_ID).execute();
+ return createQuery().setSelect(TopiaEntity.ID).execute();
}
@Override
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -37,58 +37,167 @@
package org.nuiton.topia.persistence;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.generator.EntityAbstractTransformer;
+import org.nuiton.topia.generator.EntityHibernateMappingGenerator;
+import org.nuiton.topia.generator.EntityImplTransformer;
+import org.nuiton.topia.generator.EntityInterfaceTransformer;
+import org.nuiton.topia.generator.TopiaMetaTransformer;
+
import java.beans.PropertyChangeListener;
import java.beans.VetoableChangeListener;
import java.util.Date;
import java.util.List;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaException;
-
/**
- * TopiaEntity.
- *
- * Toutes les methodes set ne doivent être utilisé que par le framework. Elle
- * sont publique car on ne peut pas faire autrement sur une interface.
- *
+ * The TopiaEntity is the main interface for each entities generated with {@link
+ * TopiaMetaTransformer}. An entity is simply a persistent bean mapped with
+ * hibernate. The manipulation on entities (create, update, delete, find) is
+ * made by the dao associated. The corresponding dao interface is {@link
+ * TopiaDAO}.
+ * <p/>
+ * Setter methods have to be used only in internal. They are in the interface to
+ * make easier their usages in internal.
+ *
* @author poussin <poussin(a)codelutin.com>
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ * @see EntityHibernateMappingGenerator
+ * @see EntityInterfaceTransformer
+ * @see EntityAbstractTransformer
+ * @see EntityImplTransformer
*/
@SearchFields
public interface TopiaEntity {
+ /** @deprecated since 2.4 use {@link #ID} instead */
+ @Deprecated
String TOPIA_ID = "topiaId";
+
+ /** @deprecated since 2.4 use {@link #CREATE_DATE} instead */
+ @Deprecated
String TOPIA_CREATE_DATE = "topiaCreateDate";
+
+ /** @deprecated since 2.4 use {@link #VERSION} instead */
+ @Deprecated
String TOPIA_VERSION = "topiaVersion";
+ /** Property name of the unique technical {@code id} of the entity */
+ String ID = "topiaId";
+
+ /** Property name of the technical {@code createDate} of the entity */
+ String CREATE_DATE = "topiaCreateDate";
+
+ /** Property name of the technical {@code version} of the entity */
+ String ENTITY_VERSION = "topiaVersion";
+
+ /** @deprecated since 2.4 use {@link #getId()} instead */
+ @Deprecated
String getTopiaId();
+ /** @deprecated since 2.4 use {@link #setId(String)} instead */
+ @Deprecated
void setTopiaId(String v);
+ /** @deprecated since 2.4 use {@link #getVersion()} instead */
+ @Deprecated
long getTopiaVersion();
+ /** @deprecated since 2.4 use {@link #setVersion(long)} instead */
+ @Deprecated
void setTopiaVersion(long v);
+ /** @deprecated since 2.4 use {@link #getCreateDate()} */
+ @Deprecated
+ Date getTopiaCreateDate();
+
+ /** @deprecated since 2.4 use {@link #setCreateDate(Date)} */
+ @Deprecated
+ void setTopiaCreateDate(Date topiaCreatedate);
+
/**
- * @return Returns the topiaCreateTime.
+ * Unique technical Id of the entity. This id contains the full qualified
+ * name of the entity interface. This id has also an index and his used to
+ * identify uniquely the entity in the database.
+ *
+ * @return the technical Id of the entity
*/
- Date getTopiaCreateDate();
+ String getId();
/**
- * @param topiaCreatedate the topiaCreateTime to set.
+ * Set the technical {@code id} of the entity. Careful, use this method only
+ * for copy. The technical id is generated by ToPIA when entity is created
+ * using {@link TopiaDAO#create(Object...)}.
+ *
+ * @param id technical id to set
*/
- void setTopiaCreateDate(Date topiaCreatedate);
+ void setId(String id);
+ /**
+ * Technical property to keep versionning of the entity. The version is
+ * incremented on each change of the entity.
+ *
+ * @return the current version of the entity
+ */
+ long getEntityVersion();
+
+ /**
+ * Set the technical {@code version} of the entity. Careful, use this method
+ * only for copy. The version is automatically incremented on entity
+ * changes.
+ *
+ * @param version technical version to set
+ */
+ void setEntityVersion(long version);
+
+ /**
+ * Technical date creation of the entity. This date doesn't change through
+ * time and was initialized on entity creation when using {@link
+ * TopiaDAO#create(Object...)}.
+ *
+ * @return the creation date of the entity
+ */
+ Date getCreateDate();
+
+ /**
+ * Set the technical creation {@code date} of the entity. Careful, use this
+ * method only for copy. This date is immutable and was created on entity
+ * creation.
+ *
+ * @param date technical create date to set
+ */
+ void setCreateDate(Date date);
+
+ @Deprecated
TopiaContext getTopiaContext();
/**
- * called just after object creation and initialisation
- * each entity impl can overide it to do something after creation
+ * Called just after object creation and initialisation each entity impl can
+ * overide it to do something after creation
+ *
* @throws TopiaException
+ * @deprecated since 2.4 : don't really know is concrete usage, the needed
+ * treatment can be directly done after creating the entity with
+ * {@link TopiaDAO#create(Object...)}
*/
+ @Deprecated
void postCreate() throws TopiaException;
+ /**
+ * @deprecated since 2.4 : context will no longer be keeped by the entity,
+ * so it will be impossible to do such operation. Use {@link
+ * TopiaDAO#update(TopiaEntity)} instead.
+ */
+ @Deprecated
void update() throws TopiaException;
+ /**
+ * @deprecated since 2.4 : context will no longer be keeped by the entity,
+ * so it will be impossible to do such operation. Use {@link
+ * TopiaDAO#delete(TopiaEntity)} instead.
+ */
+ @Deprecated
void delete() throws TopiaException;
/**
@@ -99,45 +208,45 @@
/**
* @return all object that are aggregate with this instance, aggreate object
- * are not removed automaticaly
+ * are not removed automaticaly
* @throws TopiaException
*/
List<TopiaEntity> getAggregate() throws TopiaException;
/**
* Add listener for property writing.
- *
+ *
* @param propertyName
* @param listener
*/
void addPropertyChangeListener(String propertyName,
- PropertyChangeListener listener);
+ PropertyChangeListener listener);
/**
* Add listener for property writing.
- *
+ *
* @param listener
*/
void addPropertyChangeListener(PropertyChangeListener listener);
void addVetoableChangeListener(String propertyName,
- VetoableChangeListener vetoable);
+ VetoableChangeListener vetoable);
void addVetoableChangeListener(VetoableChangeListener vetoable);
void removePropertyChangeListener(String propertyName,
- PropertyChangeListener listener);
+ PropertyChangeListener listener);
void removePropertyChangeListener(PropertyChangeListener listener);
void removeVetoableChangeListener(String propertyName,
- VetoableChangeListener vetoable);
+ VetoableChangeListener vetoable);
void removeVetoableChangeListener(VetoableChangeListener vetoable);
/**
* Add listener for property reading.
- *
+ *
* @param propertyName
* @param listener
*/
@@ -146,32 +255,32 @@
/**
* Add listener for property reading.
- *
+ *
* @param listener
*/
void addPropertyListener(PropertyChangeListener listener);
void addVetoableListener(String propertyName,
- VetoableChangeListener vetoable);
+ VetoableChangeListener vetoable);
void addVetoableListener(VetoableChangeListener vetoable);
void removePropertyListener(String propertyName,
- PropertyChangeListener listener);
+ PropertyChangeListener listener);
void removePropertyListener(PropertyChangeListener listener);
void removeVetoableListener(String propertyName,
- VetoableChangeListener vetoable);
+ VetoableChangeListener vetoable);
void removeVetoableListener(VetoableChangeListener vetoable);
/**
- * Parcourt de l'entité via un visiteur.
- *
- * @param visitor visitor le visiteur utilise
- * @throws TopiaException pour toute erreur pendant le parcours
+ * Route the entity using a {@code visitor}.
+ *
+ * @param visitor to used
+ * @throws TopiaException for all type of error
*/
void accept(EntityVisitor visitor) throws TopiaException;
-
+
} //TopiaEntity
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -82,6 +82,36 @@
new PropertyChangeSupport(this);
@Override
+ public String getId() {
+ return getTopiaId();
+ }
+
+ @Override
+ public void setId(String id) {
+ setTopiaId(id);
+ }
+
+ @Override
+ public long getEntityVersion() {
+ return getTopiaVersion();
+ }
+
+ @Override
+ public void setEntityVersion(long version) {
+ setTopiaVersion(version);
+ }
+
+ @Override
+ public Date getCreateDate() {
+ return getTopiaCreateDate();
+ }
+
+ @Override
+ public void setCreateDate(Date date) {
+ setTopiaCreateDate(date);
+ }
+
+ @Override
public String getTopiaId() {
return topiaId;
}
@@ -184,10 +214,10 @@
return false;
}
TopiaEntity other = (TopiaEntity) obj;
- if (getTopiaId() == null || other.getTopiaId() == null) {
+ if (getTopiaId() == null || other.getId() == null) {
return false;
}
- boolean result = getTopiaId().equals(other.getTopiaId());
+ boolean result = getTopiaId().equals(other.getId());
return result;
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -69,7 +69,7 @@
* Le pattern d'une reference sur une association
*/
public static final String ASSOCIATION_PATTERN =
- "%1$s[@" + TopiaEntity.TOPIA_ID + "=\"%2$s\"]";
+ "%1$s[@" + TopiaEntity.ID + "=\"%2$s\"]";
/**
* Bind les valeurs techniques depuis une entitée vers une autre.
@@ -79,13 +79,13 @@
*/
public static void bindTechnical(TopiaEntity from, TopiaEntity dst) {
if (from == null) {
- dst.setTopiaId(null);
- dst.setTopiaVersion(0);
- dst.setTopiaCreateDate(null);
+ dst.setId(null);
+ dst.setEntityVersion(0);
+ dst.setCreateDate(null);
} else {
- dst.setTopiaId(from.getTopiaId());
- dst.setTopiaVersion(from.getTopiaVersion());
- dst.setTopiaCreateDate(from.getTopiaCreateDate());
+ dst.setId(from.getId());
+ dst.setEntityVersion(from.getEntityVersion());
+ dst.setCreateDate(from.getCreateDate());
}
}
@@ -126,7 +126,7 @@
Collection<E> entities, String topiaId) {
if (entities != null) {
for (E e : entities) {
- if (topiaId.equals(e.getTopiaId())) {
+ if (topiaId.equals(e.getId())) {
return e;
}
}
@@ -149,7 +149,7 @@
if (bean == null) {
throw new NullPointerException(paramName + " can not be null");
}
- if (bean.getTopiaId() == null) {
+ if (bean.getId() == null) {
// can not create bean here
throw new IllegalStateException(
"can not create " + bean.getClass() + " here...");
@@ -171,7 +171,7 @@
if (bean == null) {
throw new NullPointerException(paramName + " can not be null");
}
- if (bean.getTopiaId() != null) {
+ if (bean.getId() != null) {
// can not create bean here
throw new IllegalStateException(
"can not update " + bean.getClass() + " here...");
@@ -297,13 +297,13 @@
@Override
public int compare(TopiaEntity o1, TopiaEntity o2) {
- if (o1.getTopiaId() == null) {
+ if (o1.getId() == null) {
return -1;
}
- if (o2.getTopiaId() == null) {
+ if (o2.getId() == null) {
return 1;
}
- return o1.getTopiaId().compareTo(o2.getTopiaId());
+ return o1.getId().compareTo(o2.getId());
}
};
}
@@ -481,7 +481,7 @@
super.onStarting(e);
Class<? extends TopiaEntity> entityClass = e.getClass();
if (log.isDebugEnabled()) {
- log.debug(entityClass + " : " + e.getTopiaId());
+ log.debug(entityClass + " : " + e.getId());
}
detectedTypes.add(entityClass);
return true;
@@ -539,7 +539,7 @@
}
if (log.isDebugEnabled()) {
- log.debug(entityClass + " : " + e.getTopiaId());
+ log.debug(entityClass + " : " + e.getId());
}
List<TopiaEntity> refs = detectedRefs.get(entityClass);
@@ -601,7 +601,7 @@
}
if (log.isDebugEnabled()) {
- log.debug(entityClass + " : " + e.getTopiaId());
+ log.debug(entityClass + " : " + e.getId());
}
List<String> refs = detectedRefs.get(entityClass);
@@ -609,7 +609,7 @@
refs = new ArrayList<String>();
detectedRefs.put(entityClass, refs);
}
- refs.add(e.getTopiaId());
+ refs.add(e.getId());
}
@Override
@@ -694,7 +694,7 @@
@Override
protected boolean onStarting(TopiaEntity e) {
- log.debug(e.getTopiaId());
+ log.debug(e.getId());
if (root == null) {
// start come in start method since
// last clear method invocation
@@ -735,7 +735,7 @@
if (visitor.getAlreadyExplored().contains(e1)) {
boolean contains = visitor.getStack().contains(e1);
if (log.isDebugEnabled()) {
- log.debug("already enter " + e1.getTopiaId() +
+ log.debug("already enter " + e1.getId() +
", can reenter ? " + !contains);
}
if (!contains) {
@@ -787,7 +787,7 @@
if (visitor.getAlreadyExplored().contains(e1)) {
boolean contains = visitor.getStack().contains(e1);
if (log.isDebugEnabled()) {
- log.debug("already enter " + e1.getTopiaId() +
+ log.debug("already enter " + e1.getId() +
", can reenter ? " + !contains);
}
if (!contains) {
@@ -840,7 +840,7 @@
}
boolean accept(TopiaEntity e) {
- return ids.contains(e.getTopiaId());
+ return ids.contains(e.getId());
}
void addPath(TopiaEntity e, String name, int index) {
@@ -851,16 +851,16 @@
accessorExpression.append(name);
if (index > -1) {
String association = String.format(
- ASSOCIATION_PATTERN, "", e.getTopiaId());
+ ASSOCIATION_PATTERN, "", e.getId());
accessorExpression.append(association);
}
// if (index > -1) {
// accessorExpression.append("[@topiaId=\"");
-// accessorExpression.append(e.getTopiaId());
+// accessorExpression.append(e.getId());
// accessorExpression.append("\"]");
// }
if (log.isTraceEnabled()) {
- log.trace("add to stack : " + e.getTopiaId() +
+ log.trace("add to stack : " + e.getId() +
", new size : " + path.size() + ", path : " +
accessorExpression.toString());
}
@@ -879,7 +879,7 @@
}
}
if (log.isTraceEnabled()) {
- log.trace("remove from stack : " + e.getTopiaId() +
+ log.trace("remove from stack : " + e.getId() +
", new size : " + path.size() + ", path : " +
accessorExpression.toString());
}
@@ -905,11 +905,11 @@
);
if (log.isDebugEnabled()) {
- log.debug(expression + " (" + e.getTopiaId() + ") - " +
- list.size() + " , root:" + root.getTopiaId());
+ log.debug(expression + " (" + e.getId() + ") - " +
+ list.size() + " , root:" + root.getId());
}
if (log.isTraceEnabled()) {
- log.trace(e.getTopiaId() + " : new size " + list.size() +
+ log.trace(e.getId() + " : new size " + list.size() +
", path : " + expression);
}
}
@@ -932,7 +932,7 @@
List<? extends TopiaEntity> entities) {
List<String> ids = new ArrayList<String>(entities.size());
for (TopiaEntity entity : entities) {
- ids.add(entity.getTopiaId());
+ ids.add(entity.getId());
}
return ids;
}
@@ -952,7 +952,7 @@
List<E> r = new ArrayList<E>(list == null ? 0 : list.size());
if (list != null) {
for (E e : list) {
- if (topiaIds.contains(e.getTopiaId())) {
+ if (topiaIds.contains(e.getId())) {
r.add(e);
}
}
@@ -982,7 +982,7 @@
for (E aReferentiel : referentiel) {
TopiaEntity referentielEntity = aReferentiel;
- String refId = referentielEntity.getTopiaId();
+ String refId = referentielEntity.getId();
if (localeIdList.contains(refId)) {
// id existant sur le storage locale
@@ -991,13 +991,13 @@
// ordre, on parcourt donc la liste cible pour retrouver
// l'entité cible
for (TopiaEntity e : locale) {
- if (e.getTopiaId().equals(refId)) {
+ if (e.getId().equals(refId)) {
localeEntity = e;
break;
}
}
- boolean wasModified = referentielEntity.getTopiaVersion() >
- localeEntity.getTopiaVersion();
+ boolean wasModified = referentielEntity.getEntityVersion() >
+ localeEntity.getEntityVersion();
if (wasModified) {
result.get(DiffState.MODIFIED).add(refId);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityRef.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityRef.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityRef.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -99,6 +99,6 @@
@Override
public int compareTo(TopiaEntityRef o) {
- return ref.getTopiaId().compareTo(o.getRef().getTopiaId());
+ return ref.getId().compareTo(o.getRef().getId());
}
}
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -154,7 +154,7 @@
companyDAO = TopiaTestDAOHelper.getCompanyDAO(newContext);
- company = companyDAO.findByTopiaId(company.getTopiaId());
+ company = companyDAO.findByTopiaId(company.getId());
Assert.assertEquals(company.getName(),"Ma société");
Assert.assertEquals(company.getDepartment().size(),4);
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/ExportXMLVisitor.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/ExportXMLVisitor.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/ExportXMLVisitor.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -58,9 +58,9 @@
}
buffer.append("<").append(e.getClass().getName());
- buffer.append(" topiaId=\"").append(e.getTopiaId()).append("\"");
- buffer.append(" topiaCreateDate=\"").append(e.getTopiaCreateDate()).append("\"");
- buffer.append(" topiaVersion=\"").append(e.getTopiaVersion()).append("\"");
+ buffer.append(" topiaId=\"").append(e.getId()).append("\"");
+ buffer.append(" topiaCreateDate=\"").append(e.getCreateDate()).append("\"");
+ buffer.append(" topiaVersion=\"").append(e.getEntityVersion()).append("\"");
buffer.append(">\n");
}
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/EntityOperatorTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/EntityOperatorTest.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/EntityOperatorTest.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -164,7 +164,7 @@
actual = operationC.getChild(Company.DEPARTMENT, c, topiaId);
assertNull(actual);
- d.setTopiaId(topiaId);
+ d.setId(topiaId);
actual = operationC.getChild(Company.DEPARTMENT, c, topiaId);
assertNotNull(actual);
assertEquals(d, actual);
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityBinderTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityBinderTest.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityBinderTest.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -87,7 +87,7 @@
BinderBuilder builder = new BinderBuilder();
builder.createBinderModel(Company.class, CompanyDTO.class);
builder.addSimpleProperties(Company.NAME, Company.SIRET);
- builder.addProperties(TopiaEntity.TOPIA_ID, "id");
+ builder.addProperties(TopiaEntity.ID, "id");
BinderProvider.registerBinder(builder);
Binder<Company, CompanyDTO> binder =
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityRefTester.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityRefTester.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityRefTester.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -94,7 +94,7 @@
InstantiationException {
Class<? extends TopiaEntity> impl = constant.getImplementation();
TopiaEntity topiaEntity = impl.newInstance();
- topiaEntity.setTopiaId(topiaId);
+ topiaEntity.setId(topiaId);
return (T) topiaEntity;
}
@@ -111,7 +111,7 @@
* @return the reference of the association
*/
protected String getAssociationRef(String associationName, TopiaEntity e) {
- return getAssociationRef(associationName, e.getTopiaId());
+ return getAssociationRef(associationName, e.getId());
}
/**
@@ -276,7 +276,7 @@
TopiaEntity[] path = actual.getPath();
Assert.assertEquals(expected.length, path.length);
for (int i = 0; i < expected.length; i++) {
- Assert.assertEquals(expected[i].getTopiaId(), path[i].getTopiaId());
+ Assert.assertEquals(expected[i].getId(), path[i].getId());
}
}
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -123,7 +123,7 @@
log.debug("CREATE PERSONNE : Bob Marley");
Personne personne = dao.create(Personne.NAME,"Bob Marley");
transaction.commitTransaction();
- String idPersonne = personne.getTopiaId();
+ String idPersonne = personne.getId();
assertNotNull(idPersonne);
log.debug("ENTITY PERSONNE SAVED !");
@@ -137,7 +137,7 @@
log.debug("CREATE PERSONNE : Ziggy Marley");
Personne personne2 = dao.create(Personne.NAME,"Ziggy Marley");
transaction.commitTransaction();
- String idPersonne2 = personne2.getTopiaId();
+ String idPersonne2 = personne2.getId();
assertNotNull(idPersonne2);
log.debug("ENTITY PERSONNE SAVED !");
@@ -175,7 +175,7 @@
log.debug("CREATE PERSONNE : Bob Marley");
Personne personne = dao.create(Personne.NAME,"Bob Marley");
transaction.commitTransaction();
- String idPersonne = personne.getTopiaId();
+ String idPersonne = personne.getId();
assertNotNull(idPersonne);
log.debug("ENTITY PERSONNE SAVED !");
@@ -184,7 +184,7 @@
log.debug("CREATE CONTACT : jaja(a)codelutin.com");
Contact2 contact = contactDAO.create(Contact2.CONTACT_VALUE,"jaja(a)codelutin.com");
transaction.commitTransaction();
- String idContact = contact.getTopiaId();
+ String idContact = contact.getId();
assertNotNull(idContact);
log.debug("ENTITY CONTACT SAVED !");
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/ManualMigrationEngine.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/ManualMigrationEngine.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/ManualMigrationEngine.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -471,7 +471,7 @@
//FIXME on pourrait conserver l'information sur les date de mise a jour
List<TMSVersion> toDelete = dao.findAll();
for (TMSVersion v : toDelete) {
- v.delete();
+ dao.delete(v);
}
log.info(_("topia.migration.saving.db.version", version));
Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachAssociation.java
===================================================================
--- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachAssociation.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachAssociation.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -175,7 +175,7 @@
// l'entite repliquee a laquelle on veut attacher l'association
- TopiaEntity dst = dstCtxt.findByTopiaId(src.getTopiaId());
+ TopiaEntity dst = dstCtxt.findByTopiaId(src.getId());
// les association cibles connues pour l'entite sur la base destination
Collection<?> dstTargetEntities = (Collection<?>) ownerOperator.get(name, dst);
@@ -188,8 +188,8 @@
TopiaEntity assosiationSrc = (TopiaEntity) a;
// on verifie que l'association doit etre rattachee
- if (associationsId.contains(assosiationSrc.getTopiaId())) {
- if (dstTargetAssociationsId.contains(assosiationSrc.getTopiaId())) {
+ if (associationsId.contains(assosiationSrc.getId())) {
+ if (dstTargetAssociationsId.contains(assosiationSrc.getId())) {
// deja attache
if (log.isDebugEnabled()) {
log.debug("already attached association '" + name + "' : " + assosiationSrc);
@@ -200,7 +200,7 @@
// la donnees doit etre attachee
- TopiaEntity assosiationDst = dstCtxt.findByTopiaId(assosiationSrc.getTopiaId());
+ TopiaEntity assosiationDst = dstCtxt.findByTopiaId(assosiationSrc.getId());
ownerOperator.addChild(name, dst, assosiationDst);
if (log.isDebugEnabled()) {
log.debug("will attach association '" + name + "' : " + assosiationDst);
@@ -212,7 +212,7 @@
if (shouldUpdate) {
if (log.isTraceEnabled()) {
- log.trace("will update " + dst.getTopiaId());
+ log.trace("will update " + dst.getId());
}
//FIXME: on ne peut pas updater l'objet car l'objet peut rentre
// en conflit dans la session hibernate
Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachLink.java
===================================================================
--- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachLink.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachLink.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -163,7 +163,7 @@
// l'entite repliquee a laquelle on veut attacher l'association
- TopiaEntity dst = dstCtxt.findByTopiaId(src.getTopiaId());
+ TopiaEntity dst = dstCtxt.findByTopiaId(src.getId());
// les association cibles connues pour l'entite sur la base destination
Collection<?> dstTargetEntities = (Collection<?>) ownerOperator.get(name, dst);
@@ -176,8 +176,8 @@
TopiaEntity assosiationSrc = (TopiaEntity) a;
// on verifie que l'association doit etre rattachee
- if (associationIds.contains(assosiationSrc.getTopiaId())) {
- if (dstTargetAssociationsId.contains(assosiationSrc.getTopiaId())) {
+ if (associationIds.contains(assosiationSrc.getId())) {
+ if (dstTargetAssociationsId.contains(assosiationSrc.getId())) {
// deja attache
if (log.isDebugEnabled()) {
log.debug("already attached association '" + name + "' : " + assosiationSrc);
@@ -188,7 +188,7 @@
// la donnees doit etre attachee
- TopiaEntity assosiationDst = dstCtxt.findByTopiaId(assosiationSrc.getTopiaId());
+ TopiaEntity assosiationDst = dstCtxt.findByTopiaId(assosiationSrc.getId());
ownerOperator.addChild(name, dst, assosiationDst);
if (log.isDebugEnabled()) {
log.debug("will attach association '" + name + "' : " + assosiationDst);
@@ -200,7 +200,7 @@
if (shouldUpdate) {
if (log.isTraceEnabled()) {
- log.trace("will update " + dst.getTopiaId());
+ log.trace("will update " + dst.getId());
}
//FIXME: on ne peut pas updater l'objet car l'objet peut rentre
// en conflit dans la session hibernate
Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractReplicationEngineTest.java
===================================================================
--- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractReplicationEngineTest.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractReplicationEngineTest.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -125,7 +125,7 @@
protected <E extends TopiaEntity> E update(E e) throws TopiaException {
Class<E> k = (Class<E>) TopiaEntityHelper.getContractClass(getContracts(), e.getClass());
TopiaDAO<E> dao = ((TopiaContextImplementor) ctxt).getDAO(k);
- return dao.findByTopiaId(e.getTopiaId());
+ return dao.findByTopiaId(e.getId());
}
/**
@@ -195,7 +195,7 @@
Set<?> detectTypes;
- detectTypes = service.detectTypes(getContracts(), entity.getTopiaId());
+ detectTypes = service.detectTypes(getContracts(), entity.getId());
assertEquals("expected types : "+
Arrays.toString(expectedCouple) +
" but was "+detectTypes,
@@ -293,7 +293,7 @@
//
// Iterator<List<ReplicationNode>> order = dependencies.iterator();
// if (entity != null) {
-// getLog().info("for " + entity.getTopiaId());
+// getLog().info("for " + entity.getId());
// }
// int index = 0;
// for (TopiaEntityEnum[] expectedLevel : expected) {
@@ -348,7 +348,7 @@
if (entity == null) {
prepareModel();
} else {
- prepareModel(entity.getTopiaId());
+ prepareModel(entity.getId());
}
// createModel(entity);
// model.detectAssociations();
@@ -364,7 +364,7 @@
getLog().info("resume of operations for all ");
} else {
- getLog().info("resume of operations for entity " + entity.getTopiaId());
+ getLog().info("resume of operations for entity " + entity.getId());
}
for (ReplicationNode node : model.getOrder()) {
@@ -400,7 +400,7 @@
dstCtxt = (TopiaContextImplementor) rootCtxt.beginTransaction();
for (TopiaEntity e : entity) {
- TopiaEntity actual = dstCtxt.findByTopiaId(e.getTopiaId());
+ TopiaEntity actual = dstCtxt.findByTopiaId(e.getId());
assertNotNull(actual);
assertEquals(e, actual);
}
@@ -490,14 +490,14 @@
if (treated == null) {
treated = new HashSet<String>();
}
- if (treated.contains(actual.getTopiaId())) {
+ if (treated.contains(actual.getId())) {
return;
}
if (getLog().isDebugEnabled()) {
getLog().debug(expected);
}
- assertEquals(actual.getTopiaId(), expected.getTopiaId());
- treated.add(actual.getTopiaId());
+ assertEquals(actual.getId(), expected.getId());
+ treated.add(actual.getId());
if (getLog().isDebugEnabled()) {
getLog().debug("expected : " + expected + " / actual " + actual);
}
@@ -565,8 +565,8 @@
protected void createUnsupportedBeforeOperation(TopiaEntityEnum contract, TopiaEntity entity, Class<? extends TopiaReplicationOperation> operationClass, Object... parameters) throws Exception {
- getLog().info("entity " + entity.getTopiaId());
- prepareModel(entity.getTopiaId());
+ getLog().info("entity " + entity.getId());
+ prepareModel(entity.getId());
service.addBeforeOperation(model, contract, operationClass, parameters);
// on ne doit pas avoir le droit de creer cette operation
@@ -575,8 +575,8 @@
protected void createUnsupportedAfterOperation(TopiaEntityEnum contract, TopiaEntity entity, Class<? extends TopiaReplicationOperation> operationClass, Object... parameters) throws Exception {
- getLog().info("entity " + entity.getTopiaId());
- prepareModel(entity.getTopiaId());
+ getLog().info("entity " + entity.getId());
+ prepareModel(entity.getId());
// model = service.createModel(getContracts());
// model.detectDirectDependencies();
service.addAfterOperation(model, contract, operationClass, parameters);
@@ -606,7 +606,7 @@
}
protected void createModel(TopiaEntity entity) throws TopiaException {
- model = service.createModel(getContracts(), entity.getTopiaId());
+ model = service.createModel(getContracts(), entity.getId());
}
protected void prepareModel(String... ids) throws TopiaException {
Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/ReplicationEngineTest.java
===================================================================
--- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/ReplicationEngineTest.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/ReplicationEngineTest.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -253,7 +253,7 @@
TopiaContext dstRootCtxt = createDb2("testSimpleReplicateFailed");
- //model = service.prepare(contracts, pet.getTopiaId());
+ //model = service.prepare(contracts, pet.getId());
TopiaContext srcCtxt = ctxt.beginTransaction();
dstCtxt = (TopiaContextImplementor) dstRootCtxt.beginTransaction();
@@ -288,7 +288,7 @@
TopiaContext dstRootCtxt = createDb2("testSimpleReplicateNotSure");
- //model = service.prepare(contracts, pet.getTopiaId());
+ //model = service.prepare(contracts, pet.getId());
TopiaContext srcCtxt = ctxt;
dstCtxt = (TopiaContextImplementor) dstRootCtxt.beginTransaction();
@@ -307,13 +307,13 @@
srcCtxt.replicateEntity(dstCtxt, person);
dstCtxt.commitTransaction();
- ((Pet) dstCtxt.findByTopiaId(pet.getTopiaId())).setPerson((Person) dstCtxt.findByTopiaId(person.getTopiaId()));
+ ((Pet) dstCtxt.findByTopiaId(pet.getId())).setPerson((Person) dstCtxt.findByTopiaId(person.getId()));
dstCtxt.commitTransaction();
srcCtxt.rollbackTransaction();
person = update(person);
- assertEntityEquals(person, dstCtxt.findByTopiaId(person.getTopiaId()), null);
+ assertEntityEquals(person, dstCtxt.findByTopiaId(person.getId()), null);
} finally {
srcCtxt.rollbackTransaction();
//srcCtxt.closeContext();
@@ -341,7 +341,7 @@
TopiaContext dstRootCtxt = createDb2("testSimpleReplicateSure");
- //model = service.prepare(contracts, pet.getTopiaId());
+ //model = service.prepare(contracts, pet.getId());
TopiaContext srcCtxt = ctxt;
dstCtxt = (TopiaContextImplementor) dstRootCtxt.beginTransaction();
@@ -357,7 +357,7 @@
srcCtxt.rollbackTransaction();
dstCtxt.commitTransaction();
- //((Person) dstCtxt.findByTopiaId(person.getTopiaId())).addPet(((Pet) dstCtxt.findByTopiaId(pet.getTopiaId())));
+ //((Person) dstCtxt.findByTopiaId(person.getId())).addPet(((Pet) dstCtxt.findByTopiaId(pet.getId())));
//dstCtxt.commitTransaction();
srcCtxt.rollbackTransaction();
@@ -370,7 +370,7 @@
person = update(person);
- assertEntityEquals(person, dstCtxt.findByTopiaId(person.getTopiaId()), null);
+ assertEntityEquals(person, dstCtxt.findByTopiaId(person.getId()), null);
} finally {
dstCtxt.closeContext();
Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java
===================================================================
--- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -261,7 +261,7 @@
@Test(expected = IllegalArgumentException.class)
public void testCreateOperation_wrongParameterNumber() throws Exception {
- model = service.createModel(contracts, pet.getTopiaId());
+ model = service.createModel(contracts, pet.getId());
service.addBeforeOperation(model, TopiaTestEntityEnum.Pet, FakeOperation.class);
}
@@ -269,7 +269,7 @@
@Test(expected = IllegalArgumentException.class)
public void testCreateOperation_wrongParameterNumber2() throws Exception {
- model = service.createModel(contracts, pet.getTopiaId());
+ model = service.createModel(contracts, pet.getId());
service.addBeforeOperation(model, TopiaTestEntityEnum.Pet, FakeOperation.class, String.class, String.class);
}
@@ -277,7 +277,7 @@
@Test(expected = IllegalArgumentException.class)
public void testCreateOperation_wrongParameterType() throws Exception {
- model = service.createModel(contracts, pet.getTopiaId());
+ model = service.createModel(contracts, pet.getId());
service.addBeforeOperation(model, TopiaTestEntityEnum.Pet, FakeOperation.class, Integer.class);
}
@@ -285,7 +285,7 @@
@Test(expected = IllegalArgumentException.class)
public void testCreateOperation_nullParameter() throws Exception {
- model = service.createModel(contracts, pet.getTopiaId());
+ model = service.createModel(contracts, pet.getId());
service.addBeforeOperation(model, TopiaTestEntityEnum.Pet, FakeOperation.class, (Object) null);
}
@@ -293,7 +293,7 @@
@Test
public void testCreateOperation() throws Exception {
- model = service.createModel(contracts, pet.getTopiaId());
+ model = service.createModel(contracts, pet.getId());
service.addBeforeOperation(model, TopiaTestEntityEnum.Pet, FakeOperation.class, "before");
service.addAfterOperation(model, TopiaTestEntityEnum.Race, FakeOperation.class, "after");
}
Modified: trunk/topia-service-security/src/main/java/org/nuiton/topia/security/TopiaSecurityServiceImpl.java
===================================================================
--- trunk/topia-service-security/src/main/java/org/nuiton/topia/security/TopiaSecurityServiceImpl.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-service-security/src/main/java/org/nuiton/topia/security/TopiaSecurityServiceImpl.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -401,7 +401,8 @@
try {
Class<?> klass = TopiaId.getClassName(topiaId);
- if(TopiaSecurityUtil.isImplement(klass, NoSecurityLoad.class)) {
+ //if(TopiaSecurityUtil.isImplement(klass, NoSecurityLoad.class)) {
+ if (NoSecurityLoad.class.isAssignableFrom(klass)) {
//LOAD
actions &= UPDATE + DELETE + CREATE;
}
Modified: trunk/topia-service-security/src/main/java/org/nuiton/topia/security/jaas/TopiaLoginModule.java
===================================================================
--- trunk/topia-service-security/src/main/java/org/nuiton/topia/security/jaas/TopiaLoginModule.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-service-security/src/main/java/org/nuiton/topia/security/jaas/TopiaLoginModule.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -135,7 +135,7 @@
// R�cup�ration des principals
principals = new HashSet<Principal>();
- String topiaIdUser = user.getTopiaId();
+ String topiaIdUser = user.getId();
principals.add(new TopiaPrincipal(topiaIdUser));
securityManager.putPermissionsCache(topiaIdUser);
securityManager.removeEntitiesLoadingCache(topiaIdUser);
@@ -149,11 +149,11 @@
if(groups != null) {
for(TopiaGroup group : groups) {
for (TopiaGroup superGroup : (List<TopiaGroup>)group.getAllSuperGroup()) {
- String topiaIdGroup = superGroup.getTopiaId();
+ String topiaIdGroup = superGroup.getId();
principals.add(new TopiaPrincipal(topiaIdGroup));
securityManager.putPermissionsCache(topiaIdGroup);
}
- String topiaIdGroup = group.getTopiaId();
+ String topiaIdGroup = group.getId();
principals.add(new TopiaPrincipal(topiaIdGroup));
securityManager.putPermissionsCache(topiaIdGroup);
}
Modified: trunk/topia-service-security/src/main/java/org/nuiton/topia/security/util/TopiaSecurityFactoryFilter.java
===================================================================
--- trunk/topia-service-security/src/main/java/org/nuiton/topia/security/util/TopiaSecurityFactoryFilter.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-service-security/src/main/java/org/nuiton/topia/security/util/TopiaSecurityFactoryFilter.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -66,7 +66,7 @@
*/
public TopiaEntity filter(TopiaEntity entity, int actions) {
try {
- securityManager.checkPermission(entity.getTopiaId(), actions);
+ securityManager.checkPermission(entity.getId(), actions);
} catch (SecurityException e) {
if(log.isDebugEnabled()) {
log.debug("Return Null because : " + e);
@@ -87,7 +87,7 @@
for (Iterator<?> iterator = result.iterator(); iterator.hasNext();) {
TopiaEntity entity = (TopiaEntity) iterator.next();
try {
- securityManager.checkPermission(entity.getTopiaId(), actions);
+ securityManager.checkPermission(entity.getId(), actions);
} catch (SecurityException e) {
iterator.remove();
if(log.isDebugEnabled()) {
Modified: trunk/topia-service-security/src/main/java/org/nuiton/topia/security/util/TopiaSecurityUtil.java
===================================================================
--- trunk/topia-service-security/src/main/java/org/nuiton/topia/security/util/TopiaSecurityUtil.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-service-security/src/main/java/org/nuiton/topia/security/util/TopiaSecurityUtil.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -257,34 +257,4 @@
TopiaContext topiaContext = TopiaContextFactory.getContext(config);
return topiaContext.beginTransaction();
}
-
- /**
- * Détermine si la classe implémente une interface
- * <p>
- * interface A <---- class B <---- class C
- * <p>
- * interface D <---- class E
- * <p>
- * isImplement(C, A) = true
- * <p>
- * isImplement(E, A) = false
- *
- * @param klass la classe
- * @param iface l'interface
- * @return vrai si la classe implémente l'interface sinon faux
- * @deprecated je pense que {@link Class#isAssignableFrom(Class)} doit faire l'affaire :)
- */
- public static boolean isImplement(Class klass, Class iface) {
- boolean result = false;
-
- Class<?>[] interfaces = klass.getInterfaces();
- result = ArrayUtils.contains(interfaces, iface);
-
- Class<?> superclass = klass.getSuperclass();
- if(!result && superclass != null) {
- result |= isImplement(superclass, iface);
- }
-
- return result;
- }
} //TopiaSecurityUtil
Modified: trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/TaasService.java
===================================================================
--- trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/TaasService.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/TaasService.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -256,7 +256,7 @@
for (Iterator<? extends TopiaEntity> iterator = entities.iterator(); iterator.hasNext();) {
TopiaEntity entity = iterator.next();
try {
- AccessController.checkPermission(new TaasPermission(entity.getTopiaId(), actions));
+ AccessController.checkPermission(new TaasPermission(entity.getId(), actions));
} catch (SecurityException se) {
if (log.isDebugEnabled()) {
log.debug(getPrincipalNames(subj) + " does not have permissions to load: " + entity);
@@ -279,9 +279,9 @@
Subject subj = findSubject();
if (subj != null) {
try {
- AccessController.checkPermission(new TaasPermission(entity.getTopiaId(), actions));
+ AccessController.checkPermission(new TaasPermission(entity.getId(), actions));
} catch (SecurityException se) {
- throw new SecurityException("Access denied to object \"" + entity.getTopiaId() + "\" for \"" + getPrincipalNames(subj) + "\"");
+ throw new SecurityException("Access denied to object \"" + entity.getId() + "\" for \"" + getPrincipalNames(subj) + "\"");
}
} else {
throw new SecurityException("Use doAs() and login first");
@@ -321,9 +321,9 @@
if(permissions == null) {
try {
- AccessController.checkPermission(new TaasPermission(entity.getTopiaId(), actions));
+ AccessController.checkPermission(new TaasPermission(entity.getId(), actions));
} catch (SecurityException se) {
- throw new SecurityException("Access denied to object \"" + entity.getTopiaId() + "\" for \"" + getPrincipalNames(subj) + "\"");
+ throw new SecurityException("Access denied to object \"" + entity.getId() + "\" for \"" + getPrincipalNames(subj) + "\"");
}
} else {
for (Permission permission : permissions) {
@@ -331,7 +331,7 @@
AccessController.checkPermission(permission);
break;
} catch (SecurityException se) {
- throw new SecurityException("Access denied to object \"" + entity.getTopiaId() + "\" for \"" + getPrincipalNames(subj) + "\"");
+ throw new SecurityException("Access denied to object \"" + entity.getId() + "\" for \"" + getPrincipalNames(subj) + "\"");
}
}
}
@@ -356,7 +356,7 @@
if(permissions == null) {
try {
- AccessController.checkPermission(new TaasPermission(entity.getTopiaId(), actions));
+ AccessController.checkPermission(new TaasPermission(entity.getId(), actions));
} catch (SecurityException se) {
iterator.remove();
}
@@ -383,7 +383,7 @@
* @return permissions � v�rifier
*/
public List<Permission> getRequestPermission(TopiaEntity entity, int actions) {
- String topiaId = entity.getTopiaId();
+ String topiaId = entity.getId();
Class<? extends TopiaEntity> klass = null;
try {
Modified: trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/event/TaasEntityVetoable.java
===================================================================
--- trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/event/TaasEntityVetoable.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/event/TaasEntityVetoable.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -59,7 +59,7 @@
*/
public void create(TopiaEntityEvent event) {
TopiaEntity entity = event.getEntity();
- String topiaId = entity.getTopiaId();
+ String topiaId = entity.getId();
Class<? extends TopiaEntity> clazz;
if (log.isDebugEnabled()) {
@@ -73,7 +73,7 @@
*/
public void delete(TopiaEntityEvent event) {
TopiaEntity entity = event.getEntity();
- String topiaId = entity.getTopiaId();
+ String topiaId = entity.getId();
if (log.isDebugEnabled()) {
log.debug("[Security] delete entity : " + topiaId);
@@ -87,7 +87,7 @@
*/
public void load(TopiaEntityEvent event) {
// TopiaEntity entity = event.getEntity();
-// String topiaId = entity.getTopiaId();
+// String topiaId = entity.getId();
//
// if (log.isDebugEnabled()) {
// log.debug("[Security] load entity : " + topiaId);
@@ -100,7 +100,7 @@
*/
public void update(TopiaEntityEvent event) {
TopiaEntity entity = event.getEntity();
- String topiaId = entity.getTopiaId();
+ String topiaId = entity.getId();
if (log.isDebugEnabled()) {
log.debug("[Security] update entity : " + topiaId);
Modified: trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/event/TaasEntityVetoableRequestPermission.java
===================================================================
--- trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/event/TaasEntityVetoableRequestPermission.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/event/TaasEntityVetoableRequestPermission.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -56,7 +56,7 @@
*/
public void create(TopiaEntityEvent event) {
TopiaEntity entity = event.getEntity();
- String topiaId = entity.getTopiaId();
+ String topiaId = entity.getId();
Class<? extends TopiaEntity> clazz;
if (log.isDebugEnabled()) {
@@ -70,7 +70,7 @@
*/
public void delete(TopiaEntityEvent event) {
TopiaEntity entity = event.getEntity();
- String topiaId = entity.getTopiaId();
+ String topiaId = entity.getId();
if (log.isDebugEnabled()) {
log.debug("[Security] delete entity : " + topiaId);
@@ -84,7 +84,7 @@
*/
public void load(TopiaEntityEvent event) {
// TopiaEntity entity = event.getEntity();
-// String topiaId = entity.getTopiaId();
+// String topiaId = entity.getId();
//
// if (log.isDebugEnabled()) {
// log.debug("[Security] load entity : " + topiaId);
@@ -97,7 +97,7 @@
*/
public void update(TopiaEntityEvent event) {
TopiaEntity entity = event.getEntity();
- String topiaId = entity.getTopiaId();
+ String topiaId = entity.getId();
if (log.isDebugEnabled()) {
log.debug("[Security] update entity : " + topiaId);
Modified: trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/jaas/TaasLoginModule.java
===================================================================
--- trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/jaas/TaasLoginModule.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/jaas/TaasLoginModule.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -148,7 +148,7 @@
user.setLastConnectionDate(new Date());
int numberOfConnection = user.getNumberOfConnection();
user.setNumberOfConnection(numberOfConnection + 1);
- user.update();
+ userDAO.update(user);
// Récupération des principals
principals = new HashSet<TaasPrincipalWrapper>();
Modified: trunk/topia-service-security/src/test/java/org/nuiton/topia/security/TopiaSecurityTest.java
===================================================================
--- trunk/topia-service-security/src/test/java/org/nuiton/topia/security/TopiaSecurityTest.java 2010-05-07 19:02:02 UTC (rev 1937)
+++ trunk/topia-service-security/src/test/java/org/nuiton/topia/security/TopiaSecurityTest.java 2010-05-07 20:50:21 UTC (rev 1938)
@@ -140,14 +140,14 @@
TopiaUser admin = topiaUserDAO.create();
admin.setLogin("admin");
admin.setPassword("azerty");
- admin.update();
+ topiaUserDAO.update(admin);
childContext.commitTransaction();
/* Création d'un utilisateur */
TopiaUser thimel = topiaUserDAO.create();
thimel.setLogin("thimel");
thimel.setPassword("zou;bi@da");
- thimel.update();
+ topiaUserDAO.update(thimel);
childContext.commitTransaction();
/* Création d'un groupe avec un utilisateur */
@@ -160,8 +160,8 @@
groupRuchaud.setTopiaUser(new ArrayList<TopiaUser>());
ruchaud.addTopiaGroup(groupRuchaud);
- groupRuchaud.update();
- ruchaud.update();
+ topiaGroupDAO.update(groupRuchaud);
+ topiaUserDAO.update(ruchaud);
childContext.commitTransaction();
/* Création des personnes */
@@ -188,67 +188,67 @@
debux.setName("debux");
debux.setType("chat");
debux.setPerson(jacques);
- debux.update();
+ petDAO.update(debux);
childContext.commitTransaction();
Pet pluto = petDAO.create();
pluto.setName("pluto");
pluto.setType("chien");
pluto.setPerson(jacques);
- pluto.update();
+ petDAO.update(pluto);
childContext.commitTransaction();
Pet fliper = petDAO.create();
fliper.setName("fliper");
fliper.setType("dauphin");
fliper.setPerson(mylene);
- fliper.update();
+ petDAO.update(fliper);
childContext.commitTransaction();
/* Création des autorisations Entity */
TopiaEntityAuthorization authorizationForAdmin = topiaEntityAuthorizationDAO.create();
authorizationForAdmin.setExpression("*");
authorizationForAdmin.setActions(15);
- authorizationForAdmin.setPrincipals(admin.getTopiaId());
- authorizationForAdmin.update();
+ authorizationForAdmin.setPrincipals(admin.getId());
+ topiaEntityAuthorizationDAO.update(authorizationForAdmin);
childContext.commitTransaction();
TopiaEntityAuthorization authorizationForRuchaud = topiaEntityAuthorizationDAO.create();
authorizationForRuchaud.setExpression(Person.class.getName() + "#*");
authorizationForRuchaud.setActions(LOAD);
- authorizationForRuchaud.setPrincipals(groupRuchaud.getTopiaId());
- authorizationForRuchaud.update();
+ authorizationForRuchaud.setPrincipals(groupRuchaud.getId());
+ topiaEntityAuthorizationDAO.update(authorizationForRuchaud);
childContext.commitTransaction();
TopiaEntityAuthorization authorizationForThimel = topiaEntityAuthorizationDAO.create();
- authorizationForThimel.setExpression(jacques.getTopiaId());
+ authorizationForThimel.setExpression(jacques.getId());
authorizationForThimel.setActions(LOAD);
- authorizationForThimel.setPrincipals(thimel.getTopiaId());
- authorizationForThimel.update();
+ authorizationForThimel.setPrincipals(thimel.getId());
+ topiaEntityAuthorizationDAO.update(authorizationForThimel);
childContext.commitTransaction();
/* Création d'une autorisation Link */
TopiaExpressionLink link = linkDAO.create();
- link.setReplace(mylene.getTopiaId());
- link.setBy(jacques.getTopiaId());
- link.update();
+ link.setReplace(mylene.getId());
+ link.setBy(jacques.getId());
+ linkDAO.update(link);
childContext.commitTransaction();
/* Création d'une authorisation association */
TopiaAssociationAuthorization associationAuthorization = topiaAssociationAuthorizationDAO.create();
- associationAuthorization.setIdBeginAssociation(jacques.getTopiaId());
+ associationAuthorization.setIdBeginAssociation(jacques.getId());
associationAuthorization.setNameAssociation("pet");
associationAuthorization.setActions(LOAD);
- associationAuthorization.setPrincipals(ruchaud.getTopiaId());
- associationAuthorization.update();
+ associationAuthorization.setPrincipals(ruchaud.getId());
+ topiaAssociationAuthorizationDAO.update(associationAuthorization);
childContext.commitTransaction();
associationAuthorization = topiaAssociationAuthorizationDAO.create();
- associationAuthorization.setIdBeginAssociation(mylene.getTopiaId());
+ associationAuthorization.setIdBeginAssociation(mylene.getId());
associationAuthorization.setNameAssociation("pet");
associationAuthorization.setActions(UPDATE);
- associationAuthorization.setPrincipals(ruchaud.getTopiaId());
- associationAuthorization.update();
+ associationAuthorization.setPrincipals(ruchaud.getId());
+ topiaAssociationAuthorizationDAO.update(associationAuthorization);
childContext.commitTransaction();
childContext.closeContext();
1
0
r1937 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by tchemit@users.nuiton.org 07 May '10
by tchemit@users.nuiton.org 07 May '10
07 May '10
Author: tchemit
Date: 2010-05-07 21:02:02 +0200 (Fri, 07 May 2010)
New Revision: 1937
Url: http://nuiton.org/repositories/revision/topia/1937
Log:
Evolution
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java 2010-05-07 16:34:39 UTC (rev 1936)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java 2010-05-07 19:02:02 UTC (rev 1937)
@@ -267,21 +267,33 @@
protected String getType(ObjectModelAttribute attr, boolean isAssoc) {
String type = attr.getType();
- if (TopiaGeneratorUtil.notEmpty(model.getTagValue(type))) {
- String typeString = model.getTagValue(type);
- int bracketIndex = typeString.indexOf('(');
- if (bracketIndex != -1) {
- type = typeString.substring(0, bracketIndex);
- int bracketEndIndex = typeString.indexOf(')', bracketIndex + 1);
- String colmunList;
- if (bracketEndIndex != -1) {
- colmunList = typeString.substring(bracketIndex + 1, bracketEndIndex);
+ String attrType = attr.getTagValue(TopiaGeneratorUtil.TAG_TYPE);
+ if (TopiaGeneratorUtil.notEmpty(attrType)) {
+
+ // tag value detected of the attribute
+ type = attrType;
+ } else {
+
+ String modelType = model.getTagValue(type);
+ if (TopiaGeneratorUtil.notEmpty(modelType)) {
+
+ // tag value detected of the model
+
+ //TODO TChemit 20100507 Explain What todes it do ? Dont understand the story of columnNamesMap
+ int bracketIndex = modelType.indexOf('(');
+ if (bracketIndex != -1) {
+ type = modelType.substring(0, bracketIndex);
+ int bracketEndIndex = modelType.indexOf(')', bracketIndex + 1);
+ String colmunList;
+ if (bracketEndIndex != -1) {
+ colmunList = modelType.substring(bracketIndex + 1, bracketEndIndex);
+ } else {
+ colmunList = modelType.substring(bracketIndex);
+ }
+ columnNamesMap.put(type, colmunList.split(","));
} else {
- colmunList = typeString.substring(bracketIndex);
+ type = modelType;
}
- columnNamesMap.put(type, colmunList.split(","));
- } else {
- type = typeString;
}
}
if (attr.hasAssociationClass() && !isAssoc) {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2010-05-07 16:34:39 UTC (rev 1936)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2010-05-07 19:02:02 UTC (rev 1937)
@@ -239,6 +239,10 @@
*/
public static final String TAG_GENERATE_OPERATOR_FOR_DAO_HELPER = "generateOperatorForDAOHelper";
/**
+ * Tag pour spécifier le type d'une propriété dans le mapping hibernate
+ */
+ public static final String TAG_TYPE= "type";
+ /**
* Type de persistence Hibernate
*/
public static final String PERSISTENCE_TYPE_HIBERNATE = "hibernate";
1
0
r1936 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by fdesbois@users.nuiton.org 07 May '10
by fdesbois@users.nuiton.org 07 May '10
07 May '10
Author: fdesbois
Date: 2010-05-07 18:34:39 +0200 (Fri, 07 May 2010)
New Revision: 1936
Url: http://nuiton.org/repositories/revision/topia/1936
Log:
- Evo #298 : Remove old deprecated Generator
- Refactor package.html in package-info.java
- Clean headers
Added:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/package-info.java
Removed:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BeanGenerator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractGenerator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOGenerator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperGenerator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOImplGenerator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DTOGenerator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityAbstractGenerator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDTOGenerator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityImplGenerator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityInterfaceGenerator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/InterfaceGenerator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaGenerator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/package.html
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BeanTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BinderHelperTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOImplTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DTOTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityAbstractTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDTOTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityImplTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityInterfaceTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/InterfaceTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaJavaValidator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaRelationValidator.java
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BeanGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BeanGenerator.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BeanGenerator.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -1,635 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-/*{generator option: parentheses = true}*/
-/*{generator option: writeString = output.write}*/
-
-/* *
-* BeanGenerator.java
-*
-* Created: 17 avril 2009
-*
-* @author tony Chemit <chemit(a)codelutin.com>
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-
-package org.nuiton.topia.generator;
-
-import org.apache.commons.lang.StringUtils;
-import static org.nuiton.topia.generator.TopiaGeneratorUtil.TAG_ANNOTATION;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Serializable;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.Iterator;
-
-import java.util.List;
-import java.util.Set;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.models.object.ObjectModelGenerator;
-import org.nuiton.eugene.GeneratorUtil;
-import org.nuiton.eugene.java.ImportsManager;
-import org.nuiton.eugene.models.object.ObjectModelAttribute;
-import org.nuiton.eugene.models.object.ObjectModelClass;
-import org.nuiton.eugene.models.object.ObjectModelClassifier;
-import org.nuiton.eugene.models.object.ObjectModelDependency;
-import org.nuiton.eugene.models.object.ObjectModelInterface;
-import org.nuiton.eugene.models.object.ObjectModelOperation;
-import org.nuiton.eugene.models.object.ObjectModelParameter;
-import org.nuiton.topia.persistence.TopiaEntity;
-import static org.nuiton.topia.generator.TopiaGeneratorUtil.isPrimitiveType;
-import static org.nuiton.topia.generator.TopiaGeneratorUtil.isDateType;
-
-/**
- * DTO generator
- *
- * @deprecated since 2.3.0, prefer use the corresponding {@link org.nuiton.eugene.Transformer} : {@link BeanTransformer}
- * @see BeanTransformer
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.BeanGenerator"
- */
-@Deprecated
-public class BeanGenerator extends ObjectModelGenerator {
-
- /**
- * Logger for this class
- */
- private static final Log log = LogFactory.getLog(BeanGenerator.class);
-
- public BeanGenerator() {
- super();
- }
-
- @Override
- public String getFilenameForClass(ObjectModelClass clazz) {
- return clazz.getQualifiedName().replace('.', File.separatorChar) + ".java";
- }
-
- @Override
- public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException {
- if (!clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_BEAN) &&
- !clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) {
- return;
- }
- //
- // première phase : calcul des variables
- //
- String copyright = TopiaGeneratorUtil.getCopyright(model);
- String clazzName = clazz.getName();
- String abstractStr = isAbstract(clazz) ? " abstract " : " ";
- boolean needGetEntityMethod = false;
- boolean generateToString = TopiaGeneratorUtil.generateToString(clazz, model);
-
- ImportsManager imports = new ImportsManager();
-
- String extendClass = "";
- Iterator<ObjectModelClass> j = clazz.getSuperclasses().iterator();
- if (j.hasNext()) {
- ObjectModelClassifier p = j.next();
- imports.addImport(p.getQualifiedName());
- extendClass += p.getName();
- }
- String implInterface = "";
- for (Iterator<ObjectModelInterface> i=clazz.getInterfaces().iterator(); i.hasNext();) {
- ObjectModelClassifier parentInterface = i.next();
- imports.addImport(parentInterface.getQualifiedName());
- implInterface += parentInterface.getName();
- if (i.hasNext()) {
- implInterface += ", ";
- }
- }
- // Add Serializable implements for DTO generation
- if (clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) {
- imports.addImport(Serializable.class);
- if (!implInterface.isEmpty()) {
- implInterface += ", ";
- }
- implInterface += Serializable.class.getName();
- }
- String svUID = TopiaGeneratorUtil.findTagValue("dto-serialVersionUID", clazz, model);
-
- List<ObjectModelAttribute> attributes = new ArrayList<ObjectModelAttribute>();
- List<ObjectModelAttribute> multipleAttr = new ArrayList<ObjectModelAttribute>();
-
- setAttributesForDTO(clazz, attributes,imports);
-
- boolean needListInImport=false;
-
- for (ObjectModelAttribute attr : clazz.getAttributes()) {
- if (attr.isNavigable()) {
- attributes.add(attr);
- imports.addImport(attr.getType());
- if (GeneratorUtil.isNMultiplicity(attr)) {
- multipleAttr.add(attr);
- ObjectModelClass attrEntity = null;
- if (model.hasClass(attr.getType())) {
- attrEntity = model.getClass(attr.getType());
- }
- boolean isEntity = (attrEntity != null && attrEntity.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY));
- needGetEntityMethod |= isEntity;
- if (attr.isOrdered()) {
- needListInImport = true;
- }
- }
- }
- }
-
- imports.addImport(java.beans.PropertyChangeListener.class.getName());
- imports.addImport(java.beans.PropertyChangeSupport.class.getName());
-
- for (ObjectModelOperation operation : clazz.getOperations()) {
- imports.addImport(operation.getReturnType());
- for (ObjectModelParameter parameter : operation.getParameters()) {
- imports.addImport(parameter.getType());
- }
- }
-
- if (needGetEntityMethod) {
- imports.addImport(TopiaEntity.class);
- }
- if (!multipleAttr.isEmpty()) {
- imports.addImport(Collection.class);
- }
- if (needListInImport) {
- imports.addImport(List.class);
- }
- if (generateToString) {
- imports.addImport(org.apache.commons.lang.builder.ToStringBuilder.class);
- }
-
- boolean sortAttribute = TopiaGeneratorUtil.sortAttribute(clazz, model);
- if (sortAttribute) {
- Comparator<ObjectModelAttribute> comp = new Comparator<ObjectModelAttribute>(){
-
- @Override
- public int compare(ObjectModelAttribute o1, ObjectModelAttribute o2) {
- return o1.getName().compareTo(o2.getName());
- }
- };
- java.util.Collections.sort(attributes,comp);
- java.util.Collections.sort(multipleAttr,comp);
- }
- //
- // seconde phase : génération
- //
-
- if (TopiaGeneratorUtil.notEmpty(copyright)) {
-/*{<%=copyright%>
-}*/
- }
-
-/*{package <%=clazz.getPackageName()%>;
-
- }*/
-
- if (log.isDebugEnabled()) {
- log.debug("imports for class <" + clazzName + ">");
- }
- //for (String anImport : imports) {
- for (String anImport : imports.getImports(clazz.getPackageName())) {
- if (log.isDebugEnabled()) {
- log.debug("import " + anImport);
- }
-/*{import <%=anImport%>;
-}*/
- }
-/*{
-public<%=abstractStr%>class <%=clazzName%>}*/
-
-/*
- * Définition de la super classe : il ne doit y avoir qu'une
- */
- if (extendClass.length() > 0) {
-/*{ extends <%=extendClass%>}*/
- }
-
- if (implInterface.length() > 0) {
-/*{ implements <%=implInterface%> {
-
-}*/
- } else {
- /*{ {
-
-}*/
- }
-
-
- // TODO Calculer un serialVersionUID si il n'y en a pas
- if (svUID != null) {
-/*{ public static final long serialVersionUID = <%=svUID%>;
-
-}*/
- }
- generateInterfaceOperations(output, clazz);
- generateAttributes(output, attributes);
-/*{ protected final PropertyChangeSupport pcs;
-
- /**
- * Default constructor of <%=clazzName%>.
- *)
- public <%=clazzName%>() {
- pcs = new PropertyChangeSupport(this);
- }
-
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(listener);
- }
-
- public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(propertyName, listener);
- }
-
-}*/
- generateGetters(output, attributes);
- generateSetters(output, attributes);
- generateGetChild(output, multipleAttr);
- generateAddChild(output, multipleAttr);
- generateRemoveChild(output, multipleAttr);
- if (generateToString) {
- generateToString(output, clazz);
- }
- if (!multipleAttr.isEmpty()) {
-/*{
-
- protected <T> T getChild(Collection<T> childs, int index) {
- if (childs != null) {
- int i = 0;
- for (T o : childs) {
- if (index == i) {
- return o;
- }
- i++;
- }
- }
- return null;
- }
-
- }*/
- if (needGetEntityMethod) {
-/*{ protected <T extends TopiaEntity> T getEntity(Collection<T> childs, String topiaId) {
- if (childs != null) {
- for (T o : childs) {
- if (topiaId.equals(o.getTopiaId())) {
- return o;
- }
- }
- }
- return null;
- }
- }*/
- }
- }
-
-/*{
- protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
- pcs.firePropertyChange(propertyName, oldValue, newValue);
- }
-
-} //<%=clazz.getName()%>
-}*/
- }
-
- protected void generateAttributes(Writer output, List<ObjectModelAttribute> attributes) throws IOException {
-
- for (ObjectModelAttribute attr : attributes) {
-
- if (!(attr.isNavigable()
- || attr.hasAssociationClass())) {
- continue;
- }
-
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
-/*{ /**
- * <%=attr.getDocumentation()%>
- *)
-}*/
- }
- String annotation = attr.getTagValue(TAG_ANNOTATION);
- if (annotation != null && annotation.length() > 0) {
-/*{ <%=annotation%>
-}*/
- }
- String attrName = attr.getName();
- String attrVisibility = attr.getVisibility();
- String attrType = attr.getType();
- if (attr.hasAssociationClass()) {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
- attrType = attr.getAssociationClass().getName();
- }
- int dot = attrType.lastIndexOf(".");
- if (dot>-1) {
- attrType = attrType.substring(dot + 1);
- }
- if (GeneratorUtil.isNMultiplicity(attr)) {
- attrType = getCollection(attr, attrType);
- }
-
-/*{ <%=attrVisibility%> <%=attrType%> <%=attrName%>;
-}*/
- }
- }
-
- protected void generateGetters(Writer output, List<ObjectModelAttribute> attributes) throws IOException {
- /*
- * Définition des getteurs et setteurs
- */
- for (ObjectModelAttribute attr : attributes) {
-
- if (!attr.isNavigable()) {
- continue;
- }
-
- String attrName = attr.getName();
- String attrType = attr.getType();
- if (attr.hasAssociationClass()) {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
- attrType = attr.getAssociationClass().getName();
- }
- String attrNameCapitalized = StringUtils.capitalize(attrName);
- int dot = attrType.lastIndexOf(".");
- if (dot>-1) {
- attrType = attrType.substring(dot + 1);
- }
- if (GeneratorUtil.isNMultiplicity(attr)) {
- attrType = getCollection(attr, attrType);
- }
-/*{ public <%=attrType%> get<%=attrNameCapitalized%>() {
- return <%=attrName%>;
- }
-
-}*/
- }
- }
-
- protected void generateSetters(Writer output, List<ObjectModelAttribute> attributes) throws IOException {
- /*
- * Définition des getteurs et setteurs
- */
- for (ObjectModelAttribute attr : attributes) {
-
- if (!attr.isNavigable()) {
- continue;
- }
-
- String attrName = attr.getName();
- String attrType = attr.getType();
-
- if (attr.hasAssociationClass()) {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
- attrType = attr.getAssociationClass().getName();
- }
- String attrNameCapitalized = StringUtils.capitalize(attrName);
- int dot = attrType.lastIndexOf(".");
- if (dot>-1) {
- attrType = attrType.substring(dot + 1);
- }
- if (GeneratorUtil.isNMultiplicity(attr)) {
- attrType = getCollection(attr, attrType);
- }
-/*{ public void set<%=attrNameCapitalized%>(<%=attrType%> newValue) {
- <%=attrType%> oldValue = get<%=attrNameCapitalized%>();
- this.<%=attrName%> = newValue;
- firePropertyChange("<%=attrName%>", oldValue, newValue);
- }
-
-}*/
- }
- }
-
- protected void generateGetChild(Writer output, List<ObjectModelAttribute> multipleAttr) throws IOException {
-
- for (ObjectModelAttribute attr : multipleAttr) {
-
- String attrName = attr.getName();
- String attrNameCapitalized = StringUtils.capitalize(attrName);
- String attrType = attr.getType();
- int dot = attrType.lastIndexOf(".");
- if (dot>-1) {
- attrType = attrType.substring(dot + 1);
- }
- ObjectModelClass attrEntity=null;
- if (model.hasClass(attr.getType())) {
- attrEntity = model.getClass(attr.getType());
- }
- boolean isEntity = (attrEntity != null && attrEntity.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY));
-/*{ public <%=attrType%> get<%=attrNameCapitalized%>(int index) {
- <%=attrType%> o = getChild(<%=attrName%>, index);
- return o;
- }
-
-}*/
- if (isEntity) {
-/*{ public <%=attrType%> get<%=attrNameCapitalized%>(String topiaId) {
- <%=attrType%> o = getEntity(<%=attrName%>, topiaId);
- return o;
- }
-
-}*/
- }
- }
- }
- protected void generateAddChild(Writer output, List<ObjectModelAttribute> multipleAttr) throws IOException {
- for (ObjectModelAttribute attr : multipleAttr) {
-
- String attrName = attr.getName();
- String attrNameCapitalized = StringUtils.capitalize(attrName);
- String attrType = attr.getType();
- int dot = attrType.lastIndexOf(".");
- if (dot>-1) {
- attrType = attrType.substring(dot + 1);
- }
-/*{ public <%=attrType%> add<%=attrNameCapitalized%>(<%=attrType%> <%=attrName%>) {
- get<%=attrNameCapitalized%>().add(<%=attrName%>);
- firePropertyChange("<%=attrName%>", null, <%=attrName%>);
- return <%=attrName%>;
- }
-
-}*/
- }
- }
-
- protected void generateRemoveChild(Writer output, List<ObjectModelAttribute> multipleAttr) throws IOException {
- for (ObjectModelAttribute attr : multipleAttr) {
- String attrName = attr.getName();
- String attrNameCapitalized = StringUtils.capitalize(attrName);
- String attrType = attr.getType();
- int dot = attrType.lastIndexOf(".");
- if (dot>-1) {
- attrType = attrType.substring(dot + 1);
- }
-/*{ public boolean remove<%=attrNameCapitalized%>(<%=attrType%> <%=attrName%>) {
- boolean removed = get<%=attrNameCapitalized%>().remove(<%=attrName%>);
- if (removed) {
- firePropertyChange("<%=attrName%>", <%=attrName%>, null);
- }
- return removed;
- }
-
-}*/
- }
- }
-
- protected void generateInterfaceOperations(Writer output, ObjectModelClassifier classifier) throws IOException {
- for (ObjectModelOperation op : classifier.getOperations()) {
- String opName = op.getName();
-/*{ /**
-}*/
- if (TopiaGeneratorUtil.hasDocumentation(op)) {
- String opDocumentation = op.getDocumentation();
-/*{ * <%=opName%> : <%=opDocumentation%>
-}*/
- }
- Collection<ObjectModelParameter> params = op.getParameters();
- for (ObjectModelParameter param : params) {
- String paramName = param.getName();
- String paramDocumentation = param.getDocumentation();
-/*{ * @param <%=paramName%> <%=paramDocumentation%>
- }*/
- }
- String opVisibility = op.getVisibility();
- String opType = op.getReturnType();
-/*{ *)
- <%=opVisibility%> abstract <%=opType%> <%=opName%>(}*/
- String comma = "";
- for (ObjectModelParameter param : params) {
- String paramName = param.getName();
- String paramType = param.getType();
-/*{<%=comma%><%=paramType%> <%=paramName%>}*/
- comma = ", ";
- }
-/*{)}*/
- Set<String> exceptions = op.getExceptions();
- comma = " throws ";
- for (String exception : exceptions) {
-/*{<%=comma%><%=exception%>}*/
- comma = ", ";
- }
-/*{;
-
-}*/
- }
- }
- protected void generateToString(Writer output, ObjectModelClass clazz) throws IOException {
-/*{
- @Override
- public String toString() {
- String result = new ToStringBuilder(this).
-}*/
- for (ObjectModelAttribute attr : clazz.getAttributes()) {
- if (!(attr.isNavigable() || attr.hasAssociationClass())) {
- continue;
- }
- //FIXME possibilité de boucles (non directes)
- String attrName = attr.getName();
-/*{ append("<%=attrName%>", this.<%=attrName%>).
-}*/
- }
-/*{ toString();
- return result;
- }
- }*/
- }
-
- protected String getCollection(ObjectModelAttribute attr, String attrType) {
- String nMultType;
- if (attr.isOrdered()) {
- nMultType = "List<";
- } else {
- nMultType = "Collection<";
- }
- nMultType += attrType;
- nMultType += ">";
- return nMultType;
- }
-
- protected boolean isAbstract(ObjectModelClass clazz) {
- if (clazz.isAbstract()) {
- return true;
- }
- return !clazz.getOperations().isEmpty();
- }
-
- /**
- * Dependecy gestion for DTO generation.
- * All primitives attributes (and dates) of dependencies entities of the DTO are
- * copied in the DTO. This method only prepare a list of attributes to be generated.
- * @param clazz DTO ObjectModelClass
- * @param attributes list of attributes for the generation (may be not empty)
- * @param imports the ImportsManager used to generate the header imports of the DTO
- * @return the same list of attributes in parameter with attributes from entities dependencies
- * @see org.nuiton.eugene.ImportsManager
- * @see org.nuiton.eugene.models.object.ObjectModelDependency
- */
- private List<ObjectModelAttribute> setAttributesForDTO(ObjectModelClass clazz,
- List<ObjectModelAttribute> attributes, ImportsManager imports) {
-
- if (clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) {
- if (log.isInfoEnabled()) {
- log.info("DTO dependency gestion");
- }
- for (ObjectModelDependency dependency : clazz.getDependencies()) {
- ObjectModelClass supplier = (ObjectModelClass)dependency.getSupplier();
-
- // ENTITY dependency
- // Copy all primitives attributes from the Entity (supplier) to the DTO
- // Prepare a list to future generation of all object generated attributes
- if (supplier.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)) {
- if (log.isInfoEnabled()) {
- log.info("Create primitive and date fields in DTO from Entity : "
- + supplier.getQualifiedName());
- }
- for (ObjectModelAttribute attr : supplier.getAttributes()) {
- if (isPrimitiveType(attr) || isDateType(attr)) {
- attributes.add(attr);
- imports.addImport(attr.getType());
- }
- if (GeneratorUtil.isNMultiplicity(attr)) {
- imports.addImport("java.util.Collection");
- }
- }
- }
- }
- }
- return attributes;
- }
-} //BeanGenerator
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BeanTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BeanTransformer.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BeanTransformer.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -45,11 +45,10 @@
* <p/>
* Created: 28 oct. 2009
*
- * @author fdesbois
- * @version $Revision$
- * <p/>
- * Mise a jour: $Date$
- * par : @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.BeanTransformer"
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @author tchemit <tchemit(a)codelutin.com>
+ * @version $Id$
+ * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.BeanTransformer"
*/
public class BeanTransformer extends ObjectModelTransformerToJava {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BinderHelperTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BinderHelperTransformer.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BinderHelperTransformer.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -49,6 +49,7 @@
* A template to generate a helper for {@link TopiaEntityBinder}.
*
* @author tchemit <chemit(a)codelutin.com>
+ * @version $Id$
* @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.BinderHelperTransformer"
* @since 2.3.1
*/
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractGenerator.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractGenerator.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -1,537 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-/*{generator option: parentheses = true}*/
-/*{generator option: writeString = output.write}*/
-
-/* *
-* EntityGenerator.java
-*
-* Created: 12 déc. 2005
-*
-* @author Arnaud Thimel <thimel(a)codelutin.com>
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-
-package org.nuiton.topia.generator;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.commons.lang.StringUtils;
-import org.nuiton.eugene.GeneratorUtil;
-import org.nuiton.eugene.models.object.ObjectModelGenerator;
-import org.nuiton.eugene.models.object.ObjectModelAssociationClass;
-import org.nuiton.eugene.models.object.ObjectModelAttribute;
-import org.nuiton.eugene.models.object.ObjectModelClass;
-import org.nuiton.eugene.models.object.ObjectModelClassifier;
-import org.nuiton.eugene.models.object.ObjectModelOperation;
-import org.nuiton.eugene.models.object.ObjectModelParameter;
-import org.nuiton.util.StringUtil;
-
-/**
- * Genere des DAOs abstrait par defaut, l'utilisateur peut ensuite en herite
- * pour implanter d'autre methode find, ou bien laisser l'implantation par
- * defaut de l'autre generateur qui genere une classe DAO qui herite de celle-ci
- * mais completement vide.
-
- * @author poussin
- *
- * @deprecated since 2.3.0, prefer use the corresponding {@link org.nuiton.eugene.Transformer} :
- * {@link DAOAbstractTransformer}.
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.DAOAbstractGenerator"
- */
-@Deprecated
-public class DAOAbstractGenerator extends ObjectModelGenerator {
-
- @Override
- public String getFilenameForClass(ObjectModelClass clazz) {
- return clazz.getQualifiedName().replace('.', File.separatorChar) + "DAOAbstract.java";
- }
-
- @Override
- public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException {
- if (!clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)) {
- return;
- }
- String copyright = TopiaGeneratorUtil.getCopyright(model);
- if (TopiaGeneratorUtil.notEmpty(copyright)) {
-/*{<%=copyright%>
-}*/
- }
-/*{package <%=clazz.getPackageName()%>;
-
-import java.util.List;
-
-}*/
- Collection<ObjectModelOperation> DAOoperations = getDAOOperations(clazz);
- if (isCollectionNeeded(DAOoperations)) {
-/*{
-import java.util.Collection;
-}*/
- }
- if (isSetNeeded(DAOoperations)) {
-/*{
-import java.util.Set;
-}*/
- }
-/*{
-import java.util.Arrays;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.framework.TopiaContextImplementor;
-}*/
- boolean enableSecurity = (
- clazz.hasTagValue(TopiaGeneratorUtil.TAG_SECURITY_CREATE) ||
- clazz.hasTagValue(TopiaGeneratorUtil.TAG_SECURITY_LOAD) ||
- clazz.hasTagValue(TopiaGeneratorUtil.TAG_SECURITY_UPDATE) ||
- clazz.hasTagValue(TopiaGeneratorUtil.TAG_SECURITY_DELETE)
- );
-
- if (enableSecurity) {
-/*{
-import java.util.ArrayList;
-import java.security.Permission;
-import org.nuiton.topia.taas.entities.TaasAuthorizationImpl;
-import org.nuiton.topia.taas.jaas.TaasPermission;
-import org.nuiton.topia.persistence.TopiaDAO;
-import static org.nuiton.topia.taas.TaasUtil.CREATE;
-import static org.nuiton.topia.taas.TaasUtil.DELETE;
-import static org.nuiton.topia.taas.TaasUtil.LOAD;
-import static org.nuiton.topia.taas.TaasUtil.UPDATE;
-}*/
- }
- String clazzName = clazz.getName();
-/*{
-/**
- * Implantation DAO pour l'entité <%=GeneratorUtil.toUpperCaseFirstLetter(clazz.getName())%>.
- * Cette classe contient une implantation de TopiaDAO a laquel elle peut
- * deleguer des traitements
- *
- *)
-public abstract class <%=clazzName%>DAOAbstract<E extends <%=clazzName%>> extends }*/
- String extendClass = "";
- for (Iterator<ObjectModelClass> i=clazz.getSuperclasses().iterator(); i.hasNext();) {
- ObjectModelClassifier parent = i.next();
- extendClass += parent.getQualifiedName();
- if (parent.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)) {
- extendClass += "DAOImpl<E>";
- }
- if (i.hasNext()) {
- extendClass += ", ";
- }
- }
- if (extendClass.length() == 0) {
- extendClass += "org.nuiton.topia.persistence.TopiaDAOImpl<E>";
- }
-
- /*{<%=extendClass%> implements org.nuiton.topia.persistence.TopiaDAO<E> {
-
- public Class<E> getEntityClass() {
- return (Class<E>)<%=clazzName%>.class;
- }
-}*/
-
- generateDAOOperations(output, DAOoperations);
-/*{
- public void delete(E entity) throws TopiaException {
-}*/
- String modelName = StringUtils.capitalize(model.getName());
- String providerFQN = getProperty("defaultPackage") + "." + modelName + "DAOHelper.getImplementationClass";
- for (ObjectModelAttribute attr : clazz.getAttributes()) {
- String attrType = attr.getType();
- String reverseAttrName = attr.getReverseAttributeName();
- ObjectModelAttribute reverse = attr.getReverseAttribute();
- if (!attr.hasAssociationClass() && reverse != null && reverse.isNavigable()
- && GeneratorUtil.isNMultiplicity(attr) && GeneratorUtil.isNMultiplicity(reverse)) {
- // On doit absolument supprimer pour les relations many-to-many
- // le this de la collection de l'autre cote
-
- String attrDBName = TopiaGeneratorUtil.getDBName(attr);
- String attrClassifierDBName = TopiaGeneratorUtil.getDBName(attr.getClassifier());
- String attrJoinTableName = TopiaGeneratorUtil.getManyToManyTableName(attr);
- String attrReverseDBName = TopiaGeneratorUtil.getReverseDBName(attr);
-/*{
- {
- List<<%=attrType%>> list = getContext().getHibernate().createSQLQuery(
- "SELECT main.topiaid " +
- "from <%=attrClassifierDBName%> main, <%=attrJoinTableName%> secondary " +
- "where main.topiaid=secondary.<%=attrDBName%>" +
- " and secondary.<%=attrReverseDBName%>='" + entity.getTopiaId() + "'")
- .addEntity("main", <%=providerFQN%>(<%=attrType%>.class)).list();
- for (<%=attrType%> item : list) {
- item.remove<%=TopiaGeneratorUtil.capitalize(reverseAttrName)%>(entity);
- }
- }
-}*/
- } else if (!attr.hasAssociationClass() && reverse != null
- && reverse.isNavigable() && !GeneratorUtil.isNMultiplicity(reverse)) {
- // On doit mettre a null les attributs qui ont cet objet sur les
- // autres entites en one-to-*
- // TODO peut-etre qu'hibernate est capable de faire ca tout seul ?
- // THIMEL: J'ai remplacé reverse.getName() par reverseAttrName sans certitude
- /*{
- {
- List<<%=attrType%>> list = getContext()
- .getDAO(<%=attrType%>.class)
- .findAllByProperties("<%=reverseAttrName%>", entity);
- for (<%=attrType%> item : list) {
- item.set<%=GeneratorUtil.capitalize(reverseAttrName)%>(null);
-}*/
- if(attr.isAggregate()){
-/*{
- item.delete();
-}*/
- }
-/*{
- }
- }
- }*/
-
- }
- }
-/*{
- super.delete(entity);
- }
-
-}*/
- for (ObjectModelAttribute attr : clazz.getAttributes()) {
- if (!attr.isNavigable()) {
- continue;
- }
- String attrName = attr.getName();
-
-/*{ /**
- * Recherche sur l'attribut <%=attrName%>
- *)
-}*/
- if (!GeneratorUtil.isNMultiplicity(attr)) {
- generateNoNMultiplicity(output, attr, false);
- } else {
- generateNMultiplicity(output, attr);
- }
- }
-
- if (clazz instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assocClass = (ObjectModelAssociationClass)clazz;
- for (ObjectModelAttribute attr : assocClass.getParticipantsAttributes()) {
- if (attr != null) {
- if (!GeneratorUtil.isNMultiplicity(attr)) {
- generateNoNMultiplicity(output, attr, true);
- } else {
- generateNMultiplicity(output, attr);
- }
- }
- }
- }
-
- if(enableSecurity) {
-/*{
- /**
- * Retourne les permissions a verifier pour l'acces a l'entite pour le service Taas
- * @param topiaId topiaId d'une entite
- * @param actions actions souhaitées
- * @return la liste des permissions
- *)
- public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException {
- List<Permission> resultPermissions = new ArrayList<Permission>();
- if ((actions & CREATE) == CREATE) {
-}*/
- generateSecurity(output, clazz, TopiaGeneratorUtil.TAG_SECURITY_CREATE);
-/*{
- }
- if ((actions & LOAD) == LOAD) {
-}*/
- generateSecurity(output, clazz, TopiaGeneratorUtil.TAG_SECURITY_LOAD);
-/*{
- }
- if ((actions & UPDATE) == UPDATE) {
-}*/
- generateSecurity(output, clazz, TopiaGeneratorUtil.TAG_SECURITY_UPDATE);
-/*{
- }
- if ((actions & DELETE) == DELETE) {
-}*/
- generateSecurity(output, clazz, TopiaGeneratorUtil.TAG_SECURITY_DELETE);
-/*{
- }
- return resultPermissions;
- }
-
-}*/
- // THIMEL : Le code suivant doit pouvoir être déplacé dans DAODelegator ?
-/*{
- /**
- * Retourne les permissions a verifier pour l'acces a l'entite pour le service Taas
- * @param topiaId topiaId d'une entite
- * @param actions actions souhaitées
- * @param query requete pour avoir le prochain topiaId
- * @param daoClass delegation du getRequestPermission
- * @return la liste des permissions
- *)
- protected List<Permission> getRequestPermission(String topiaId, int actions, String query, Class daoClass) throws TopiaException {
- TopiaContextImplementor context = getContext();
- List<String> result = context.find(query, "id", topiaId);
-
- List<Permission> resultPermissions = new ArrayList<Permission>();
- for (String topiaIdPermission : result) {
- TopiaDAO dao = context.getDAO(daoClass);
- List<Permission> permissions = dao.getRequestPermission(topiaIdPermission, actions);
- if(permissions != null) {
- resultPermissions.addAll(permissions);
- } else {
- TaasPermission permission = new TaasPermission(topiaIdPermission, actions);
- resultPermissions.add(permission);
- }
- }
- return resultPermissions;
- }
-}*/
- }
-/*{
-} // <%=clazz.getName()%>DAOAbstract
-}*/
- }
-
- /**
- * Generation of DAO operations signatures from class.
- * These operations are abstract and identified by <<dao>> stereotype in the model.
- * The developper must defined these methods in the DAOImpl associated to this DAOAbstract.
- * @param output
- * @param operations operations to generate
- */
- private void generateDAOOperations(Writer output, Collection<ObjectModelOperation> operations) throws IOException {
- for (ObjectModelOperation op : operations) {
- String opName = op.getName();
-
-/*{ /**
-}*/
- if (TopiaGeneratorUtil.hasDocumentation(op)) {
- String opDocumentation = op.getDocumentation();
-/*{ * <%=opName%> : <%=opDocumentation%>
-}*/
- }
- Collection<ObjectModelParameter> params = op.getParameters();
- for (ObjectModelParameter param : params) {
- String paramName = param.getName();
- String paramDocumentation = param.getDocumentation();
-/*{ * @param <%=paramName%> <%=paramDocumentation%>
- }*/
- }
- String opVisibility = op.getVisibility();
- String opType = op.getReturnType();
- //ObjectModelClass clazz = (ObjectModelClass)op.getDeclaringElement();
- //opType = opType.replace(clazz.getQualifiedName(),clazz.getName());
- //opType = opType.replace(clazz.getName(), "E"); // Generic usage for inheritance
-/*{ *)
- <%=opVisibility%> abstract <%=opType%> <%=opName%>(}*/
- String comma = "";
- for (ObjectModelParameter param : params) {
- String paramName = param.getName();
- String paramType = param.getType();
-/*{<%=comma%><%=paramType%> <%=paramName%>}*/
- comma = ", ";
- }
-/*{)}*/
- Set<String> exceptions = op.getExceptions();
- exceptions.add("TopiaException");
- comma = " throws ";
- for (String exception : exceptions) {
-/*{<%=comma%><%=exception%>}*/
- comma = ", ";
- }
-/*{;
-
-}*/
- }
- }
-
- private boolean isCollectionNeeded(Collection<ObjectModelOperation> operations) {
- return isImportNeeded(operations, "Collection");
- }
-
- private boolean isSetNeeded(Collection<ObjectModelOperation> operations) {
- return isImportNeeded(operations, "Set");
- }
-
- private boolean isImportNeeded(Collection<ObjectModelOperation> operations, String importName) {
- for (ObjectModelOperation op : operations) {
- if (op.getReturnType().contains(importName)){
- return true;
- }
- for (ObjectModelParameter param : op.getParameters()) {
- if (param.getType().contains(importName)){
- return true;
- }
- }
- }
- return false;
- }
-
- public static Collection<ObjectModelOperation> getDAOOperations(ObjectModelClass clazz) {
- Collection<ObjectModelOperation> results = new ArrayList<ObjectModelOperation>();
- for (ObjectModelOperation op : clazz.getOperations()) {
- if (op.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DAO)) {
- results.add(op);
- }
- }
- return results;
- }
-
- private void generateSecurity(Writer output, ObjectModelClass clazz, String securityTagName) throws IOException {
- if (clazz.hasTagValue(securityTagName)) {
- String security = clazz.getTagValue(securityTagName);
- Pattern propertiesPattern = Pattern
- .compile("((?:[_a-zA-Z0-9]+\\.)+(?:_?[A-Z][_a-zA-Z0-9]*\\.)+)attribute\\.(?:([_a-z0-9][_a-zA-Z0-9]*))#(?:(create|load|update|delete))");
- String[] valuesSecurity = security.split(":");
-
- for (String valueSecurity : valuesSecurity) {
- Matcher matcher = propertiesPattern.matcher(valueSecurity);
- matcher.find();
- // className is fully qualified name of class
- String className = matcher.group(1);
- className = StringUtil.substring(className, 0, -1); // remove ended
- // .
- // target is class, attribute or operation
- String attributeName = matcher.group(2);
- String actions = matcher.group(3).toUpperCase();
-
- String query = "";
- String daoClass = "";
- if(className.equals(clazz.getQualifiedName())) {
- query = "select " + attributeName + ".topiaId from " + clazz.getQualifiedName() + " where topiaId = :id";
- daoClass = clazz.getAttribute(attributeName).getClassifier().getQualifiedName();
- } else {
- query = "select at.topiaId from " + className + " at inner join at." + attributeName + " cl where cl.topiaId = :id";
- daoClass = className;
- }
-/*{ resultPermissions.addAll(getRequestPermission(topiaId,
- <%=actions%>,
- "<%=query%>",
- <%=daoClass%>.class));
-}*/
- }
- } else {
-/*{ return null;
-}*/
- }
- }
-
- protected void generateNoNMultiplicity(Writer output, ObjectModelAttribute attr, boolean isAssoc) throws IOException {
- String attrName = attr.getName();
- String attrType = attr.getType();
- String propertyName = attrName;
- if (!isAssoc && attr.hasAssociationClass()) {
- propertyName = TopiaGeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName()) + "." + propertyName;
- }
-/*{
- /**
- * Retourne le premier élément trouvé ayant comme valeur pour l'attribut
- * <%=attrName%> le paramètre
- * @param v la valeur que doit avoir <%=attrName%>
- * @return un element ou null
- *)
- public E findBy<%=TopiaGeneratorUtil.capitalize(attrName)%>(<%=attrType%> v) throws TopiaException {
- E result = findByProperty("<%=propertyName%>", v);
- return result;
- }
-
- /**
- * Retourne les éléments ayant comme valeur pour l'attribut
- * <%=attrName%> le paramètre
- * @param v la valeur que doit avoir <%=attrName%>
- * @return une liste
- *)
- public List<E> findAllBy<%=TopiaGeneratorUtil.capitalize(attrName)%>(<%=attrType%> v) throws TopiaException {
- List<E> result = findAllByProperty("<%=propertyName%>", v);
- return result;
- }
-}*/
- if (attr.hasAssociationClass()) {
- String assocClassName = attr.getAssociationClass().getName();
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
-/*{
- /**
- * Retourne le premier élément trouvé ayant comme valeur pour l'attribut
- * <%=TopiaGeneratorUtil.toLowerCaseFirstLetter(assocClassName)%> le paramètre
- * @param value la valeur que doit avoir <%=TopiaGeneratorUtil.toLowerCaseFirstLetter(assocClassName)%>
- * @return un element ou null
- *)
- public E findBy<%=TopiaGeneratorUtil.capitalize(assocClassName)%>(<%=assocClassFQN%> value) throws TopiaException {
- E result = findByProperty("<%=TopiaGeneratorUtil.toLowerCaseFirstLetter(assocClassName)%>", value);
- return result;
- }
-
- /**
- * Retourne les éléments ayant comme valeur pour l'attribut
- * <%=TopiaGeneratorUtil.toLowerCaseFirstLetter(assocClassName)%> le paramètre
- * @param value la valeur que doit avoir <%=TopiaGeneratorUtil.toLowerCaseFirstLetter(assocClassName)%>
- * @return une liste
- *)
- public List<E> findAllBy<%=TopiaGeneratorUtil.capitalize(assocClassName)%>(<%=assocClassFQN%> value) throws TopiaException {
- List<E> result = findAllByProperty("<%=TopiaGeneratorUtil.toLowerCaseFirstLetter(assocClassName)%>", value);
- return result;
- }
-}*/
- }
- }
-
- protected void generateNMultiplicity(Writer output, ObjectModelAttribute attr) throws IOException {
- String attrName = attr.getName();
- String attrType = attr.getType();
-/*{
- /**
- * Retourne le premier élément trouvé dont l'attribut
- * <%=attrName%> contient le paramètre
- * @param v la valeur que doit contenir <%=attrName%>
- * @return un element ou null
- *)
- public E findContains<%=TopiaGeneratorUtil.capitalize(attrName)%>(<%=attrType%> ... v) throws TopiaException {
- E result = findContainsProperties("<%=TopiaGeneratorUtil.toLowerCaseFirstLetter(attrName)%>", Arrays.asList(v));
- return result;
- }
- /**
- * Retourne les éléments trouvé dont l'attribut
- * <%=attrName%> contient le paramètre
- * @param v la valeur que doit contenir <%=attrName%>
- * @return une liste
- *)
- public List<E> findAllContains<%=TopiaGeneratorUtil.capitalize(attrName)%>(<%=attrType%> ... v) throws TopiaException {
- List<E> results = findAllContainsProperties("<%=TopiaGeneratorUtil.toLowerCaseFirstLetter(attrName)%>", Arrays.asList(v));
- return results;
- }
-}*/
- }
-
-} //DAOAbstractGenerator
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -51,11 +51,8 @@
/**
* Created: 13 déc. 2009
*
- * @author Tony Chemit <chemit(a)codelutin.com> Copyright Code Lutin
- * @version $Revision$
- * <p/>
- * Mise a jour: $Date$ par :
- * $Author$
+ * @author tchemit <chemit(a)codelutin.com>
+ * @version $Id$
* @since 2.3.0
* @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.DAOAbstractTransformer"
*/
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOGenerator.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOGenerator.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -1,92 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-/*{generator option: parentheses = true}*/
-/*{generator option: writeString = output.write}*/
-
-/* *
-* EntityPOJOGenerator.java
-*
-* Created: 12 déc. 2005
-*
-* @author Arnaud Thimel <thimel(a)codelutin.com>
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-
-package org.nuiton.topia.generator;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-
-import org.nuiton.eugene.models.object.ObjectModelGenerator;
-import org.nuiton.eugene.models.object.ObjectModelClass;
-
-/**
- *
- * @deprecated since 2.3.0, prefer use the corresponding {@link org.nuiton.eugene.Transformer} :
- * {@link DAOTransformer}.
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.DAOGenerator"
- */
-@Deprecated
-public class DAOGenerator extends ObjectModelGenerator {
-
-
- @Override
- public String getFilenameForClass(ObjectModelClass clazz) {
- return clazz.getQualifiedName().replace('.', File.separatorChar) + "DAO.java";
- }
-
- @Override
- public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException {
- if (!clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)) {
- return;
- }
- String copyright = TopiaGeneratorUtil.getCopyright(model);
- if (TopiaGeneratorUtil.notEmpty(copyright)) {
-/*{<%=copyright%>
-}*/
- }
- String clazzName = clazz.getName();
- String clazzFQN = clazz.getQualifiedName();
-/*{package <%=clazz.getPackageName()%>;
-
-/**
- * Cette classe etend le DAOImpl pour parametrer la classe avec le bon type
- * Cette classe est marque finale car l'heritage entre les DAO se fait
- * sur les DOAImpl, c-a-d que DAOAbstract peut etendre le DAOImpl
- *)
-public final class <%=clazzName%>DAO extends <%=clazzFQN%>DAOImpl<<%=clazzName%>> {
-
-}*/
-
-/*{} //<%=clazzName%>DAO
-}*/
- }
-
-} //DAOGenerator
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperGenerator.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperGenerator.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -1,369 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-/*{generator option: parentheses = true}*/
-/*{generator option: writeString = output.write}*/
-
-/*******************************************************************************
- * DAOHelperGenerator.java
- *
- * Created: 12 déc. 2005
- *
- * @author Arnaud Thimel <thimel(a)codelutin.com>
- *
- * @version $Revision$
- *
- * Mise a jour: $Date$ par : $Author$
- */
-
-package org.nuiton.topia.generator;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.models.object.ObjectModelGenerator;
-import org.nuiton.eugene.models.object.ObjectModel;
-import org.nuiton.eugene.models.object.ObjectModelClass;
-
-/**
- * Ce generateur permet d'avoir une classe permettant de recuperer les DAO
- * sans cast.
- *
- * La classe générée contient aussi une énumération nommée <code>EntityEnum</code> qui permet
- * d'avoir facilement les types d'entités gérées par ce dao.
- *
- * @author poussin
- * @deprecated since 2.3.0, prefer use the corresponding {@link org.nuiton.eugene.Transformer} :
- * {@link DAOHelperTransformer}.
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.DAOHelperGenerator"
- */
-@Deprecated
-public class DAOHelperGenerator extends ObjectModelGenerator {
-
- private Log log = LogFactory.getLog(DAOHelperGenerator.class);
-
- @Override
- public String getFilenameForModel(ObjectModel model) {
-
- String modelName = StringUtils.capitalize(model.getName());
-
- return (getProperty("defaultPackage") + ".").replace('.',
- File.separatorChar)
- + modelName + "DAOHelper.java";
- }
-
- @Override
- public void generateFromModel(Writer output, ObjectModel model)
- throws IOException {
- String copyright = TopiaGeneratorUtil.getCopyright(model);
- if (TopiaGeneratorUtil.notEmpty(copyright)) {
-/*{<%=copyright%>
-}*/
- }
- String packageName = getProperty("defaultPackage");
-/*{package <%=packageName%>;
-
-}*/
- String modelName = StringUtils.capitalize(model.getName());
- String modelVersion = model.getVersion();
- String daoHelperClazzName = modelName+"DAOHelper";
- String entityEnumName = modelName+"EntityEnum";
- List<ObjectModelClass> classes = TopiaGeneratorUtil.getEntityClasses(model,true);
- boolean generateOperator = TopiaGeneratorUtil.shouldgenerateOperatorForDAOHelper(null, model);
-
- List<String> imports = computeImports(generateOperator,packageName, classes);
- if (log.isDebugEnabled()) {
- log.debug("imports for class <" + daoHelperClazzName + ">");
- }
- for (String anImport : imports) {
- if (log.isDebugEnabled()) {
- log.debug("import " + anImport);
- }
-/*{import <%=anImport%>;
-}*/
- }
-/*{
-public class <%=daoHelperClazzName%> {
-
-}*/
-
-/*{ /**
- * no instance for this helper
- *)
- protected <%=daoHelperClazzName%>() {
- }
-
- /**
- * Model version.
- *
- * @return model version
- *)
- public static String getModelVersion() {
- return "<%=modelVersion%>";
- }
-}*/
-
- for (ObjectModelClass clazz : classes) {
- String clazzName = clazz.getName();
- String daoClazzName = clazzName + "DAO";
-/*{
- public static <%=daoClazzName%> get<%=daoClazzName%>(TopiaContext context) throws TopiaException {
- TopiaContextImplementor ci = (TopiaContextImplementor) context;
- <%=daoClazzName%> result = (<%=daoClazzName%>) ci.getDAO(<%=clazzName%>.class);
- return result;
- }
-}*/
- }
-/*{
- @SuppressWarnings({"unchecked"})
- public static <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDAO(TopiaContext context, Class<T> klass) throws TopiaException {
- TopiaContextImplementor ci = (TopiaContextImplementor) context;
- <%=entityEnumName%> constant = <%=entityEnumName%>.valueOf(klass);
- D dao = (D) ci.getDAO(constant.getContract());
- return dao;
- }
-
- @SuppressWarnings({"unchecked"})
- public static <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDAO(TopiaContext context, T entity) throws TopiaException {
- TopiaContextImplementor ci = (TopiaContextImplementor) context;
- <%=entityEnumName%> constant = <%=entityEnumName%>.valueOf(entity);
- D dao = (D) ci.getDAO(constant.getContract());
- return dao;
- }
-
- @SuppressWarnings({"unchecked"})
- public static <T extends TopiaEntity> Class<T> getContractClass(Class<T> klass) {
- <%=entityEnumName%> constant = <%=entityEnumName%>.valueOf(klass);
- return (Class<T>) constant.getContract();
- }
-
- @SuppressWarnings({"unchecked"})
- public static <T extends TopiaEntity> Class<T> getImplementationClass(Class<T> klass) {
- <%=entityEnumName%> constant = <%=entityEnumName%>.valueOf(klass);
- return (Class<T>) constant.getImplementation();
- }
-
- @SuppressWarnings({"unchecked"})
- public static Class<? extends TopiaEntity>[] getContractClasses() {
- <%=entityEnumName%>[] values = <%=entityEnumName%>.values();
- Class<? extends TopiaEntity>[] result = (Class<? extends TopiaEntity>[]) Array.newInstance(Class.class, values.length);
- for (int i = 0; i < values.length; i++) {
- result[i] = values[i].getContract();
- }
- return result;
- }
-
- @SuppressWarnings({"unchecked"})
- public static Class<? extends TopiaEntity>[] getImplementationClasses() {
- <%=entityEnumName%>[] values = <%=entityEnumName%>.values();
- Class<? extends TopiaEntity>[] result = (Class<? extends TopiaEntity>[]) Array.newInstance(Class.class, values.length);
- for (int i = 0; i < values.length; i++) {
- result[i] = values[i].getImplementation();
- }
- return result;
- }
-
- public static String getImplementationClassesAsString() {
- StringBuilder buffer = new StringBuilder();
- for (Class<? extends TopiaEntity> aClass : getImplementationClasses()) {
- buffer.append(',').append(aClass.getName());
- }
- return buffer.substring(1);
- }
-
- public static <%=entityEnumName%>[] getContracts() {
- return <%=entityEnumName%>.values();
- }
-}*/
- if (generateOperator) {
-/*{
- @SuppressWarnings({"unchecked"})
- public static <T extends TopiaEntity> EntityOperator<T> getOperator(Class<T> klass) {
- <%=entityEnumName%> constant = <%=entityEnumName%>.valueOf(klass);
- return (EntityOperator<T>) EntityOperatorStore.getOperator(constant);
- }
-}*/
- }
-/*{
- /*
- * Enumeration of all types of entities managed by this helper.
- *)
- public enum <%=entityEnumName%> implements org.nuiton.topia.persistence.TopiaEntityEnum {
-}*/
-
- for (Iterator<ObjectModelClass> i=classes.iterator(); i.hasNext();) {
- ObjectModelClass clazz = i.next();
- String clazzName = clazz.getName();
-/*{
- <%=clazzName%>(<%=clazzName%>.class)<%=(i.hasNext() ? "," : ";")%>}*/
- }
-/*{
-
- /** the contract of the entity *)
- private Class<? extends TopiaEntity> contract;
-
- /** the fully qualified name of the implementation of the entity *)
- private String implementationFQN;
-
- /** the implementation class of the entity (will be lazy computed at runtime)*)
- private Class<? extends TopiaEntity> implementation;
-
- <%=entityEnumName%>(Class<? extends TopiaEntity > contract) {
- this.contract = contract;
- this.implementationFQN = contract.getName()+"Impl";
- }
-
- @Override
- public Class<? extends TopiaEntity> getContract() {
- return contract;
- }
-
- @Deprecated
- public Class<? extends TopiaEntity> getContractClass() {
- return getContract();
- }
-
- @Deprecated
- public Class<? extends TopiaEntity> getImplementationClass() {
- return getImplementation();
- }
-
- @Override
- public String getImplementationFQN() {
- return implementationFQN;
- }
-
- @Override
- public synchronized void setImplementationFQN(String implementationFQN) {
- this.implementationFQN = implementationFQN;
- this.implementation = null;
-}*/
- if (generateOperator) {
-/*{ // on reinitialise le magasin d'operators
- EntityOperatorStore.clear();
-}*/
- }
-/*{ }
-
- @Override
- public boolean accept(Class<? extends TopiaEntity> klass) {
- return <%=daoHelperClazzName%>.getContractClass(klass) == contract;
- }
-
- @Override
- @SuppressWarnings({"unchecked"})
- public Class<? extends TopiaEntity> getImplementation() {
- if (implementation == null) {
- try {
- implementation = (Class<? extends TopiaEntity>) Class.forName(implementationFQN);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException("could not find class " + implementationFQN);
- }
- }
- return implementation;
- }
-
- public static <%=entityEnumName%> valueOf(TopiaEntity entity) {
- return valueOf(entity.getClass());
- }
-
- public static <%=entityEnumName%> valueOf(Class<?> klass) {
- if (klass.isInterface()) {
- return <%=entityEnumName%>.valueOf(klass.getSimpleName());
- }
- for (<%=entityEnumName%> entityEnum : <%=entityEnumName%>.values()) {
- if (entityEnum.getContract().isAssignableFrom(klass)) {
- //todo check it works for inheritance
- return entityEnum;
- }
- }
- throw new IllegalArgumentException("no entity defined for the class " + klass + " in : " + Arrays.toString(<%=entityEnumName%>.values()));
- }
- }
-}*/
- String entitiesList = "";
- if (classes.isEmpty()) {
-/*{
- /**
- * @eprecated (prefer use {@link #getImplementationClassesAsString()}
- *)
- public static final String entitiesList = "";
-}*/
- } else {
-/*{
- /**
- * use {@link #getImplementationClassesAsString()}
- *
- * @deprecated (will be removed soon).
- *)
- public static final String entitiesList = "" +
-}*/
-
- for (Iterator<ObjectModelClass> i=classes.iterator(); i.hasNext();) {
- ObjectModelClass clazz = i.next();
- String doType = TopiaGeneratorUtil.getDOType(clazz, model);
- entitiesList += doType + (i.hasNext()?",":"");
-/*{ "<%=doType%><%=(i.hasNext()?",\" +":"\";")%>
-}*/
- }
- }
- if (log.isDebugEnabled()) {
- log.debug("Full entities list : " + entitiesList);
- }
-/*{
-} //<%=daoHelperClazzName%>
-}*/
- }
-
- protected List<String> computeImports(boolean generateOperator,String packageName, List<ObjectModelClass> classes) {
- java.util.Set<String> imports = new java.util.HashSet<String>(java.util.Arrays.asList(
- java.lang.reflect.Array.class.getName(),
- java.util.Arrays.class.getName(),
- org.nuiton.topia.TopiaContext.class.getName(),
- org.nuiton.topia.TopiaException.class.getName(),
- org.nuiton.topia.framework.TopiaContextImplementor.class.getName(),
- org.nuiton.topia.persistence.TopiaDAO.class.getName(),
- org.nuiton.topia.persistence.TopiaEntity.class.getName()));
- if (generateOperator) {
- imports.add(org.nuiton.topia.persistence.util.EntityOperator.class.getName());
- imports.add(org.nuiton.topia.persistence.util.EntityOperatorStore.class.getName());
-
- }
- for (ObjectModelClass clazz : classes) {
- String clazzFQN = clazz.getQualifiedName();
- imports.add(clazzFQN);
- imports.add(clazzFQN + "DAO");
- }
- List<String> cleanImports = TopiaGeneratorUtil.cleanImports(packageName, imports);
- java.util.Collections.sort(cleanImports);
- return cleanImports;
- }
-} //DAOHelperGenerator
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -51,10 +51,10 @@
/*{generator option: writeString = +}*/
/**
- * User: chemit
- * Date: 13 nov. 2009
- * Time: 09:05:17
+ * Created: 13 nov. 2009 09:05:17
*
+ * @author tchemit <chemit(a)codelutin.com>
+ * @version $Id$
* @since 2.3.0
* @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.DAOHelperTransformer"
*/
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOImplGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOImplGenerator.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOImplGenerator.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -1,104 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-/*{generator option: parentheses = true}*/
-/*{generator option: writeString = output.write}*/
-
-/* *
-* EntityPOJOGenerator.java
-*
-* Created: 12 déc. 2005
-*
-* @author Arnaud Thimel <thimel(a)codelutin.com>
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-
-package org.nuiton.topia.generator;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-
-import org.nuiton.eugene.models.object.ObjectModelGenerator;
-import org.nuiton.eugene.models.object.ObjectModelClass;
-import org.nuiton.eugene.models.object.ObjectModelOperation;
-/**
- *
- * @deprecated since 2.3.0, prefer use the corresponding {@link org.nuiton.eugene.Transformer} :
- * {@link DAOImplTransformer}.
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.DAOImplGenerator"
- */
-@Deprecated
-public class DAOImplGenerator extends ObjectModelGenerator {
-
- @Override
- public String getFilenameForClass(ObjectModelClass clazz) {
- return clazz.getQualifiedName().replace('.', File.separatorChar) + "DAOImpl.java";
- }
-
- @Override
- public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException {
- if (!clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY) || hasDAOOperations(clazz)) {
- return;
- }
- String copyright = TopiaGeneratorUtil.getCopyright(model);
- if (TopiaGeneratorUtil.notEmpty(copyright)) {
-/*{<%=copyright%>
-}*/
- }
- String clazzName = clazz.getName();
- String clazzFQN = clazz.getQualifiedName();
-/*{package <%=clazz.getPackageName()%>;
-
-/**
- * Implantation du DAO pour l'entité <%=clazzName%>.
- * L'utilisateur peut remplacer cette classe par la sienne en la mettant
- * simplement dans ces sources. Cette classe générée sera alors simplement
- * écrasée.
- *)
-public class <%=clazzName%>DAOImpl<E extends <%=clazzName%>> extends <%=clazzFQN%>DAOAbstract<E> {
-
-} //<%=clazzName%>DAO
-}*/
- }
-
- /**
- * Detect if the class has DAO operations identified with <<dao>> stereotype.
- * @param clazz The ObjectModelClass with operations (Corresponding to the Entity)
- * @return true if the class has some dao operations, false if not
- */
- public static boolean hasDAOOperations(ObjectModelClass clazz) {
- for (ObjectModelOperation op : clazz.getOperations()) {
- if (op.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DAO)) {
- return true;
- }
- }
- return false;
- }
-
-} //DAOGenerator
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOImplTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOImplTransformer.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOImplTransformer.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -33,10 +33,8 @@
* Created: 14 déc. 2009
*
* @author Tony Chemit <chemit(a)codelutin.com> Copyright Code Lutin
- * @version $Revision$
- * <p/>
- * Mise a jour: $Date$ par :
- * $Author$
+ * @version $Id$
+ * @since 2.3.0
* @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.DAOImplTransformer"
*/
public class DAOImplTransformer extends ObjectModelTransformerToJava {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOTransformer.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOTransformer.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -35,10 +35,7 @@
* Created: 13 déc. 2009
*
* @author Tony Chemit <chemit(a)codelutin.com> Copyright Code Lutin
- * @version $Revision$
- * <p/>
- * Mise a jour: $Date$ par :
- * $Author$
+ * @version $Id$
* @since 2.3.0
* @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.DAOTransformer"
*/
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DTOGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DTOGenerator.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DTOGenerator.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -1,552 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-/*{generator option: parentheses = true}*/
-/*{generator option: writeString = output.write}*/
-
-/* *
-* EntityAbstractGenerator.java
-*
-* Created: 12 déc. 2005
-*
-* @author Arnaud Thimel <thimel(a)codelutin.com>
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-
-package org.nuiton.topia.generator;
-
-import static org.nuiton.topia.generator.TopiaGeneratorUtil.TAG_ANNOTATION;
-
-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.nuiton.eugene.Transformer;
-import org.nuiton.eugene.models.object.ObjectModelGenerator;
-import org.nuiton.eugene.GeneratorUtil;
-import org.nuiton.eugene.models.object.ObjectModelAssociationClass;
-import org.nuiton.eugene.models.object.ObjectModelAttribute;
-import org.nuiton.eugene.models.object.ObjectModelClass;
-import org.nuiton.eugene.models.object.ObjectModelClassifier;
-import org.nuiton.eugene.models.object.ObjectModelInterface;
-
-// do not remove me :)
-import org.apache.commons.lang.StringUtils;
-
-/**
- * DTO generator
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.DTOGenerator"
- * @deprecated since 2.3.0, prefer use the corresponding {@link Transformer} :
- * {@link DTOTransformer}.
- */
-@Deprecated
-public class DTOGenerator extends ObjectModelGenerator {
-
- /**
- * Logger for this class
- */
- private static final Log log = LogFactory.getLog(DTOGenerator.class);
-
- @Override
- public String getFilenameForClass(ObjectModelClass clazz) {
- return clazz.getQualifiedName().replace('.', File.separatorChar) + "DTO.java";
- }
-
- public boolean isDTO(String type) {
- ObjectModelClassifier clazz = model.getClassifier(type);
- return clazz != null && clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO);
- }
-
- @Override
- public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException {
- if (!clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) {
- return;
- }
- String copyright = TopiaGeneratorUtil.getCopyright(model);
- if (TopiaGeneratorUtil.notEmpty(copyright)) {
-/*{<%=copyright%>
-}*/
- }
- String clazzName = clazz.getName();
-/*{package <%=clazz.getPackageName()%>;
-
-import org.apache.commons.lang.builder.ToStringBuilder;
-import java.beans.PropertyChangeListener;
-import java.util.List;
-import java.util.Collection;
-
-/**
- * DTO implantation for <%=StringUtils.capitalize(clazzName)%> entity.
- *)
-public class <%=clazzName%>DTO}*/
-
-/*
- * Définition de la super classe : il ne doit y avoir qu'une
- */
-
- String extendClass = "";
- Iterator<ObjectModelClass> j = clazz.getSuperclasses().iterator();
- if (j.hasNext()) {
- ObjectModelClassifier parent = j.next();
- if (parent.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) {
- extendClass += parent.getName() + "DTO";
- } else {
- extendClass += parent.getName();
- }
- }
-
- if (extendClass.length() > 0) {
-/*{ extends <%=extendClass%>}*/
- }
-/*
- * Définition des interfaces
- */
-/*{ implements java.io.Serializable}*/
- String implInterface = "";
- for (Iterator<ObjectModelInterface> i=clazz.getInterfaces().iterator(); i.hasNext();) {
- ObjectModelClassifier parentInterface = i.next();
- if (parentInterface.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) {
- implInterface += parentInterface.getName() + "DTO";
- } else {
- implInterface += parentInterface.getName();
- }
-
- if (i.hasNext()) {
- implInterface += ", ";
- }
- }
- if (implInterface.length() > 0) {
-/*{, <%=implInterface%> {
-
-}*/
- } else {
- /*{ {
-
-}*/
- }
-
- String svUID = TopiaGeneratorUtil.findTagValue("dto-serialVersionUID", clazz, model);
- // TODO Calculer un serialVersionUID si il n'y en a pas
- if (svUID != null) {
-/*{ public static final long serialVersionUID = <%=svUID%>;
-
-}*/
- }
-/*
- * Définition des attributs
- */
- for (ObjectModelAttribute attr : clazz.getAttributes()) {
- ObjectModelAttribute reverse = attr.getReverseAttribute();
-
- if (!(attr.isNavigable()
- || attr.hasAssociationClass())) {
- continue;
- }
-
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
-/*{ /**
- * <%=attr.getDocumentation()%>
- *)
-}*/
- }
- String annotation = attr.getTagValue(TAG_ANNOTATION);
- if (annotation != null && annotation.length() > 0) {
-/*{ <%=annotation%>
-}*/
- }
- String attrName = attr.getName();
- String attrVisibility = attr.getVisibility();
- String attrType = attr.getType();
- if (!GeneratorUtil.isNMultiplicity(attr)) {
- if (!attr.hasAssociationClass()) {
- if (isDTO(attrType)) {
- attrType += "DTO";
- }
-/*{ <%=attrVisibility%> <%=attrType%> <%=attrName%>;
-}*/
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
-/*{ <%=attrVisibility%> <%=assocClassFQN%>DTO <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
-}*/
- }
- } else {
- if (!attr.hasAssociationClass()) {
- String nMultType;
- if (attr.isOrdered()) {
- nMultType = "List<";
- } else {
- nMultType = "Collection<";
- }
- nMultType += attrType;
- if (isDTO(attrType)) {
- nMultType += "DTO";
- }
- nMultType += ">";
-/*{ <%=attrVisibility%> <%=nMultType%> <%=attrName%>;
-}*/
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
- String nMultType;
- if (attr.isOrdered()) {
- nMultType = "List<";
- } else {
- nMultType = "Collection<";
- }
- nMultType += assocClassFQN;
- if (isDTO(attrType)) {
- nMultType += "DTO";
- }
- nMultType += ">";
-/*{ <%=attrVisibility%> <%=nMultType%> <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
-}*/
- }
- }
- } /* end for*/
-
- //Déclaration des attributs d'une classe d'associations
- if (clazz instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assoc = (ObjectModelAssociationClass)clazz;
- for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) {
- if (attr != null) {
- String attrName = attr.getName();
- String attrVisibility = attr.getVisibility();
- String attrType = attr.getType();
- if (isDTO(attrType)) {
- attrType += "DTO";
- }
-/*{ <%=attrVisibility%> <%=attrType%> <%=GeneratorUtil.toLowerCaseFirstLetter(attrName)%>;
-}*/
- }
- }
- }
-/*{
- protected java.beans.PropertyChangeSupport p;
-
- /**
- * Default constructor of <%=clazzName%>DTO.
- *)
- public <%=clazzName%>DTO() {
- p = new java.beans.PropertyChangeSupport(this);
- }
-
- /**
- * Constructor of <%=clazzName%>DTO with all parameters.
- *)
- public <%=clazzName%>DTO(}*/
-
- boolean une_fois = true;
- for (ObjectModelAttribute attr : clazz.getAttributes()) {
-
- if (!(attr.isNavigable()
- || attr.hasAssociationClass())) {
- continue;
- }
-
- if (une_fois) {
- une_fois = false;
- } else {
-/*{, }*/
- }
-
- String attrName = attr.getName();
- String attrVisibility = attr.getVisibility();
- String attrType = attr.getType();
- String attrTypeDTO = attr.getType();
- if (isDTO(attrType)) {
- attrTypeDTO += "DTO";
- }
- if (!GeneratorUtil.isNMultiplicity(attr)) {
- if (!attr.hasAssociationClass()) {
-/*{<%=attrTypeDTO%> <%=attrName%>}*/
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
-/*{<%=assocClassFQN%>DTO <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>}*/
- }
- } else {
- if (!attr.hasAssociationClass()) {
- String nMultType;
- if (attr.isOrdered()) {
- nMultType = "List<" + attrTypeDTO + ">";
- } else {
- nMultType = "Collection<" + attrTypeDTO + ">";
- }
-/*{<%=nMultType%> <%=attrName%>}*/
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
- String nMultType;
- if (attr.isOrdered()) {
- nMultType = "List<" + assocClassFQN + "DTO>";
- } else {
- nMultType = "Collection<" + assocClassFQN + "DTO>";
- }
-/*{<%=nMultType%> <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>}*/
- }
- }
-
-
- } // end for
-
- /*{ ) {
- this();
-}*/
-
-
- for (ObjectModelAttribute attr : clazz.getAttributes()) {
-
- if (!(attr.isNavigable()
- || attr.hasAssociationClass())) {
- continue;
- }
-
- String attrName = attr.getName();
-
- if (!GeneratorUtil.isNMultiplicity(attr)) {
- if (!attr.hasAssociationClass()) {
-/*{ this.<%=attrName%> = <%=attrName%>;
-}*/
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
-/*{ this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> = <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
-}*/
- }
- } else {
- if (!attr.hasAssociationClass()) {
-/*{ this.<%=attrName%> = <%=attrName%>;
-}*/
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
-/*{ this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> = <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
-}*/
- }
- }
- }
-/*{ }
-
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- p.addPropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- p.addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- p.removePropertyChangeListener(listener);
- }
-
- public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- p.removePropertyChangeListener(propertyName, listener);
- }
-
-}*/
-
-
- /*
- * Définition des getteurs et setteurs
- */
- for (Object o : clazz.getAttributes()) {
- ObjectModelAttribute attr = (ObjectModelAttribute) o;
- ObjectModelAttribute reverse = attr.getReverseAttribute();
-
- if (!attr.isNavigable()) {
- continue;
- }
-
- String attrName = attr.getName();
- String attrType = attr.getType();
- String attrTypeDTO = attr.getType();
- if (isDTO(attrType)) {
- attrTypeDTO += "DTO";
- }
-
- if (!GeneratorUtil.isNMultiplicity(attr)) {
- if (!attr.hasAssociationClass()) {
-/*{ public void set<%=StringUtils.capitalize(attrName)%>(<%=attrTypeDTO%> value) {
- <%=attrTypeDTO%> oldValue = this.<%=attrName%>;
- this.<%=attrName%> = value;
- p.firePropertyChange("<%=attrName%>", oldValue, value);
- }
-
- public <%=attrTypeDTO%> get<%=StringUtils.capitalize(attrName)%>() {
- return <%=attrName%>;
- }
-
-}*/
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
- if (log.isTraceEnabled()) {
- log.trace("assocAttrName: " + assocAttrName);
- }
-/*{ public void set<%=StringUtils.capitalize(assocAttrName)%>(<%=assocClassFQN%>DTO association) {
- <%=assocClassFQN%>DTO oldAssocation = this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
- this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> = association;
- p.firePropertyChange("<%=attrName%>", oldAssocation, assocation);
- }
-
- public <%=assocClassFQN%>DTO get<%=StringUtils.capitalize(assocAttrName)%>() {
- return <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
- }
-
-}*/
- }
- } else { //NMultiplicity
- if (!attr.hasAssociationClass()) { //Méthodes remplacées par des accesseurs sur les classes d'assoc
-
- String nMultType;
- if (attr.isOrdered()) {
- nMultType = "List<" + attrTypeDTO + ">";
- } else {
- nMultType = "Collection<" + attrTypeDTO + ">";
- }
-/*{ public void set<%=StringUtils.capitalize(attrName)%>(<%=nMultType%> values) {
- <%=nMultType%> oldValues = this.<%=attrName%>;
- this.<%=attrName%> = values;
- p.firePropertyChange("<%=attrName%>", oldValues, values);
- }
-
-}*/
-
- //AddChild
-/*{ public <%=attrTypeDTO%> addChild(<%=attrTypeDTO%> <%=attrName%>) {
- this.<%=attrName%>.add(<%=attrName%>);
-}*/
- if (reverse != null && reverse.isNavigable()) {
- String reverseAttrName = reverse.getName();
-/*{ <%=attrName%>.set<%=StringUtils.capitalize(reverseAttrName)%>(this);
-}*/
- }
-/*{ return <%=attrName%>;
- }
-
-}*/
- //RemoveChild
-/*{ public void removeChild(<%=attrTypeDTO%> <%=attrName%>) {
- this.<%=attrName%>.remove(<%=attrName%>);
-}*/
- if (reverse != null && reverse.isNavigable()) {
- String reverseAttrName = reverse.getName();
-/*{ <%=attrName%>.set<%=StringUtils.capitalize(reverseAttrName)%>(null);
-}*/
- }
-/*{ }
-
-}*/
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
- String nMultType;
- if (attr.isOrdered()) {
- nMultType = "List<" + assocClassFQN + "DTO>";
- } else {
- nMultType = "Collection<" + assocClassFQN + "DTO>";
- }
- if (log.isTraceEnabled()) {
- log.trace("assocAttrName: " + assocAttrName);
- }
-/*{ public void set<%=StringUtils.capitalize(assocAttrName)%>(<%=nMultType%> values) {
- <%=nMultType%> oldValues = this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
- this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> = values;
- p.firePropertyChange("<%=attrName%>", oldValues, values);
- }
-
-}*/
- }
- if (!attr.hasAssociationClass()) {
- String nMultType;
- if (attr.isOrdered()) {
- nMultType = "List<" + attrTypeDTO + ">";
- } else {
- nMultType = "Collection<" + attrTypeDTO + ">";
- }
-/*{ public <%=nMultType%> get<%=StringUtils.capitalize(attrName)%>() {
- return this.<%=attrName%>;
- }
-
-}*/
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
- String nMultType;
- if (attr.isOrdered()) {
- nMultType = "List<" + assocClassFQN + "DTO>";
- } else {
- nMultType = "Collection<" + assocClassFQN + "DTO>";
- }
- if (log.isTraceEnabled()) {
- log.trace("assocAttrName: " + assocAttrName);
- }
-/*{ public <%=nMultType%> get<%=StringUtils.capitalize(assocAttrName)%>() {
- return this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
- }
-
-}*/
- }
- }
- }
-
-/*{
- @Override
- public String toString() {
- String result = new ToStringBuilder(this).
-}*/
- for (ObjectModelAttribute attr : clazz.getAttributes()) {
- if (!(attr.isNavigable()
- || attr.hasAssociationClass())) {
- continue;
- }
-
- //FIXME possibilité de boucles (non directes)
- ObjectModelClass attrEntity = null;
- if (model.hasClass(attr.getType())) {
- attrEntity = model.getClass(attr.getType());
- }
- boolean isDTO = (attrEntity != null && attrEntity.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)); //THIMEL : STEREOTYPE ENTITY ???
- ObjectModelAttribute reverse = attr.getReverseAttribute();
- if ((isDTO && (reverse == null || !reverse.isNavigable()) && !attr.hasAssociationClass()) || (!isDTO)) {
- String attrName = attr.getName();
-/*{ append("<%=attrName%>", this.<%=attrName%>).
-}*/
- }
- }
-/*{ toString();
- return result;
- }
-
-} //<%=clazz.getName()%>DTO
-}*/
- }
-
-} //DTOGenerator
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DTOTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DTOTransformer.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DTOTransformer.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -49,12 +49,9 @@
* Created: 20 déc. 2009
*
* @author Tony Chemit <chemit(a)codelutin.com> Copyright Code Lutin
- * @version $Revision$
- * <p/>
- * Mise a jour: $Date$ par :
- * $Author$
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.DTOTransformer"
+ * @version $Id$
* @since 2.3.0
+ * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.DTOTransformer"
*/
public class DTOTransformer extends ObjectModelTransformerToJava {
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityAbstractGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityAbstractGenerator.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityAbstractGenerator.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -1,914 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-/*{generator option: parentheses = true}*/
-/*{generator option: writeString = output.write}*/
-
-/* *
-* EntityAbstractGenerator.java
-*
-* Created: 12 déc. 2005
-*
-* @author Arnaud Thimel <thimel(a)codelutin.com>
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-
-package org.nuiton.topia.generator;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.models.object.ObjectModelGenerator;
-import org.nuiton.eugene.GeneratorUtil;
-import org.nuiton.eugene.models.object.ObjectModelAssociationClass;
-import org.nuiton.eugene.models.object.ObjectModelAttribute;
-import org.nuiton.eugene.models.object.ObjectModelClass;
-import static org.nuiton.topia.generator.TopiaGeneratorUtil.hasUnidirectionalRelationOnAbstractType;
-import static org.nuiton.topia.generator.TopiaGeneratorUtil.shouldBeAbstract;
-import static org.nuiton.topia.generator.TopiaGeneratorUtil.isPrimitiveType;
-import static org.nuiton.topia.generator.TopiaGeneratorUtil.isDateType;
-import org.nuiton.topia.persistence.TopiaEntityAbstract;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Iterator;
-import java.util.List;
-
-
-/**
- * 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
- * n'est pas abstraite. La surcharge peut etre ecrite par l'utilisateur.
- *
- * @deprecated since 2.3.0, prefer use the corresponding {@link org.nuiton.eugene.Transformer} :
- * {@link EntityAbstractTransformer}.
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.EntityAbstractGenerator"
- */
-@Deprecated
-public class EntityAbstractGenerator extends ObjectModelGenerator {
-
- /** Logger for this class */
- private static final Log log = LogFactory.getLog(EntityAbstractGenerator.class);
-
- // TODO THIMEL : Je pense qu'il faudrait que l'EntityInterfaceGenerator
- // hérite de ce générateur, avec generateBody qui renvoie false, et que dans
- // ce générateur, on ne génère pas les corps de méthode, etc ... quand
- // generateBoody() renvoie false
- protected boolean generateBody() {
- return true;
- }
-
- @Override
- public String getFilenameForClass(ObjectModelClass clazz) {
- return clazz.getQualifiedName().replace('.', File.separatorChar) + "Abstract.java";
- }
-
- @Override
- public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException {
- if (!clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)) {
- return;
- }
- String copyright = TopiaGeneratorUtil.getCopyright(model);
- if (TopiaGeneratorUtil.notEmpty(copyright)) {
-/*{<%=copyright%>
-}*/
- }
- String clazzName = clazz.getName();
- String clazzFQN = TopiaGeneratorUtil.getSimpleName(clazz.getQualifiedName());
-/*{package <%=clazz.getPackageName()%>;
-}*/
- List<String> imports = TopiaGeneratorUtil.getImports(clazz,
- org.apache.commons.lang.builder.ToStringBuilder.class.getName(),
- org.nuiton.topia.TopiaException.class.getName(),
- org.nuiton.topia.framework.TopiaContextImplementor.class.getName(),
- org.nuiton.topia.persistence.TopiaEntity.class.getName(),
- TopiaEntityAbstract.class.getName(),
- org.nuiton.topia.persistence.EntityVisitor.class.getName(),
- java.util.List.class.getName(),
- java.util.ArrayList.class.getName(),
- java.io.Serializable.class.getName()
- );
- if (log.isDebugEnabled()) {
- log.debug("imports for class <" + clazzFQN + ">");
- }
- for (String anImport : imports) {
- if (log.isDebugEnabled()) {
- log.debug("import " + anImport);
- }
-/*{import <%=anImport%>;
-}*/
- }
-/*{
-/**
- * Implantation POJO pour l'entité {@link <%=StringUtils.capitalize(clazzFQN)%>}.
-}*/
- {
- String dbName = clazz.getTagValue(TopiaGeneratorUtil.TAG_DB_NAME);
- if (dbName != null) {
-/*{ *
- * <p>Nom de l'entité en BD : <%=dbName%>.</p>
-}*/
- }
- }
-/*{ *)
-}*/
- String extendClass = "";
- for (Iterator<ObjectModelClass> i = clazz.getSuperclasses().iterator(); i.hasNext();) {
- ObjectModelClass parent = 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(parent);
- }
- if (parent.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)) {
- if (abstractParent) {
- extendClass += "Abstract";
- } else {
- extendClass += "Impl";
- }
- }
- if (i.hasNext()) {
- extendClass += ", ";
- }
- }
- if (extendClass.length() == 0) {
- extendClass += TopiaEntityAbstract.class.getSimpleName();
- }
-
-/*{public abstract class <%=clazzName%>Abstract extends <%=extendClass%> implements <%=clazzName%> {
-
-}*/
-
- String svUID = TopiaGeneratorUtil.findTagValue("serialVersionUID", clazz, model);
- if (svUID != null) {
-/*{ public static final long serialVersionUID = <%=svUID%>;
-
-}*/
- }
- 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
- if (!(attr.isNavigable()
- || hasUnidirectionalRelationOnAbstractType(reverse, model)
- || attr.hasAssociationClass())) {
- continue;
- }
- if (TopiaGeneratorUtil.hasDocumentation(attr) || attr.hasTagValue(TopiaGeneratorUtil.TAG_DB_NAME)) {
-/*{ /**
-}*/
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
- String attrDocumentation = attr.getDocumentation();
-/*{ * <%=attrDocumentation%>
-}*/
- }
- if (attr.hasTagValue(TopiaGeneratorUtil.TAG_DB_NAME)) {
- String dbName = attr.getTagValue(TopiaGeneratorUtil.TAG_DB_NAME);
-/*{ * Nom de l'attribut en BD : <%=dbName%>.
-}*/
- }
-/*{ *)
-}*/
- }
- if (attr.hasTagValue(TopiaGeneratorUtil.TAG_ANNOTATION)) {
- String annotation = attr.getTagValue(TopiaGeneratorUtil.TAG_ANNOTATION);
-/*{ <%=annotation%>
-}*/
- }
-
- String attrVisibility = attr.getVisibility();
-
- // In case attribute is NMultiplicity
- String collectionType = TopiaGeneratorUtil.getSimpleName(TopiaGeneratorUtil.getNMultiplicityInterfaceType(attr));
-
- if (!attr.hasAssociationClass()) {
- String attrName = attr.getName();
- String attrType = TopiaGeneratorUtil.getSimpleName(attr.getType());
- if (!GeneratorUtil.isNMultiplicity(attr)) {
-/*{ <%=attrVisibility%> <%=attrType%> <%=attrName%>;
-
-}*/
- } else {
-/*{ <%=attrVisibility%> <%=collectionType%><<%=attrType%>> <%=attrName%>;
-
-}*/
- }
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = TopiaGeneratorUtil.getSimpleName(attr.getAssociationClass().getQualifiedName());
- if (!GeneratorUtil.isNMultiplicity(attr)) {
- //TODO THIMEL : Je pense que les GeneratorUtil.toLowerCaseFirstLetter sont inutiles ici, ou alors il faudrait le faire partout
-/*{ <%=attrVisibility%> <%=assocClassFQN%> <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
-
-}*/
- } else {
-/*{ <%=attrVisibility%> <%=collectionType%><<%=assocClassFQN%>> <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
-
-}*/
- }
- }
- }
-
- //Déclaration des attributs d'une classe d'associations
- if (clazz instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) clazz;
- for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) {
- if (attr != null) {
- String attrVisibility = attr.getVisibility();
- String attrType = TopiaGeneratorUtil.getSimpleName(attr.getType());
- String attrName = attr.getName();
-/*{ <%=attrVisibility%> <%=attrType%> <%=GeneratorUtil.toLowerCaseFirstLetter(attrName)%>;
-
-}*/
- }
- }
- }
-
-/*{ /**
- * Constructeur de <%=clazzName%>Abstract par défaut.
- *)
- public <%=clazzName%>Abstract() {
- }
-
- @Override
- public void update() throws TopiaException {
- ((TopiaContextImplementor)getTopiaContext()).getDAO(<%=clazzName%>.class).update(this);
- }
-
- @Override
- public void delete() throws TopiaException {
- ((TopiaContextImplementor)getTopiaContext()).getDAO(<%=clazzName%>.class).delete(this);
- }
-
- /**
- * Envoi via les methodes du visitor l'ensemble des champs de l'entity
- * avec leur nom, type et valeur.
- *
- * @param visitor le visiteur de l'entite.
- *
- * @throws TopiaException if any pb while visit
- *)
- @Override
- public void accept(EntityVisitor visitor) throws TopiaException {
- visitor.start(this);
-}*/
-
- 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
- if (!(attr.isNavigable()
- || hasUnidirectionalRelationOnAbstractType(reverse, model)
- || attr.hasAssociationClass())) {
- continue;
- }
-
- if (!attr.hasAssociationClass()) {
- String attrType = TopiaGeneratorUtil.getSimpleName(attr.getType());
- String attrName = attr.getName();
- if (!GeneratorUtil.isNMultiplicity(attr)) {
-/*{ visitor.visit(this, "<%=attrName%>", <%=attrType%>.class, <%=attrName%>);
-}*/
- } else {
- String collectionType = TopiaGeneratorUtil.getSimpleName(TopiaGeneratorUtil.getNMultiplicityInterfaceType(attr));
-/*{ visitor.visit(this, "<%=attrName%>", <%=collectionType%>.class, <%=attrType%>.class, <%=attrName%>);
-}*/
- }
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- assocAttrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
- String assocClassFQN = TopiaGeneratorUtil.getSimpleName(attr.getAssociationClass().getQualifiedName());
- if (!GeneratorUtil.isNMultiplicity(attr)) {
-/*{ visitor.visit(this, "<%=assocAttrName%>", <%=assocClassFQN%>.class, <%=assocAttrName%>);
-}*/
- } else {
- String collectionType = TopiaGeneratorUtil.getNMultiplicityInterfaceType(attr);
-/*{ visitor.visit(this, "<%=assocAttrName%>", <%=collectionType%>.class, <%=assocClassFQN%>.class, <%=assocAttrName%>);
-}*/
- }
- }
- }
-
- //Déclaration des attributs d'une classe d'associations
- if (clazz instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) clazz;
- for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) {
- if (attr != null) {
- String attrType = TopiaGeneratorUtil.getSimpleName(attr.getType());
- String attrName = attr.getName();
- attrName = GeneratorUtil.toLowerCaseFirstLetter(attrName);
-/*{ visitor.visit(this, "<%=attrName%>", <%=attrType%>.class, <%=attrName%>);
-}*/
- }
- }
- }
-/*{ visitor.end(this);
- }
-
- @Override
- 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 (ObjectModelAttribute attr : clazz.getAttributes()) {
- if (attr.referenceClassifier() && attr.getClassifier().hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)) {
- if (attr.isAggregate()) {
- String attrName = attr.getName();
- String getterName = "get" + StringUtils.capitalize(attrName);
- if (GeneratorUtil.isNMultiplicity(attr)) {
-/*{ tmp.addAll(<%=getterName%>());
-}*/
- } else {
-/*{ tmp.add(<%=getterName%>());
-}*/
- }
- }
- }
- }
-/*{
- // on refait un tour sur chaque entity de tmp pour recuperer leur
- // composite
- List<TopiaEntity> result = new ArrayList<TopiaEntity>();
- for (TopiaEntity entity : tmp) {
- result.add(entity);
- result.addAll(entity.getAggregate());
- }
-
- return result;
- }
-
- @Override
- 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 (ObjectModelAttribute attr : clazz.getAttributes()) {
- if (attr.referenceClassifier() && attr.getClassifier().hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)) {
- if (attr.isComposite()) {
- String attrName = attr.getName();
- String getterName = "get" + StringUtils.capitalize(attrName);
- if (GeneratorUtil.isNMultiplicity(attr)) {
-/*{ if (<%=getterName%>() != null) {
- tmp.addAll(<%=getterName%>());
- }
-}*/
- } else {
-/*{ tmp.add(<%=getterName%>());
-}*/
- }
- } else if (attr.hasAssociationClass()) {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = TopiaGeneratorUtil.getSimpleName(attr.getAssociationClass().getQualifiedName());
- String ref = "this." + GeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
- if (!GeneratorUtil.isNMultiplicity(attr)) {
-/*{
- if (<%=ref%> != null) {
- tmp.add(<%=ref%>);
- }
-}*/
- } else {
- ObjectModelAttribute reverse = attr.getReverseAttribute();
- String reverseAttrName = reverse.getName();
- // On utilise pas l'attribut car il est potentiellement
- // pas a jour, car pour les asso avec cardinalité
- // personne ne fait de add. Ce qui est normal, mais
- // pour pouvoir faire tout de meme des delete en cascade
- // sur les asso, le champs est dans le mapping
- // hibernate et donc il le faut aussi dans la classe
- // sinon hibernate rale lorsqu'il charge l'objet
-// if (<%=ref%> != null) {
-// tmp.addAll(<%=ref%>);
-// }
-/*{
- {
- org.nuiton.topia.persistence.TopiaDAO<<%=assocClassFQN%>> dao = ((TopiaContextImplementor) getTopiaContext()).getDAO(<%=assocClassFQN%>.class);
- List<<%=assocClassFQN%>> findAllByProperties = dao.findAllByProperties("<%=reverseAttrName%>", this);
- if (findAllByProperties != null) {
- tmp.addAll(findAllByProperties);
- }
- }
-}*/
- }
- }
- }
- }
-/*{
- // on refait un tour sur chaque entity de tmp pour recuperer leur
- // composite
- List<TopiaEntity> result = new ArrayList<TopiaEntity>();
- for (TopiaEntity entity : tmp) {
- if (entity != null) {
- result.add(entity);
- result.addAll(entity.getComposite());
- }
- }
-
- return result;
- }
-
-}*/
-
- for (ObjectModelAttribute attr : clazz.getAttributes()) {
- ObjectModelAttribute reverse = attr.getReverseAttribute();
-
- String attrName = attr.getName();
- String attrType = TopiaGeneratorUtil.getSimpleName(attr.getType());
-
- if (!(attr.isNavigable()
- || hasUnidirectionalRelationOnAbstractType(reverse, model))) {
- continue;
- }
- if (!GeneratorUtil.isNMultiplicity(attr)) {
- if (!attr.hasAssociationClass()) {
-/*{ /* (non-Javadoc)
- * @see <%=clazzFQN%>#set<%=StringUtils.capitalize(attrName)%>(<%=attrType%>)
- *)
- @Override
- public void set<%=StringUtils.capitalize(attrName)%>(<%=attrType%> value) {
- <%=attrType%> _oldValue = this.<%=attrName%>;
- fireOnPreWrite("<%=attrName%>", _oldValue, value);
- this.<%=attrName%> = value;
- fireOnPostWrite("<%=attrName%>", _oldValue, value);
- }
-
- /* (non-Javadoc)
- * @see <%=clazzFQN%>#get<%=StringUtils.capitalize(attrName)%>()
- *)
- @Override
- public <%=attrType%> get<%=StringUtils.capitalize(attrName)%>() {
- fireOnPreRead("<%=attrName%>", <%=attrName%>);
- <%=attrType%> result = this.<%=attrName%>;
- fireOnPostRead("<%=attrName%>", <%=attrName%>);
- return result;
- }
-
-}*/
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = TopiaGeneratorUtil.getSimpleName(attr.getAssociationClass().getQualifiedName());
-/*{ /* (non-Javadoc)
- * @see <%=clazzFQN%>#set<%=StringUtils.capitalize(assocAttrName)%>(<%=assocClassFQN%>)
- *)
- @Override
- public void set<%=StringUtils.capitalize(assocAttrName)%>(<%=assocClassFQN%> association) {
- <%=assocClassFQN%> _oldValue = this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
- fireOnPreWrite("<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>", _oldValue, association);
- this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> = association;
- fireOnPostWrite("<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>", _oldValue, association);
- }
-
- /* (non-Javadoc)
- * @see <%=clazzFQN%>#get<%=StringUtils.capitalize(assocAttrName)%>()
- *)
- @Override
- public <%=assocClassFQN%> get<%=StringUtils.capitalize(assocAttrName)%>() {
- return <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
- }
-
-}*/
- }
- } else { //NMultiplicity
- String collectionInterface = TopiaGeneratorUtil.getSimpleName(TopiaGeneratorUtil.getNMultiplicityInterfaceType(attr));
- String collectionObject = TopiaGeneratorUtil.getSimpleName(TopiaGeneratorUtil.getNMultiplicityObjectType(attr));
- if (!attr.hasAssociationClass()) { //Méthodes remplacées par des accesseurs sur les classes d'assoc
-/*{ /* (non-Javadoc)
- * @see <%=clazzFQN%>#add<%=StringUtils.capitalize(attrName)%>(<%=attrType%>)
- *)
- @Override
- public void add<%=StringUtils.capitalize(attrName)%>(<%=attrType%> <%=attrName%>) {
- fireOnPreWrite("<%=attrName%>", null, <%=attrName%>);
- if (this.<%=attrName%> == null) {
- this.<%=attrName%> = new <%=collectionObject%><<%=attrType%>>();
- }
-}*/
- if (reverse != null && (reverse.isNavigable() ||
- hasUnidirectionalRelationOnAbstractType(attr, model))) {
- String reverseAttrName = reverse.getName();
- String reverseAttrType = TopiaGeneratorUtil.getSimpleName(reverse.getType());
- if (!GeneratorUtil.isNMultiplicity(reverse)) {
-/*{ <%=attrName%>.set<%=StringUtils.capitalize(reverseAttrName)%>(this);
-}*/
- } else {
-/*{ if (<%=attrName%>.get<%=StringUtils.capitalize(reverseAttrName)%>() == null) {
- <%=attrName%>.set<%=StringUtils.capitalize(reverseAttrName)%>(new <%=collectionObject%><<%=reverseAttrType%>>());
- }
- <%=attrName%>.get<%=StringUtils.capitalize(reverseAttrName)%>().add(this);
-}*/
- }
- }
-/*{ this.<%=attrName%>.add(<%=attrName%>);
- fireOnPostWrite("<%=attrName%>", this.<%=attrName%>.size(), null, <%=attrName%>);
- }
-
- /* (non-Javadoc)
- * @see <%=clazzFQN%>#addAll<%=StringUtils.capitalize(attrName)%>(<%=collectionInterface%><<%=attrType%>>)
- *)
- @Override
- public void addAll<%=StringUtils.capitalize(attrName)%>(<%=collectionInterface%><<%=attrType%>> values) {
- if (values == null) {
- return;
- }
- for (<%=attrType%> item : values) {
- add<%=StringUtils.capitalize(attrName)%>(item);
- }
- }
-}*/
- if (!isPrimitiveType(attr) && !isDateType(attr)) {
-/*{
- /* (non-Javadoc)
- * @see <%=clazzFQN%>#get<%=StringUtils.capitalize(attrName)%>ByTopiaId(String)
- *)
- @Override
- public <%=attrType%> get<%=StringUtils.capitalize(attrName)%>ByTopiaId(String topiaId) {
- return org.nuiton.topia.persistence.util.TopiaEntityHelper.getEntityByTopiaId(<%=attrName%>, topiaId);
- }
- }*/
- }
-/*{
- /* (non-Javadoc)
- * @see <%=clazzFQN%>#set<%=StringUtils.capitalize(attrName)%>(<%=collectionInterface%><<%=attrType%>>)
- *)
- @Override
- public void set<%=StringUtils.capitalize(attrName)%>(<%=collectionInterface%><<%=attrType%>> values) {
- <%=collectionInterface%><<%=attrType%>> _oldValue = <%=attrName%>;
- fireOnPreWrite("<%=attrName%>", _oldValue, values);
- <%=attrName%> = values;
- fireOnPostWrite("<%=attrName%>", _oldValue, values);
- }
-
- /* (non-Javadoc)
- * @see <%=clazzFQN%>#remove<%=StringUtils.capitalize(attrName)%>(<%=attrType%>)
- *)
- @Override
- public void remove<%=StringUtils.capitalize(attrName)%>(<%=attrType%> value) {
- fireOnPreWrite("<%=attrName%>", value, null);
- if ((this.<%=attrName%> == null) || (!this.<%=attrName%>.remove(value))) {
- throw new IllegalArgumentException("List does not contain given element");
- }
-}*/
- if (reverse != null && (reverse.isNavigable() ||
- hasUnidirectionalRelationOnAbstractType(attr, model))) {
- String reverseAttrName = reverse.getName();
- if (!GeneratorUtil.isNMultiplicity(reverse)) {
-/*{ value.set<%=StringUtils.capitalize(reverseAttrName)%>(null);
-}*/
- } else {
-/*{ value.get<%=StringUtils.capitalize(reverseAttrName)%>().remove(this);
-}*/
- }
- }
-/*{ fireOnPostWrite("<%=attrName%>", this.<%=attrName%>.size()+1, value, null);
- }
-
- /* (non-Javadoc)
- * @see <%=clazzFQN%>#clear<%=StringUtils.capitalize(attrName)%>()
- *)
- @Override
- public void clear<%=StringUtils.capitalize(attrName)%>() {
- if (this.<%=attrName%> == null) {
- return;
- }
-}*/
- if (reverse != null && (reverse.isNavigable() ||
- hasUnidirectionalRelationOnAbstractType(attr, model))) {
- String reverseAttrName = reverse.getName();
-/*{ for (<%=attrType%> item : this.<%=attrName%>) {
-}*/
- if (!GeneratorUtil.isNMultiplicity(reverse)) {
-/*{ item.set<%=StringUtils.capitalize(reverseAttrName)%>(null);
-}*/
- } else {
-/*{ item.get<%=StringUtils.capitalize(reverseAttrName)%>().remove(this);
-}*/
- }
-/*{ }
-}*/
- }
-/*{ <%=collectionInterface%><<%=attrType%>> _oldValue = new <%=collectionObject%><<%=attrType%>>(this.<%=attrName%>);
- fireOnPreWrite("<%=attrName%>", _oldValue, this.<%=attrName%>);
- this.<%=attrName%>.clear();
- fireOnPostWrite("<%=attrName%>", _oldValue, this.<%=attrName%>);
- }
-
-}*/
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = TopiaGeneratorUtil.getSimpleName(attr.getAssociationClass().getQualifiedName());
-/*{ /* (non-Javadoc)
- * @see <%=clazzFQN%>#add<%=StringUtils.capitalize(assocAttrName)%>(<%=assocClassFQN%>)
- *)
- @Override
- public void add<%=StringUtils.capitalize(assocAttrName)%>(<%=assocClassFQN%> value) {
- fireOnPreWrite("<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>", null, value);
- if (this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> == null) {
- this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> = new <%=collectionObject%><<%=assocClassFQN%>>();
- }
-}*/
- if (reverse != null && (reverse.isNavigable() ||
- hasUnidirectionalRelationOnAbstractType(attr, model))) {
- String reverseAttrName = reverse.getName();
-/*{ value.set<%=StringUtils.capitalize(reverseAttrName)%>(this);
-}*/
- }
-/*{ this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>.add(value);
- fireOnPostWrite("<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>", this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>.size(), null, value);
- }
-}*/
- if (!isPrimitiveType(attr) && !isDateType(attr)) {
-/*{
- /* (non-Javadoc)
- * @see <%=clazzFQN%>#get<%=StringUtils.capitalize(attrName)%>ByTopiaId(String)
- *)
- @Override
- public <%=assocClassFQN%> get<%=StringUtils.capitalize(assocAttrName)%>ByTopiaId(String topiaId) {
- return org.nuiton.topia.persistence.util.TopiaEntityHelper.getEntityByTopiaId(<%=assocAttrName%>, topiaId);
- }
-}*/
- }
-/*{
- /* (non-Javadoc)
- * @see <%=clazzFQN%>#addAll<%=StringUtils.capitalize(assocAttrName)%>(<%=collectionInterface%><<%=assocClassFQN%>>()
- *)
- @Override
- public void addAll<%=StringUtils.capitalize(assocAttrName)%>(<%=collectionInterface%><<%=assocClassFQN%>> values) {
- if (values == null) {
- return;
- }
- for (<%=assocClassFQN%> item : values) {
- add<%=StringUtils.capitalize(assocAttrName)%>(item);
- }
- }
-
- /* (non-Javadoc)
- * @see <%=clazzFQN%>#set<%=StringUtils.capitalize(assocAttrName)%>(<%=collectionInterface%><<%=assocClassFQN%>>()
- *)
- @Override
- public void set<%=StringUtils.capitalize(assocAttrName)%>(<%=collectionInterface%><<%=assocClassFQN%>> values) {
-// clear<%=StringUtils.capitalize(assocAttrName)%>();
-// addAll<%=StringUtils.capitalize(assocAttrName)%>(values);
-// FIXME
- <%=collectionInterface%><<%=assocClassFQN%>> _oldValue = <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
- fireOnPreWrite("<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>", _oldValue, values);
- <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> = values;
- fireOnPostWrite("<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>", _oldValue, values);
- }
-
- /* (non-Javadoc)
- * @see <%=clazzFQN%>#remove<%=StringUtils.capitalize(assocAttrName)%>(<%=assocClassFQN%>)
- *)
- @Override
- public void remove<%=StringUtils.capitalize(assocAttrName)%>(<%=assocClassFQN%> value) {
- fireOnPreWrite("<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>", value, null);
- if ((this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> == null) || (!this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>.remove(value))) {
- throw new IllegalArgumentException("List does not contain given element");
- }
-}*/
- if (reverse != null && (reverse.isNavigable() ||
- hasUnidirectionalRelationOnAbstractType(attr, model))) {
- String reverseAttrName = reverse.getName();
-/*{ value.set<%=StringUtils.capitalize(reverseAttrName)%>(null);
-}*/
- }
-/*{ fireOnPostWrite("<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>", this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>.size()+1, value, null);
- }
-
- /* (non-Javadoc)
- * @see <%=clazzFQN%>#clear<%=StringUtils.capitalize(assocAttrName)%>()
- *)
- @Override
- public void clear<%=StringUtils.capitalize(assocAttrName)%>() {
- if (this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> == null) {
- return;
- }
-}*/
- if (reverse != null && (reverse.isNavigable() ||
- hasUnidirectionalRelationOnAbstractType(attr, model))) {
- String reverseAttrName = reverse.getName();
-/*{ for (<%=assocClassFQN%> item : this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>) {
- item.set<%=StringUtils.capitalize(reverseAttrName)%>(null);
- }
-}*/
- }
-/*{ <%=collectionInterface%><<%=assocClassFQN%>> _oldValue = new <%=collectionObject%><<%=assocClassFQN%>>(this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>);
- fireOnPreWrite("<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>", _oldValue, null);
- this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>.clear();
- fireOnPostWrite("<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>", _oldValue, null);
- }
-
-}*/
- }
- if (!attr.hasAssociationClass()) {
-/*{ /* (non-Javadoc)
- * @see <%=clazzFQN%>#get<%=StringUtils.capitalize(attrName)%>()
- *)
- @Override
- public <%=collectionInterface%><<%=attrType%>> get<%=StringUtils.capitalize(attrName)%>() {
- return <%=attrName%>;
- }
-
- /* (non-Javadoc)
- * @see <%=clazzFQN%>#size<%=StringUtils.capitalize(attrName)%>()
- *)
- @Override
- public int size<%=StringUtils.capitalize(attrName)%>() {
- if (<%=attrName%> == null) {
- return 0;
- }
- return <%=attrName%>.size();
- }
-
- /* (non-Javadoc)
- * @see <%=clazzFQN%>#is<%=StringUtils.capitalize(attrName)%>Empty()
- *)
- @Override
- public boolean is<%=StringUtils.capitalize(attrName)%>Empty() {
- int size = size<%=StringUtils.capitalize(attrName)%>();
- return size == 0;
- }
-
-}*/
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = TopiaGeneratorUtil.getSimpleName(attr.getAssociationClass().getQualifiedName());
-/*{ /* (non-Javadoc)
- * @see <%=clazzFQN%>#get<%=StringUtils.capitalize(assocAttrName)%>()
- *)
- @Override
- public <%=collectionInterface%><<%=assocClassFQN%>> get<%=StringUtils.capitalize(assocAttrName)%>() {
- return <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
- }
-
- /* (non-Javadoc)
- * @see <%=clazzFQN%>#get<%=StringUtils.capitalize(assocAttrName)%>(<%=attrType%>)
- *)
- @Override
- public <%=assocClassFQN%> get<%=StringUtils.capitalize(assocAttrName)%>(<%=attrType%> value) {
- if (value == null || <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> == null) {
- return null;
- }
- for (<%=assocClassFQN%> item : <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>) {
- if (value.equals(item.get<%=StringUtils.capitalize(attrName)%>())) {
- return item;
- }
- }
- return null;
- }
-
- /* (non-Javadoc)
- * @see <%=clazzFQN%>#size<%=StringUtils.capitalize(assocAttrName)%>()
- *)
- @Override
- public int size<%=StringUtils.capitalize(assocAttrName)%>() {
- if (<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> == null) {
- return 0;
- }
- return <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>.size();
- }
-
- /* (non-Javadoc)
- * @see <%=clazzFQN%>#is<%=StringUtils.capitalize(assocAttrName)%>Empty()
- *)
- @Override
- public boolean is<%=StringUtils.capitalize(assocAttrName)%>Empty() {
- int size = size<%=StringUtils.capitalize(assocAttrName)%>();
- return size == 0;
- }
-
-}*/
- }
- }
- }
-
- //Méthodes d'accès aux attributs d'une classe d'associations
- if (clazz instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) clazz;
- for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) {
- if (attr != null) {
- String attrType = TopiaGeneratorUtil.getSimpleName(attr.getType());
- String attrName = attr.getName();
- generateAssociationAccessors(output, attrName, attrType);
-// //Ne sert plus à rien normalement avec la navigabilité
-// ObjectModelAttribute reverse = attr.getReverseAttribute();
-// if (reverse == null) {
-// attrType = ((ObjectModelClassifier)attr.getDeclaringElement()).getQualifiedName();
-// attrName = attr.getDeclaringElement().getName();
-// generateAssociationAccessors(output, attrName, attrType);
-// }
- }
- }
- }
- boolean doGenerateToString = TopiaGeneratorUtil.generateToString(clazz, model);
- if (doGenerateToString) {
-/*{ /* (non-Javadoc)
- * @see java.lang.Object#toString()
- *)
- @Override
- public String toString() {
- String result = new ToStringBuilder(this).
-}*/
- for (ObjectModelAttribute attr : clazz.getAttributes()) {
- //FIXME possibilité de boucles (non directes)
- ObjectModelClass attrEntity = null;
- if (model.hasClass(attr.getType())) {
- attrEntity = model.getClass(attr.getType());
- }
- boolean isEntity = (attrEntity != null && attrEntity.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY));
- ObjectModelAttribute reverse = attr.getReverseAttribute();
- if ((isEntity && (reverse == null || !reverse.isNavigable()) && !attr.hasAssociationClass()) || (!isEntity)) {
- String attrName = attr.getName();
-/*{ append("<%=attrName%>", this.<%=attrName%>).
-}*/
- }
- }
-/*{ toString();
- return result;
- }
-}*/
- }
- String i18nPrefix = TopiaGeneratorUtil.getI18nPrefix(clazz, model);
- if (i18nPrefix != null) {
- // generate i18n prefix
- generateI18n(output, i18nPrefix, clazz);
- }
-/*{
-} //<%=clazzName%>Abstract
-}*/
- }
-
- private void generateAssociationAccessors(Writer output, String name, String type) throws IOException {
-/*{ /**
- * @param value La valeur de l'attribut <%=name%> à positionner.
- *)
- @Override
- public void set<%=StringUtils.capitalize(name)%>(<%=type%> value) {
- <%=type%> _oldValue = this.<%=GeneratorUtil.toLowerCaseFirstLetter(name)%>;
- fireOnPreWrite("<%=name%>", _oldValue, value);
- this.<%=GeneratorUtil.toLowerCaseFirstLetter(name)%> = value;
- fireOnPostWrite("<%=name%>", _oldValue, value);
- }
-
- /**
- * @return La valeur de l'attribut <%=name%>.
- *)
- @Override
- public <%=type%> get<%=StringUtils.capitalize(name)%>() {
- return <%=GeneratorUtil.toLowerCaseFirstLetter(name)%>;
- }
-
-}*/
- }
-
- 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.nuiton.i18n.I18n.n_(\"").append(i18nPrefix).append(suffix).append("\");\n");
- }
-
-} //EntityAbstractGenerator
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityAbstractTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityAbstractTransformer.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityAbstractTransformer.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -51,10 +51,8 @@
* Created: 14 déc. 2009
*
* @author Tony Chemit <chemit(a)codelutin.com> Copyright Code Lutin
- * @version $Revision$
- * <p/>
- * Mise a jour: $Date$ par :
- * $Author$
+ * @version $Id$
+ * @since 2.3.0
* @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.EntityAbstractTransformer"
*/
public class EntityAbstractTransformer extends ObjectModelTransformerToJava {
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDTOGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDTOGenerator.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDTOGenerator.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -1,342 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-/*{generator option: parentheses = true}*/
-/*{generator option: writeString = output.write}*/
-
-/* *
-* EntityAbstractGenerator.java
-*
-* Created: 12 déc. 2005
-*
-* @author Arnaud Thimel <thimel(a)codelutin.com>
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-
-package org.nuiton.topia.generator;
-
-import org.nuiton.eugene.models.object.*;
-import static org.nuiton.topia.generator.TopiaGeneratorUtil.TAG_ANNOTATION;
-import static org.nuiton.topia.generator.TopiaGeneratorUtil.hasUnidirectionalRelationOnAbstractType;
-
-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.nuiton.eugene.models.object.ObjectModelGenerator;
-import org.nuiton.eugene.GeneratorUtil;
-
-// do not remove me
-import org.apache.commons.lang.StringUtils;
-/**
- * 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
- * n'est pas abstraite. La surcharge peut etre ecrite par l'utilisateur.
- *
- * @deprecated since 2.3.0, prefer use the corresponding {@link org.nuiton.eugene.Transformer} :
- * {@link EntityDTOTransformer}.
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.EntityDTOGenerator"
- */
-@Deprecated
-public class EntityDTOGenerator extends ObjectModelGenerator {
-
- /**
- * Logger for this class
- */
- private static final Log log = LogFactory.getLog(EntityDTOGenerator.class);
-
- @Override
- public String getFilenameForClass(ObjectModelClass clazz) {
- return clazz.getQualifiedName().replace('.', File.separatorChar) + "DTO.java";
- }
-
- public boolean isEntity(String type) {
- ObjectModelClassifier clazz = model.getClassifier(type);
- return clazz != null && clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY);
- }
-
- @Override
- public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException {
- if (!clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)) {
- return;
- }
- String copyright = TopiaGeneratorUtil.getCopyright(model);
- if (TopiaGeneratorUtil.notEmpty(copyright)) {
-/*{<%=copyright%>
-}*/
- }
- String clazzName = clazz.getName();
-/*{package <%=clazz.getPackageName()%>;
-
-import org.apache.commons.lang.builder.ToStringBuilder;
-import java.beans.PropertyChangeListener;
-
-/**
- * Implantation DTO pour l'entité <%=StringUtils.capitalize(clazzName)%>.
- *)
-}*/
- String extendClass = "";
- for (Iterator<ObjectModelClass> i=clazz.getSuperclasses().iterator(); i.hasNext();) {
- ObjectModelClass parent = i.next();
- extendClass += parent.getQualifiedName() + "DTO";
- if (i.hasNext()) {
- extendClass += ", ";
- }
- }
- if (extendClass.length() > 0) {
- extendClass = "extends " + extendClass + " ";
- }
-
-/*{public class <%=clazzName%>DTO <%=extendClass%>implements java.io.Serializable {
-
-}*/
-
- String svUID = TopiaGeneratorUtil.findTagValue("dto-serialVersionUID", clazz, model);
- if (svUID != null) {
-/*{ public static final long serialVersionUID = <%=svUID%>;
-
-}*/
- }
- 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
- if (!(attr.isNavigable()
- || hasUnidirectionalRelationOnAbstractType(reverse, model)
- || attr.hasAssociationClass())) {
- continue;
- }
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
-/*{ /**
- * <%=attr.getDocumentation()%>
- *)
-}*/
- }
- if (attr.hasTagValue(TAG_ANNOTATION)) {
- String annotation = attr.getTagValue(TAG_ANNOTATION);
-/*{ <%=annotation%>
-}*/
- }
-
- String attrVisibility = attr.getVisibility();
- if (!attr.hasAssociationClass()) {
- String attrType = attr.getType();
- String attrName = attr.getName();
- if (isEntity(attrType)) {
- attrType += "DTO";
- }
- if (!GeneratorUtil.isNMultiplicity(attr)) {
-/*{ <%=attrVisibility%> <%=attrType%> <%=attrName%>;
-
-}*/
- } else {
-/*{ <%=attrVisibility%> <%=attrType%>[] <%=attrName%>;
-
-}*/
- }
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
- if (!GeneratorUtil.isNMultiplicity(attr)) {
-/*{ <%=attrVisibility%> <%=assocClassFQN%>DTO <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
-
-}*/
- } else {
-/*{ <%=attrVisibility%> <%=assocClassFQN%>DTO[] <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
-
-}*/
- }
- }
- }
-
- //Déclaration des attributs d'une classe d'associations
- if (clazz instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assoc = (ObjectModelAssociationClass)clazz;
- for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) {
- if (attr != null) {
- String attrVisibility = attr.getVisibility();
- String attrType = attr.getType();
- String attrName = attr.getName();
- if (isEntity(attrType)) {
- attrType += "DTO";
- }
-/*{ <%=attrVisibility%> <%=attrType%> <%=GeneratorUtil.toLowerCaseFirstLetter(attrName)%>;
-
-}*/
- }
- }
- }
-
-/*{
- protected java.beans.PropertyChangeSupport p;
-
-}*/
-
-/*{ /**
- * Constructeur de <%=clazzName%>DTO par défaut.
- *)
- public <%=clazzName%>DTO() { p = new java.beans.PropertyChangeSupport(this); }
-
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- p.addPropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- p.addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- p.removePropertyChangeListener(listener);
- }
-
- public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- p.removePropertyChangeListener(propertyName, listener);
- }
-
-}*/
-
- for (ObjectModelAttribute attr : clazz.getAttributes()) {
- ObjectModelAttribute reverse = attr.getReverseAttribute();
-
- if (!(attr.isNavigable()
- || hasUnidirectionalRelationOnAbstractType(reverse, model))) {
- continue;
- }
- String attrName = attr.getName();
-
- if (!attr.hasAssociationClass()) {
- String attrType = attr.getType();
- if (isEntity(attrType)) {
- attrType += "DTO";
- }
- if (!GeneratorUtil.isNMultiplicity(attr)) {
-/*{ public void set<%=StringUtils.capitalize(attrName)%>(<%=attrType%> value) {
- <%=attrType%> oldValue = this.<%=attrName%>;
- this.<%=attrName%> = value;
- p.firePropertyChange("<%=attrName%>", oldValue, value);
- }
-
- public <%=attrType%> get<%=StringUtils.capitalize(attrName)%>() {
- return <%=attrName%>;
- }
-
-}*/
- } else {
-/*{ public void set<%=StringUtils.capitalize(attrName)%>(<%=attrType%>[] values) {
- <%=attrType%>[] oldValues = this.<%=attrName%>;
- this.<%=attrName%> = values;
- p.firePropertyChange("<%=attrName%>", oldValues, values);
- }
-
- public <%=attrType%>[] get<%=StringUtils.capitalize(attrName)%>() {
- return this.<%=attrName%>;
- }
-
-}*/
- }
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
- if (!GeneratorUtil.isNMultiplicity(attr)) {
-/*{ public void set<%=StringUtils.capitalize(assocAttrName)%>(<%=assocClassFQN%>DTO association) {
- <%=assocClassFQN%>DTO oldAssocation= this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
- this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> = association;
- p.firePropertyChange("<%=attrName%>", oldAssocation, assocation);
- }
-
- public <%=assocClassFQN%>DTO get<%=StringUtils.capitalize(assocAttrName)%>() {
- return <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
- }
-
-}*/
- } else {
-/*{ public void set<%=StringUtils.capitalize(assocAttrName)%>(<%=assocClassFQN%>DTO[] values) {
- <%=assocClassFQN%>DTO[] oldValues = this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
- this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> = values;
- p.firePropertyChange("<%=attrName%>", oldValues, values);
- }
-
- public <%=assocClassFQN%>DTO[] get<%=StringUtils.capitalize(assocAttrName)%>() {
- return this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
- }
-
-}*/
- }
- }
-
- }
-
-/*{
- @Override
- public String toString() {
- String result = new ToStringBuilder(this).
-}*/
- for (Object o : clazz.getAttributes()) {
- ObjectModelAttribute attr = (ObjectModelAttribute) o;
- //FIXME possibilité de boucles (non directes)
- ObjectModelClass attrEntity = null;
- if (model.hasClass(attr.getType())) {
- attrEntity = model.getClass(attr.getType());
- }
- boolean isEntity = (attrEntity != null && attrEntity.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY));
- ObjectModelAttribute reverse = attr.getReverseAttribute();
- if ((isEntity && (reverse == null || !reverse.isNavigable()) && !attr.hasAssociationClass()) || (!isEntity)) {
- String attrName = attr.getName();
-/*{ append("<%=attrName%>", this.<%=attrName%>).
-}*/
- }
- }
-/*{ toString();
- return result;
- }
-
-} //<%=clazzName%>DTO
-}*/
- }
-
- //TODO Check wether this method could be used to generate getter and setters
- protected void generateNormalGetterAndSetterWithPropertyChangeSupport(Writer output, String attrType, String attrName) throws IOException {
-/*{ public void set<%=StringUtils.capitalize(attrName)%>(<%=attrType%> value) {
- <%=attrType%> _oldValue = this.<%=attrName%>;
- this.<%=attrName%> = value;
- p.firePropertyChange("<%=attrName%>", _oldValue, value);
- }
-
- public <%=attrType%> get<%=StringUtils.capitalize(attrName)%>() {
- return this.<%=attrName%>;
- }
-
-}*/
- }
-
-} //EntityDTOGenerator
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDTOTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDTOTransformer.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDTOTransformer.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -45,10 +45,8 @@
* Created: 14 déc. 2009
*
* @author Tony Chemit <chemit(a)codelutin.com> Copyright Code Lutin
- * @version $Revision$
- * <p/>
- * Mise a jour: $Date$ par :
- * $Author$
+ * @version $Id$
+ * @since 2.3.0
* @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.EntityDTOTransformer"
*/
public class EntityDTOTransformer extends ObjectModelTransformerToJava {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -65,8 +65,10 @@
import org.apache.commons.lang.BooleanUtils;
/**
- * FIXME mettre les attributs node="..." sur tous les attributs
+ * FIXME-poussin-20060102 mettre les attributs node="..." sur tous les attributs
+ *
* @author poussin <poussin(a)codelutin.com>
+ * @version $Id$
* @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.EntityHibernateMappingGenerator"
*/
public class EntityHibernateMappingGenerator extends ObjectModelGenerator {
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityImplGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityImplGenerator.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityImplGenerator.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -1,161 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-/*{generator option: parentheses = true}*/
-/*{generator option: writeString = output.write}*/
-
-/* *
-* EntityPOJOGenerator.java
-*
-* Created: 12 déc. 2005
-*
-* @author Arnaud Thimel <thimel(a)codelutin.com>
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-
-package org.nuiton.topia.generator;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Collection;
-
-import org.nuiton.eugene.models.object.ObjectModelGenerator;
-import org.nuiton.eugene.models.object.ObjectModelClass;
-import org.nuiton.eugene.models.object.ObjectModelOperation;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- *
- * @deprecated since 2.3.0, prefer use the corresponding {@link org.nuiton.eugene.Transformer} :
- * {@link EntityImplTransformer}.
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.EntityImplGenerator"
- */
-@Deprecated
-public class EntityImplGenerator extends ObjectModelGenerator {
-
- private static final Log log = LogFactory.getLog(EntityImplGenerator.class);
-
- @Override
- public String getFilenameForClass(ObjectModelClass clazz) {
- return clazz.getQualifiedName().replace('.', File.separatorChar) + "Impl.java";
- }
-
- @Override
- public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException {
- if (!clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)) {
- return;
- }
- // On ne génère pas le impl si l'entité a des opérations qui ne sont pas seulement pour le DAO
- if (clazz.getOperations().size() > 0 && !hasOnlyDAOOperations(clazz)) {
- return;
- }
- //De même, on ne génère pas le impl si il y a des opérations venant des
- // superclasses non implémentées
- for (ObjectModelOperation otherOp : clazz.getAllOtherOperations(false)) {
- if (otherOp.isAbstract()) {
- return;
- }
- }
-
- String copyright = TopiaGeneratorUtil.getCopyright(model);
- if (TopiaGeneratorUtil.notEmpty(copyright)) {
-/*{<%=copyright%>
-}*/
- }
- String clazzName = clazz.getName();
- String clazzFQN = clazz.getQualifiedName();
- String abstractStr = isAbstract(clazz)?"abstract ":" ";
-/*{package <%=clazz.getPackageName()%>;
-
-import java.io.Serializable;
-
-/**
- * Implantation des operations pour l'entité <%=TopiaGeneratorUtil.capitalize(clazz.getName())%>.
- *)
-public <%=abstractStr%>class <%=clazzName%>Impl extends <%=clazzFQN%>Abstract implements Serializable, <%=clazzFQN%> {
-
- private static final long serialVersionUID = 1L;
-
-}*/
-
-/*{} //<%=clazzName%>Impl
-}*/
- }
-
- protected boolean isAbstract(ObjectModelClass clazz) {
- if (clazz.isAbstract()) {
- return true;
- }
-
- //Une classe peut être abstraite si elle a des méthodes définies dans
- // ses superinterface et non implantées dans ses superclasses
- Collection<ObjectModelOperation> allInterfaceOperations = clazz.getAllInterfaceOperations(true);
- allInterfaceOperations.removeAll(clazz.getAllOtherOperations(true));
- for (ObjectModelOperation op : allInterfaceOperations) {
- boolean implementationFound = false;
- for (ObjectModelClass superClazz : clazz.getSuperclasses()) {
- for (ObjectModelOperation matchingOp : superClazz.getOperations(op.getName())) {
- implementationFound = (op.equals(matchingOp) && !matchingOp.isAbstract());
- if (implementationFound) {
- break;
- }
- }
- if (implementationFound) {
- break;
- }
- }
- if (!implementationFound) {
- log.info(clazz.getName()+" : abstract operation "+op);
- return true;
- }
- }
- return false;
- }
-
- /**
- * Detect if the clazz has only operations for DAO implementation.
- * These operations are identified with the stereotype <<dao>>.
- * @param clazz The ObjectModelClass with all operations.
- * @return true if there is only dao operations, false if there is no operations or some without
- * dao stereotype.
- */
- public static boolean hasOnlyDAOOperations(ObjectModelClass clazz) {
- boolean res = true;
- Collection<ObjectModelOperation> operations = clazz.getOperations();
- if (operations.size() == 0) {
- res = false;
- }
- for (ObjectModelOperation op : operations) {
- res &= op.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DAO);
- }
- return res;
- }
-
-} //EntityImplGenerator
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityImplTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityImplTransformer.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityImplTransformer.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -38,10 +38,8 @@
* Created: 14 déc. 2009
*
* @author Tony Chemit <chemit(a)codelutin.com> Copyright Code Lutin
- * @version $Revision$
- * <p/>
- * Mise a jour: $Date$ par :
- * $Author$
+ * @version $Id$
+ * @since 2.3.0
* @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.EntityImplTransformer"
*/
public class EntityImplTransformer extends ObjectModelTransformerToJava {
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityInterfaceGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityInterfaceGenerator.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityInterfaceGenerator.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -1,567 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-/*{generator option: parentheses = true}*/
-/*{generator option: writeString = output.write}*/
-
-/* *
-* EntityGenerator.java
-*
-* Created: 12 déc. 2005
-*
-* @author Arnaud Thimel <thimel(a)codelutin.com>
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-
-package org.nuiton.topia.generator;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.Transformer;
-import org.nuiton.eugene.models.object.ObjectModelGenerator;
-import org.nuiton.eugene.GeneratorUtil;
-import org.nuiton.eugene.models.object.ObjectModelAssociationClass;
-import org.nuiton.eugene.models.object.ObjectModelAttribute;
-import org.nuiton.eugene.models.object.ObjectModelClass;
-import org.nuiton.eugene.models.object.ObjectModelClassifier;
-import org.nuiton.eugene.models.object.ObjectModelInterface;
-import org.nuiton.eugene.models.object.ObjectModelOperation;
-import org.nuiton.eugene.models.object.ObjectModelParameter;
-import static org.nuiton.topia.generator.TopiaGeneratorUtil.hasUnidirectionalRelationOnAbstractType;
-import static org.nuiton.topia.generator.TopiaGeneratorUtil.isBooleanType;
-import static org.nuiton.topia.generator.TopiaGeneratorUtil.isNumericType;
-import static org.nuiton.topia.generator.TopiaGeneratorUtil.isTextType;
-import static org.nuiton.topia.generator.TopiaGeneratorUtil.isPrimitiveType;
-import static org.nuiton.topia.generator.TopiaGeneratorUtil.isDateType;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-// do not remove me :)
-import org.apache.commons.lang.StringUtils;
-
-/**
- *
- * @deprecated since 2.3.0, prefer use the corresponding {@link Transformer} :
- * {@link EntityInterfaceTransformer}.
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.EntityInterfaceGenerator"
- */
-@Deprecated
-public class EntityInterfaceGenerator extends ObjectModelGenerator {
-
- /** Logger for this class */
- private static final Log log = LogFactory.getLog(EntityInterfaceGenerator.class);
-
- @Override
- public String getFilenameForClass(ObjectModelClass clazz) {
- return clazz.getQualifiedName().replace('.', File.separatorChar) + ".java";
- }
-
- @Override
- public String getFilenameForInterface(ObjectModelInterface interfacez) {
- return interfacez.getQualifiedName().replace('.', File.separatorChar) + ".java";
- }
-
- //TC-20091214 : never used : always generate from a <<entity>> class
-// @Override
-// public void generateFromInterface(Writer output, ObjectModelInterface interfacez) throws IOException {
-// if (!interfacez.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)) {
-// return;
-// }
-//
-// if (log.isDebugEnabled()) {
-// log.debug("Generating interface for : " + interfacez.getName());
-// }
-//
-// generateInterfaceHeaderFromClassifier(output, interfacez);
-//
-// generateInterfaceOperations(output, interfacez);
-//
-///{} //<%=interfacez.getName()%>
-//}*/
-// }
-
- private String getStringRepresentation(List<String> strings) {
- StringBuffer result = new StringBuffer();
- String doubleQuote = "\"";
- String comma = ",";
- Iterator<String> it = strings.iterator();
- while (it.hasNext()) {
- result.append(doubleQuote);
- result.append(it.next());
- result.append(doubleQuote);
- if (it.hasNext()) {
- result.append(comma);
- }
- }
- return result.toString();
- }
-
- private void generateSearchFields(Writer output, ObjectModelClass clazz) throws IOException {
- List<String> txtFields = new ArrayList<String>();
- List<String> numFields = new ArrayList<String>();
- List<String> boolFields = new ArrayList<String>();
- List<String> dateFields = new ArrayList<String>();
- List<ObjectModelAttribute> allAttrs = new ArrayList<ObjectModelAttribute>();
- allAttrs.addAll(clazz.getAttributes());
- allAttrs.addAll(clazz.getAllOtherAttributes());
- boolean needAnnotation = false;
- for (ObjectModelAttribute attr : allAttrs) {
- String name = GeneratorUtil.toLowerCaseFirstLetter(attr.getName());
- if (isTextType(attr)) {
- txtFields.add(name);
- needAnnotation = true;
- } else if (isNumericType(attr)) {
- numFields.add(name);
- needAnnotation = true;
- } else if (isBooleanType(attr)) {
- boolFields.add(name);
- needAnnotation = true;
- } else if (isDateType(attr)) {
- dateFields.add(name);
- needAnnotation = true;
- }
- }
-/*{@SearchFields (}*/
- if (needAnnotation) {
- StringBuilder buffer = new StringBuilder();
- if (!txtFields.isEmpty()) {
- buffer.append("\n txtFields={").append(getStringRepresentation(txtFields)).append("}");
- if (!numFields.isEmpty() || !boolFields.isEmpty() || !dateFields.isEmpty()) {
- buffer.append(",");
- }
- }
- if (!numFields.isEmpty()) {
- buffer.append("\n numFields={").append(getStringRepresentation(numFields)).append("}");
- if (!boolFields.isEmpty() || !dateFields.isEmpty()) {
- buffer.append(",");
- }
- }
- if (!boolFields.isEmpty()) {
- buffer.append("\n boolFields={").append(getStringRepresentation(boolFields)).append("}");
- if (!dateFields.isEmpty()) {
- buffer.append(",");
- }
- }
- if (!dateFields.isEmpty()) {
- buffer.append("\n dateFields={").append(getStringRepresentation(dateFields)).append("}");
- }
-/*{<%=buffer.toString()%>
-}*/
- }
-/*{)
-}*/
- }
-
- private void generateInterfaceHeaderFromClassifier(Writer output, ObjectModelClassifier classifier) throws IOException {
- String copyright = TopiaGeneratorUtil.getCopyright(model);
- if (TopiaGeneratorUtil.notEmpty(copyright)) {
-/*{<%=copyright%>
-}*/
- }
-/*{package <%=classifier.getPackageName()%>;
-
-import org.nuiton.topia.persistence.SearchFields;
-import org.nuiton.topia.persistence.TopiaEntity;
-
-}*/
- if (TopiaGeneratorUtil.hasDocumentation(classifier)) {
- String documentation = classifier.getDocumentation();
-/*{
-/**
- * <%=documentation%>
- *)
-}*/
- }
- //
- if (classifier instanceof ObjectModelClass) {
- generateSearchFields(output, (ObjectModelClass) classifier);
- }
- String classifierName = classifier.getName();
-/*{public interface <%=classifierName%> extends }*/
- String extendClass = "";
- for (ObjectModelClassifier parent : classifier.getInterfaces()) {
- extendClass += parent.getQualifiedName();
- extendClass += ", ";
- }
- if (classifier instanceof ObjectModelClass) {
- ObjectModelClass clazz = (ObjectModelClass) classifier;
- for (ObjectModelClassifier parent : clazz.getSuperclasses()) {
- if (parent.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)) {
- extendClass += parent.getQualifiedName();
- }
- extendClass += ", ";
- }
- }
-
-/*{<%=extendClass%>TopiaEntity {
-
-}*/
- }
-
- @Override
- public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException {
- if (!clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)) {
- return;
- }
- String clazzName = clazz.getName();
- generateInterfaceHeaderFromClassifier(output, clazz);
-
- generateStaticColumnNames(output, clazz);
-
- for (ObjectModelAttribute attr : clazz.getAttributes()) {
- ObjectModelAttribute reverse = attr.getReverseAttribute();
- if (!attr.isNavigable()
- && !hasUnidirectionalRelationOnAbstractType(reverse, model)) {
- continue;
- }
-
- String attrName = attr.getName();
- String attrType = attr.getType();
- if (!attr.hasAssociationClass()) {
- if (!GeneratorUtil.isNMultiplicity(attr)) {
-/*{ /**
-}*/
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
-/*{ * <%=attrName%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @param <%=GeneratorUtil.toLowerCaseFirstLetter(attrName)%> La valeur de l'attribut <%=attrName%> à positionner.
- *)
- public void set<%=StringUtils.capitalize(attrName)%>(<%=attrType%> <%=GeneratorUtil.toLowerCaseFirstLetter(attrName)%>);
-
-}*/
-/*{ /**
-}*/
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
-/*{ * <%=attrName%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @return La valeur de l'attribut <%=attrName%>.
- *)
- public <%=attrType%> get<%=StringUtils.capitalize(attrName)%>();
-
-}*/
- } else {
- String collectionInterface = TopiaGeneratorUtil.getNMultiplicityInterfaceType(attr);
-/*{ /**
-}*/
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
-/*{ * <%=attrName%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @param <%=GeneratorUtil.toLowerCaseFirstLetter(attrName)%> L'instance de <%=attrName%> à ajouter.
- *)
- public void add<%=StringUtils.capitalize(attrName)%>(<%=attrType%> <%=GeneratorUtil.toLowerCaseFirstLetter(attrName)%>);
-
- /**
-}*/
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
-/*{ * <%=attrName%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @param <%=GeneratorUtil.toLowerCaseFirstLetter(attrName)%> Les instances de <%=attrName%> à ajouter.
- *)
- public void addAll<%=StringUtils.capitalize(attrName)%>(<%=collectionInterface%><<%=attrType%>> <%=GeneratorUtil.toLowerCaseFirstLetter(attrName)%>);
-
- /**
-}*/
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
-/*{ * <%=attrName%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @param <%=GeneratorUtil.toLowerCaseFirstLetter(attrName)%> La Collection de <%=attrName%> à positionner.
- *)
- public void set<%=StringUtils.capitalize(attrName)%>(<%=collectionInterface%><<%=attrType%>> <%=GeneratorUtil.toLowerCaseFirstLetter(attrName)%>);
-
- /**
-}*/
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
-/*{ * <%=attrName%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @param <%=GeneratorUtil.toLowerCaseFirstLetter(attrName)%> L'instance de <%=attrName%> à retirer.
- *)
- public void remove<%=StringUtils.capitalize(attrName)%>(<%=attrType%> <%=GeneratorUtil.toLowerCaseFirstLetter(attrName)%>);
-
- /**
-}*/
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
-/*{ * <%=attrName%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * Vide la Collection de <%=attrName%>.
- *)
- public void clear<%=StringUtils.capitalize(attrName)%>();
-
-}*/
-
-/*{ /**
-}*/
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
-/*{ * <%=attrName%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @return La Liste de <%=attrName%>.
- *)
- public <%=collectionInterface%><<%=attrType%>> get<%=StringUtils.capitalize(attrName)%>();
-
-}*/
- if (!isPrimitiveType(attr) && !isDateType(attr)) {
-/*{
- /**
- * Recupère l'attribut <%=attrName%> à 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 <%=attrType%> get<%=StringUtils.capitalize(attrName)%>ByTopiaId(String topiaId);
- }*/
- }
-/*{
- /**
- * @return Le nombre d'éléments de la collection <%=attrName%>.
- *)
- public int size<%=StringUtils.capitalize(attrName)%>();
-
- /**
- * @return <code>true</code> si la collection <%=attrName%> est vide.
- *)
- public boolean is<%=StringUtils.capitalize(attrName)%>Empty();
-
-}*/
-
- }
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
- String assocClassName = attr.getAssociationClass().getName();
- if (!GeneratorUtil.isNMultiplicity(attr)) {
-/*{ /**
- * @param <%=GeneratorUtil.toLowerCaseFirstLetter(assocClassName)%> La valeur de l'attribut <%=assocClassName%> à positionner.
- *)
- public void set<%=StringUtils.capitalize(assocAttrName)%>(<%=assocClassFQN%> <%=GeneratorUtil.toLowerCaseFirstLetter(assocClassName)%>);
-
- /**
- * @return La valeur de l'attribut <%=assocClassName%>.
- *)
- public <%=assocClassFQN%> get<%=StringUtils.capitalize(assocAttrName)%>();
-
-}*/
- } else {
- String collectionInterface = TopiaGeneratorUtil.getNMultiplicityInterfaceType(attr);
-/*{ /**
- * @param <%=GeneratorUtil.toLowerCaseFirstLetter(assocClassName)%> L'instance de <%=assocClassName%> à ajouter.
- *)
- public void add<%=StringUtils.capitalize(assocAttrName)%>(<%=assocClassFQN%> <%=GeneratorUtil.toLowerCaseFirstLetter(assocClassName)%>);
-
- /**
- * @param <%=GeneratorUtil.toLowerCaseFirstLetter(assocClassName)%> Les instances de <%=assocClassName%> à ajouter.
- *)
- public void addAll<%=StringUtils.capitalize(assocAttrName)%>(<%=collectionInterface%><<%=assocClassFQN%>> <%=GeneratorUtil.toLowerCaseFirstLetter(assocClassName)%>);
-
- /**
- * @param <%=GeneratorUtil.toLowerCaseFirstLetter(assocClassName)%> La Collection de <%=assocClassName%> à positionner.
- *)
- public void set<%=StringUtils.capitalize(assocAttrName)%>(<%=collectionInterface%><<%=assocClassFQN%>> <%=GeneratorUtil.toLowerCaseFirstLetter(assocClassName)%>);
-
- /**
- * @param <%=GeneratorUtil.toLowerCaseFirstLetter(assocClassName)%> L'instance de <%=assocClassName%> à retirer.
- *)
- public void remove<%=StringUtils.capitalize(assocAttrName)%>(<%=assocClassFQN%> <%=GeneratorUtil.toLowerCaseFirstLetter(assocClassName)%>);
-
- /**
- * Vide la Collection de <%=assocClassName%>.
- *)
- public void clear<%=StringUtils.capitalize(assocAttrName)%>();
-
- /**
- * @return La liste des attributs <%=assocClassName%>.
- *)
- public <%=collectionInterface%><<%=assocClassFQN%>> get<%=StringUtils.capitalize(assocAttrName)%>();
-}*/
- if (!isPrimitiveType(attr) && !isDateType(attr)) {
-/*{
- /**
- * Recupère l'attribut <%=attrName%> à 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 <%=assocClassFQN%> get<%=StringUtils.capitalize(assocAttrName)%>ByTopiaId(String topiaId);
-}*/
- }
-/*{
- /**
- * @return L'attribut <%=assocClassName%> associé à la valeur <code>value</code> de l'attribut <%=attrName%>.
- *)
- public <%=assocClassFQN%> get<%=StringUtils.capitalize(assocAttrName)%>(<%=attrType%> value);
-
- /**
- * @return Le nombre d'éléments de la collection <%=attrName%>.
- *)
- public int size<%=StringUtils.capitalize(assocAttrName)%>();
-
- /**
- * @return <code>true</code> si la collection <%=assocAttrName%> est vide.
- *)
- public boolean is<%=StringUtils.capitalize(assocAttrName)%>Empty();
-}*/
-
- }
- }
- }
-
- //Méthodes d'accès aux attributs d'une classe d'associations
- if (clazz instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) clazz;
- for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) {
- if (attr != null) {
- String type = attr.getType();
- String name = attr.getName();
- generateAssociationAccessors(output, name, type);
- if (attr.getReverseAttribute() == null) {
- type = ((ObjectModelClassifier) attr.getDeclaringElement()).getQualifiedName();
- name = attr.getDeclaringElement().getName();
- generateAssociationAccessors(output, name, type);
- }
- }
- }
- }
-
- generateInterfaceOperations(output, clazz);
-
-/*{} //<%=clazzName%>
-}*/
- }
-
- private void generateInterfaceOperations(Writer output, ObjectModelClassifier classifier) throws IOException {
- for (ObjectModelOperation op : classifier.getOperations()) {
- // Pas de génération des signatures de méthodes pour celles à intégrer au DAO de l'entité
- if (!op.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DAO)) {
- String opName = op.getName();
-/*{ /**
-}*/
- if (TopiaGeneratorUtil.hasDocumentation(op)) {
- String opDocumentation = op.getDocumentation();
-/*{ * <%=opName%> : <%=opDocumentation%>
-}*/
- }
- Collection<ObjectModelParameter> params = op.getParameters();
- for (ObjectModelParameter param : params) {
- String paramName = param.getName();
- String paramDocumentation = param.getDocumentation();
-/*{ * @param <%=paramName%> <%=paramDocumentation%>
- }*/
- }
- String opVisibility = op.getVisibility();
- String opType = op.getReturnType();
-/*{ *)
- <%=opVisibility%> <%=opType%> <%=opName%>(}*/
- String comma = "";
- for (ObjectModelParameter param : params) {
- String paramName = param.getName();
- String paramType = param.getType();
-/*{<%=comma%><%=paramType%> <%=paramName%>}*/
- comma = ", ";
- }
-/*{)}*/
- Set<String> exceptions = op.getExceptions();
- comma = " throws ";
- for (String exception : exceptions) {
-/*{<%=comma%><%=exception%>}*/
- comma = ", ";
- }
-/*{;
-
-}*/
- }
- }
- }
-
- private void generateAssociationAccessors(Writer output, String attrName, String attrType) throws IOException {
-/*{ /**
- * @param value La valeur de l'attribut <%=attrName%> à positionner.
- *)
- public void set<%=StringUtils.capitalize(attrName)%>(<%=attrType%> value);
-
- /**
- * @return La valeur de l'attribut <%=attrName%>.
- *)
- public <%=attrType%> get<%=StringUtils.capitalize(attrName)%>();
-
-}*/
- }
-
- private void generateStaticColumnNames(Writer output, ObjectModelClass clazz) throws IOException {
- for (ObjectModelAttribute attr : clazz.getAttributes()) {
- ObjectModelAttribute reverse = attr.getReverseAttribute();
- if (!(attr.isNavigable()
- || hasUnidirectionalRelationOnAbstractType(reverse, model)
- || attr.hasAssociationClass())) {
- continue;
- }
- String attrName;
- if (!attr.hasAssociationClass()) {
- attrName = attr.getName();
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
- }
- String attrColName = TopiaGeneratorUtil.convertVariableNameToConstantName(attrName);
- //String attrColName = attrName.toUpperCase();
-/*{ public static final String <%=attrColName%> = "<%=attrName%>";
-
-}*/
- }
-
- //Déclaration des noms des champs des attributs d'une classe d'associations
- if (clazz instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) clazz;
- for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) {
- if (attr != null) {
- String attrName = attr.getName();
- String attrColName = TopiaGeneratorUtil.convertVariableNameToConstantName(attrName);
- //String attrColName = attrName.toUpperCase();
-/*{ public static final String <%=attrColName%> = "<%=attrName%>";
-
-}*/
- }
- }
- }
- }
-
-} //EntityGenerator
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityInterfaceTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityInterfaceTransformer.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityInterfaceTransformer.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -45,10 +45,8 @@
* Created: 14 déc. 2009
*
* @author Tony Chemit <chemit(a)codelutin.com> Copyright Code Lutin
- * @version $Revision$
- * <p/>
- * Mise a jour: $Date$ par :
- * $Author$
+ * @version $Id$
+ * @since 2.3.0
* @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.EntityInterfaceTransformer"
*/
public class EntityInterfaceTransformer extends ObjectModelTransformerToJava {
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/InterfaceGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/InterfaceGenerator.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/InterfaceGenerator.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -1,187 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-/*{generator option: parentheses = true}*/
-/*{generator option: writeString = output.write}*/
-
-/**
- * InterfaceGenerator.java
- *
- * Created: 12 déc. 2005
- *
- * @author Arnaud Thimel <thimel(a)codelutin.com>
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- * @deprecated since 2.3.0, use {@link InterfaceTransformer} instead
- */
-
-package org.nuiton.topia.generator;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.Transformer;
-import org.nuiton.eugene.models.object.*;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Collection;
-import java.util.Set;
-
-
-/**
- *
- * @deprecated since 2.3.0, prefer use the corresponding {@link Transformer} :
- * {@link InterfaceTransformer}.
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.InterfaceGenerator"
- */
-@Deprecated
-public class InterfaceGenerator extends ObjectModelGenerator { //InterfaceGenerator
-
- /** Logger for this class */
- private static final Log log = LogFactory.getLog(InterfaceGenerator.class);
-
- @Override
- public String getFilenameForClass(ObjectModelClass clazz) {
- return clazz.getQualifiedName().replace('.', File.separatorChar) + ".java";
- }
-
- @Override
- public String getFilenameForInterface(ObjectModelInterface interfacez) {
- return interfacez.getQualifiedName().replace('.', File.separatorChar) + ".java";
- }
-
- @Override
- public void generateFromInterface(Writer output, ObjectModelInterface interfacez) throws IOException {
- if (!interfacez.getStereotypes().isEmpty()) {
- // can only generate an interface with there is no other stereotypes
- return;
- }
-
- // log
- if (log.isDebugEnabled()) {
- log.debug("Generating interface for : " + interfacez.getName());
- }
-
- String interfacezName = interfacez.getName();
-
- generateInterfaceHeader(output, interfacez);
-
- generateInterfaceOperations(output, interfacez);
-
-/*{} //<%=interfacezName%>
-}*/
- }
-
- private void generateInterfaceHeader(Writer output, ObjectModelInterface interfacez) throws IOException {
- String copyright = TopiaGeneratorUtil.getCopyright(model);
- if (TopiaGeneratorUtil.notEmpty(copyright)) {
-/*{<%=copyright%>
-}*/
- }
-/*{package <%=interfacez.getPackageName()%>;
-
-}*/
- if (TopiaGeneratorUtil.hasDocumentation(interfacez)) {
- String documentation = interfacez.getDocumentation();
-/*{
-/**
- * <%=documentation%>
- *)
-}*/
- }
- String interfacezName = interfacez.getName();
-/*{public interface <%=interfacezName%> }*/
- String extendClass = "";
- if (!interfacez.getInterfaces().isEmpty()) {
- for (ObjectModelClassifier parent : interfacez.getInterfaces()) {
- extendClass += parent.getQualifiedName();
- extendClass += ", ";
- }
- if (log.isTraceEnabled()) {
- log.trace("Interface : " + extendClass);
- }
-
-/*{ extends <%=extendClass%> {
-
-}*/
- }
-/*{ {
-}*/
- }
-
- private void generateInterfaceOperations(Writer output, ObjectModelClassifier classifier) throws IOException {
- for (ObjectModelOperation op : classifier.getOperations()) {
-/*{ /**
-}*/
- if (TopiaGeneratorUtil.hasDocumentation(op)) {
- String documentation = op.getDocumentation();
-/*{ * <%=documentation%>
-}*/
- }
- Collection<ObjectModelParameter> params = op.getParameters();
- for (ObjectModelParameter param : params) {
- if (log.isTraceEnabled()) {
- log.trace("Param" + param);
- }
- String paramName = param.getName();
- String paramDocumentation = param.getDocumentation();
-/*{ * @param <%=paramName%> <%=paramDocumentation%>
- }*/
- }
- String opVisibility = op.getVisibility();
- String opType = op.getReturnType();
- String opName = op.getName();
-/*{ *)
- <%=opVisibility%> <%=opType%> <%=opName%>(}*/
- String comma = "";
- for (ObjectModelParameter param : params) {
- if (log.isTraceEnabled()) {
- log.trace("Param" + param + " comma" + comma);
- }
- String paramName = param.getName();
- String paramType = param.getType();
-/*{<%=comma%><%=paramType%> <%=paramName%>}*/
- comma = ", ";
- }
-/*{)}*/
- Set<String> exceptions = op.getExceptions();
- comma = " throws ";
- for (String exception : exceptions) {
- if (log.isTraceEnabled()) {
- log.trace("exception" + exception + " vir" + comma);
- }
-/*{<%=comma%><%=exception%>}*/
- comma = ", ";
- }
-/*{;
-
-}*/
- }
- }
-
-} //InterfaceGenerator
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/InterfaceTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/InterfaceTransformer.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/InterfaceTransformer.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -41,11 +41,8 @@
*
* Created: 7 nov. 2009
*
- * @author fdesbois
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
* @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.InterfaceTransformer"
* @deprecated since 2.4 use {@link org.nuiton.eugene.java.JavaInterfaceTransformer} instead
*/
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -174,20 +174,19 @@
* to specify that all contract methods will throw this exception.</p>
* </div>
* <p>It is smooth, isn't it :p ?</p>
- * <p>TODO : may be refactor to integrate JTA or webservice or may be not in this
- * transformer.</p>
- * <p>TODO : find a good way to change log level</p>
+ * <p>
+ * TODO : may be refactor to integrate JTA or webservice or may be not in this transformer.
+ * </p>
+ * <p>
+ * TODO : find a good way to change log level
+ * </p>
*
* Created: 23 mars 2010
*
- * @author fdesbois
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- *
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.ServiceTransformer"
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
* @since 2.3.1
+ * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.ServiceTransformer"
*/
public class ServiceTransformer extends ObjectModelTransformerToJava {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -55,6 +55,12 @@
/**
* Classe regroupant divers méthodes utiles pour la génération des entités
+ *
+ * @author tchemit <tchemit(a)codelutin.com>
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @author chatellier <chatellier(a)codelutin.com>
+ * @author thimel <thimel(a)codelutin.com>
+ * @version $Id$
*/
public class TopiaGeneratorUtil extends JavaGeneratorUtil {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaJavaValidator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaJavaValidator.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaJavaValidator.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -39,11 +39,8 @@
* - les nom des attributs
* - les duplication d'attibuts
*
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
+ * @author chatellier <chatellier(a)codelutin.com>
+ * @version $Id$
*/
public class TopiaJavaValidator extends ObjectModelValidator {
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaGenerator.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaGenerator.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -1,184 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-
-/*******************************************************************************
- * ObjectModelToEntityGenerator.java
- *
- * Created: 3 juil. 2004
- *
- * @author Grégoire DESSARD <dessard(a)codelutin.com> Copyright Code Lutin, Grégoire
- * Dessard
- *
- * @version $Revision$
- *
- * Mise a jour: $Date$ par : $Author$
- */
-
-package org.nuiton.topia.generator;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.AbstractGenerator;
-import org.nuiton.eugene.models.object.ObjectModelGenerator;
-import org.nuiton.eugene.Template;
-import org.nuiton.eugene.Transformer;
-import org.nuiton.eugene.models.object.ObjectModel;
-import org.nuiton.eugene.models.object.validator.AttributeNamesValidator;
-import org.nuiton.eugene.models.object.validator.ClassNamesValidator;
-import org.nuiton.eugene.models.object.validator.ObjectModelValidator;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import org.nuiton.eugene.models.object.ObjectModelClass;
-
-/**
- * Cette classe est un Generateur qui constitue le point d'entree dans ToPIA.
- * Il repercute la generation de code sur chacun des generateurs de ToPIA en se
- * positionnant en tant que parent de ces generateurs.
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.TopiaMetaGenerator"
- * @deprecated since 2.3.0, prefer use the corresponding {@link Transformer} : {@link TopiaMetaTransformer}.
- */
-@Deprecated
-public class TopiaMetaGenerator extends ObjectModelGenerator {
-
- protected static Log log = LogFactory.getLog(TopiaMetaGenerator.class);
-
- /**
- * la liste des generateurs par defaut a utiliser
- */
- protected static final List<Class<? extends ObjectModelGenerator>> DEFAULT_GENERATORS = Collections
- .unmodifiableList(Arrays.asList(
- EntityInterfaceGenerator.class,
- EntityAbstractGenerator.class,
- EntityImplGenerator.class,
- EntityHibernateMappingGenerator.class,
- DAOGenerator.class,
- DAOImplGenerator.class,
- DAOAbstractGenerator.class,
- DAOHelperGenerator.class
- ));
-
- protected boolean validateModel(ObjectModel model) {
- List<ObjectModelValidator> validators = new ArrayList<ObjectModelValidator>();
-
- AttributeNamesValidator attrValidator = new AttributeNamesValidator(
- model);
- attrValidator.addNameAndReason("next",
- "Le nom d'attribut \"next\" est incompatible avec HSQL");
- attrValidator.addNameAndReason("value",
- "Le nom d'attribut \"value\" est incompatible avec certains SGBD");
- attrValidator.addNameAndReason("values",
- "Le nom d'attribut \"values\" est incompatible avec certains SGBD");
- attrValidator.addNameAndReason("begin",
- "Le nom d'attribut \"begin\" est incompatible avec certains SGBD");
- attrValidator.addNameAndReason("end",
- "Le nom d'attribut \"end\" est incompatible avec certains SGBD");
- attrValidator.addNameAndReason("authorization",
- "Le nom d'attribut \"authorization\" est incompatible avec certains SGBD");
- attrValidator.addNameAndReason("order",
- "Le nom d'attribut \"order\" est incompatible avec certains SGBD");
- validators.add(attrValidator);
-
- ClassNamesValidator classValidator = new ClassNamesValidator(model);
- classValidator.addNameAndReason("constraint", "Nom de classe incompatible avec certains SGBD");
- classValidator.addNameAndReason("user", "Nom de classe incompatible avec certains SGBD");
- validators.add(classValidator);
-
- validators.add(new TopiaJavaValidator(model));
- validators.add(new TopiaRelationValidator(model));
-
- boolean isValid = true;
- for (ObjectModelValidator validator : validators) {
- if (!validator.validate()) {
- for (String error : validator.getErrors()) {
- log.info("[VALIDATION] " + error);
- }
- isValid = false;
- }
- }
- return isValid;
- }
-
- @Override
- public void applyTemplate(ObjectModel model, File destDir) throws IOException {
-
- //On n'empeche pas la génération si le modèle n'est pas valide
- validateModel(model);
-
- // test before all if there is some entities to generate
- List<ObjectModelClass> classes = TopiaGeneratorUtil.getEntityClasses(model, true);
-
- if (classes.isEmpty()) {
- // no entity to generate, can stop safely
- log.warn("no entity to generate, " + getClass().getName() + " is skipped");
- return;
- }
-
- generatePersistence(model, destDir);
- }
-
- public void generatePersistence(ObjectModel model, File destDir)
- throws IOException {
- for (Class<? extends Template<ObjectModel>> generatorClass : DEFAULT_GENERATORS) {
- Template<ObjectModel> generator;
- if (getExcludeTemplates().contains(generatorClass.getName())) {
- // exclude generator
- log.info("exclude generator " + generatorClass);
- continue;
- }
- try {
-
- generator = generatorClass.newInstance();
-
- // init generator
-
- if (generator instanceof AbstractGenerator) {
- ((AbstractGenerator<ObjectModel>)generator).setParent(this);
- }
- if (generator instanceof Transformer) {
- generator.setProperties(properties);
- }
- } catch (Exception e) {
- // should never happens
- if(log.isErrorEnabled()) {
- log.error("An error occurs when generating persistence", e);
- }
- throw new RuntimeException(e);
- }
-
- // log
- if(log.isDebugEnabled()) {
- log.debug("call template : " + generatorClass.getSimpleName());
- }
- generator.applyTemplate(model, destDir);
- }
- }
-
-} //TopiaMetaGenerator
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -41,10 +41,8 @@
* Created: 20 déc. 2009
*
* @author Tony Chemit <chemit(a)codelutin.com> Copyright Code Lutin
- * @version $Revision$
- * <p/>
- * Mise a jour: $Date$ par :
- * $Author$
+ * @version $Id$
+ * @since 2.3.0
* @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.TopiaMetaTransformer"
*/
public class TopiaMetaTransformer extends AbstractMetaTransformer<ObjectModel> {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaRelationValidator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaRelationValidator.java 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaRelationValidator.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -51,6 +51,9 @@
* sous-classes dans le modèle est incompatibe avec Hibernate</li>
* <li>Toutes les relations ont des reverseAttribute</li>
* </ul>
+ *
+ * @author
+ * @version $Id$
*/
public class TopiaRelationValidator extends ObjectModelValidator {
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/package-info.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/package-info.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/package-info.java 2010-05-07 16:34:39 UTC (rev 1936)
@@ -0,0 +1,94 @@
+/**
+ * TODO-FD20100507 : Need update this javadoc for ToPIA 2.4
+ *
+ * <h1>Les Générateurs</h1>
+ *
+ * <h2>TopiaMetaGenerator</h2>
+ *
+ * <p>TopiaMetaGenerator permet d'enchainer les différents
+ * générateurs.</p>
+ *
+ * <h2>Les DAO</h2>
+ *
+ * <p>Il il y a trois générateurs pour les DAO</p>
+ *
+ * <ul>
+ * <li>DAOHelperGenerator</li>
+ *
+ * <li>DAOAbstractGenerator</li>
+ *
+ * <li>DAOGenerator</li>
+ * </ul>
+ *
+ * <p><b><i>DAOHelperGenerator</i></b> permet de récupérer les DAOs
+ * générés spécifiquement pour l'application sans avoir besoin de passer
+ * le type de l'entité en paramètre. Cette classe contient donc une
+ * methode get par type d'entity qui permet de récupérer le DAO associé.
+ * Ces méthodes sont des méthodes statiques et prennent en paramètre un
+ * TopiaContext.</p>
+ *
+ * <p><b><i>DAOAbstractGenerator</i></b> est une classe abstraite même si
+ * elle peut implanter toutes les méthodes de l'interface TopiaDAO. De
+ * cette façon on oblige l'existance d'une classe concrète qui en hérite
+ * soit développé par le développeur soit généré par DAOGenerator.
+ * DAOAbstractGenerator contient toutes les méthodes findBy, findAllBy,
+ * ... associées aux attributs existants. La classe généré hérite
+ * directement ou indirectement de TopiaDAODelegator.</p>
+ *
+ * <p><b><i>DAOGenerator</i></b> génère une classe vide qui permet au
+ * programme de compiler, si le développeur à besoin de méthode find
+ * supplémentaire sur son DAO, il lui suffit de d'implanter cette classe
+ * dans ses sources, le processus de génération écrasera alors la classe
+ * généré par la classe développée spécifiquement.</p>
+ *
+ * <h2>Les entités</h2>
+ *
+ * <p>Les entités sont de pure POJO et ne contiennent pas de référence en
+ * interne sur le TopiaContext ou le DAO qui les à créée, elle peuvent
+ * donc facilement migrer, être utilisé dans différents context, ... le
+ * but etant qu'elle reste des classes complètement déconnecté à
+ * l'exécution du framework.</p>
+ *
+ * <p>La seul contrainte est qu'elles implante TopiaEntity</p>
+ *
+ * <p>Il il y a trois générateurs pour les entités, plus un pour le
+ * mapping hibernate</p>
+ *
+ * <ul>
+ * <li>EntityInterfaceGenerator</li>
+ *
+ * <li>EntityAbstractGenerator</li>
+ *
+ * <li>EntityImplGenerator</li>
+ *
+ * <li>EntityHibernateMappingGenerator</li>
+ * </ul>
+ *
+ * <p><b><i>EntityInterfaceGenerator</i></b> génère l'interface de
+ * l'entité avec les méthodes d'accès aux attributs et les opérations
+ * définis par l'utilisateur dans son diagrammme de classe. Elle implante
+ * TopiaEntity</p>
+ *
+ * <p><b><i>EntityAbstractGenerator</i></b> génère une classe qui
+ * implante l'interface de l'entité et étend TopiaEntityAbstract qui
+ * implante les méthodes du framework, méthode d'accès aux attributs
+ * topiaId, topiaVersion et topiaCreateDate.</p>
+ *
+ * <p><b><i>EntityImplGenerator</i></b> génère une classe vide qui permet
+ * au programme de compiler si l'entité n'a pas d'opération spécifique.
+ * Si elle a des opérations spécifiques le développeur doit implanter
+ * cette classe dans ses sources et y mettre le code pour les opérations
+ * spécifiques, le processus de génération écrasera alors la classe
+ * généré par la classe développée spécifiquement.</p>
+ *
+ * <p><b><i>EntityHibernateMappingGenerator</i></b> génère le fichier de
+ * mapping pour entité. L'interface est déclaré dans le mapping et est
+ * mappé sur une table préfixé par I. Ensuite le Impl est déclaré en
+ * union-subclass de cette interface. On a besoin de l'interface car les
+ * méthodes l'utilise dans les signatures de méthode lorsqu'il y a un
+ * lien entre deux entités.</p>
+ *
+ * @author poussin <poussin(a)codelutin.com>
+ * @version $Id$
+ */
+package org.nuiton.topia.generator;
\ No newline at end of file
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/package-info.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/package.html
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/package.html 2010-05-07 15:19:41 UTC (rev 1935)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/package.html 2010-05-07 16:34:39 UTC (rev 1936)
@@ -1,101 +0,0 @@
-<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
-
-<html>
- <head>
- <meta
- name="generator"
- content="HTML Tidy, see www.w3.org">
-
- <title></title>
- </head>
-
- <body>
- <h1>Les G�n�rateurs</h1>
-
- <h2>TopiaMetaGenerator</h2>
-
- <p>TopiaMetaGenerator permet d'enchainer les diff�rents
- g�n�rateurs.</p>
-
- <h2>Les DAO</h2>
-
- <p>Il il y a trois g�n�rateurs pour les DAO</p>
-
- <ul>
- <li>DAOHelperGenerator</li>
-
- <li>DAOAbstractGenerator</li>
-
- <li>DAOGenerator</li>
- </ul>
-
- <p><b><i>DAOHelperGenerator</i></b> permet de r�cup�rer les DAOs
- g�n�r�s sp�cifiquement pour l'application sans avoir besoin de passer
- le type de l'entit� en param�tre. Cette classe contient donc une
- methode get par type d'entity qui permet de r�cup�rer le DAO associ�.
- Ces m�thodes sont des m�thodes statiques et prennent en param�tre un
- TopiaContext.</p>
-
- <p><b><i>DAOAbstractGenerator</i></b> est une classe abstraite m�me si
- elle peut implanter toutes les m�thodes de l'interface TopiaDAO. De
- cette fa�on on oblige l'existance d'une classe concr�te qui en h�rite
- soit d�velopp� par le d�veloppeur soit g�n�r� par DAOGenerator.
- DAOAbstractGenerator contient toutes les m�thodes findBy, findAllBy,
- ... associ�es aux attributs existants. La classe g�n�r� h�rite
- directement ou indirectement de TopiaDAODelegator.</p>
-
- <p><b><i>DAOGenerator</i></b> g�n�re une classe vide qui permet au
- programme de compiler, si le d�veloppeur � besoin de m�thode find
- suppl�mentaire sur son DAO, il lui suffit de d'implanter cette classe
- dans ses sources, le processus de g�n�ration �crasera alors la classe
- g�n�r� par la classe d�velopp�e sp�cifiquement.</p>
-
- <h2>Les entit�s</h2>
-
- <p>Les entit�s sont de pure POJO et ne contiennent pas de r�f�rence en
- interne sur le TopiaContext ou le DAO qui les � cr��e, elle peuvent
- donc facilement migrer, �tre utilis� dans diff�rents context, ... le
- but etant qu'elle reste des classes compl�tement d�connect� �
- l'ex�cution du framework.</p>
-
- <p>La seul contrainte est qu'elles implante TopiaEntity</p>
-
- <p>Il il y a trois g�n�rateurs pour les entit�s, plus un pour le
- mapping hibernate</p>
-
- <ul>
- <li>EntityInterfaceGenerator</li>
-
- <li>EntityAbstractGenerator</li>
-
- <li>EntityImplGenerator</li>
-
- <li>EntityHibernateMappingGenerator</li>
- </ul>
-
- <p><b><i>EntityInterfaceGenerator</i></b> g�n�re l'interface de
- l'entit� avec les m�thodes d'acc�s aux attributs et les op�rations
- d�finis par l'utilisateur dans son diagrammme de classe. Elle implante
- TopiaEntity</p>
-
- <p><b><i>EntityAbstractGenerator</i></b> g�n�re une classe qui
- implante l'interface de l'entit� et �tend TopiaEntityAbstract qui
- implante les m�thodes du framework, m�thode d'acc�s aux attributs
- topiaId, topiaVersion et topiaCreateDate.</p>
-
- <p><b><i>EntityImplGenerator</i></b> g�n�re une classe vide qui permet
- au programme de compiler si l'entit� n'a pas d'op�ration sp�cifique.
- Si elle a des op�rations sp�cifiques le d�veloppeur doit implanter
- cette classe dans ses sources et y mettre le code pour les op�rations
- sp�cifiques, le processus de g�n�ration �crasera alors la classe
- g�n�r� par la classe d�velopp�e sp�cifiquement.</p>
-
- <p><b><i>EntityHibernateMappingGenerator</i></b> g�n�re le fichier de
- mapping pour entit�. L'interface est d�clar� dans le mapping et est
- mapp� sur une table pr�fix� par I. Ensuite le Impl est d�clar� en
- union-subclass de cette interface. On a besoin de l'interface car les
- m�thodes l'utilise dans les signatures de m�thode lorsqu'il y a un
- lien entre deux entit�s.</p>
- </body>
-</html>
-
1
0