Topia-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
December 2011
- 1 participants
- 2 discussions
r2386 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by tchemit@users.nuiton.org 27 Dec '11
by tchemit@users.nuiton.org 27 Dec '11
27 Dec '11
Author: tchemit
Date: 2011-12-27 15:37:01 +0100 (Tue, 27 Dec 2011)
New Revision: 2386
Url: http://nuiton.org/repositories/revision/topia/2386
Log:
Evolution #1866: New stereotype tableAssocIndex to generate index on FK
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaStereoTypes.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java 2011-12-19 22:47:20 UTC (rev 2385)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java 2011-12-27 14:37:01 UTC (rev 2386)
@@ -46,15 +46,11 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.GeneratorUtil;
-import org.nuiton.eugene.java.JavaGenerator;
-import org.nuiton.eugene.java.JavaGeneratorUtil;
import org.nuiton.eugene.models.object.ObjectModelAssociationClass;
import org.nuiton.eugene.models.object.ObjectModelAttribute;
import org.nuiton.eugene.models.object.ObjectModelClass;
import org.nuiton.eugene.models.object.ObjectModelGenerator;
-import javax.persistence.EnumType;
import java.io.File;
import java.io.IOException;
import java.io.Writer;
@@ -201,10 +197,54 @@
/*{ </class>
}*/
}
+
+ generateDatabaseObjects(output, input, naturalAttributes);
+ generateDatabaseObjects(output, input, noneNaturalAttributes);
+
/*{</hibernate-mapping>
}*/
}
+ protected void generateDatabaseObjects(Writer output,
+ ObjectModelClass clazz,
+ List<ObjectModelAttribute> attributes) throws IOException {
+
+ for (ObjectModelAttribute attribute : attributes) {
+ if (!attribute.isNavigable() ||
+ attribute.hasAssociationClass() ||
+ !TopiaGeneratorUtil.hasTableAssocIndexStereotype(attribute) ||
+ !TopiaGeneratorUtil.isNMultiplicity(attribute) ||
+ attribute.getClassifier() == null ||
+ !TopiaGeneratorUtil.isEntity(attribute.getClassifier())
+ ) {
+ // skip for this case
+
+ continue;
+ }
+
+ // add database-object to create and drop index
+
+ String tableName;
+ String indexName = "idx_" + clazz.getName() + "_" + attribute.getName();
+ String propertyName;
+
+
+ if (TopiaGeneratorUtil.isNMultiplicity(attribute.getReverseMaxMultiplicity())) {
+
+ // many to many
+ tableName = TopiaGeneratorUtil.getManyToManyTableName(attribute);
+ propertyName = TopiaGeneratorUtil.getDbName(attribute.getClassifier());
+ } else {
+
+ // one to many
+ tableName =TopiaGeneratorUtil.getDbName(attribute.getClassifier());
+ propertyName = TopiaGeneratorUtil.getDbName(clazz);
+ }
+/*{ <database-object><create>CREATE INDEX <%=indexName%> ON <%=tableName%>(<%=propertyName%>)</create><drop>DROP INDEX <%=indexName%></drop></database-object>
+}*/
+
+ }
+ }
protected void generateAttributes(Writer output,
ObjectModelClass clazz,
List<ObjectModelAttribute> attributes,
@@ -218,9 +258,9 @@
if (attr.isNavigable()
|| hasUnidirectionalRelationOnAbstractType(reverse, model)
|| attr.hasAssociationClass()) {
- if (!GeneratorUtil.isNMultiplicity(attr)) {
+ if (!TopiaGeneratorUtil.isNMultiplicity(attr)) {
if (attr.getClassifier() != null && TopiaGeneratorUtil.isEntity(attr.getClassifier())) {
- if (GeneratorUtil.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) {
+ if (TopiaGeneratorUtil.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) {
generateHibernateManyToOne(output, attr, prefix);
} else {
generateHibernateOneToOne(output, attr, prefix);
@@ -230,7 +270,7 @@
}
} else {
if (attr.getClassifier() != null && TopiaGeneratorUtil.isEntity(attr.getClassifier())) {
- if (GeneratorUtil.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) {
+ if (TopiaGeneratorUtil.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) {
generateHibernateManyToMany(output, attr, prefix);
} else {
generateHibernateOneToMany(output, attr, prefix);
@@ -264,7 +304,7 @@
// }
//Ne sert plus grâce à l'utilisation de la navigabilité
// if (!attr.getReverseAttribute().isNavigable()) {
-// String type = GeneratorUtil.getDOType(((ObjectModelClassifier)attr.getDeclaringElement()).getQualifiedName(), model);
+// String type = TopiaGeneratorUtil.getDOType(((ObjectModelClassifier)attr.getDeclaringElement()).getQualifiedName(), model);
// String name = Util.toLowerCaseFirstLetter(attr.getDeclaringElement().getName());
// if (log.isTraceEnabled()) {log.trace("reverse: " + type + " " + name);}
// if (!Util.isNMultiplicity(attr)) {
@@ -285,9 +325,9 @@
}
protected String getName(ObjectModelAttribute attr, boolean isAssoc) {
- String result = GeneratorUtil.toLowerCaseFirstLetter(attr.getName());
+ String result = TopiaGeneratorUtil.toLowerCaseFirstLetter(attr.getName());
if (attr.hasAssociationClass() && !isAssoc) {
- result = GeneratorUtil.getAssocAttrName(attr);
+ result = TopiaGeneratorUtil.getAssocAttrName(attr);
}
return result;
}
@@ -360,7 +400,7 @@
// optionalAttributes += "schema=\"" + schema + "\" ";
}
- if (JavaGeneratorUtil.hasIndexedStereotype(attr)) {
+ if (TopiaGeneratorUtil.hasIndexedStereotype(attr)) {
String indexName = tableName + "_idx";
optionalAttributes += generateFromTagValue(HIBERNATE_ATTRIBUTE_INDEX, indexName);
// optionalAttributes += "index=\"" + indexName + "\" ";
@@ -374,7 +414,7 @@
}*/
} else {
String optionalAttributes = "";
- if (JavaGeneratorUtil.hasIndexedStereotype(attr)) {
+ if (TopiaGeneratorUtil.hasIndexedStereotype(attr)) {
String indexName = tableName + "_idx";
optionalAttributes += generateFromTagValue(HIBERNATE_ATTRIBUTE_INDEX, indexName);
// optionalAttributes += "index=\"" + indexName + "\"";
@@ -495,7 +535,7 @@
ObjectModelAttribute attr,
String prefix) throws IOException {
// boolean accessField = hasUnidirectionalRelationOnAbstractType(attr.getReverseAttribute(), model);
-/// *{ <one-to-one name="<%=getName(attr)%>" class="<%=getType(attr)%>"<%=(TopiaGeneratorUtil.notEmpty(attr.getTagValue(GeneratorUtil.TAG_LENGTH))?(" length=\"" + attr.getTagValue(GeneratorUtil.TAG_LENGTH) + "\""):"")%><%=((attr.isComposite() || attr.hasAssociationClass())?" cascade=\"delete\"":"")%><%=((accessField)?" access=\"field\"":"")%> node="<%=getName(attr)%>/@topiaId" embed-xml="false"/>
+/// *{ <one-to-one name="<%=getName(attr)%>" class="<%=getType(attr)%>"<%=(TopiaGeneratorUtil.notEmpty(attr.getTagValue(TopiaGeneratorUtil.TAG_LENGTH))?(" length=\"" + attr.getTagValue(TopiaGeneratorUtil.TAG_LENGTH) + "\""):"")%><%=((attr.isComposite() || attr.hasAssociationClass())?" cascade=\"delete\"":"")%><%=((accessField)?" access=\"field\"":"")%> node="<%=getName(attr)%>/@topiaId" embed-xml="false"/>
//} */
// for hibernate many-to-one with unique="true" => one-to-one
@@ -509,7 +549,7 @@
protected void generateHibernateOneToMany(Writer output,
ObjectModelAttribute attr,
String prefix) throws IOException {
- boolean needsIndex = JavaGeneratorUtil.hasIndexedStereotype(attr);
+ boolean needsIndex = TopiaGeneratorUtil.hasIndexedStereotype(attr);
boolean isInverse = attr.getReverseAttribute().isNavigable();
isInverse |= hasUnidirectionalRelationOnAbstractType(attr, model);
@@ -584,7 +624,7 @@
protected void generateHibernateMany(Writer output,
ObjectModelAttribute attr,
String prefix) throws IOException {
- boolean needsIndex = JavaGeneratorUtil.hasIndexedStereotype(attr);
+ boolean needsIndex = TopiaGeneratorUtil.hasIndexedStereotype(attr);
String attrName = getName(attr);
String attrType = getType(attr);
String collType = TopiaGeneratorUtil.getNMultiplicityHibernateType(attr);
@@ -661,10 +701,10 @@
// premier attribut dans l'ordre alphabétique sera choisi pour porter le
// inverse="true"
} else {
- isInverse &= GeneratorUtil.isFirstAttribute(attr);
+ isInverse &= TopiaGeneratorUtil.isFirstAttribute(attr);
}
- boolean needsIndex = JavaGeneratorUtil.hasIndexedStereotype(attr);
+ boolean needsIndex = TopiaGeneratorUtil.hasIndexedStereotype(attr);
String cascade = "";
if (attr.isComposite() || attr.hasAssociationClass()) {
cascade = " cascade=\"delete,delete-orphan\"";
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2011-12-19 22:47:20 UTC (rev 2385)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2011-12-27 14:37:01 UTC (rev 2386)
@@ -1277,6 +1277,19 @@
}
/**
+ * Check if the given attribute has the
+ * {@link TopiaStereoTypes#STEREOTYPE_TABLE_ASSOC_INDEX} stereotype.
+ *
+ * @param attribute attribute to test
+ * @return {@code true} if stereotype was found, {@code false otherwise}
+ * @see TopiaStereoTypes#STEREOTYPE_TABLE_ASSOC_INDEX
+ * @since 2.6.5
+ */
+ public static boolean hasTableAssocIndexStereotype(ObjectModelAttribute attribute) {
+ return attribute.hasStereotype(TopiaStereoTypes.STEREOTYPE_TABLE_ASSOC_INDEX);
+ }
+
+ /**
* Obtain the value of the {@link TopiaTagValues#TAG_PERSISTENCE_TYPE}
* tag value on the given classifier.
* <p/>
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaStereoTypes.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaStereoTypes.java 2011-12-19 22:47:20 UTC (rev 2385)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaStereoTypes.java 2011-12-27 14:37:01 UTC (rev 2386)
@@ -115,4 +115,14 @@
@StereotypeDefinition(target = ObjectModelAttribute.class,
documentation = "To specify that an attribute is part of a primary key (Hibernate mapping)")
String STEREOTYPE_PRIMARYKAY = "primaryKey";
+
+ /**
+ * Stéréotype pour les attributs avec multiplicité nécessitant la création d'un index.
+ *
+ * @see TopiaGeneratorUtil#hasTableAssocIndexStereotype(ObjectModelAttribute)
+ * @since 2.6.5
+ */
+ @StereotypeDefinition(target = ObjectModelAttribute.class,
+ documentation = "To specify that an association attribute needs an index in db (Hibernate mapping)")
+ String STEREOTYPE_TABLE_ASSOC_INDEX = "tableAssocIndex";
}
1
0
r2385 - in trunk: . topia-persistence/src/main/java/org/nuiton/topia/generator
by tchemit@users.nuiton.org 19 Dec '11
by tchemit@users.nuiton.org 19 Dec '11
19 Dec '11
Author: tchemit
Date: 2011-12-19 23:47:20 +0100 (Mon, 19 Dec 2011)
New Revision: 2385
Url: http://nuiton.org/repositories/revision/topia/2385
Log:
Anomalie #1855: Bad property generation
T?\195?\162che #1859: Updates to eugene 2.4.2
Modified:
trunk/pom.xml
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-11-28 22:21:56 UTC (rev 2384)
+++ trunk/pom.xml 2011-12-19 22:47:20 UTC (rev 2385)
@@ -67,7 +67,7 @@
<projectId>topia</projectId>
<!-- libs version -->
- <eugeneVersion>2.4.1</eugeneVersion>
+ <eugeneVersion>2.4.2-SNAPSHOT</eugeneVersion>
<nuitonUtilsVersion>2.3.1</nuitonUtilsVersion>
<processorPluginVersion>1.2.1</processorPluginVersion>
<nuitonI18nVersion>2.4.1</nuitonI18nVersion>
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java 2011-11-28 22:21:56 UTC (rev 2384)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java 2011-12-19 22:47:20 UTC (rev 2385)
@@ -697,12 +697,14 @@
attrType = TopiaGeneratorUtil.getSimpleName(attrType);
+ String constantName = getConstantName(attrName);
+
setOperationBody(implOperation, ""
/*{
<%=attrType%> oldValue = this.<%=attrName%>;
- fireOnPreWrite(<%=getConstantName(attrName)%>, oldValue, <%=attrName%>);
+ fireOnPreWrite(<%=constantName%>, oldValue, <%=attrName%>);
this.<%=attrName%> = <%=attrName%>;
- fireOnPostWrite(<%=getConstantName(attrName)%>, oldValue, <%=attrName%>);
+ fireOnPostWrite(<%=constantName%>, oldValue, <%=attrName%>);
}*/
);
}
@@ -729,9 +731,11 @@
+ attrName + " [" + attrType + "]");
}
+ String constantName = getConstantName(attrName);
+
// Interface operation
ObjectModelOperation interfaceOperation =
- addOperation(outputInterface, operationPrefix + StringUtils.capitalize(attrName),
+ addOperation(outputInterface, getJavaBeanMethodName(operationPrefix, attrName),
attrType, ObjectModelModifier.PACKAGE);
// Implementation
@@ -742,9 +746,9 @@
setOperationBody(implOperation, ""
/*{
- fireOnPreRead(<%=getConstantName(attrName)%>, <%=attrName%>);
+ fireOnPreRead(<%=constantName%>, <%=attrName%>);
<%=attrType%> result = this.<%=attrName%>;
- fireOnPostRead(<%=getConstantName(attrName)%>, <%=attrName%>);
+ fireOnPostRead(<%=constantName%>, <%=attrName%>);
return result;
}*/
);
@@ -762,9 +766,11 @@
" [" + attrType + "]");
}
+ String constantName = getConstantName(attrName);
+
// Interface operation
ObjectModelOperation interfaceOperation =
- addOperation(outputInterface, "add" + StringUtils.capitalize(attrName),
+ addOperation(outputInterface, getJavaBeanMethodName("add", attrName),
void.class, ObjectModelModifier.PACKAGE);
ObjectModelParameter param =
addParameter(interfaceOperation, attrType, attrName);
@@ -778,7 +784,7 @@
body.append(""
/*{
- fireOnPreWrite(<%=getConstantName(attrName)%>, null, <%=attrName%>);
+ fireOnPreWrite(<%=constantName%>, null, <%=attrName%>);
if (this.<%=attrName%> == null) {
this.<%=attrName%> = new <%=collectionImpl%><<%=attrType%>>();
}
@@ -787,22 +793,25 @@
if (reverse != null && (reverse.isNavigable() ||
hasUnidirectionalRelationOnAbstractType(attribute, model))) {
- String reverseAttrName = StringUtils.capitalize(reverse.getName());
+ String getterName = getJavaBeanMethodName("get", reverse.getName());
+ String setterName = getJavaBeanMethodName("set", reverse.getName());
+
String reverseAttrType = TopiaGeneratorUtil.getSimpleName(reverse.getType());
+
if (!TopiaGeneratorUtil.isNMultiplicity(reverse)) {
body.append(""
/*{
- <%=attrName%>.set<%=reverseAttrName%>(this);
+ <%=attrName%>.<%=setterName%>(this);
}*/
);
// Don't manage reverse attribute add if attribute has associationClass
} else if (!attribute.hasAssociationClass()) {
body.append(""
/*{
- if (<%=attrName%>.get<%=reverseAttrName%>() == null) {
- <%=attrName%>.set<%=reverseAttrName%>(new <%=collectionImpl%><<%=reverseAttrType%>>());
+ if (<%=attrName%>.<%=getterName%>() == null) {
+ <%=attrName%>.<%=setterName%>(new <%=collectionImpl%><<%=reverseAttrType%>>());
}
- <%=attrName%>.get<%=reverseAttrName%>().add(this);
+ <%=attrName%>.<%=getterName%>().add(this);
}*/
);
}
@@ -810,7 +819,7 @@
body.append(""
/*{
this.<%=attrName%>.add(<%=attrName%>);
- fireOnPostWrite(<%=getConstantName(attrName)%>, this.<%=attrName%>.size(), null, <%=attrName%>);
+ fireOnPostWrite(<%=constantName%>, this.<%=attrName%>.size(), null, <%=attrName%>);
}*/
);
setOperationBody(implOperation, body.toString());
@@ -829,7 +838,7 @@
// Interface operation
ObjectModelOperation interfaceOperation =
- addOperation(outputInterface, "addAll" + StringUtils.capitalize(attrName),
+ addOperation(outputInterface, getJavaBeanMethodName("addAll", attrName),
void.class, ObjectModelModifier.PACKAGE);
ObjectModelParameter param =
addParameter(interfaceOperation, collectionInterface + "<" + attrType + ">", attrName);
@@ -839,14 +848,14 @@
createImplOperation(interfaceOperation);
attrType = TopiaGeneratorUtil.getSimpleName(attrType);
-
+ String addMethodName = getJavaBeanMethodName("add", attrName);
setOperationBody(implOperation, ""
/*{
if (<%=attrName%> == null) {
return;
}
for (<%=attrType%> item : <%=attrName%>) {
- add<%=StringUtils.capitalize(attrName)%>(item);
+ <%=addMethodName%>(item);
}
}*/
);
@@ -859,7 +868,8 @@
String attrName = getPropertyName(attribute);
String referenceType = getPropertyType(attribute);
String attrType = collectionInterface + "<" + referenceType + ">";
-
+ String constantName = getConstantName(attrName);
+
if (log.isDebugEnabled()) {
log.debug("Generate multiple 'set' operation for property : " + attrName +
" [" + attrType + "]");
@@ -880,9 +890,9 @@
/*{
// Copy elements to keep data for fire with new reference
<%=attrType%> oldValue = this.<%=attrName%> != null ? new <%=collectionImpl%><<%=referenceType%>>(this.<%=attrName%>) : null;
- fireOnPreWrite(<%=getConstantName(attrName)%>, oldValue, <%=attrName%>);
+ fireOnPreWrite(<%=constantName%>, oldValue, <%=attrName%>);
this.<%=attrName%> = <%=attrName%>;
- fireOnPostWrite(<%=getConstantName(attrName)%>, oldValue, <%=attrName%>);
+ fireOnPostWrite(<%=constantName%>, oldValue, <%=attrName%>);
}*/
);
}
@@ -892,7 +902,8 @@
String attrName = getPropertyName(attribute);
String attrType = getPropertyType(attribute);
ObjectModelAttribute reverse = attribute.getReverseAttribute();
-
+ String constantName = getConstantName(attrName);
+
if (log.isDebugEnabled()) {
log.debug("Generate 'remove' operation for property : " + attrName +
" [" + attrType + "]");
@@ -900,7 +911,7 @@
// Interface operation
ObjectModelOperation interfaceOperation =
- addOperation(outputInterface, "remove" + StringUtils.capitalize(attrName),
+ addOperation(outputInterface, getJavaBeanMethodName("remove" , attrName),
void.class, ObjectModelModifier.PACKAGE);
ObjectModelParameter param =
addParameter(interfaceOperation, attrType, attrName);
@@ -914,7 +925,7 @@
body.append(""
/*{
- fireOnPreWrite(<%=getConstantName(attrName)%>, <%=attrName%>, null);
+ fireOnPreWrite(<%=constantName%>, <%=attrName%>, null);
if (this.<%=attrName%> == null || !this.<%=attrName%>.remove(<%=attrName%>)) {
throw new IllegalArgumentException("List does not contain given element");
}
@@ -923,25 +934,26 @@
if (reverse != null && (reverse.isNavigable() ||
hasUnidirectionalRelationOnAbstractType(attribute, model))) {
- String reverseAttrName = StringUtils.capitalize(reverse.getName());
+ String getterName = getJavaBeanMethodName("get", reverse.getName());
+ String setterName = getJavaBeanMethodName("set", reverse.getName());
if (!TopiaGeneratorUtil.isNMultiplicity(reverse)) {
body.append(""
/*{
- <%=attrName%>.set<%=reverseAttrName%>(null);
+ <%=attrName%>.<%=setterName%>(null);
}*/
);
// Don't manage reverse attribute remove if attribute has associationClass
} else if (!attribute.hasAssociationClass()) {
body.append(""
/*{
- <%=attrName%>.get<%=reverseAttrName%>().remove(this);
+ <%=attrName%>.<%=getterName%>().remove(this);
}*/
);
}
}
body.append(""
/*{
- fireOnPostWrite(<%=getConstantName(attrName)%>, this.<%=attrName%>.size() + 1, <%=attrName%>, null);
+ fireOnPostWrite(<%=constantName%>, this.<%=attrName%>.size() + 1, <%=attrName%>, null);
}*/
);
setOperationBody(implOperation, body.toString());
@@ -954,7 +966,8 @@
String attrName = getPropertyName(attribute);
String attrType = getPropertyType(attribute);
ObjectModelAttribute reverse = attribute.getReverseAttribute();
-
+ String constantName = getConstantName(attrName);
+
if (log.isDebugEnabled()) {
log.debug("Generate multiple 'clear' operation for property : " + attrName +
" [" + attrType + "]");
@@ -962,7 +975,7 @@
// Interface operation
ObjectModelOperation interfaceOperation =
- addOperation(outputInterface, "clear" + StringUtils.capitalize(attrName),
+ addOperation(outputInterface, getJavaBeanMethodName("clear" , attrName),
void.class, ObjectModelModifier.PACKAGE);
// Implementation
@@ -980,20 +993,21 @@
if (reverse != null && (reverse.isNavigable() ||
hasUnidirectionalRelationOnAbstractType(attribute, model))) {
- String reverseAttrName = StringUtils.capitalize(reverse.getName());
+ String getterName = getJavaBeanMethodName("get", reverse.getName());
+ String setterName = getJavaBeanMethodName("set", reverse.getName());
body.append(""
/*{ for (<%=attrType%> item : this.<%=attrName%>) {
}*/
);
if (!TopiaGeneratorUtil.isNMultiplicity(reverse)) {
body.append(""
-/*{ item.set<%=reverseAttrName%>(null);
+/*{ item.<%=setterName%>(null);
}*/
);
// Don't manage reverse attribute remove if attribute has associationClass
} else if (!attribute.hasAssociationClass()) {
body.append(""
-/*{ item.get<%=reverseAttrName%>().remove(this);
+/*{ item.<%=getterName%>().remove(this);
}*/
);
}
@@ -1004,9 +1018,9 @@
}
body.append(""
/*{ <%=collectionInterface%><<%=attrType%>> oldValue = new <%=collectionImpl%><<%=attrType%>>(this.<%=attrName%>);
- fireOnPreWrite(<%=getConstantName(attrName)%>, oldValue, this.<%=attrName%>);
+ fireOnPreWrite(<%=constantName%>, oldValue, this.<%=attrName%>);
this.<%=attrName%>.clear();
- fireOnPostWrite(<%=getConstantName(attrName)%>, oldValue, this.<%=attrName%>);
+ fireOnPostWrite(<%=constantName%>, oldValue, this.<%=attrName%>);
}*/
);
setOperationBody(implOperation, body.toString());
@@ -1025,7 +1039,7 @@
// Interface operation
ObjectModelOperation interfaceOperation =
- addOperation(outputInterface, "get" + StringUtils.capitalize(attrName),
+ addOperation(outputInterface, getJavaBeanMethodName("get" , attrName),
attrType, ObjectModelModifier.PACKAGE);
// Implementation
@@ -1050,7 +1064,7 @@
// Interface operation
ObjectModelOperation interfaceOperation =
- addOperation(outputInterface, "get" + StringUtils.capitalize(attrName) + "ByTopiaId",
+ addOperation(outputInterface, getJavaBeanMethodName("get", attrName) + "ByTopiaId",
attrType, ObjectModelModifier.PACKAGE);
ObjectModelParameter param =
addParameter(interfaceOperation, String.class, "topiaId");
@@ -1074,6 +1088,7 @@
String referenceName = attribute.getName();
String referenceType = attribute.getType();
+ String referenceGetterName = getJavaBeanMethodName("get", referenceName);
// association attribute name
String attrName = getPropertyName(attribute);
String attrType = getPropertyType(attribute);
@@ -1086,7 +1101,7 @@
// Interface operation
ObjectModelOperation interfaceOperation =
addOperation(outputInterface,
- "get" + StringUtils.capitalize(attrName), attrType);
+ getJavaBeanMethodName("get", attrName), attrType);
addParameter(interfaceOperation, referenceType, referenceName);
@@ -1101,7 +1116,7 @@
return null;
}
for (<%=attrType%> item : this.<%=attrName%>) {
- if (<%=referenceName%>.equals(item.get<%=StringUtils.capitalize(referenceName)%>())) {
+ if (<%=referenceName%>.equals(item.<%=referenceGetterName%>())) {
return item;
}
}
@@ -1120,7 +1135,7 @@
// Interface operation
ObjectModelOperation interfaceOperation =
- addOperation(outputInterface, "size" + StringUtils.capitalize(attrName),
+ addOperation(outputInterface, getJavaBeanMethodName("size", attrName),
int.class, ObjectModelModifier.PACKAGE);
// Implementation
@@ -1144,9 +1159,10 @@
log.debug("Generate multiple 'isEmpty' operation for property : " + attrName);
}
+ String sizeMethodName = getJavaBeanMethodName("size", attrName);
// Interface operation
ObjectModelOperation interfaceOperation =
- addOperation(outputInterface, "is" + StringUtils.capitalize(attrName) + "Empty",
+ addOperation(outputInterface, getJavaBeanMethodName("is", attrName)+ "Empty",
boolean.class, ObjectModelModifier.PACKAGE);
// Implementation
@@ -1154,7 +1170,7 @@
setOperationBody(implOperation, ""
/*{
- int size = size<%=StringUtils.capitalize(attrName)%>();
+ int size = <%=sizeMethodName%>();
return size == 0;
}*/
);
@@ -1192,16 +1208,16 @@
String attrType =
TopiaGeneratorUtil.getSimpleName(getPropertyType(attribute));
String collectionType = getCollectionType(attribute);
-
+ String constantName = getConstantName(attrName);
if (collectionType != null) {
collectionType = TopiaGeneratorUtil.getSimpleName(collectionType);
acceptOperationBody.append(""
-/*{ visitor.visit(this, <%=getConstantName(attrName)%>, <%=collectionType%>.class, <%=attrType%>.class, <%=attrName%>);
+/*{ visitor.visit(this, <%=constantName%>, <%=collectionType%>.class, <%=attrType%>.class, <%=attrName%>);
}*/
);
} else {
acceptOperationBody.append(""
-/*{ visitor.visit(this, <%=getConstantName(attrName)%>, <%=attrType%>.class, <%=attrName%>);
+/*{ visitor.visit(this, <%=constantName%>, <%=attrType%>.class, <%=attrName%>);
}*/
);
}
@@ -1251,8 +1267,9 @@
if (isEntity && (reverse == null || !reverse.isNavigable())
&& !attr.hasAssociationClass() || !isEntity) {
String attrName = attr.getName();
+ String constantName = getConstantName(attrName);
body.append(""
-/*{ append(<%=getConstantName(attrName)%>, this.<%=attrName%>).
+/*{ append(<%=constantName%>, this.<%=attrName%>).
}*/
);
}
@@ -1293,7 +1310,7 @@
if (attr.isComposite()) {
String attrName = attr.getName();
- String getterName = "get" + StringUtils.capitalize(attrName);
+ String getterName = getJavaBeanMethodName("get", attrName);
if (TopiaGeneratorUtil.isNMultiplicity(attr)) {
body.append(""
/*{ if (<%=getterName%>() != null) {
@@ -1397,7 +1414,7 @@
attr.isAggregate()) {
String attrName = attr.getName();
- String getterName = "get" + StringUtils.capitalize(attrName);
+ String getterName = getJavaBeanMethodName("get", attrName);
if (TopiaGeneratorUtil.isNMultiplicity(attr)) {
body.append(""
/*{ tmp.addAll(<%=getterName%>());
@@ -1519,7 +1536,7 @@
// Operation
ObjectModelOperation operation =
addOperation(classifier,
- "set" + StringUtils.capitalize(propertyName), void.class);
+ getJavaBeanMethodName("set", propertyName), void.class);
ObjectModelParameter param =
addParameter(operation, propertyType, propertyName);
1
0