Sandbox-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
- 1825 discussions
r637 - in nuiton-jpa: . nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates
by tchemit@users.nuiton.org 29 May '13
by tchemit@users.nuiton.org 29 May '13
29 May '13
Author: tchemit
Date: 2013-05-29 15:23:18 +0200 (Wed, 29 May 2013)
New Revision: 637
Url: http://nuiton.org/projects/sandbox/repository/revisions/637
Log:
- use last snapshot of eugene
- remove generic from dao
Modified:
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
nuiton-jpa/pom.xml
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java 2013-05-29 09:21:09 UTC (rev 636)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java 2013-05-29 13:23:18 UTC (rev 637)
@@ -58,26 +58,19 @@
String packageName = JpaTemplatesGeneratorUtil.getDaoPackage(this, model, input);
- String generatedDaoName = JpaTemplatesGeneratorUtil.getDaoGeneratedName(input);
String abstractDaoName = JpaTemplatesGeneratorUtil.getDaoAbstractName(input);
String concreteDaoName = JpaTemplatesGeneratorUtil.getDaoConcreteName(input);
- String concreteEntityQualifiedName=
+ String concreteEntityQualifiedName =
JpaTemplatesGeneratorUtil.getConcreteEntityQualifiedName(this, model, input);
- boolean generateGenerated= !isInClassPath(packageName, generatedDaoName);
boolean generateAbstract = !isInClassPath(packageName, abstractDaoName);
boolean generateConcrete = !isInClassPath(packageName, concreteDaoName);
- if (generateGenerated) {
-
- generateGenerated(input, packageName, generatedDaoName, concreteEntityQualifiedName);
- }
-
if (generateAbstract) {
- generateAbstract(input, packageName, generatedDaoName, abstractDaoName, concreteEntityQualifiedName);
+ generateAbstract(input, packageName, abstractDaoName, concreteEntityQualifiedName);
}
if (generateConcrete) {
@@ -86,13 +79,15 @@
}
}
- protected ObjectModelClass generateGenerated(ObjectModelClass input,
+ protected ObjectModelClass generateAbstract(ObjectModelClass input,
String packageName,
String abstractDaoName,
String concreteEntityQualifiedName) {
+ String entityName = input.getName();
+
ObjectModelClass output =
- createAbstractClass(abstractDaoName + "<E extends " + input.getName() + ">", packageName);
+ createAbstractClass(abstractDaoName, packageName);
addImport(output, concreteEntityQualifiedName);
// test if a super class is in same package (so is yet another entity)
@@ -117,7 +112,7 @@
if (superClass == null) {
// no super-class, use default one
- superClass = AbstractJpaDao.class.getName() + "<E>";
+ superClass = AbstractJpaDao.class.getName() + "<" + entityName + ">";
addImport(output, superClass);
}
}
@@ -126,7 +121,7 @@
addConstructorWithEntityManager(output);
// detect if there is a contract to set on abstract
- String daoContractName = packageName + "." + input.getName() + "Dao";
+ String daoContractName = packageName + "." + entityName + "Dao";
boolean addUserDaoContract = isInClassPath(daoContractName);
@@ -136,11 +131,11 @@
// Add getEntityClass
- ObjectModelOperation operation = addOperation(output, "getEntityClass", "Class<E>", ObjectModelJavaModifier.PROTECTED);
+ ObjectModelOperation operation = addOperation(output, "getEntityClass", "Class<" + entityName + ">", ObjectModelJavaModifier.PROTECTED);
addAnnotation(output, operation, Override.class);
setOperationBody(operation, ""
/*{
- return (Class<E>) <%=input.getName()%>.class;
+ return <%=entityName%>.class;
}*/
);
@@ -150,33 +145,15 @@
return output;
}
- protected ObjectModelClass generateAbstract(ObjectModelClass input,
+ protected ObjectModelClass generateImpl(ObjectModelClass input,
String packageName,
- String generatedDaoName,
String abstractDaoName,
+ String concreteDaoName,
String concreteEntityQualifiedName) {
- ObjectModelClass output = createAbstractClass(abstractDaoName+ "<E extends " + input.getName() + ">", packageName);
-
- setSuperClass(output, packageName + '.' + generatedDaoName + "<E>");
- addImport(output, concreteEntityQualifiedName);
- addConstructorWithEntityManager(output);
-
- if (isVerbose()) {
- log.info("will generate " + output.getQualifiedName());
- }
- return output;
- }
-
- protected ObjectModelClass generateImpl(ObjectModelClass input,
- String packageName,
- String abstractDaoName,
- String concreteDaoName,
- String concreteEntityQualifiedName) {
-
ObjectModelClass output = createClass(concreteDaoName, packageName);
- setSuperClass(output, packageName + '.' + abstractDaoName + "<" + input.getName() + ">");
+ setSuperClass(output, packageName + '.' + abstractDaoName);
addImport(output, concreteEntityQualifiedName);
addConstructorWithEntityManager(output);
Modified: nuiton-jpa/pom.xml
===================================================================
--- nuiton-jpa/pom.xml 2013-05-29 09:21:09 UTC (rev 636)
+++ nuiton-jpa/pom.xml 2013-05-29 13:23:18 UTC (rev 637)
@@ -31,7 +31,7 @@
<redmine.skipGenerateChanges>true</redmine.skipGenerateChanges>
<!-- libs version -->
- <eugeneVersion>2.6.3-SNAPSHOT</eugeneVersion>
+ <eugeneVersion>2.6.4-SNAPSHOT</eugeneVersion>
<processorPluginVersion>1.3</processorPluginVersion>
<h2Version>1.3.170</h2Version>
<hibernateVersion>4.1.11.Final</hibernateVersion>
1
0
r636 - in nuiton-jpa/nuiton-jpa-templates/src: it/magalie main/java/org/nuiton/jpa/templates
by tchemit@users.nuiton.org 29 May '13
by tchemit@users.nuiton.org 29 May '13
29 May '13
Author: tchemit
Date: 2013-05-29 11:21:09 +0200 (Wed, 29 May 2013)
New Revision: 636
Url: http://nuiton.org/projects/sandbox/repository/revisions/636
Log:
add a jpa meta transformer
Added:
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaMetaTransformer.java
Modified:
nuiton-jpa/nuiton-jpa-templates/src/it/magalie/pom.xml
Modified: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/pom.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/it/magalie/pom.xml 2013-05-29 08:54:49 UTC (rev 635)
+++ nuiton-jpa/nuiton-jpa-templates/src/it/magalie/pom.xml 2013-05-29 09:21:09 UTC (rev 636)
@@ -86,16 +86,15 @@
<phase>generate-sources</phase>
<configuration>
<!-- Corresponding to extracted package from zargo file -->
- <fullPackagePath>com.franciaflex.magalie.persistence.entity
+ <fullPackagePath>
+ com.franciaflex.magalie.persistence.entity
</fullPackagePath>
<!-- defaultPackage used for generation -->
<defaultPackage>com.franciaflex.magalie.persistence
</defaultPackage>
<templates>
- org.nuiton.jpa.templates.JpaEntityTransformer,
- org.nuiton.jpa.templates.JpaDaoTransformer,
- org.nuiton.jpa.templates.JpaPersistenceContextTransformer,
- org.nuiton.eugene.java.JavaEnumerationTransformer
+ org.nuiton.eugene.java.JavaEnumerationTransformer,
+ org.nuiton.jpa.templates.JpaMetaTransformer
</templates>
</configuration>
<goals>
Added: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaMetaTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaMetaTransformer.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaMetaTransformer.java 2013-05-29 09:21:09 UTC (rev 636)
@@ -0,0 +1,115 @@
+package org.nuiton.jpa.templates;
+
+/*
+ * #%L
+ * Nuiton Jpa :: Temlates
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.AbstractMetaTransformer;
+import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.ObjectModelClass;
+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.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created: 20 déc. 2009
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @version $Id$
+ * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.jpa.templates.JpaMetaTransformer"
+ * @since 2.3.0
+ */
+public class JpaMetaTransformer extends AbstractMetaTransformer<ObjectModel> {
+
+ /** Logger */
+ private static final Log log = LogFactory.getLog(JpaMetaTransformer.class);
+
+ public JpaMetaTransformer() {
+
+ setTemplateTypes(
+ JpaEntityTransformer.class,
+ JpaDaoTransformer.class,
+ JpaPersistenceContextTransformer.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));
+
+ for (ObjectModelValidator validator : validators) {
+ if (!validator.validate()) {
+ for (String error : validator.getErrors()) {
+ if (log.isWarnEnabled()) {
+ log.warn("[VALIDATION] " + error);
+ }
+ }
+ }
+ }
+
+ // test before all if there is some entities to generate
+ List<ObjectModelClass> classes =
+ JpaTemplatesGeneratorUtil.getEntityClasses(model, true);
+
+ if (classes.isEmpty()) {
+ // no entity to generate, can stop safely
+ if (log.isWarnEnabled()) {
+ log.warn("No entity to generate, " + getClass().getName() +
+ " is skipped");
+ }
+ return false;
+ }
+ return true;
+ }
+
+}
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaMetaTransformer.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
r635 - in nuiton-jpa: nuiton-jpa-api/src/main/java/org/nuiton/jpa/api nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates
by tchemit@users.nuiton.org 29 May '13
by tchemit@users.nuiton.org 29 May '13
29 May '13
Author: tchemit
Date: 2013-05-29 10:54:49 +0200 (Wed, 29 May 2013)
New Revision: 635
Url: http://nuiton.org/projects/sandbox/repository/revisions/635
Log:
continue nuitpn-jpa dev
Added:
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaPersistenceContext.java
Modified:
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java 2013-05-27 21:25:49 UTC (rev 634)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java 2013-05-29 08:54:49 UTC (rev 635)
@@ -143,6 +143,51 @@
return query;
}
+ protected <E> TypedQuery<E> createQuery(Class<E> type, String hql) {
+ TypedQuery<E> query = entityManager.createQuery(hql, type);
+ return query;
+ }
+
+ protected <E> TypedQuery<E> createQuery(Class<E> type, String propertyName,
+ Object propertyValue,
+ Object... others) {
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(propertyName, propertyValue);
+ Object name = null;
+ for (int i = 0; i < others.length; ) {
+ try {
+ name = others[i++];
+ propertyValue = others[i++];
+ properties.put((String) name, propertyValue);
+ } catch (ClassCastException eee) {
+ throw new IllegalArgumentException(
+ "Les noms des propriétés doivent être des chaines et " +
+ "non pas " + propertyName.getClass().getName(),
+ eee);
+ } catch (ArrayIndexOutOfBoundsException eee) {
+ throw new IllegalArgumentException(
+ "Le nombre d'argument n'est pas un nombre pair: "
+ + (others.length + 2)
+ + " La dernière propriété était: " + name, eee);
+ }
+ }
+ return createQuery(type, properties);
+ }
+
+ protected <E>TypedQuery<E> createQuery(Class<E> type, Map<String, Object> properties) {
+ List<String> whereClauses = new LinkedList<String>();
+ for (String propertyName : properties.keySet()) {
+ whereClauses.add(propertyName + " = :" + propertyName);
+ }
+ String hql = "from " + getEntityClass().getSimpleName() + " where " + StringUtils.join(whereClauses, " and ");
+ TypedQuery<E> query = createQuery(type, hql);
+ for (Map.Entry<String, Object> property : properties.entrySet()) {
+ query.setParameter(property.getKey(), property.getValue());
+ }
+ return query;
+ }
+
protected TypedQuery<E> createQuery(String hql) {
TypedQuery<E> query = entityManager.createQuery(hql, getEntityClass());
return query;
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java 2013-05-27 21:25:49 UTC (rev 634)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java 2013-05-29 08:54:49 UTC (rev 635)
@@ -34,7 +34,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 0.1
*/
-public class AbstractJpaPersistenceContext {
+public class AbstractJpaPersistenceContext implements JpaPersistenceContext {
protected EntityManager entityManager;
@@ -48,15 +48,25 @@
}
}
+ @Override
public void commit() {
entityTransaction.commit();
entityTransaction = entityManager.getTransaction();
entityTransaction.begin();
}
+ @Override
public void rollback() {
entityTransaction.rollback();
entityTransaction = entityManager.getTransaction();
entityTransaction.begin();
}
+
+ public EntityManager getEntityManager() {
+ return entityManager;
+ }
+
+ public EntityTransaction getEntityTransaction() {
+ return entityTransaction;
+ }
}
Added: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaPersistenceContext.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaPersistenceContext.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaPersistenceContext.java 2013-05-29 08:54:49 UTC (rev 635)
@@ -0,0 +1,47 @@
+package org.nuiton.jpa.api;
+
+/*
+ * #%L
+ * Nuiton Jpa :: API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.1
+ */
+public interface JpaPersistenceContext {
+
+ EntityManager getEntityManager();
+
+ EntityTransaction getEntityTransaction();
+
+ void commit();
+
+ void rollback();
+
+
+}
Property changes on: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaPersistenceContext.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java 2013-05-27 21:25:49 UTC (rev 634)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java 2013-05-29 08:54:49 UTC (rev 635)
@@ -241,7 +241,9 @@
if (PROPERTY_ID.equals(propertyName)) {
addAnnotation(result, property, output, Id.class);
- addAnnotation(result, property, output, GeneratedValue.class);
+ if (!JpaTemplatesGeneratorUtil.hasNotGeneratedValueStereotype(input)) {
+ addAnnotation(result, property, output, GeneratedValue.class);
+ }
continue;
}
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java 2013-05-27 21:25:49 UTC (rev 634)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java 2013-05-29 08:54:49 UTC (rev 635)
@@ -359,4 +359,17 @@
public static boolean hasUniqueStereotype(ObjectModelAttribute attribute) {
return attribute.hasStereotype(JpaTemplatesStereoTypes.STEREOTYPE_UNIQUE);
}
+
+ /**
+ * Check if the given class has the
+ * {@link JpaTemplatesStereoTypes#STEREOTYPE_NOT_GENERATED_VALUE} stereotype.
+ *
+ * @param clazz class to test
+ * @return {@code true} if stereotype was found, {@code false otherwise}
+ * @see JpaTemplatesStereoTypes#STEREOTYPE_NOT_GENERATED_VALUE
+ * @since 2.5
+ */
+ public static boolean hasNotGeneratedValueStereotype(ObjectModelClass clazz) {
+ return clazz.hasStereotype(JpaTemplatesStereoTypes.STEREOTYPE_NOT_GENERATED_VALUE);
+ }
}
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java 2013-05-27 21:25:49 UTC (rev 634)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java 2013-05-29 08:54:49 UTC (rev 635)
@@ -27,7 +27,10 @@
import org.nuiton.eugene.EugeneStereoTypes;
import org.nuiton.eugene.ModelPropertiesUtil;
import org.nuiton.eugene.models.object.ObjectModelAttribute;
+import org.nuiton.eugene.models.object.ObjectModelClass;
+import javax.persistence.GeneratedValue;
+
/**
* Defines all stereotypes managed by JPA templates.
*
@@ -44,4 +47,13 @@
@ModelPropertiesUtil.StereotypeDefinition(target = ObjectModelAttribute.class,
documentation = "To specify that an attribute is unique (JPA mapping)")
String STEREOTYPE_UNIQUE = "unique";
+
+ /**
+ * Stéréotype pour ne pas générer l' annotation {@link GeneratedValue} sur une entité.
+ *
+ * @see JpaTemplatesGeneratorUtil#hasNotGeneratedValueStereotype(ObjectModelAttribute)
+ */
+ @ModelPropertiesUtil.StereotypeDefinition(target = ObjectModelClass.class,
+ documentation = "To specify that an entity deal by itself with his id, the GeneratedValue annotation will not be generated then(JPA mapping)")
+ String STEREOTYPE_NOT_GENERATED_VALUE = "notGeneratedValue";
}
1
0
r634 - nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates
by tchemit@users.nuiton.org 27 May '13
by tchemit@users.nuiton.org 27 May '13
27 May '13
Author: tchemit
Date: 2013-05-27 23:25:49 +0200 (Mon, 27 May 2013)
New Revision: 634
Url: http://nuiton.org/projects/sandbox/repository/revisions/634
Log:
- add generatedValue on each entity
- review isEntity method
- review where to generate classes
- review dao inheritance layout
Modified:
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java 2013-05-27 11:55:30 UTC (rev 633)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java 2013-05-27 21:25:49 UTC (rev 634)
@@ -58,20 +58,26 @@
String packageName = JpaTemplatesGeneratorUtil.getDaoPackage(this, model, input);
+ String generatedDaoName = JpaTemplatesGeneratorUtil.getDaoGeneratedName(input);
String abstractDaoName = JpaTemplatesGeneratorUtil.getDaoAbstractName(input);
-
String concreteDaoName = JpaTemplatesGeneratorUtil.getDaoConcreteName(input);
String concreteEntityQualifiedName=
JpaTemplatesGeneratorUtil.getConcreteEntityQualifiedName(this, model, input);
+ boolean generateGenerated= !isInClassPath(packageName, generatedDaoName);
boolean generateAbstract = !isInClassPath(packageName, abstractDaoName);
boolean generateConcrete = !isInClassPath(packageName, concreteDaoName);
+ if (generateGenerated) {
+
+ generateGenerated(input, packageName, generatedDaoName, concreteEntityQualifiedName);
+ }
+
if (generateAbstract) {
- generateAbstract(input, packageName, abstractDaoName, concreteEntityQualifiedName);
+ generateAbstract(input, packageName, generatedDaoName, abstractDaoName, concreteEntityQualifiedName);
}
if (generateConcrete) {
@@ -80,7 +86,7 @@
}
}
- protected ObjectModelClass generateAbstract(ObjectModelClass input,
+ protected ObjectModelClass generateGenerated(ObjectModelClass input,
String packageName,
String abstractDaoName,
String concreteEntityQualifiedName) {
@@ -144,12 +150,30 @@
return output;
}
- protected ObjectModelClass generateImpl(ObjectModelClass input,
+ protected ObjectModelClass generateAbstract(ObjectModelClass input,
String packageName,
+ String generatedDaoName,
String abstractDaoName,
- String concreteDaoName,
String concreteEntityQualifiedName) {
+ ObjectModelClass output = createAbstractClass(abstractDaoName+ "<E extends " + input.getName() + ">", packageName);
+
+ setSuperClass(output, packageName + '.' + generatedDaoName + "<E>");
+ addImport(output, concreteEntityQualifiedName);
+ addConstructorWithEntityManager(output);
+
+ if (isVerbose()) {
+ log.info("will generate " + output.getQualifiedName());
+ }
+ return output;
+ }
+
+ protected ObjectModelClass generateImpl(ObjectModelClass input,
+ String packageName,
+ String abstractDaoName,
+ String concreteDaoName,
+ String concreteEntityQualifiedName) {
+
ObjectModelClass output = createClass(concreteDaoName, packageName);
setSuperClass(output, packageName + '.' + abstractDaoName + "<" + input.getName() + ">");
@@ -161,5 +185,4 @@
}
return output;
}
-
}
\ No newline at end of file
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java 2013-05-27 11:55:30 UTC (rev 633)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java 2013-05-27 21:25:49 UTC (rev 634)
@@ -241,9 +241,7 @@
if (PROPERTY_ID.equals(propertyName)) {
addAnnotation(result, property, output, Id.class);
- if (JpaTemplatesGeneratorUtil.hasGeneratedValueStereotype(input)) {
- addAnnotation(result, property, output, GeneratedValue.class);
- }
+ addAnnotation(result, property, output, GeneratedValue.class);
continue;
}
@@ -260,7 +258,6 @@
if (bidirection) {
-
// compute which is master of relation
String inverseValue = JpaTemplatesGeneratorUtil.getInverseTagValue(property);
if (StringUtils.isNotEmpty(inverseValue)) {
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java 2013-05-27 11:55:30 UTC (rev 633)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java 2013-05-27 21:25:49 UTC (rev 634)
@@ -29,6 +29,8 @@
import org.nuiton.eugene.models.object.ObjectModelOperation;
import org.nuiton.jpa.api.AbstractJpaPersistenceContext;
+import java.util.List;
+
/*{generator option: parentheses = false}*/
/*{generator option: writeString = +}*/
@@ -92,10 +94,11 @@
addConstructorWithEntityManager(output);
// add dao factories
- for (ObjectModelClass aClass : getModel().getClasses()) {
- //FIXME Find a way to exclude none entities classes
-// if (packageName.equals(aClass.getPackageName())) {
+ List<ObjectModelClass> entityClasses =
+ JpaTemplatesGeneratorUtil.getEntityClasses(getModel(), true);
+ for (ObjectModelClass aClass : entityClasses) {
+
// add dao factory method
String daoPackageName = JpaTemplatesGeneratorUtil.getDaoPackage(this, model, aClass);
String daoConcreteName = JpaTemplatesGeneratorUtil.getDaoConcreteName(aClass);
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java 2013-05-27 11:55:30 UTC (rev 633)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java 2013-05-27 21:25:49 UTC (rev 634)
@@ -24,6 +24,7 @@
* #L%
*/
+import com.google.common.base.Preconditions;
import org.nuiton.eugene.java.JavaGeneratorUtil;
import org.nuiton.eugene.models.object.ObjectModel;
import org.nuiton.eugene.models.object.ObjectModelAttribute;
@@ -32,6 +33,8 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -44,16 +47,22 @@
*/
public class JpaTemplatesGeneratorUtil extends JavaGeneratorUtil {
+ /**
+ * Tests if the given class is an entity (Need only to be in a entity
+ * package).
+ *
+ * @param input the class to test
+ * @return {@code true} if class is an entity.
+ */
+ public static boolean isEntity(ObjectModelClassifier input) {
+ return input.getPackageName().endsWith(".entity");
+ }
+
public static String getPersistenceContextPackage(AbstractJpaTransformer transformer,
ObjectModel model) {
- String result = getPersistenceContextPackageTagValue(model);
- if (result == null) {
+ String result = transformer.getDefaultPackageName();
- // use default package
- result = transformer.getDefaultPackageName();
- }
-
return result;
}
@@ -61,13 +70,7 @@
ObjectModel model,
ObjectModelClassifier input) {
- String result = getEntityPackageTagValue(model, input);
- if (result == null) {
-
- // use default package
- result = transformer.getDefaultPackageName() + ".entity";
- }
-
+ String result = input.getPackageName();
return result;
}
@@ -75,16 +78,47 @@
ObjectModel model,
ObjectModelClassifier input) {
- String result = getDaoPackageTagValue(model, input);
- if (result == null) {
+ Preconditions.checkState(isEntity(input), "Cant' find dao package name for a none entity " + input);
+ int lastIndexOf = input.getPackageName().lastIndexOf(".entity");
+ String result = input.getPackageName().substring(0, lastIndexOf) + ".dao";
+ return result;
+ }
- // use default package
- result = transformer.getDefaultPackageName() + ".dao";
+ /**
+ * Obtain the list of entities classes with the possibility to sort the
+ * result.
+ *
+ * @param model the current model to scan
+ * @param sort flag to allow sort the result
+ * @return the list of filtred classes by their stereotype
+ */
+ public static List<ObjectModelClass> getEntityClasses(ObjectModel model,
+ boolean sort) {
+ List<ObjectModelClass> classes = new ArrayList<ObjectModelClass>();
+ for (ObjectModelClass clazz : model.getClasses()) {
+ if (isEntity(clazz)) {
+ classes.add(clazz);
+ }
}
+ if (sort && !classes.isEmpty()) {
- return result;
+ Collections.sort(classes, OBJECT_MODEL_CLASS_COMPARATOR);
+ }
+ return classes;
}
+ static public final Comparator<ObjectModelClass>
+ OBJECT_MODEL_CLASS_COMPARATOR =
+ new Comparator<ObjectModelClass>() {
+
+ @Override
+ public int compare(ObjectModelClass o1,
+ ObjectModelClass o2) {
+ return o1.getQualifiedName().compareTo(
+ o2.getQualifiedName());
+ }
+ };
+
public static String getPersistenceContextAbstractName(ObjectModel model) {
return "AbstractJpa" + model.getName() + "PersistenceContext";
}
@@ -105,6 +139,10 @@
return "Abstract" + input.getName() + "JpaDao";
}
+ public static String getDaoGeneratedName(ObjectModelClass input) {
+ return "Generated" + input.getName() + "JpaDao";
+ }
+
public static String getDaoConcreteName(ObjectModelClass input) {
return input.getName() + "JpaDao";
}
@@ -321,17 +359,4 @@
public static boolean hasUniqueStereotype(ObjectModelAttribute attribute) {
return attribute.hasStereotype(JpaTemplatesStereoTypes.STEREOTYPE_UNIQUE);
}
-
- /**
- * Check if the given class has the
- * {@link JpaTemplatesStereoTypes#STEREOTYPE_GENERATED_VALUE} stereotype.
- *
- * @param aClass class to test
- * @return {@code true} if stereotype was found, {@code false otherwise}
- * @see JpaTemplatesStereoTypes#STEREOTYPE_GENERATED_VALUE
- * @since 2.5
- */
- public static boolean hasGeneratedValueStereotype(ObjectModelClassifier aClass) {
- return aClass.hasStereotype(JpaTemplatesStereoTypes.STEREOTYPE_GENERATED_VALUE);
- }
}
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java 2013-05-27 11:55:30 UTC (rev 633)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java 2013-05-27 21:25:49 UTC (rev 634)
@@ -27,10 +27,7 @@
import org.nuiton.eugene.EugeneStereoTypes;
import org.nuiton.eugene.ModelPropertiesUtil;
import org.nuiton.eugene.models.object.ObjectModelAttribute;
-import org.nuiton.eugene.models.object.ObjectModelClassifier;
-import javax.persistence.GeneratedValue;
-
/**
* Defines all stereotypes managed by JPA templates.
*
@@ -47,13 +44,4 @@
@ModelPropertiesUtil.StereotypeDefinition(target = ObjectModelAttribute.class,
documentation = "To specify that an attribute is unique (JPA mapping)")
String STEREOTYPE_UNIQUE = "unique";
-
- /**
- * Stéréotype pour ajouter l'annoation {@link GeneratedValue} sur l'id.
- *
- * @see JpaTemplatesGeneratorUtil#hasGeneratedValueStereotype(ObjectModelClassifier)
- */
- @ModelPropertiesUtil.StereotypeDefinition(target = ObjectModelClassifier.class,
- documentation = "To specify that an entity has a generated id (see GeneratedValue annotation) (JPA mapping)")
- String STEREOTYPE_GENERATED_VALUE = "generatedValue";
}
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java 2013-05-27 11:55:30 UTC (rev 633)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java 2013-05-27 21:25:49 UTC (rev 634)
@@ -53,7 +53,7 @@
/**
* Tag value to specify where to generate entities.
*
- * @see JpaTemplatesGeneratorUtil#getEntityPackage(ObjectModel)
+ * @see JpaTemplatesGeneratorUtil#getEntityPackageTagValue(ObjectModel, ObjectModelClassifier)
* @since 0.1
*/
@ModelPropertiesUtil.TagValueDefinition(
@@ -76,7 +76,7 @@
/**
* Tag value to specify where to generate daos.
*
- * @see JpaTemplatesGeneratorUtil#getDaoPackage(ObjectModel)
+ * @see JpaTemplatesGeneratorUtil#getDaoPackageTagValue(ObjectModel, ObjectModelClassifier)
* @since 0.1
*/
@ModelPropertiesUtil.TagValueDefinition(
@@ -96,9 +96,9 @@
String TAG_PERSISTENCE_CONTEXT_SUPER_CLASS = "persistenceContextSuperClass";
/**
- * Tag value to specify where to generate persistenceContexts.
+ * Tag value to specify where to generate persistenceContext.
*
- * @see JpaTemplatesGeneratorUtil#getPersistenceContextPackage(ObjectModel)
+ * @see JpaTemplatesGeneratorUtil#getPersistenceContextPackageTagValue(ObjectModel)
* @since 0.1
*/
@ModelPropertiesUtil.TagValueDefinition(
1
0
r633 - nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates
by tchemit@users.nuiton.org 27 May '13
by tchemit@users.nuiton.org 27 May '13
27 May '13
Author: tchemit
Date: 2013-05-27 13:55:30 +0200 (Mon, 27 May 2013)
New Revision: 633
Url: http://nuiton.org/projects/sandbox/repository/revisions/633
Log:
fix dao implements
Modified:
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java 2013-05-27 11:53:32 UTC (rev 632)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java 2013-05-27 11:55:30 UTC (rev 633)
@@ -119,6 +119,15 @@
addConstructorWithEntityManager(output);
+ // detect if there is a contract to set on abstract
+ String daoContractName = packageName + "." + input.getName() + "Dao";
+
+ boolean addUserDaoContract = isInClassPath(daoContractName);
+
+ if (addUserDaoContract) {
+ addInterface(output, daoContractName);
+ }
+
// Add getEntityClass
ObjectModelOperation operation = addOperation(output, "getEntityClass", "Class<E>", ObjectModelJavaModifier.PROTECTED);
@@ -147,15 +156,6 @@
addImport(output, concreteEntityQualifiedName);
addConstructorWithEntityManager(output);
- // detect if there is a contract to set on abstract
- String daoContractName = packageName + "." + input.getName() + "Dao";
-
- boolean addUserDaoContract = isInClassPath(daoContractName);
-
- if (addUserDaoContract) {
- addInterface(output, daoContractName);
- }
-
if (isVerbose()) {
log.info("will generate " + output.getQualifiedName());
}
1
0
r632 - nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api
by bleny@users.nuiton.org 27 May '13
by bleny@users.nuiton.org 27 May '13
27 May '13
Author: bleny
Date: 2013-05-27 13:53:32 +0200 (Mon, 27 May 2013)
New Revision: 632
Url: http://nuiton.org/projects/sandbox/repository/revisions/632
Log:
remove duplicate line
Modified:
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java 2013-05-26 06:51:26 UTC (rev 631)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java 2013-05-27 11:53:32 UTC (rev 632)
@@ -42,7 +42,6 @@
public AbstractJpaPersistenceContext(EntityManager entityManager) {
this.entityManager = entityManager;
- this.entityManager = entityManager;
entityTransaction = entityManager.getTransaction();
if (!entityTransaction.isActive()) {
entityTransaction.begin();
1
0
Author: tchemit
Date: 2013-05-26 08:51:26 +0200 (Sun, 26 May 2013)
New Revision: 631
Url: http://nuiton.org/projects/sandbox/repository/revisions/631
Log:
updates mavenpom to 3.4.11
Modified:
nuiton-jpa/pom.xml
Modified: nuiton-jpa/pom.xml
===================================================================
--- nuiton-jpa/pom.xml 2013-05-25 15:09:41 UTC (rev 630)
+++ nuiton-jpa/pom.xml 2013-05-26 06:51:26 UTC (rev 631)
@@ -7,7 +7,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmineAndCentral</artifactId>
- <version>3.4.10</version>
+ <version>3.4.11</version>
</parent>
<artifactId>nuiton-jpa</artifactId>
1
0
r630 - in nuiton-jpa/nuiton-jpa-templates/src/it/magalie: . src src/main
by tchemit@users.nuiton.org 25 May '13
by tchemit@users.nuiton.org 25 May '13
25 May '13
Author: tchemit
Date: 2013-05-25 17:09:41 +0200 (Sat, 25 May 2013)
New Revision: 630
Url: http://nuiton.org/projects/sandbox/repository/revisions/630
Log:
add missing svn externals\!
Added:
nuiton-jpa/nuiton-jpa-templates/src/it/magalie/src/
nuiton-jpa/nuiton-jpa-templates/src/it/magalie/src/main/
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/src/main
___________________________________________________________________
Added: svn:externals
+ http://svn.forge.codelutin.com/svn/franciaflex-magalie/branches/magalie-eug… xmi
1
0
r629 - in nuiton-jpa: . nuiton-jpa-api nuiton-jpa-junit nuiton-jpa-templates nuiton-jpa-templates/src nuiton-jpa-templates/src/it nuiton-jpa-templates/src/it/magalie src src/site src/site/rst
by tchemit@users.nuiton.org 25 May '13
by tchemit@users.nuiton.org 25 May '13
25 May '13
Author: tchemit
Date: 2013-05-25 17:02:30 +0200 (Sat, 25 May 2013)
New Revision: 629
Url: http://nuiton.org/projects/sandbox/repository/revisions/629
Log:
- use magalie model as a first it
- fix pom (nearly ready to be a full project)
Added:
nuiton-jpa/nuiton-jpa-templates/src/it/
nuiton-jpa/nuiton-jpa-templates/src/it/magalie/
nuiton-jpa/nuiton-jpa-templates/src/it/magalie/LICENSE.txt
nuiton-jpa/nuiton-jpa-templates/src/it/magalie/README.txt
nuiton-jpa/nuiton-jpa-templates/src/it/magalie/changelog.txt
nuiton-jpa/nuiton-jpa-templates/src/it/magalie/goals.txt
nuiton-jpa/nuiton-jpa-templates/src/it/magalie/pom.xml
nuiton-jpa/nuiton-jpa-templates/src/it/magalie/postbuild.groovy
nuiton-jpa/nuiton-jpa-templates/src/it/settings.xml
nuiton-jpa/src/
nuiton-jpa/src/site/
nuiton-jpa/src/site/rst/
nuiton-jpa/src/site/rst/index.rst
nuiton-jpa/src/site/site.xml
Modified:
nuiton-jpa/nuiton-jpa-api/pom.xml
nuiton-jpa/nuiton-jpa-junit/pom.xml
nuiton-jpa/nuiton-jpa-templates/pom.xml
nuiton-jpa/pom.xml
Modified: nuiton-jpa/nuiton-jpa-api/pom.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-api/pom.xml 2013-05-25 14:13:01 UTC (rev 628)
+++ nuiton-jpa/nuiton-jpa-api/pom.xml 2013-05-25 15:02:30 UTC (rev 629)
@@ -12,6 +12,7 @@
<groupId>org.nuiton.jpa</groupId>
<artifactId>nuiton-jpa-api</artifactId>
+ <name>Nuiton Jpa :: API</name>
<dependencies>
Modified: nuiton-jpa/nuiton-jpa-junit/pom.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-junit/pom.xml 2013-05-25 14:13:01 UTC (rev 628)
+++ nuiton-jpa/nuiton-jpa-junit/pom.xml 2013-05-25 15:02:30 UTC (rev 629)
@@ -12,6 +12,7 @@
<groupId>org.nuiton.jpa</groupId>
<artifactId>nuiton-jpa-junit</artifactId>
+ <name>Nuiton Jpa :: Junit</name>
<dependencies>
Modified: nuiton-jpa/nuiton-jpa-templates/pom.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/pom.xml 2013-05-25 14:13:01 UTC (rev 628)
+++ nuiton-jpa/nuiton-jpa-templates/pom.xml 2013-05-25 15:02:30 UTC (rev 629)
@@ -14,6 +14,7 @@
<groupId>org.nuiton.jpa</groupId>
<artifactId>nuiton-jpa-templates</artifactId>
+ <name>Nuiton Jpa :: Temlates</name>
<dependencies>
@@ -110,10 +111,52 @@
<version>${plexusPluginVersion}</version>
</plugin>
+ <plugin>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <version>${invokerPluginVersion}</version>
+ </plugin>
+
</plugins>
</reporting>
</profile>
+
+ <profile>
+ <id>run-its</id>
+ <activation>
+ <property>
+ <name>skipIts</name>
+ <value>!true</value>
+ </property>
+ </activation>
+ <build>
+ <defaultGoal>integration-test</defaultGoal>
+ <plugins>
+ <plugin>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <configuration>
+ <pomIncludes>
+ <pomInclude>*/pom.xml</pomInclude>
+ </pomIncludes>
+ <localRepositoryPath>${basedir}/target/local-repo</localRepositoryPath>
+ <settingsFile>src/it/settings.xml</settingsFile>
+ <cloneProjectsTo>${project.build.directory}/its</cloneProjectsTo>
+ </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>
Added: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/LICENSE.txt
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/it/magalie/LICENSE.txt (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/it/magalie/LICENSE.txt 2013-05-25 15:02:30 UTC (rev 629)
@@ -0,0 +1,166 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
+
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/LICENSE.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/README.txt
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/it/magalie/README.txt (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/it/magalie/README.txt 2013-05-25 15:02:30 UTC (rev 629)
@@ -0,0 +1 @@
+Test jpa templates on project Magalie (see http://forge.codelutin.com/projects/franciaflex-magalie)
\ No newline at end of file
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/README.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/changelog.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/goals.txt
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/it/magalie/goals.txt (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/it/magalie/goals.txt 2013-05-25 15:02:30 UTC (rev 629)
@@ -0,0 +1 @@
+clean compile
\ No newline at end of file
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/goals.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/pom.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/it/magalie/pom.xml (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/it/magalie/pom.xml 2013-05-25 15:02:30 UTC (rev 629)
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ #%L
+ EUGene :: Maven plugin
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2006 - 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%
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.nuiton.jpa.templates.test</groupId>
+ <artifactId>magalie</artifactId>
+ <version>@pom.version@</version>
+
+ <name>Nuiton Jpa Temlates :: Test magalie model</name>
+
+ <properties>
+
+ <eugeneVersion>@eugeneVersion@</eugeneVersion>
+
+ <!-- default encoding -->
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+ <!-- compiler configuration -->
+ <maven.compiler.source>1.6</maven.compiler.source>
+ <maven.compiler.target>1.6</maven.compiler.target>
+
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.nuiton.jpa</groupId>
+ <artifactId>nuiton-jpa-api</artifactId>
+ <version>@pom.version@</version>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.nuiton.eugene</groupId>
+ <artifactId>eugene-maven-plugin</artifactId>
+ <version>${eugeneVersion}</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
+ <plugins>
+
+ <plugin>
+ <groupId>org.nuiton.eugene</groupId>
+ <artifactId>eugene-maven-plugin</artifactId>
+ <configuration>
+ <inputs>zargo</inputs>
+ <resolver>org.nuiton.util.FasterCachedResourceResolver</resolver>
+ </configuration>
+ <executions>
+ <execution>
+ <id>generate-entities</id>
+ <phase>generate-sources</phase>
+ <configuration>
+ <!-- Corresponding to extracted package from zargo file -->
+ <fullPackagePath>com.franciaflex.magalie.persistence.entity
+ </fullPackagePath>
+ <!-- defaultPackage used for generation -->
+ <defaultPackage>com.franciaflex.magalie.persistence
+ </defaultPackage>
+ <templates>
+ org.nuiton.jpa.templates.JpaEntityTransformer,
+ org.nuiton.jpa.templates.JpaDaoTransformer,
+ org.nuiton.jpa.templates.JpaPersistenceContextTransformer,
+ org.nuiton.eugene.java.JavaEnumerationTransformer
+ </templates>
+ </configuration>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.nuiton.jpa</groupId>
+ <artifactId>nuiton-jpa-templates</artifactId>
+ <version>@pom.version@</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+
+ </plugins>
+ </build>
+</project>
+
+
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/pom.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/postbuild.groovy
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/it/magalie/postbuild.groovy (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/it/magalie/postbuild.groovy 2013-05-25 15:02:30 UTC (rev 629)
@@ -0,0 +1,39 @@
+/*
+ * #%L
+ * nuiton-jpa-templates
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+outputDir = new File(basedir, 'target/generated-sources/java');
+
+file = new File(outputDir, 'com/franciaflex/magalie/persistence');
+assert file.exists();
+assert file.isDirectory();
+
+file = new File(outputDir, 'com/franciaflex/magalie/persistence/entity');
+assert file.exists();
+assert file.isDirectory();
+
+file = new File(outputDir, 'com/franciaflex/magalie/persistence/dao');
+assert file.exists();
+assert file.isDirectory();
+
+return true;
\ No newline at end of file
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/postbuild.groovy
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: nuiton-jpa/nuiton-jpa-templates/src/it/settings.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/it/settings.xml (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/it/settings.xml 2013-05-25 15:02:30 UTC (rev 629)
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ #%L
+ EUGene :: Maven plugin
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2006 - 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%
+ -->
+
+<settings>
+
+ <profiles>
+ <profile>
+ <id>it-repo</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <repositories>
+ <repository>
+ <id>local.central</id>
+ <url>file:///@localRepository@</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+
+ <!-- depot des releases nuiton -->
+ <repository>
+ <id>nuiton.release</id>
+ <name>NuitonReleaseRepository</name>
+ <url>http://maven.nuiton.org/release</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <releases>
+ <enabled>true</enabled>
+ <checksumPolicy>warn</checksumPolicy>
+ </releases>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>local.central</id>
+ <url>file:///@localRepository@</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </pluginRepository>
+
+ <pluginRepository>
+ <id>nuiton.release</id>
+ <name>NuitonReleaseRepository</name>
+ <url>http://maven.nuiton.org/release</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
+ </profiles>
+</settings>
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/it/settings.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: nuiton-jpa/pom.xml
===================================================================
--- nuiton-jpa/pom.xml 2013-05-25 14:13:01 UTC (rev 628)
+++ nuiton-jpa/pom.xml 2013-05-25 15:02:30 UTC (rev 629)
@@ -4,9 +4,6 @@
<modelVersion>4.0.0</modelVersion>
- <!-- ************************************************************* -->
- <!-- *** POM Relationships *************************************** -->
- <!-- ************************************************************* -->
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmineAndCentral</artifactId>
@@ -22,7 +19,7 @@
<module>nuiton-jpa-templates</module>
</modules>
- <name>nuiton-jpa</name>
+ <name>Nuiton Jpa</name>
<inceptionYear>2013</inceptionYear>
<url>http://maven-site.nuiton.org/nuiton-jpa</url>
@@ -35,27 +32,22 @@
<!-- libs version -->
<eugeneVersion>2.6.3-SNAPSHOT</eugeneVersion>
- <nuitonUtilsVersion>2.6.12</nuitonUtilsVersion>
<processorPluginVersion>1.3</processorPluginVersion>
<h2Version>1.3.170</h2Version>
- <hibernateVersion>4.1.9.Final</hibernateVersion>
+ <hibernateVersion>4.1.11.Final</hibernateVersion>
</properties>
- <!-- ************************************************************* -->
- <!-- *** Build Environment ************************************** -->
- <!-- ************************************************************* -->
-
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/topia/trunk</connection>
- <developerConnection>scm:svn:http://svn.nuiton.org/svn/topia/trunk</developerConnection>
- <url>http://nuiton.org/projects/topia/repository/show/branches/trunk</url>
+ <connection>scm:svn:http://svn.nuiton.org/svn/sandbox/nuiton-jpa</connection>
+ <developerConnection>scm:svn:http://svn.nuiton.org/svn/sandbox/nuiton-jpa</developerConnection>
+ <url>http://nuiton.org/projects/sandbox/repository/show/nuiton-jpa</url>
</scm>
<distributionManagement>
<site>
<id>${platform}</id>
- <url>${our.site.repository}/${projectId}</url>
+ <url>${our.site.repository}/sandbox/${projectId}</url>
</site>
</distributionManagement>
@@ -105,11 +97,6 @@
</dependencyManagement>
- <!-- ************************************************************* -->
- <!-- *** Project Information ************************************* -->
- <!-- ************************************************************* -->
-
-
<developers>
<developer>
@@ -137,10 +124,6 @@
</developer>
</developers>
-
- <!-- ************************************************************* -->
- <!-- *** Build Settings ****************************************** -->
- <!-- ************************************************************* -->
<packaging>pom</packaging>
@@ -181,12 +164,6 @@
</plugin>
<plugin>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>i18n-maven-plugin</artifactId>
- <version>${nuitonI18nVersion}</version>
- </plugin>
-
- <plugin>
<artifactId>maven-site-plugin</artifactId>
<dependencies>
<dependency>
Added: nuiton-jpa/src/site/rst/index.rst
===================================================================
--- nuiton-jpa/src/site/rst/index.rst (rev 0)
+++ nuiton-jpa/src/site/rst/index.rst 2013-05-25 15:02:30 UTC (rev 629)
@@ -0,0 +1,28 @@
+.. -
+.. * #%L
+.. * Nuiton Jpa
+.. * $Id$
+.. * $HeadURL$
+.. * %%
+.. * Copyright (C) 2013 CodeLutin
+.. * %%
+.. * This program is free software: you can redistribute it and/or modify
+.. * it under the terms of the GNU Lesser General Public License as
+.. * published by the Free Software Foundation, either version 3 of the
+.. * License, or (at your option) any later version.
+.. *
+.. * This program is distributed in the hope that it will be useful,
+.. * but WITHOUT ANY WARRANTY; without even the implied warranty of
+.. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+.. * GNU General Lesser Public License for more details.
+.. *
+.. * You should have received a copy of the GNU General Lesser Public
+.. * License along with this program. If not, see
+.. * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+.. * #L%
+.. -
+==========
+Nuiton Jpa
+==========
+
+TODO
Property changes on: nuiton-jpa/src/site/rst/index.rst
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: nuiton-jpa/src/site/site.xml
===================================================================
--- nuiton-jpa/src/site/site.xml (rev 0)
+++ nuiton-jpa/src/site/site.xml 2013-05-25 15:02:30 UTC (rev 629)
@@ -0,0 +1,123 @@
+<!--
+ #%L
+ Nuiton Jpa
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2013 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Lesser Public License for more details.
+
+ You should have received a copy of the GNU General Lesser Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ #L%
+ -->
+
+<project name="${project.name}">
+
+ <skin>
+ <groupId>org.apache.maven.skins</groupId>
+ <artifactId>maven-fluido-skin</artifactId>
+ <version>1.3.0</version>
+ </skin>
+
+ <custom>
+ <fluidoSkin>
+ <topBarEnabled>false</topBarEnabled>
+ <googleSearch/>
+ <sideBarEnabled>true</sideBarEnabled>
+ <searchEnabled>true</searchEnabled>
+ <sourceLineNumbersEnabled>true</sourceLineNumbersEnabled>
+ </fluidoSkin>
+ </custom>
+
+ <bannerLeft>
+ <name>${project.name}</name>
+ <href>index.html</href>
+ </bannerLeft>
+
+ <bannerRight>
+ <src>http://www.codelutin.com/images/lutinorange-codelutin.png</src>
+ <href>http://www.codelutin.com</href>
+ </bannerRight>
+
+ <publishDate position="right"/>
+ <version position="right"/>
+
+ <poweredBy>
+ <logo href="http://maven.apache.org" name="Maven"
+ img="http://maven-site.nuiton.org/public/images/logos/maven-feather.png"/>
+ <logo href="http://maven-site.nuiton.org/jrst/" name="JRst"
+ img="http://maven-site.nuiton.org/public/images/logos/jrst-logo.png"/>
+ <logo href="http://docutils.sourceforge.net/rst.html"
+ name="ReStructuredText"
+ img="http://maven-site.nuiton.org/public/images/logos/restructuredtext-logo.png"/>
+ </poweredBy>
+
+ <body>
+
+ <breadcrumbs>
+ <item name="${project.name}" href="./index.html"/>
+ </breadcrumbs>
+
+ <head>
+ <script type="text/javascript"
+ src="http://maven-site.nuiton.org/public/js/maven-site-nuiton.org.js">
+ </script>
+ </head>
+
+ <links>
+ <item name="Nuiton.org" href="http://nuiton.org"/>
+ <item name="Code Lutin" href="http://www.codelutin.com"/>
+ <item name="Libre-Entreprise" href="http://www.libre-entreprise.org/"/>
+ </links>
+
+ <menu name="Home">
+ <item name="Home" href="index.html"/>
+ </menu>
+
+ <menu name="Project">
+ <item name="Forge" href="http://nuiton.org/projects/show/nuiton-jpa"/>
+ <item name="Downloads"
+ href="http://nuiton.org/projects/nuiton-jpa/files"/>
+ <item name="Trackers" href="http://nuiton.org/projects/nuiton-jpa/issues"/>
+ </menu>
+
+ <menu name="Links">
+ <item name="Nuiton-processor"
+ href="http://maven-site.nuiton.org/processor"/>
+ <item name="Eugene" href="http://maven-site.nuiton.org/eugene"/>
+ <item name="ArgoUML" href="http://argouml.tigris.org/"/>
+ <item name="UML" href="http://www.uml.org/"/>
+ <item name="XMI" href="http://www.omg.org/spec/XMI/"/>
+ </menu>
+
+ <menu ref="modules"/>
+
+ <menu ref="reports"/>
+
+ <footer>
+
+ <div id='projectMetas' locale='en'
+ projectversion='${project.version}'
+ platform='${project.platform}'
+ projectid='${project.projectId}'
+ scm='${project.scm.developerConnection}'
+ scmwebeditorenabled='${project.scmwebeditorEnabled}'
+ scmwebeditorurl='${project.scmwebeditorUrl}'
+ siteSourcesType='${project.siteSourcesType}'
+ piwikEnabled='${project.piwikEnabled}'
+ piwikId='${project.piwikId}'>
+ </div>
+ </footer>
+ </body>
+</project>
\ No newline at end of file
Property changes on: nuiton-jpa/src/site/site.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
r628 - in nuiton-jpa: . nuiton-jpa-api nuiton-jpa-api/src/main/java/org/nuiton/jpa/api nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit nuiton-jpa-templates nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates
by tchemit@users.nuiton.org 25 May '13
by tchemit@users.nuiton.org 25 May '13
25 May '13
Author: tchemit
Date: 2013-05-25 16:13:01 +0200 (Sat, 25 May 2013)
New Revision: 628
Url: http://nuiton.org/projects/sandbox/repository/revisions/628
Log:
continue nuiton-jpa (works now on magalie project)
Added:
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntities.java
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntity.java
Modified:
nuiton-jpa/nuiton-jpa-api/pom.xml
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java
nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java
nuiton-jpa/nuiton-jpa-templates/pom.xml
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/AbstractJpaTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java
nuiton-jpa/pom.xml
Modified: nuiton-jpa/nuiton-jpa-api/pom.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-api/pom.xml 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-api/pom.xml 2013-05-25 14:13:01 UTC (rev 628)
@@ -36,6 +36,11 @@
</dependency>
<dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -45,7 +45,7 @@
*
* @since 0.1
*/
-public abstract class AbstractJpaDao<E extends AbstractJpaEntity> implements JpaDao<E> {
+public abstract class AbstractJpaDao<E extends JpaEntity> implements JpaDao<E> {
protected EntityManager entityManager;
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -26,17 +26,15 @@
/**
* A AbstractJpaEntity must have a technical id.
- *
+ * <p/>
* Also equals() is defined for compliance with JPA expectations.
*
* @author bleny <leny(a)codelutin.com>
* @author tchemit <chemit(a)codelutin.com>
* @since 0.1
*/
-public abstract class AbstractJpaEntity {
+public abstract class AbstractJpaEntity implements JpaEntity{
- public abstract String getId();
-
@Override
public boolean equals(Object other) {
String id = getId();
@@ -55,7 +53,7 @@
@Override
public String toString() {
- return "AbstractJpaEntity{id=" + getId() + "}";
+ return getClass().getSimpleName() + "{id=" + getId() + "}";
}
}
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -2,7 +2,7 @@
/*
* #%L
- * MagaLiE :: Persistence
+ * nuiton-jpa-api
* $Id$
* $HeadURL$
* %%
@@ -35,7 +35,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 0.1
*/
-public interface JpaDao<E extends AbstractJpaEntity> {
+public interface JpaDao<E extends JpaEntity> {
E findById(String id);
Added: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntities.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntities.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntities.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -0,0 +1,74 @@
+package org.nuiton.jpa.api;
+
+/*
+ * #%L
+ * nuiton-jpa-api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+import org.apache.commons.lang3.ObjectUtils;
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+/**
+ * Helper class around {@link JpaEntity}.
+ *
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.1
+ */
+public class JpaEntities {
+
+ public static class GetIdFunction implements Function<JpaEntity, String> {
+
+ @Override
+ public String apply(JpaEntity entity) {
+ return entity.getId();
+ }
+ }
+
+ public static class ArbitraryComparator<E extends JpaEntity> implements Comparator<E>, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public int compare(E x, E y) {
+ return ObjectUtils.compare(x.getId(), y.getId());
+ }
+
+ }
+
+ public static Function<JpaEntity, String> getIdFunction() {
+ return new GetIdFunction();
+ }
+
+ public static Predicate<JpaEntity> entityHasId(String id) {
+ return Predicates.compose(Predicates.equalTo(id), getIdFunction());
+ }
+
+ public static <E extends JpaEntity> Comparator<E> arbitraryComparator() {
+ return new ArbitraryComparator<E>();
+ }
+}
Property changes on: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntities.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntity.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntity.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntity.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -0,0 +1,42 @@
+package org.nuiton.jpa.api;
+
+/*
+ * #%L
+ * nuiton-jpa-api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+/**
+ * A JpaEntity must have a technical id.
+ * <p/>
+ * Also {@link #equals(Object)} and {@link #hashCode()} {@code MUST} be defined
+ * for compliance with JPA expectations.
+ *
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @see AbstractJpaEntity
+ * @since 0.1
+ */
+public interface JpaEntity {
+
+ String getId();
+
+}
Property changes on: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntity.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java
===================================================================
--- nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -2,7 +2,7 @@
/*
* #%L
- * MagaLiE :: Services
+ * nuiton-jpa-junit
* $Id$
* $HeadURL$
* %%
Modified: nuiton-jpa/nuiton-jpa-templates/pom.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/pom.xml 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-templates/pom.xml 2013-05-25 14:13:01 UTC (rev 628)
@@ -39,6 +39,11 @@
</dependency>
<dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/AbstractJpaTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/AbstractJpaTransformer.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/AbstractJpaTransformer.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -31,6 +31,7 @@
import org.nuiton.eugene.java.ObjectModelTransformerToJava;
import org.nuiton.eugene.models.object.ObjectModelAttribute;
import org.nuiton.eugene.models.object.ObjectModelClass;
+import org.nuiton.eugene.models.object.ObjectModelElement;
import org.nuiton.eugene.models.object.ObjectModelInterface;
import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
import org.nuiton.eugene.models.object.ObjectModelOperation;
@@ -39,9 +40,7 @@
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
import java.util.Set;
/**
@@ -55,6 +54,27 @@
public static final String DEFAULT_CONSTANT_PREFIX = "PROPERTY_";
+ public String getDefaultPackageName() {
+ String packageName =
+ getOutputProperties().getProperty(PROP_DEFAULT_PACKAGE);
+ return packageName;
+ }
+
+ protected void addAnnotation(
+ ObjectModelClass output,
+ Class annotation) {
+ addAnnotation(output, output, annotation.getSimpleName());
+ addImport(output, annotation);
+ }
+
+ protected void addAnnotation(
+ ObjectModelClass output,
+ ObjectModelElement element,
+ Class annotation) {
+ addAnnotation(output, element, annotation.getSimpleName());
+ addImport(output, annotation);
+ }
+
protected void addConstructorWithEntityManager(ObjectModelClass output) {
ObjectModelOperation constructor = addConstructor(
@@ -105,7 +125,7 @@
String prefix,
Set<String> constantNames) {
- String attrName = getAttributeName(attr);
+ String attrName = JpaTemplatesGeneratorUtil.getAttributeName(attr);
String constantName = prefix + builder.getConstantName(attrName);
@@ -120,330 +140,6 @@
}
}
- protected String getAttributeName(ObjectModelAttribute attr) {
- String attrName = attr.getName();
- if (attr.hasAssociationClass()) {
- String assocAttrName = JpaTemplatesGeneratorUtil.getAssocAttrName(attr);
- attrName = JpaTemplatesGeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
- }
- return attrName;
- }
-
- protected String getAttributeType(ObjectModelAttribute attr) {
- String attrType = attr.getType();
- if (attr.hasAssociationClass()) {
- attrType = attr.getAssociationClass().getName();
- }
- return attrType;
- }
-
- protected boolean containsMutiple(List<ObjectModelAttribute> attributes) {
-
- boolean result = false;
-
- for (ObjectModelAttribute attr : attributes) {
-
- if (JpaTemplatesGeneratorUtil.isNMultiplicity(attr)) {
- result = true;
-
- break;
- }
-
- }
- return result;
- }
-
-
- protected List<ObjectModelAttribute> getProperties(ObjectModelClass input) {
- List<ObjectModelAttribute> attributes =
- (List<ObjectModelAttribute>) input.getAttributes();
-
- List<ObjectModelAttribute> attrs =
- new ArrayList<ObjectModelAttribute>();
- for (ObjectModelAttribute attr : attributes) {
- if (attr.isNavigable()) {
-
- // only keep navigable attributes
- attrs.add(attr);
- }
- }
- return attrs;
- }
-
- protected void createGetMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String methodPrefix) {
-
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName(methodPrefix, attrName),
- attrType,
- ObjectModelJavaModifier.PUBLIC
- );
- setOperationBody(operation, ""
- /*{
- return <%=attrName%>;
- }*/
- );
- }
-
- protected void createGetChildMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String simpleType) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("get", attrName),
- attrType,
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, "int", "index");
- setOperationBody(operation, ""
- /*{
- <%=simpleType%> o = getChild(<%=attrName%>, index);
- return o;
- }*/
- );
- }
-
- protected void createIsEmptyMethod(ObjectModelClass output,
- String attrName) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("is", attrName) + "Empty",
- boolean.class,
- ObjectModelJavaModifier.PUBLIC
- );
- setOperationBody(operation, ""
- /*{
- return <%=attrName%> == null || <%=attrName%>.isEmpty();
- }*/
- );
- }
-
- protected void createSizeMethod(ObjectModelClass output,
- String attrName) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("size", attrName),
- int.class,
- ObjectModelJavaModifier.PUBLIC
- );
- setOperationBody(operation, ""
- /*{
- return <%=attrName%> == null ? 0 : <%=attrName%>.size();
- }*/
- );
- }
-
- protected void createAddChildMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String constantName,
- boolean usePCS) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("add", attrName),
- "void",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, attrType, attrName);
-
- String methodName = getJavaBeanMethodName("get", attrName);
- StringBuilder buffer = new StringBuilder(""
- /*{
- <%=methodName%>().add(<%=attrName%>);
- }*/
- );
- if (usePCS) {
- buffer.append(""
- /*{ firePropertyChange(<%=constantName%>, null, <%=attrName%>);
- }*/
- );
- }
- setOperationBody(operation, buffer.toString());
- }
-
- protected void createAddAllChildrenMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String constantName,
- boolean usePCS) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("addAll", attrName),
- "void",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, Collection.class.getName() + "<" + attrType + ">", attrName);
-
- String methodName = getJavaBeanMethodName("get", attrName);
- StringBuilder buffer = new StringBuilder(""
- /*{
- <%=methodName%>().addAll(<%=attrName%>);
- }*/
- );
- if (usePCS) {
- buffer.append(""
- /*{ firePropertyChange(<%=constantName%>, null, <%=attrName%>);
- }*/
- );
- }
- setOperationBody(operation, buffer.toString());
- }
-
- protected void createRemoveChildMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String constantName,
- boolean usePCS) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("remove", attrName),
- "boolean",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, attrType, attrName);
- String methodName = getJavaBeanMethodName("get", attrName);
- StringBuilder buffer = new StringBuilder();
- buffer.append(""
- /*{
- boolean removed = <%=methodName%>().remove(<%=attrName%>);}*/
- );
-
- if (usePCS) {
- buffer.append(""
- /*{
- if (removed) {
- firePropertyChange(<%=constantName%>, <%=attrName%>, null);
- }}*/
- );
- }
- buffer.append(""
- /*{
- return removed;
- }*/
- );
- setOperationBody(operation, buffer.toString());
- }
-
- protected void createRemoveAllChildrenMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String constantName,
- boolean usePCS) {
-
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("removeAll", attrName),
- "boolean",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, "java.util.Collection<" + attrType + ">", attrName);
- StringBuilder buffer = new StringBuilder();
- String methodName = getJavaBeanMethodName("get", attrName);
- buffer.append(""
- /*{
- boolean removed = <%=methodName%>().removeAll(<%=attrName%>);}*/
- );
-
- if (usePCS) {
- buffer.append(""
- /*{
- if (removed) {
- firePropertyChange(<%=constantName%>, <%=attrName%>, null);
- }}*/
- );
- }
- buffer.append(""
- /*{
- return removed;
- }*/
- );
- setOperationBody(operation, buffer.toString());
- }
-
- protected void createContainsChildMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String constantName,
- boolean usePCS) {
-
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("contains", attrName),
- "boolean",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, attrType, attrName);
- StringBuilder buffer = new StringBuilder();
- String methodName = getJavaBeanMethodName("get", attrName);
- buffer.append(""
- /*{
- boolean contains = <%=methodName%>().contains(<%=attrName%>);
- return contains;
- }*/
- );
- setOperationBody(operation, buffer.toString());
- }
-
- protected void createContainsAllChildrenMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String constantName,
- boolean usePCS) {
-
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("containsAll", attrName),
- "boolean",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, Collection.class.getName() + "<" + attrType + ">", attrName);
- StringBuilder buffer = new StringBuilder();
- String methodName = getJavaBeanMethodName("get", attrName);
- buffer.append(""
- /*{
- boolean contains = <%=methodName%>().containsAll(<%=attrName%>);
- return contains;
- }*/
- );
- setOperationBody(operation, buffer.toString());
- }
-
- protected void createSetMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String simpleType,
- String constantName,
- boolean usePCS) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("set", attrName),
- "void",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, attrType, attrName);
-
- if (usePCS) {
- String methodName = getJavaBeanMethodName("get", attrName);
- setOperationBody(operation, ""
- /*{
- <%=simpleType%> oldValue = <%=methodName%>();
- this.<%=attrName%> = <%=attrName%>;
- firePropertyChange(<%=constantName%>, oldValue, <%=attrName%>);
- }*/
- );
- } else {
- setOperationBody(operation, ""
- /*{
- this.<%=attrName%> = <%=attrName%>;
- }*/
- );
- }
- }
-
protected void addSerializable(ObjectModelClass input,
ObjectModelClass output,
boolean interfaceFound) {
@@ -577,37 +273,4 @@
);
}
- protected void createGetChildMethod(ObjectModelClass output) {
- ObjectModelOperation getChild = addOperation(
- output,
- "getChild", "<T> T",
- ObjectModelJavaModifier.PROTECTED
- );
- addImport(output, List.class);
-
- addParameter(getChild, "java.util.Collection<T>", "childs");
- addParameter(getChild, "int", "index");
- setOperationBody(getChild, ""
- /*{
- T result = null;
- if (childs != null) {
- if (childs instanceof List) {
- if (index < childs.size()) {
- result = ((List<T>) childs).get(index);
- }
- } else {
- int i = 0;
- for (T o : childs) {
- if (index == i) {
- result = o;
- break;
- }
- i++;
- }
- }
- }
- return result;
- }*/
- );
- }
}
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -31,6 +31,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.eugene.models.object.ObjectModelClass;
+import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
import org.nuiton.eugene.models.object.ObjectModelOperation;
import org.nuiton.jpa.api.AbstractJpaDao;
@@ -41,7 +42,6 @@
* <li>{@code AbstractXXXJpaDao}: abstract jpa dao for entity named {@code XXX}, will find here the generated stuff (with jpa mapping, technical stuff)</li>
* <li>{@code XXXJpaDao}: concrete public jpa dao to use in your persistence layer</li>
* </ul>
- * <p/>
* {@code Note:} All classes found in class-path are not generated.
*
* @author tchemit <chemit(a)codelutin.com>
@@ -56,35 +56,38 @@
@Override
public void transformFromClass(ObjectModelClass input) {
- String entityAbstractName = "Abstract" + input.getName() + "JpaDao";
+ String packageName = JpaTemplatesGeneratorUtil.getDaoPackage(this, model, input);
- String entityConcreteName = JpaTemplatesGeneratorUtil.getDaoConcreteName(input);
+ String abstractDaoName = JpaTemplatesGeneratorUtil.getDaoAbstractName(input);
- boolean generateAbstract = !isInClassPath(input.getPackageName(),
- entityAbstractName);
+ String concreteDaoName = JpaTemplatesGeneratorUtil.getDaoConcreteName(input);
- boolean generateConcrete = !isInClassPath(input.getPackageName(),
- entityConcreteName);
+ String concreteEntityQualifiedName=
+ JpaTemplatesGeneratorUtil.getConcreteEntityQualifiedName(this, model, input);
+ boolean generateAbstract = !isInClassPath(packageName, abstractDaoName);
+
+ boolean generateConcrete = !isInClassPath(packageName, concreteDaoName);
+
if (generateAbstract) {
- generateAbstract(input, entityAbstractName);
+ generateAbstract(input, packageName, abstractDaoName, concreteEntityQualifiedName);
}
if (generateConcrete) {
- generateImpl(input, entityAbstractName, entityConcreteName);
+ generateImpl(input, packageName, abstractDaoName, concreteDaoName, concreteEntityQualifiedName);
}
}
protected ObjectModelClass generateAbstract(ObjectModelClass input,
- String entityAbstractName) {
+ String packageName,
+ String abstractDaoName,
+ String concreteEntityQualifiedName) {
- String packageName = input.getPackageName();
-
ObjectModelClass output =
- createAbstractClass(entityAbstractName + "<E extends " + input.getName() + ">", packageName);
- addImport(output, input.getQualifiedName());
+ createAbstractClass(abstractDaoName + "<E extends " + input.getName() + ">", packageName);
+ addImport(output, concreteEntityQualifiedName);
// test if a super class is in same package (so is yet another entity)
boolean superClassIsEntity = isSuperClassEntity(input);
@@ -95,7 +98,9 @@
// get first super-class
ObjectModelClass superClassModel = input.getSuperclasses().iterator().next();
- superClass = JpaTemplatesGeneratorUtil.getDaoConcreteName(superClassModel);
+ superClass = JpaTemplatesGeneratorUtil.getDaoPackage(this, model, superClassModel) +
+ "." +
+ JpaTemplatesGeneratorUtil.getDaoConcreteName(superClassModel);
} else {
@@ -110,56 +115,50 @@
addImport(output, superClass);
}
}
-
- // detect if there is a contract to set on abstract
- String daoContractName = input.getPackageName() + "." + input.getName() + "Dao";
-
- boolean addUserDaoContract = isInClassPath(daoContractName);
-
setSuperClass(output, superClass);
- if (addUserDaoContract) {
- addInterface(output, daoContractName);
- }
-
addConstructorWithEntityManager(output);
// Add getEntityClass
- if (log.isDebugEnabled()) {
- log.debug("will generate " + output.getQualifiedName());
- }
- ObjectModelOperation operation = addOperation(output, "getEntityClass", "Class<E>");
- addAnnotation(output, operation, Override.class.getSimpleName());
+ ObjectModelOperation operation = addOperation(output, "getEntityClass", "Class<E>", ObjectModelJavaModifier.PROTECTED);
+ addAnnotation(output, operation, Override.class);
setOperationBody(operation, ""
/*{
return (Class<E>) <%=input.getName()%>.class;
}*/
);
-
+ if (isVerbose()) {
+ log.info("will generate " + output.getQualifiedName());
+ }
return output;
}
protected ObjectModelClass generateImpl(ObjectModelClass input,
- String entityAbstractName,
- String entityConcreteName) {
+ String packageName,
+ String abstractDaoName,
+ String concreteDaoName,
+ String concreteEntityQualifiedName) {
- ObjectModelClass output = createClass(
- entityConcreteName,
- input.getPackageName()
- );
+ ObjectModelClass output = createClass(concreteDaoName, packageName);
- // set the abstract resulClass as the resultClassImpl super class
- setSuperClass(output, input.getPackageName() + '.' + entityAbstractName + "<" + input.getName() + ">");
- addImport(output, input);
+ setSuperClass(output, packageName + '.' + abstractDaoName + "<" + input.getName() + ">");
+ addImport(output, concreteEntityQualifiedName);
addConstructorWithEntityManager(output);
- output.getSuperclasses();
- if (log.isDebugEnabled()) {
- log.debug("will generate " + output.getQualifiedName());
+ // detect if there is a contract to set on abstract
+ String daoContractName = packageName + "." + input.getName() + "Dao";
+
+ boolean addUserDaoContract = isInClassPath(daoContractName);
+
+ if (addUserDaoContract) {
+ addInterface(output, daoContractName);
}
+ if (isVerbose()) {
+ log.info("will generate " + output.getQualifiedName());
+ }
return output;
}
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -24,9 +24,12 @@
* #L%
*/
-import com.google.common.base.Preconditions;
+import com.google.common.base.Joiner;
import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ListMultimap;
+import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.eugene.models.object.ObjectModelAttribute;
@@ -36,9 +39,11 @@
import org.nuiton.eugene.models.object.xml.ObjectModelAttributeImpl;
import org.nuiton.jpa.api.AbstractJpaEntity;
+import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
@@ -47,7 +52,6 @@
import javax.persistence.OneToOne;
import javax.persistence.OrderColumn;
import java.util.Collection;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -63,7 +67,6 @@
* <p/>
* {@code Note:} All classes found in class-path are not generated.
*
- * TODO Deal with @GeneratedValue
* @author tchemit <chemit(a)codelutin.com>
* @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.jpa.templates.JpaEntityTransformer"
* @since 0.1
@@ -73,44 +76,34 @@
private static final Log log =
LogFactory.getLog(JpaEntityTransformer.class);
- protected String getConcreteName(ObjectModelClass input) {
- return input.getName();
- }
+ public static final String PROPERTY_ID = "id";
@Override
public void transformFromClass(ObjectModelClass input) {
- String entityAbstractName = "Jpa" + input.getName();
+ String packageName = JpaTemplatesGeneratorUtil.getEntityPackage(this, model, input);
- String entityConcreteName = getConcreteName(input);
+ String entityAbstractName = JpaTemplatesGeneratorUtil.getEntityAbstractName(input);
- boolean generateAbstract = !isInClassPath(input.getPackageName(), entityAbstractName);
+ String entityConcreteName = JpaTemplatesGeneratorUtil.getEntityConcreteName(input);
- boolean generateConcrete = !isInClassPath(input.getPackageName(), entityConcreteName);
+ boolean generateAbstract = !isInClassPath(packageName, entityAbstractName);
+ boolean generateConcrete = !isInClassPath(packageName, entityConcreteName);
+
if (generateAbstract) {
- generateAbstract(input, entityAbstractName);
+ generateAbstract(input, packageName, entityAbstractName);
}
if (generateConcrete) {
- generateImpl(input, entityAbstractName, entityConcreteName);
+ generateImpl(input, packageName, entityAbstractName, entityConcreteName);
}
}
- protected void createAbstractOperations(ObjectModelClass ouput,
- Iterable<ObjectModelOperation> operations) {
- JpaTemplatesGeneratorUtil.cloneOperations(
- this,
- operations,
- ouput,
- true,
- ObjectModelJavaModifier.ABSTRACT
- );
- }
-
protected ObjectModelClass generateAbstract(ObjectModelClass input,
+ String packageName,
String entityAbstractName) {
// test if a super class is in same package (so is yet another entity)
@@ -123,8 +116,9 @@
// get first super-class
ObjectModelClass superClassModel =
input.getSuperclasses().iterator().next();
- superClass = getConcreteName(superClassModel);
-
+ superClass = JpaTemplatesGeneratorUtil.getEntityPackage(this, model, superClassModel) +
+ "." +
+ JpaTemplatesGeneratorUtil.getEntityConcreteName(superClassModel);
} else {
// try to find a super class by tag-value
@@ -144,18 +138,12 @@
}
ObjectModelClass output =
- createAbstractClass(entityAbstractName, input.getPackageName());
+ createAbstractClass(entityAbstractName, packageName);
setSuperClass(output, superClass);
- // Add annotation MappedSuperclass
- addAnnotation(output, output, MappedSuperclass.class.getSimpleName());
- addImport(output, MappedSuperclass.class);
+ addAnnotation(output, MappedSuperclass.class);
- if (log.isDebugEnabled()) {
- log.debug("will generate " + output.getQualifiedName());
- }
-
String prefix = getConstantPrefix(input, DEFAULT_CONSTANT_PREFIX);
setConstantPrefix(prefix);
@@ -171,29 +159,22 @@
Set<String> constantNames = addConstantsFromDependency(input, output);
// Get available properties
- List<ObjectModelAttribute> properties = getProperties(input);
+ List<ObjectModelAttribute> properties =
+ JpaTemplatesGeneratorUtil.getProperties(input);
- //TODO Deal with @GeneratedValue
+ // Create an id property
ObjectModelAttributeImpl idAttr = new ObjectModelAttributeImpl();
idAttr.setDeclaringElement(input);
- idAttr.setName("id");
+ idAttr.setName(PROPERTY_ID);
idAttr.setType(String.class.getName());
- properties.add(idAttr);
+ properties.add(0, idAttr);
- //TODO Add attribute id (+ @Id)
- //TODO 1 -> 1 @OnetoOne (uniquement navigeable sans bidi) si composition (Cascade = ALL) si aggregeation Cascade = (tout sauf ALL TODO A check) + orphanRemoval = true)
- //TODO * -> 1 @ManyToOne (uniquement navigeable sans bidi) si composition (Cascade = ALL) si aggregeation Cascade = (tout sauf ALL TODO A check) + orphanRemoval = true)
- //TODO 1 -> * @OneToMany (uniquement navigeable sans bidi) si composition (Cascade = ALL) si aggregeation Cascade = (tout sauf ALL TODO A check) + orphanRemoval = true)
- //TODO * -> * @ManyToMany (uniquement navigeable sans bidi) si composition (Cascade = ALL) si aggregeation Cascade = (tout sauf ALL TODO A check) + orphanRemoval = true)
-
//TODO Si ORDERED ou et UNIQUE choisir le bon type de collection (O+U = LHS (laisser ça comme definition), (U = HS + S), (O = ArrayList +L), ( = ArrayList + C)
- //TODO Si ORDERED ajouter l'annotation @OrderColumn
//TODO Si enumeration @Enumeration(value = EnumType.STRING) (Voir pour mettre une tag-value pour mettre en ordinal) + voir comment ça marche pour les collections
Multimap<ObjectModelAttribute, String> annotationsForAttributes =
generateAnnotationsForProperties(input, output, properties);
-
// Add properties constant
for (ObjectModelAttribute attr : properties) {
@@ -206,18 +187,48 @@
createProperty(output, attr, annotationsForAttributes.get(attr));
}
- boolean hasAMultipleProperty = containsMutiple(properties);
+ boolean hasAMultipleProperty =
+ JpaTemplatesGeneratorUtil.containsMutiple(properties);
// Add helper operations
if (hasAMultipleProperty) {
-
// add getChild methods
createGetChildMethod(output);
}
+
+ if (isVerbose()) {
+ log.info("will generate " + output.getQualifiedName());
+ }
return output;
}
+ protected ObjectModelClass generateImpl(ObjectModelClass input,
+ String packageName,
+ String entityAbstractName,
+ String entityConcreteName) {
+
+ ObjectModelClass output = createClass(entityConcreteName, packageName);
+
+ setSuperClass(output, entityAbstractName);
+
+ // add Entity annotation
+ addAnnotation(output, Entity.class);
+
+ // add a fix serialVersionUID, since the class has no field nor method
+ addConstant(output,
+ JpaTemplatesGeneratorUtil.SERIAL_VERSION_UID,
+ "long",
+ "1L",
+ ObjectModelJavaModifier.PRIVATE
+ );
+
+ if (isVerbose()) {
+ log.info("will generate " + output.getQualifiedName());
+ }
+ return output;
+ }
+
protected Multimap<ObjectModelAttribute, String> generateAnnotationsForProperties(ObjectModelClass input,
ObjectModelClass output,
List<ObjectModelAttribute> properties) {
@@ -227,10 +238,12 @@
for (ObjectModelAttribute property : properties) {
String propertyName = property.getName();
String propertyType = property.getType();
- if ("id".equals(propertyName)) {
+ if (PROPERTY_ID.equals(propertyName)) {
- result.put(property, Id.class.getSimpleName());
- addImport(output, Id.class);
+ addAnnotation(result, property, output, Id.class);
+ if (JpaTemplatesGeneratorUtil.hasGeneratedValueStereotype(input)) {
+ addAnnotation(result, property, output, GeneratedValue.class);
+ }
continue;
}
@@ -243,34 +256,61 @@
boolean bidirection = reverseAttribute != null &&
reverseAttribute.isNavigable();
- //TODO Deal with bidirection
- Preconditions.checkState(
- !bidirection,
- "Still can not deal with bidirection, but found one " + input.getQualifiedName() + "#" + propertyName);
+ boolean isInverse = false;
+ if (bidirection) {
+
+
+ // compute which is master of relation
+ String inverseValue = JpaTemplatesGeneratorUtil.getInverseTagValue(property);
+ if (StringUtils.isNotEmpty(inverseValue)) {
+ isInverse &= Boolean.parseBoolean(inverseValue);
+ // Si aucun tagvalue n'est défini, le choix est arbitraire : le
+ // premier attribut dans l'ordre alphabétique sera choisi pour porter le
+ // inverse="true"
+ } else {
+ isInverse &= JpaTemplatesGeneratorUtil.isFirstAttribute(property);
+ }
+ }
+
+ boolean composite = property.isComposite();
+
boolean entity = isEntity(input, propertyType);
boolean enumeration = getModel().getEnumeration(propertyType) != null;
if (JpaTemplatesGeneratorUtil.isNMultiplicity(property)) {
+ List<String> annotationParams = Lists.newArrayList();
+
+ if (composite) {
+ annotationParams.add("cascade = CascadeType.ALL");
+ annotationParams.add("orphanRemoval = true");
+ addImport(output, CascadeType.class);
+ }
+
+ if (bidirection && !isInverse) {
+
+ // add the mappedBy parameter
+ annotationParams.add("mappedBy = " + reverseAttribute.getName());
+ }
+
if (nMultiplicity) {
// * -> * (ManyToMany)
- result.put(property, ManyToMany.class.getSimpleName());
- addImport(output, ManyToMany.class);
+ addAnnotation(result, property, output, ManyToMany.class, annotationParams.toArray(new String[annotationParams.size()]));
+
} else {
// 0..1 -> * (OneToMany)
- result.put(property, OneToMany.class.getSimpleName());
- addImport(output, OneToMany.class);
+ addAnnotation(result, property, output, OneToMany.class, annotationParams.toArray(new String[annotationParams.size()]));
}
- boolean withOrdererStereotype = property.isOrdered() ||
+ boolean withOrdererStereotype =
+ property.isOrdered() ||
JpaTemplatesGeneratorUtil.hasOrderedStereotype(property);
if (withOrdererStereotype) {
- result.put(property, OrderColumn.class.getSimpleName());
- addImport(output, OrderColumn.class);
+ addAnnotation(result, property, output, OrderColumn.class);
}
continue;
}
@@ -278,8 +318,8 @@
if (enumeration) {
// is an enumeration
- result.put(property, Enumerated.class.getSimpleName() + "( value = " + EnumType.class.getSimpleName() + "." + EnumType.STRING + ")");
- addImport(output, Enumerated.class);
+ addAnnotation(result, property, output, Enumerated.class,
+ "value = EnumType.STRING");
addImport(output, EnumType.class);
}
@@ -288,13 +328,11 @@
if (nMultiplicity) {
// * -> 0..1 (ManyToOne)
- result.put(property, ManyToOne.class.getSimpleName());
- addImport(output, ManyToOne.class);
+ addAnnotation(result, property, output, ManyToOne.class);
} else {
// 0..1 -> 0..1 (OneToOne)
- result.put(property, OneToOne.class.getSimpleName());
- addImport(output, OneToOne.class);
+ addAnnotation(result, property, output, OneToOne.class);
}
continue;
@@ -306,30 +344,18 @@
return result;
}
- protected ObjectModelClass generateImpl(ObjectModelClass input,
- String entityAbstractName,
- String entityConcreteName) {
-
- ObjectModelClass output = createClass(
- entityConcreteName,
- input.getPackageName()
- );
-
- // set the abstract resulClass as the resultClassImpl super class
- setSuperClass(output, entityAbstractName);
-
- // add Entity annotation
- addAnnotation(output, output, Entity.class.getSimpleName());
- addImport(output, Entity.class);
-
- // add a fix serialVersionUID, since the class has no field nor method
- addConstant(output,
- JpaTemplatesGeneratorUtil.SERIAL_VERSION_UID,
- "long",
- "1L",
- ObjectModelJavaModifier.PRIVATE
- );
- return output;
+ protected void addAnnotation(
+ ListMultimap<ObjectModelAttribute, String> result,
+ ObjectModelAttribute property,
+ ObjectModelClass output,
+ Class annotation,
+ String... extraPart) {
+ String annotationStr = annotation.getSimpleName();
+ if (extraPart.length > 0) {
+ annotationStr += "(" + Joiner.on(',').join(extraPart) + ")";
+ }
+ result.put(property, annotationStr);
+ addImport(output, annotation);
}
protected void createProperty(ObjectModelClass output,
@@ -338,8 +364,8 @@
boolean usePCS = false;
- String attrName = getAttributeName(attr);
- String attrType = getAttributeType(attr);
+ String attrName = JpaTemplatesGeneratorUtil.getAttributeName(attr);
+ String attrType = JpaTemplatesGeneratorUtil.getAttributeType(attr);
boolean multiple = JpaTemplatesGeneratorUtil.isNMultiplicity(attr);
@@ -404,29 +430,10 @@
usePCS
);
- boolean ordered = attr.isOrdered() ||
- JpaTemplatesGeneratorUtil.hasOrderedStereotype(attr);
- boolean unique = JpaTemplatesGeneratorUtil.hasUniqueStereotype(attr);
-
// Change type for Multiple attribute
- if (ordered) {
+ Class<?> collectionType = JpaTemplatesGeneratorUtil.getCollectionType(attr);
+ attrType = collectionType.getName() + "<" + attrType + ">";
- if (unique) {
-
- attrType = LinkedHashSet.class.getName() + "<" + attrType + ">";
- } else {
-
- attrType = List.class.getName() + "<" + attrType + ">";
- }
- } else {
-
- if (unique) {
- attrType = Set.class.getName() + "<" + attrType + ">";
- } else {
- attrType = Collection.class.getName() + "<" + attrType + ">";
- }
- }
-
simpleType = JpaTemplatesGeneratorUtil.getSimpleName(attrType);
}
@@ -444,12 +451,16 @@
if (multiple || !booleanProperty) {
- createGetMethod(output,
- attrName,
- attrType,
- JpaTemplatesGeneratorUtil.OPERATION_GETTER_DEFAULT_PREFIX
+ ObjectModelOperation getMethod = createGetMethod(output,
+ attrName,
+ attrType,
+ JpaTemplatesGeneratorUtil.OPERATION_GETTER_DEFAULT_PREFIX
);
+ if (PROPERTY_ID.equals(attrName)) {
+ addAnnotation(output, getMethod, Override.class);
+ }
+
}
createSetMethod(output,
attrName,
@@ -473,4 +484,312 @@
}
+ protected ObjectModelOperation createGetMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String methodPrefix) {
+
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName(methodPrefix, attrName),
+ attrType,
+ ObjectModelJavaModifier.PUBLIC
+ );
+ setOperationBody(operation, ""
+ /*{
+ return <%=attrName%>;
+ }*/
+ );
+ return operation;
+ }
+
+ protected void createGetChildMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String simpleType) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("get", attrName),
+ attrType,
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, "int", "index");
+ setOperationBody(operation, ""
+ /*{
+ <%=simpleType%> o = getChild(<%=attrName%>, index);
+ return o;
+ }*/
+ );
+ }
+
+ protected void createIsEmptyMethod(ObjectModelClass output,
+ String attrName) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("is", attrName) + "Empty",
+ boolean.class,
+ ObjectModelJavaModifier.PUBLIC
+ );
+ setOperationBody(operation, ""
+ /*{
+ return <%=attrName%> == null || <%=attrName%>.isEmpty();
+ }*/
+ );
+ }
+
+ protected void createSizeMethod(ObjectModelClass output,
+ String attrName) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("size", attrName),
+ int.class,
+ ObjectModelJavaModifier.PUBLIC
+ );
+ setOperationBody(operation, ""
+ /*{
+ return <%=attrName%> == null ? 0 : <%=attrName%>.size();
+ }*/
+ );
+ }
+
+ protected void createAddChildMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("add", attrName),
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, attrType, attrName);
+
+ String methodName = getJavaBeanMethodName("get", attrName);
+ StringBuilder buffer = new StringBuilder(""
+ /*{
+ <%=methodName%>().add(<%=attrName%>);
+ }*/
+ );
+ if (usePCS) {
+ buffer.append(""
+ /*{ firePropertyChange(<%=constantName%>, null, <%=attrName%>);
+ }*/
+ );
+ }
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createAddAllChildrenMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("addAll", attrName),
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, Collection.class.getName() + "<" + attrType + ">", attrName);
+
+ String methodName = getJavaBeanMethodName("get", attrName);
+ StringBuilder buffer = new StringBuilder(""
+ /*{
+ <%=methodName%>().addAll(<%=attrName%>);
+ }*/
+ );
+ if (usePCS) {
+ buffer.append(""
+ /*{ firePropertyChange(<%=constantName%>, null, <%=attrName%>);
+ }*/
+ );
+ }
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createRemoveChildMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("remove", attrName),
+ "boolean",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, attrType, attrName);
+ String methodName = getJavaBeanMethodName("get", attrName);
+ StringBuilder buffer = new StringBuilder();
+ buffer.append(""
+ /*{
+ boolean removed = <%=methodName%>().remove(<%=attrName%>);}*/
+ );
+
+ if (usePCS) {
+ buffer.append(""
+ /*{
+ if (removed) {
+ firePropertyChange(<%=constantName%>, <%=attrName%>, null);
+ }}*/
+ );
+ }
+ buffer.append(""
+ /*{
+ return removed;
+ }*/
+ );
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createRemoveAllChildrenMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("removeAll", attrName),
+ "boolean",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, "java.util.Collection<" + attrType + ">", attrName);
+ StringBuilder buffer = new StringBuilder();
+ String methodName = getJavaBeanMethodName("get", attrName);
+ buffer.append(""
+ /*{
+ boolean removed = <%=methodName%>().removeAll(<%=attrName%>);}*/
+ );
+
+ if (usePCS) {
+ buffer.append(""
+ /*{
+ if (removed) {
+ firePropertyChange(<%=constantName%>, <%=attrName%>, null);
+ }}*/
+ );
+ }
+ buffer.append(""
+ /*{
+ return removed;
+ }*/
+ );
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createContainsChildMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("contains", attrName),
+ "boolean",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, attrType, attrName);
+ StringBuilder buffer = new StringBuilder();
+ String methodName = getJavaBeanMethodName("get", attrName);
+ buffer.append(""
+ /*{
+ boolean contains = <%=methodName%>().contains(<%=attrName%>);
+ return contains;
+ }*/
+ );
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createContainsAllChildrenMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("containsAll", attrName),
+ "boolean",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, Collection.class.getName() + "<" + attrType + ">", attrName);
+ StringBuilder buffer = new StringBuilder();
+ String methodName = getJavaBeanMethodName("get", attrName);
+ buffer.append(""
+ /*{
+ boolean contains = <%=methodName%>().containsAll(<%=attrName%>);
+ return contains;
+ }*/
+ );
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createSetMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String simpleType,
+ String constantName,
+ boolean usePCS) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("set", attrName),
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, attrType, attrName);
+
+ if (usePCS) {
+ String methodName = getJavaBeanMethodName("get", attrName);
+ setOperationBody(operation, ""
+ /*{
+ <%=simpleType%> oldValue = <%=methodName%>();
+ this.<%=attrName%> = <%=attrName%>;
+ firePropertyChange(<%=constantName%>, oldValue, <%=attrName%>);
+ }*/
+ );
+ } else {
+ setOperationBody(operation, ""
+ /*{
+ this.<%=attrName%> = <%=attrName%>;
+ }*/
+ );
+ }
+ }
+
+ protected void createGetChildMethod(ObjectModelClass output) {
+ ObjectModelOperation getChild = addOperation(
+ output,
+ "getChild", "<T> T",
+ ObjectModelJavaModifier.PROTECTED
+ );
+ addImport(output, List.class);
+
+ addParameter(getChild, "java.util.Collection<T>", "childs");
+ addParameter(getChild, "int", "index");
+ setOperationBody(getChild, ""
+ /*{
+ T result = null;
+ if (childs != null) {
+ if (childs instanceof List) {
+ if (index < childs.size()) {
+ result = ((List<T>) childs).get(index);
+ }
+ } else {
+ int i = 0;
+ for (T o : childs) {
+ if (index == i) {
+ result = o;
+ break;
+ }
+ i++;
+ }
+ }
+ }
+ return result;
+ }*/
+ );
+ }
}
\ No newline at end of file
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -33,6 +33,13 @@
/*{generator option: writeString = +}*/
/**
+ * JpaPersistenceContextTransformer generates the persistence context for an model.
+ * <ul>
+ * <li>{@code AbstractXXXJpaPersistenceContext}: abstract jpa persistence context with all the technical stuff</li>
+ * <li>{@code XXXJpaPersistenceContext}: concrete public jpa persistence context to use in your persistence layer</li>
+ * </ul>
+ * {@code Note:} All classes found in class-path are not generated.
+ * <p/>
* TODO Liste des entités (A voir meta-modèle...)
*
* @author tchemit <chemit(a)codelutin.com>
@@ -44,20 +51,29 @@
@Override
public void transformFromModel(ObjectModel model) {
- String className = "Jpa" + model.getName() + "PersistenceContext";
+ String packageName = JpaTemplatesGeneratorUtil.getPersistenceContextPackage(this, model);
- String packageName =
- getOutputProperties().getProperty(PROP_DEFAULT_PACKAGE);
+ String entityAbstractName = JpaTemplatesGeneratorUtil.getPersistenceContextAbstractName(model);
- boolean generateAbstract = !isInClassPath(packageName, className);
+ String entityConcreteName = JpaTemplatesGeneratorUtil.getPersistenceContextConcreteName(model);
+ boolean generateAbstract = !isInClassPath(packageName, entityAbstractName);
+
+ boolean generateConcrete = !isInClassPath(packageName, entityConcreteName);
+
if (generateAbstract) {
- generate(packageName, className);
+ generateAbstract(packageName, entityAbstractName);
}
+
+ if (generateConcrete) {
+
+ generateImpl(packageName, entityAbstractName, entityConcreteName);
+ }
}
- protected void generate(String packageName, String className) {
+ protected void generateAbstract(String packageName,
+ String className) {
// try to find a super class by tag-value
String superClass = JpaTemplatesGeneratorUtil.getPersistenceContextSuperClassTagValue(
@@ -69,30 +85,44 @@
superClass = AbstractJpaPersistenceContext.class.getName();
}
- ObjectModelClass output = createClass(className, packageName);
+ ObjectModelClass output = createAbstractClass(className, packageName);
setSuperClass(output, superClass);
addConstructorWithEntityManager(output);
+ // add dao factories
for (ObjectModelClass aClass : getModel().getClasses()) {
- if (packageName.equals(aClass.getPackageName())) {
+ //FIXME Find a way to exclude none entities classes
+// if (packageName.equals(aClass.getPackageName())) {
- // add dao factory method
- String daoConcreteName = JpaTemplatesGeneratorUtil.getDaoConcreteName(aClass);
+ // add dao factory method
+ String daoPackageName = JpaTemplatesGeneratorUtil.getDaoPackage(this, model, aClass);
+ String daoConcreteName = JpaTemplatesGeneratorUtil.getDaoConcreteName(aClass);
- ObjectModelOperation operation = addOperation(
- output,
- "get" + daoConcreteName,
- packageName + "." + daoConcreteName);
- setOperationBody(operation, ""
+ ObjectModelOperation operation = addOperation(
+ output,
+ "get" + aClass.getName() + "Dao",
+ daoPackageName + "." + daoConcreteName);
+ setOperationBody(operation, ""
/*{
return new <%=daoConcreteName%>(entityManager);
}*/
- );
-
- }
+ );
+// }
}
}
+
+ protected ObjectModelClass generateImpl(String packageName,
+ String entityAbstractName,
+ String entityConcreteName) {
+
+ ObjectModelClass output = createClass(entityConcreteName, packageName);
+
+ setSuperClass(output, entityAbstractName);
+
+ addConstructorWithEntityManager(output);
+ return output;
+ }
}
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -30,6 +30,12 @@
import org.nuiton.eugene.models.object.ObjectModelClass;
import org.nuiton.eugene.models.object.ObjectModelClassifier;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
/**
* Utility class for pure jpa templates.
*
@@ -38,10 +44,157 @@
*/
public class JpaTemplatesGeneratorUtil extends JavaGeneratorUtil {
+ public static String getPersistenceContextPackage(AbstractJpaTransformer transformer,
+ ObjectModel model) {
+
+ String result = getPersistenceContextPackageTagValue(model);
+ if (result == null) {
+
+ // use default package
+ result = transformer.getDefaultPackageName();
+ }
+
+ return result;
+ }
+
+ public static String getEntityPackage(AbstractJpaTransformer transformer,
+ ObjectModel model,
+ ObjectModelClassifier input) {
+
+ String result = getEntityPackageTagValue(model, input);
+ if (result == null) {
+
+ // use default package
+ result = transformer.getDefaultPackageName() + ".entity";
+ }
+
+ return result;
+ }
+
+ public static String getDaoPackage(AbstractJpaTransformer transformer,
+ ObjectModel model,
+ ObjectModelClassifier input) {
+
+ String result = getDaoPackageTagValue(model, input);
+ if (result == null) {
+
+ // use default package
+ result = transformer.getDefaultPackageName() + ".dao";
+ }
+
+ return result;
+ }
+
+ public static String getPersistenceContextAbstractName(ObjectModel model) {
+ return "AbstractJpa" + model.getName() + "PersistenceContext";
+ }
+
+ public static String getPersistenceContextConcreteName(ObjectModel model) {
+ return "Jpa" + model.getName() + "PersistenceContext";
+ }
+
+ public static String getEntityAbstractName(ObjectModelClass input) {
+ return "AbstractJpa" + input.getName();
+ }
+
+ public static String getEntityConcreteName(ObjectModelClass input) {
+ return input.getName();
+ }
+
+ public static String getDaoAbstractName(ObjectModelClass input) {
+ return "Abstract" + input.getName() + "JpaDao";
+ }
+
public static String getDaoConcreteName(ObjectModelClass input) {
return input.getName() + "JpaDao";
}
+ public static String getConcreteEntityQualifiedName(AbstractJpaTransformer transformer, ObjectModel model, ObjectModelClass input) {
+ return getEntityPackage(transformer, model, input) + "." + getEntityConcreteName(input);
+ }
+
+ public static String getConcreteDaoQualifiedName(AbstractJpaTransformer transformer, ObjectModel model, ObjectModelClass input) {
+ return getDaoPackage(transformer, model, input) + "." + getDaoConcreteName(input);
+ }
+
+ public static Class<?> getCollectionType(ObjectModelAttribute attr) {
+
+ boolean ordered = attr.isOrdered() ||
+ JpaTemplatesGeneratorUtil.hasOrderedStereotype(attr);
+ boolean unique = JpaTemplatesGeneratorUtil.hasUniqueStereotype(attr);
+
+ // Change type for Multiple attribute
+ Class<?> result;
+
+ if (ordered) {
+
+ if (unique) {
+
+ result = LinkedHashSet.class;
+ } else {
+
+ result = List.class;
+ }
+ } else {
+
+ if (unique) {
+ result = Set.class;
+ } else {
+ result = Collection.class;
+ }
+ }
+ return result;
+ }
+
+ public static boolean containsMutiple(List<ObjectModelAttribute> attributes) {
+
+ boolean result = false;
+
+ for (ObjectModelAttribute attr : attributes) {
+
+ if (isNMultiplicity(attr)) {
+ result = true;
+
+ break;
+ }
+
+ }
+ return result;
+ }
+
+ public static String getAttributeName(ObjectModelAttribute attr) {
+ String attrName = attr.getName();
+ if (attr.hasAssociationClass()) {
+ String assocAttrName = getAssocAttrName(attr);
+ attrName = toLowerCaseFirstLetter(assocAttrName);
+ }
+ return attrName;
+ }
+
+ public static String getAttributeType(ObjectModelAttribute attr) {
+ String attrType = attr.getType();
+ if (attr.hasAssociationClass()) {
+ attrType = attr.getAssociationClass().getName();
+ }
+ return attrType;
+ }
+
+ public static List<ObjectModelAttribute> getProperties(ObjectModelClass input) {
+ List<ObjectModelAttribute> attributes =
+ (List<ObjectModelAttribute>) input.getAttributes();
+
+ List<ObjectModelAttribute> attrs =
+ new ArrayList<ObjectModelAttribute>();
+ for (ObjectModelAttribute attr : attributes) {
+ if (attr.isNavigable()) {
+
+ // only keep navigable attributes
+ attrs.add(attr);
+ }
+ }
+ return attrs;
+ }
+
/**
* Obtain the value of the {@link JpaTemplatesTagValues#TAG_ENTITY_SUPER_CLASS}
* tag value on the given model or classifier.
@@ -60,6 +213,24 @@
}
/**
+ * Obtain the value of the {@link JpaTemplatesTagValues#TAG_ENTITY_PACKAGE}
+ * tag value on the given model.
+ * <p/>
+ * It will first look on the model, and then in the given classifier.
+ *
+ * @param model model to seek
+ * @param classifier classifier to seek
+ * @return the none empty value of the found tag value or {@code null} if not found nor empty.
+ * @see JpaTemplatesTagValues#TAG_ENTITY_PACKAGE
+ * @since 2.3
+ */
+ public static String getEntityPackageTagValue(ObjectModel model,
+ ObjectModelClassifier classifier) {
+ String value = findTagValue(JpaTemplatesTagValues.TAG_ENTITY_PACKAGE, classifier, model);
+ return value;
+ }
+
+ /**
* Obtain the value of the {@link JpaTemplatesTagValues#TAG_DAO_SUPER_CLASS}
* tag value on the given model or classifier.
* <p/>
@@ -77,6 +248,24 @@
}
/**
+ * Obtain the value of the {@link JpaTemplatesTagValues#TAG_DAO_PACKAGE}
+ * tag value on the given model.
+ * <p/>
+ * It will first look on the model, and then in the given classifier.
+ *
+ * @param model model to seek
+ * @param classifier classifier to seek
+ * @return the none empty value of the found tag value or {@code null} if not found nor empty.
+ * @see JpaTemplatesTagValues#TAG_DAO_PACKAGE
+ * @since 2.3
+ */
+ public static String getDaoPackageTagValue(ObjectModel model,
+ ObjectModelClassifier classifier) {
+ String value = findTagValue(JpaTemplatesTagValues.TAG_DAO_PACKAGE, classifier, model);
+ return value;
+ }
+
+ /**
* Obtain the value of the {@link JpaTemplatesTagValues#TAG_PERSISTENCE_CONTEXT_SUPER_CLASS}
* tag value on the given model.
*
@@ -91,6 +280,36 @@
}
/**
+ * Obtain the value of the {@link JpaTemplatesTagValues#TAG_PERSISTENCE_CONTEXT_PACKAGE}
+ * tag value on the given model.
+ * <p/>
+ *
+ * @param model model to seek
+ * @return the none empty value of the found tag value or {@code null} if not found nor empty.
+ * @see JpaTemplatesTagValues#TAG_PERSISTENCE_CONTEXT_PACKAGE
+ * @since 2.3
+ */
+ public static String getPersistenceContextPackageTagValue(ObjectModel model) {
+ String value = findTagValue(JpaTemplatesTagValues.TAG_PERSISTENCE_CONTEXT_PACKAGE, null, model);
+ return value;
+ }
+
+ /**
+ * Obtain the value of the {@link JpaTemplatesTagValues#TAG_INVERSE}
+ * tag value on the given attribute.
+ * <p/>
+ *
+ * @param attribute attribute to seek
+ * @return the none empty value of the found tag value or {@code null} if not found nor empty.
+ * @see JpaTemplatesTagValues#TAG_INVERSE
+ * @since 2.5
+ */
+ public static String getInverseTagValue(ObjectModelAttribute attribute) {
+ String value = findTagValue(JpaTemplatesTagValues.TAG_INVERSE, attribute, null);
+ return value;
+ }
+
+ /**
* Check if the given attribute has the
* {@link JpaTemplatesStereoTypes#STEREOTYPE_UNIQUE} stereotype.
*
@@ -102,4 +321,17 @@
public static boolean hasUniqueStereotype(ObjectModelAttribute attribute) {
return attribute.hasStereotype(JpaTemplatesStereoTypes.STEREOTYPE_UNIQUE);
}
+
+ /**
+ * Check if the given class has the
+ * {@link JpaTemplatesStereoTypes#STEREOTYPE_GENERATED_VALUE} stereotype.
+ *
+ * @param aClass class to test
+ * @return {@code true} if stereotype was found, {@code false otherwise}
+ * @see JpaTemplatesStereoTypes#STEREOTYPE_GENERATED_VALUE
+ * @since 2.5
+ */
+ public static boolean hasGeneratedValueStereotype(ObjectModelClassifier aClass) {
+ return aClass.hasStereotype(JpaTemplatesStereoTypes.STEREOTYPE_GENERATED_VALUE);
+ }
}
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -27,7 +27,10 @@
import org.nuiton.eugene.EugeneStereoTypes;
import org.nuiton.eugene.ModelPropertiesUtil;
import org.nuiton.eugene.models.object.ObjectModelAttribute;
+import org.nuiton.eugene.models.object.ObjectModelClassifier;
+import javax.persistence.GeneratedValue;
+
/**
* Defines all stereotypes managed by JPA templates.
*
@@ -44,4 +47,13 @@
@ModelPropertiesUtil.StereotypeDefinition(target = ObjectModelAttribute.class,
documentation = "To specify that an attribute is unique (JPA mapping)")
String STEREOTYPE_UNIQUE = "unique";
+
+ /**
+ * Stéréotype pour ajouter l'annoation {@link GeneratedValue} sur l'id.
+ *
+ * @see JpaTemplatesGeneratorUtil#hasGeneratedValueStereotype(ObjectModelClassifier)
+ */
+ @ModelPropertiesUtil.StereotypeDefinition(target = ObjectModelClassifier.class,
+ documentation = "To specify that an entity has a generated id (see GeneratedValue annotation) (JPA mapping)")
+ String STEREOTYPE_GENERATED_VALUE = "generatedValue";
}
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -27,6 +27,7 @@
import org.nuiton.eugene.EugeneTagValues;
import org.nuiton.eugene.ModelPropertiesUtil;
import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.ObjectModelAttribute;
import org.nuiton.eugene.models.object.ObjectModelClassifier;
/**
@@ -49,6 +50,16 @@
"for a class or any class of a model")
String TAG_ENTITY_SUPER_CLASS = "entitySuperClass";
+ /**
+ * Tag value to specify where to generate entities.
+ *
+ * @see JpaTemplatesGeneratorUtil#getEntityPackage(ObjectModel)
+ * @since 0.1
+ */
+ @ModelPropertiesUtil.TagValueDefinition(
+ target = {ObjectModel.class},
+ documentation = "To specify the package where to generate entities")
+ String TAG_ENTITY_PACKAGE = "entityPackage";
/**
* Tag value to use a super class for generated bean.
@@ -62,6 +73,16 @@
"for a class or any class of a model")
String TAG_DAO_SUPER_CLASS = "daoSuperClass";
+ /**
+ * Tag value to specify where to generate daos.
+ *
+ * @see JpaTemplatesGeneratorUtil#getDaoPackage(ObjectModel)
+ * @since 0.1
+ */
+ @ModelPropertiesUtil.TagValueDefinition(
+ target = {ObjectModel.class},
+ documentation = "To specify the package where to generate daos")
+ String TAG_DAO_PACKAGE = "daoPackage";
/**
* Tag value to use a super class for generated bean.
@@ -72,6 +93,31 @@
@ModelPropertiesUtil.TagValueDefinition(
target = {ObjectModel.class},
documentation = "To specify a super-class to used on generated persistence context")
- String TAG_PERSISTENCE_CONTEXT_SUPER_CLASS = "daoSuperClass";
+ String TAG_PERSISTENCE_CONTEXT_SUPER_CLASS = "persistenceContextSuperClass";
+ /**
+ * Tag value to specify where to generate persistenceContexts.
+ *
+ * @see JpaTemplatesGeneratorUtil#getPersistenceContextPackage(ObjectModel)
+ * @since 0.1
+ */
+ @ModelPropertiesUtil.TagValueDefinition(
+ target = {ObjectModel.class},
+ documentation = "To specify the package where to generate persistenceContexts")
+ String TAG_PERSISTENCE_CONTEXT_PACKAGE = "persistenceContextPackage";
+
+
+ /**
+ * Tag pour permettre de choisir qui contrôle la relation N-N
+ * bidirectionnelle. On a inverse=true sur le père de la relation..
+ * <p/>
+ * Par défaut le inverse=true est placé sur le premier rôle trouvé dans
+ * l'ordre alphabétique.
+ *
+ * @see JpaTemplatesGeneratorUtil#getInverseTagValue(ObjectModelAttribute)
+ * @since 2.5
+ */
+ @ModelPropertiesUtil.TagValueDefinition(target = {ObjectModelAttribute.class},
+ documentation = "Sets which part of a N-N relation is master (inverse=true) and slave (inverse=false) (must be put on each side on a such relation) (Hibernate mapping)")
+ String TAG_INVERSE = "inverse";
}
Modified: nuiton-jpa/pom.xml
===================================================================
--- nuiton-jpa/pom.xml 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/pom.xml 2013-05-25 14:13:01 UTC (rev 628)
@@ -31,6 +31,8 @@
<!-- pour un muli module on doit fixer le projectId -->
<projectId>nuiton-jpa</projectId>
+ <redmine.skipGenerateChanges>true</redmine.skipGenerateChanges>
+
<!-- libs version -->
<eugeneVersion>2.6.3-SNAPSHOT</eugeneVersion>
<nuitonUtilsVersion>2.6.12</nuitonUtilsVersion>
1
0