You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2008/07/31 14:12:06 UTC
svn commit: r681351 - in /cayenne/main/trunk/framework:
cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/
cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/
cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util...
Author: aadamchik
Date: Thu Jul 31 05:12:04 2008
New Revision: 681351
URL: http://svn.apache.org/viewvc?rev=681351&view=rev
Log:
CAY-1070 Generating Query and Procedure Access Code
(patch by Dzmitry Rusak - support for selectquery code generation; first cut)
Added:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/DataMapArtifact.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/DataMapUtils.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/datamap-singleclass.vm
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/datamap-subclass.vm
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/datamap-superclass.vm
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ArtifactsGenerationMode.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/TemplateType.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/NameConverter.java
cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java
cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java
cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModeController.java
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ArtifactsGenerationMode.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ArtifactsGenerationMode.java?rev=681351&r1=681350&r2=681351&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ArtifactsGenerationMode.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ArtifactsGenerationMode.java Thu Jul 31 05:12:04 2008
@@ -27,7 +27,7 @@
public enum ArtifactsGenerationMode {
// TODO: andrus 12/9/2007 - label names are old... need to call it something else...
- SINGLE_RUN("datamap"), RUN_PER_ARTIFACT("entity");
+ DATAMAP("datamap"), ENTITY("entity"), ALL("all");
private String label;
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java?rev=681351&r1=681350&r2=681351&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java Thu Jul 31 05:12:04 2008
@@ -29,6 +29,7 @@
import java.util.Properties;
import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.query.Query;
import org.apache.cayenne.map.DataMap;
import org.apache.cayenne.map.Embeddable;
import org.apache.cayenne.map.ObjEntity;
@@ -54,6 +55,10 @@
public static final String EMBEDDABLE_SUBCLASS_TEMPLATE = "dotemplates/v1_2/embeddable-subclass.vm";
public static final String EMBEDDABLE_SUPERCLASS_TEMPLATE = "dotemplates/v1_2/embeddable-superclass.vm";
+ public static final String DATAMAP_SINGLE_CLASS_TEMPLATE = "dotemplates/v1_2/datamap-singleclass.vm";
+ public static final String DATAMAP_SUBCLASS_TEMPLATE = "dotemplates/v1_2/datamap-subclass.vm";
+ public static final String DATAMAP_SUPERCLASS_TEMPLATE = "dotemplates/v1_2/datamap-superclass.vm";
+
public static final String SUPERCLASS_PREFIX = "_";
private static final String WILDCARD = "*";
@@ -74,6 +79,8 @@
protected String superTemplate;
protected String embeddableTemplate;
protected String embeddableSuperTemplate;
+ protected String queryTemplate;
+ protected String querySuperTemplate;
protected long timestamp;
protected String outputPattern;
protected String encoding;
@@ -107,6 +114,12 @@
return ClassGenerationAction.EMBEDDABLE_SUPERCLASS_TEMPLATE;
case EMBEDDABLE_SINGLE_CLASS:
return ClassGenerationAction.EMBEDDABLE_SINGLE_CLASS_TEMPLATE;
+ case DATAMAP_SINGLE_CLASS:
+ return ClassGenerationAction.DATAMAP_SINGLE_CLASS_TEMPLATE;
+ case DATAMAP_SUPERCLASS:
+ return ClassGenerationAction.DATAMAP_SUPERCLASS_TEMPLATE;
+ case DATAMAP_SUBCLASS:
+ return ClassGenerationAction.DATAMAP_SUBCLASS_TEMPLATE;
default:
throw new IllegalArgumentException("Invalid template type: " + type);
}
@@ -124,6 +137,12 @@
return embeddableTemplate;
case EMBEDDABLE_SUPERCLASS:
return embeddableSuperTemplate;
+ case DATAMAP_SINGLE_CLASS:
+ return queryTemplate;
+ case DATAMAP_SUPERCLASS:
+ return querySuperTemplate;
+ case DATAMAP_SUBCLASS:
+ return queryTemplate;
default:
throw new IllegalArgumentException("Invalid template type: " + type);
}
@@ -193,12 +212,6 @@
try {
for (Artifact artifact : artifacts) {
execute(artifact);
-
- if (artifactsGenerationMode == ArtifactsGenerationMode.SINGLE_RUN) {
- // TODO: andrus 12/9/2007 - should we run at least once if there are
- // no artifacts? Current behavior is copied from the legacy code.
- break;
- }
}
}
finally {
@@ -321,6 +334,14 @@
this.superTemplate = superTemplate;
}
+ public void setQueryTemplate(String queryTemplate) {
+ this.queryTemplate = queryTemplate;
+ }
+
+ public void setQuerySuperTemplate(String querySuperTemplate) {
+ this.querySuperTemplate = querySuperTemplate;
+ }
+
/**
* Sets <code>usepkgpath</code> property.
*/
@@ -498,17 +519,32 @@
* Adds entities to the internal entity list.
*/
public void addEntities(Collection<ObjEntity> entities) {
- if (entities != null) {
- for (ObjEntity entity : entities) {
- artifacts.add(new EntityArtifact(entity));
+ if (artifactsGenerationMode == ArtifactsGenerationMode.ENTITY ||
+ artifactsGenerationMode == ArtifactsGenerationMode.ALL ) {
+ if (entities != null) {
+ for (ObjEntity entity : entities) {
+ artifacts.add(new EntityArtifact(entity));
+ }
}
}
}
public void addEmbeddables(Collection<Embeddable> embeddables) {
- if (embeddables != null) {
- for (Embeddable embeddable : embeddables) {
- artifacts.add(new EmbeddableArtifact(embeddable));
+ if (artifactsGenerationMode == ArtifactsGenerationMode.ENTITY ||
+ artifactsGenerationMode == ArtifactsGenerationMode.ALL ) {
+ if (embeddables != null) {
+ for (Embeddable embeddable : embeddables) {
+ artifacts.add(new EmbeddableArtifact(embeddable));
+ }
+ }
+ }
+ }
+
+ public void addQueries(Collection<Query> queries) {
+ if (artifactsGenerationMode == ArtifactsGenerationMode.DATAMAP ||
+ artifactsGenerationMode == ArtifactsGenerationMode.ALL ) {
+ if (queries != null) {
+ artifacts.add(new DataMapArtifact(dataMap, queries));
}
}
}
@@ -538,10 +574,17 @@
}
public void setArtifactsGenerationMode(String mode) {
- this.artifactsGenerationMode = ArtifactsGenerationMode.RUN_PER_ARTIFACT
- .getLabel()
- .equalsIgnoreCase(mode)
- ? ArtifactsGenerationMode.RUN_PER_ARTIFACT
- : ArtifactsGenerationMode.SINGLE_RUN;
+ if (ArtifactsGenerationMode.ENTITY.getLabel()
+ .equalsIgnoreCase(mode)){
+ this.artifactsGenerationMode = ArtifactsGenerationMode.ENTITY;
+ } else {
+ if (ArtifactsGenerationMode.DATAMAP.getLabel()
+ .equalsIgnoreCase(mode)){
+ this.artifactsGenerationMode = ArtifactsGenerationMode.DATAMAP;
+ } else {
+ this.artifactsGenerationMode = ArtifactsGenerationMode.ALL;
+ }
+ }
+
}
}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/DataMapArtifact.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/DataMapArtifact.java?rev=681351&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/DataMapArtifact.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/DataMapArtifact.java Thu Jul 31 05:12:04 2008
@@ -0,0 +1,106 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.gen;
+
+import org.apache.velocity.VelocityContext;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.query.Query;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.query.SQLTemplate;
+import org.apache.cayenne.query.ProcedureQuery;
+import org.apache.cayenne.util.NameConverter;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+/**
+ * {@link Artifact} facade for a DataMap.
+ *
+ * @author Dzmitry Rusak
+ * @since 3.0
+ */
+public class DataMapArtifact implements Artifact {
+
+ public static String DATAMAP_UTILS_KEY = "dataMapUtils";
+
+ protected DataMap dataMap;
+ protected Collection<SelectQuery> selectQueries;
+ protected Collection<SQLTemplate> sqlTemplateQueries;
+ protected Collection<ProcedureQuery> procedureQueries;
+
+ public DataMapArtifact(DataMap dataMap, Collection<Query> queries) {
+ this.dataMap = dataMap;
+ selectQueries = new LinkedList<SelectQuery>();
+ sqlTemplateQueries = new LinkedList<SQLTemplate>();
+ procedureQueries = new LinkedList<ProcedureQuery>();
+ addQueries(queries);
+ }
+
+ public String getQualifiedBaseClassName() {
+ return Object.class.getName();
+ }
+
+ public String getQualifiedClassName() {
+ return dataMap.getDefaultPackage() + '.' + NameConverter.specialCharsToJava(dataMap.getName());
+ }
+
+ public Object getObject() {
+ return this;
+ }
+
+ public void postInitContext(VelocityContext context) {
+ DataMapUtils dataMapUtils = new DataMapUtils();
+ context.put(DATAMAP_UTILS_KEY, dataMapUtils);
+ }
+
+ public TemplateType[] getTemplateTypes(ArtifactGenerationMode mode) {
+ switch (mode) {
+ case SINGLE_CLASS:
+ return new TemplateType[]{
+ TemplateType.DATAMAP_SINGLE_CLASS
+ };
+ case GENERATION_GAP:
+ return new TemplateType[]{
+ TemplateType.DATAMAP_SUPERCLASS, TemplateType.DATAMAP_SUBCLASS
+ };
+ default:
+ return new TemplateType[0];
+ }
+ }
+
+ private void addQueries(Collection<Query> queries) {
+ if (queries != null) {
+ for (Query query : queries) {
+ addQuery(query);
+ }
+ }
+ }
+
+ private void addQuery(Query query) {
+ if (query instanceof SelectQuery) {
+ selectQueries.add((SelectQuery) query);
+ }
+ }
+
+ public Collection<SelectQuery> getSelectQueries() {
+ return selectQueries;
+ }
+
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/DataMapUtils.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/DataMapUtils.java?rev=681351&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/DataMapUtils.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/DataMapUtils.java Thu Jul 31 05:12:04 2008
@@ -0,0 +1,173 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.gen;
+
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionParameter;
+import org.apache.cayenne.exp.parser.ASTList;
+import org.apache.cayenne.exp.parser.ASTObjPath;
+import org.apache.cayenne.map.Entity;
+import org.apache.cayenne.map.ObjAttribute;
+import org.apache.cayenne.map.ObjRelationship;
+import org.apache.cayenne.map.PathComponent;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.query.QualifiedQuery;
+import org.apache.cayenne.query.Query;
+import org.apache.cayenne.util.NameConverter;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Collections;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+
+/**
+ * Attributes and Methods for working with Queries.
+ *
+ * @author Dzmitry Rusak
+ * @since 3.0
+ */
+public class DataMapUtils {
+
+ Map<String, Map<String, String>> queriesMap = new HashMap<String, Map<String, String>>();
+
+ /**
+ * Return valid method name based on query name (replace all illegal characters with
+ * underscore '_').
+ *
+ * @param query
+ * @return Method name that perform query.
+ */
+ public String getQueryMethodName(Query query) {
+ return NameConverter.specialCharsToJava(query.getName());
+ }
+
+ /**
+ * Get all parameter names that used in query qualifier.
+ *
+ * @param query
+ * @return Parameter names.
+ */
+ public Collection<String> getParameterNames(QualifiedQuery query) {
+ Map<String, String> queryParameters = queriesMap.get(query.getName());
+
+ if ( queryParameters == null) {
+ queryParameters = getParameterNames(query.getQualifier(), query.getRoot());
+ queriesMap.put(query.getName(), queryParameters);
+ }
+
+ return parseQualifier(query.getQualifier().toString());
+ }
+
+ /**
+ * Get list of parameter names in the same order as in qualifier.
+ *
+ * @param qualifierString to be parsed
+ * @return List of parameter names.
+ */
+ private List<String> parseQualifier(String qualifierString) {
+ List<String> result = new LinkedList<String>();
+ Pattern pattern = Pattern.compile("\\$[\\w]+");
+ Matcher matcher = pattern.matcher(qualifierString);
+ while(matcher.find()) {
+ String name = matcher.group();
+ result.add(name.substring(1));
+ }
+
+ return result;
+ }
+
+ public boolean hasParameters(QualifiedQuery query) {
+ Map queryParameters = queriesMap.get(query.getName());
+
+ if (queryParameters == null) {
+ return false;
+ }
+
+ return queryParameters.keySet().size() > 0;
+
+ }
+
+ /**
+ * Get type of parameter for given name.
+ *
+ * @param query
+ * @param name
+ * @return Parameter type.
+ */
+ public String getParameterType(QualifiedQuery query, String name) {
+ return queriesMap.get(query.getName()).get(name);
+ }
+
+ private Map<String, String> getParameterNames(Expression expression, Object root) {
+ if (expression != null) {
+ Map<String, String> types = new HashMap<String, String>();
+ String typeName = "";
+ List<String> names = new LinkedList<String>();
+
+ for (int i = 0; i < expression.getOperandCount(); i++) {
+ Object operand = expression.getOperand(i);
+
+ if (operand instanceof Expression) {
+ types.putAll(getParameterNames((Expression) operand, root));
+ }
+
+ if (operand instanceof ASTObjPath) {
+ PathComponent<ObjAttribute, ObjRelationship> component = ((Entity) root).lastPathComponent((ASTObjPath) operand, null);
+ ObjAttribute attribute = component.getAttribute();
+ if (attribute != null) {
+ typeName = attribute.getType();
+ } else {
+ ObjRelationship relationship = component.getRelationship();
+ if (relationship != null) {
+ typeName = ((ObjEntity) relationship.getTargetEntity()).getClassName();
+ } else {
+ typeName = "Object";
+ }
+ }
+ }
+
+ if (operand instanceof ASTList) {
+ Object[] values = (Object[]) ((ASTList) operand).getOperand(0);
+ for (Object value : values) {
+ if (value instanceof ExpressionParameter) {
+ names.add(((ExpressionParameter) value).getName());
+ }
+ }
+ }
+
+ if (operand instanceof ExpressionParameter) {
+ names.add(((ExpressionParameter) operand).getName());
+ }
+
+ }
+
+ for (String name : names) {
+ types.put(name, typeName);
+ }
+
+ return types;
+ }
+ return Collections.EMPTY_MAP;
+ }
+}
\ No newline at end of file
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/TemplateType.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/TemplateType.java?rev=681351&r1=681350&r2=681351&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/TemplateType.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/TemplateType.java Thu Jul 31 05:12:04 2008
@@ -36,7 +36,13 @@
EMBEDDABLE_SUPERCLASS(true),
- EMBEDDABLE_SUBCLASS(false);
+ EMBEDDABLE_SUBCLASS(false),
+
+ DATAMAP_SINGLE_CLASS(false),
+
+ DATAMAP_SUPERCLASS(true),
+
+ DATAMAP_SUBCLASS(false);
private boolean superclass;
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java?rev=681351&r1=681350&r2=681351&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java Thu Jul 31 05:12:04 2008
@@ -67,7 +67,7 @@
public CayenneGeneratorTask() {
this.makepairs = true;
- this.mode = ArtifactsGenerationMode.RUN_PER_ARTIFACT.getLabel();
+ this.mode = ArtifactsGenerationMode.ENTITY.getLabel();
this.outputPattern = "*.java";
this.usepkgpath = true;
}
@@ -159,6 +159,7 @@
generatorAction.setDataMap(dataMap);
generatorAction.addEntities(filterAction.getFilteredEntities(dataMap));
generatorAction.addEmbeddables(filterAction.getFilteredEmbeddables(dataMap));
+ generatorAction.addQueries(dataMap.getQueries());
generatorAction.execute();
}
catch (Exception e) {
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/NameConverter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/NameConverter.java?rev=681351&r1=681350&r2=681351&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/NameConverter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/NameConverter.java Thu Jul 31 05:12:04 2008
@@ -135,7 +135,7 @@
/**
* Replaces special chars with human-readable and Java-id-compatible symbols.
*/
- static String specialCharsToJava(String string) {
+ public static String specialCharsToJava(String string) {
int len = string.length();
if (len == 0) {
return string;
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/datamap-singleclass.vm
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/datamap-singleclass.vm?rev=681351&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/datamap-singleclass.vm (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/datamap-singleclass.vm Thu Jul 31 05:12:04 2008
@@ -0,0 +1,90 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements. See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership. The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied. See the License for the
+## specific language governing permissions and limitations
+## under the License.
+##
+##Terminology:
+## Base class - super superclass of entity, ie, org.apache.cayenne.CayenneDataObject or MyBaseClass
+## Super class - superclass of entity, ie, org.apache.cayenne.art.auto._Artist
+## Sub class - class of entity, ie, org.apache.cayenne.art.Artist
+##
+## Classes available in template
+## object (duplicated as 'objEntity') - the ObjEntity class: See org.apache.cayenne.map.ObjectEntity
+## stringUtils - class for string "helper" functions: See org.apache.cayenne.gen.StringUtils
+## dataMapUtils - class for query "helper" functions: See org.apache.cayenne.gen.DataMapUtils
+## importUtils - class for import statement management: See org.apache.cayenne.gen.ImportUtils
+## superClassName
+## superPackageName
+## subClassName
+## subPackageName
+## baseClassName
+## basePackageName
+##
+##
+${importUtils.setPackage($subPackageName)}##
+${importUtils.addReservedType("${subPackageName}.${subClassName}")}##
+${importUtils.addType("${basePackageName}.${baseClassName}")}##
+${importUtils.addType('java.util.List')}
+${importUtils.addType('java.util.Map')}
+${importUtils.addType('java.util.HashMap')}
+${importUtils.addType('org.apache.cayenne.ObjectContext')}
+#foreach( $selectQuery in ${object.SelectQueries})
+${importUtils.addType(${selectQuery.Root.ClassName})}
+#foreach( $parameter in ${dataMapUtils.getParameterNames(${selectQuery})})
+${importUtils.addType(${dataMapUtils.getParameterType(${selectQuery}, ${parameter})})}
+#end
+#end
+${importUtils.generate()}
+
+/**
+ * This class was generated by Cayenne.
+ * It is probably a good idea to avoid changing this class manually,
+ * since it may be overwritten next time code is regenerated.
+ * If you need to make any customizations, please use subclass.
+ */
+public class ${subClassName} {
+
+ private static ${subClassName} instance;
+
+ private ${subClassName}() {}
+
+ public ${subClassName} getInstance() {
+ if( instance == null) {
+ instance = new ${subClassName}();
+ }
+ return instance;
+ }
+
+#foreach( $selectQuery in ${object.SelectQueries})
+ public List<${stringUtils.stripPackageName($selectQuery.Root.ClassName)}> perform${dataMapUtils.getQueryMethodName(${selectQuery})}(ObjectContext context #foreach( $parameter in ${dataMapUtils.getParameterNames(${selectQuery})}), ${stringUtils.stripPackageName(${dataMapUtils.getParameterType(${selectQuery}, ${parameter})})} ${parameter} #end) {
+ #if(${dataMapUtils.hasParameters($selectQuery)})
+ String[] parameters = new String[] {
+ #foreach( $parameter in ${dataMapUtils.getParameterNames(${selectQuery})})
+ "${parameter}",
+ #end
+ };
+
+ Object[] values = new Object[] {
+ #foreach( $parameter in ${dataMapUtils.getParameterNames(${selectQuery})})
+ ${parameter},
+ #end
+ };
+ #end
+
+ NamedQuery query = new NamedQuery("${selectQuery.Name}"#if(${dataMapUtils.hasParameters($selectQuery)}), parameters, values#end);
+ return context.performQuery(query);
+ }
+#end
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/datamap-subclass.vm
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/datamap-subclass.vm?rev=681351&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/datamap-subclass.vm (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/datamap-subclass.vm Thu Jul 31 05:12:04 2008
@@ -0,0 +1,48 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements. See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership. The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied. See the License for the
+## specific language governing permissions and limitations
+## under the License.
+##
+##Terminology:
+## Base class - super superclass of entity, ie, org.apache.cayenne.CayenneDataObject or MyBaseClass
+## Super class - superclass of entity, ie, org.apache.cayenne.art.auto._Artist
+## Sub class - class of entity, ie, org.apache.cayenne.art.Artist
+##
+## Classes available in template
+## stringUtils - class for string "helper" functions: See org.apache.cayenne.gen.StringUtils
+## dataMapUtils - class for query "helper" functions: See org.apache.cayenne.gen.dataMapUtils
+## importUtils - class for import statement management: See org.apache.cayenne.gen.ImportUtils
+##
+##
+${importUtils.setPackage($subPackageName)}##
+${importUtils.addReservedType("${subPackageName}.${subClassName}")}##
+${importUtils.addType("${superPackageName}.${superClassName}")}##
+${importUtils.generate()}
+
+public class ${subClassName} extends ${superClassName} {
+
+ private static ${subClassName} instance;
+
+ private ${subClassName}() {}
+
+ public ${subClassName} getInstance() {
+ if( instance == null) {
+ instance = new ${subClassName}();
+ }
+
+ return instance;
+ }
+
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/datamap-superclass.vm
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/datamap-superclass.vm?rev=681351&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/datamap-superclass.vm (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/datamap-superclass.vm Thu Jul 31 05:12:04 2008
@@ -0,0 +1,79 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements. See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership. The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied. See the License for the
+## specific language governing permissions and limitations
+## under the License.
+##
+##Terminology:
+## Base class - super superclass of entity, ie, org.apache.cayenne.CayenneDataObject or MyBaseClass
+## Super class - superclass of entity, ie, org.apache.cayenne.art.auto._Artist
+## Sub class - class of entity, ie, org.apache.cayenne.art.Artist
+##
+## Classes available in template
+## stringUtils - class for string "helper" functions: See org.apache.cayenne.gen.StringUtils
+## dataMapUtils - class for query "helper" functions: See org.apache.cayenne.gen.DataMapUtils
+## importUtils - class for import statement management: See org.apache.cayenne.gen.ImportUtils
+## superClassName
+## superPackageName
+## subClassName
+## subPackageName
+## baseClassName
+## basePackageName
+##
+${importUtils.setPackage($superPackageName)}##
+${importUtils.addReservedType("${superPackageName}.${superClassName}")}##
+${importUtils.addType("${basePackageName}.${baseClassName}")}##
+${importUtils.addType('java.util.List')}##
+${importUtils.addType('java.util.Map')}##
+${importUtils.addType('java.util.HashMap')}##
+${importUtils.addType('org.apache.cayenne.ObjectContext')}##
+${importUtils.addType('org.apache.cayenne.query.NamedQuery')}##
+#foreach( $selectQuery in ${object.SelectQueries})
+${importUtils.addType(${selectQuery.Root.ClassName})}##
+#foreach( $parameter in ${dataMapUtils.getParameterNames(${selectQuery})})
+${importUtils.addType(${dataMapUtils.getParameterType(${selectQuery}, ${parameter})})}##
+#end
+#end
+${importUtils.generate()}
+
+/**
+ * This class was generated by Cayenne.
+ * It is probably a good idea to avoid changing this class manually,
+ * since it may be overwritten next time code is regenerated.
+ * If you need to make any customizations, please use subclass.
+ */
+public class ${superClassName} {
+
+#foreach( $selectQuery in ${object.SelectQueries})
+ public List<${stringUtils.stripPackageName($selectQuery.Root.ClassName)}> perform${dataMapUtils.getQueryMethodName(${selectQuery})}(ObjectContext context #foreach( $parameter in ${dataMapUtils.getParameterNames(${selectQuery})}), ${stringUtils.stripPackageName(${dataMapUtils.getParameterType(${selectQuery}, ${parameter})})} ${parameter} #end) {
+ #if(${dataMapUtils.hasParameters($selectQuery)})
+ String[] parameters = new String[] {
+ #foreach( $parameter in ${dataMapUtils.getParameterNames(${selectQuery})})
+ "${parameter}",
+ #end
+ };
+
+ Object[] values = new Object[] {
+ #foreach( $parameter in ${dataMapUtils.getParameterNames(${selectQuery})})
+ ${parameter},
+ #end
+ };
+ #end
+
+ NamedQuery query = new NamedQuery("${selectQuery.Name}"#if(${dataMapUtils.hasParameters($selectQuery)}), parameters, values#end);
+ return context.performQuery(query);
+ }
+
+#end
+}
\ No newline at end of file
Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java?rev=681351&r1=681350&r2=681351&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java Thu Jul 31 05:12:04 2008
@@ -48,14 +48,17 @@
// correspond to non-public constants on MapClassGenerator.
static final String MODE_DATAMAP = "datamap";
static final String MODE_ENTITY = "entity";
+ static final String MODE_ALL = "all";
- static final String DATA_MAP_MODE_LABEL = "One run per DataMap";
- static final String ENTITY_MODE_LABEL = "One run per each selected Entity";
+ static final String DATA_MAP_MODE_LABEL = "DataMap generation";
+ static final String ENTITY_MODE_LABEL = "Entity and Embeddable generation";
+ static final String ALL_MODE_LABEL = "Generate all";
static final Map<String, String> modesByLabel = new HashMap<String, String>();
static {
modesByLabel.put(DATA_MAP_MODE_LABEL, MODE_DATAMAP);
modesByLabel.put(ENTITY_MODE_LABEL, MODE_ENTITY);
+ modesByLabel.put(ALL_MODE_LABEL, MODE_ALL);
}
protected CustomModePanel view;
@@ -68,7 +71,7 @@
super(parent);
Object[] modeChoices = new Object[] {
- ENTITY_MODE_LABEL, DATA_MAP_MODE_LABEL
+ ENTITY_MODE_LABEL, DATA_MAP_MODE_LABEL, ALL_MODE_LABEL
};
view.getGenerationMode().setModel(new DefaultComboBoxModel(modeChoices));
@@ -218,12 +221,11 @@
public ClassGenerationAction createGenerator() {
- ClassGenerationAction generator = super.createGenerator();
-
- String mode = modesByLabel
+ mode = modesByLabel
.get(view.getGenerationMode().getSelectedItem())
.toString();
- generator.setArtifactsGenerationMode(mode);
+
+ ClassGenerationAction generator = super.createGenerator();
String version = getVersion();
Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java?rev=681351&r1=681350&r2=681351&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java Thu Jul 31 05:12:04 2008
@@ -31,6 +31,7 @@
import javax.swing.JTextField;
import org.apache.cayenne.gen.ClassGenerationAction;
+import org.apache.cayenne.gen.ArtifactsGenerationMode;
import org.apache.cayenne.map.Attribute;
import org.apache.cayenne.map.EmbeddedAttribute;
import org.apache.cayenne.map.ObjAttribute;
@@ -60,6 +61,7 @@
public abstract class GeneratorController extends CayenneController {
protected DataMapDefaults preferences;
+ protected String mode = ArtifactsGenerationMode.ENTITY.getLabel();
public GeneratorController(CodeGeneratorControllerBase parent) {
super(parent);
@@ -147,9 +149,11 @@
}
ClassGenerationAction generator = newGenerator();
+ generator.setArtifactsGenerationMode(mode);
generator.setDataMap(getParentController().getDataMap());
generator.addEntities(entities);
generator.addEmbeddables(getParentController().getSelectedEmbeddables());
+ generator.addQueries(getParentController().getDataMap().getQueries());
// configure encoding from preferences
Domain generatorPrefs = Application
Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModeController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModeController.java?rev=681351&r1=681350&r2=681351&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModeController.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModeController.java Thu Jul 31 05:12:04 2008
@@ -22,6 +22,7 @@
import java.awt.Component;
import org.apache.cayenne.gen.ClassGenerationAction;
+import org.apache.cayenne.gen.ArtifactsGenerationMode;
import org.apache.cayenne.modeler.pref.DataMapDefaults;
import org.apache.cayenne.swing.BindingBuilder;
@@ -65,4 +66,10 @@
protected ClassGenerationAction newGenerator() {
return new ClassGenerationAction();
}
+
+ @Override
+ public ClassGenerationAction createGenerator() {
+ mode = ArtifactsGenerationMode.ALL.getLabel();
+ return super.createGenerator();
+ }
}