This commit is the first cut of supporting java source generation for mongo db.
diff --git a/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/DatabaseType.java b/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/DatabaseType.java
index d60a1da..6677a52 100644
--- a/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/DatabaseType.java
+++ b/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/DatabaseType.java
@@ -24,7 +24,7 @@
* to solicit feedback from pioneering adopters on the understanding that any code that uses this
* API will almost certainly be broken (repeatedly) as the API evolves.<p>
*
- * @see DynamicEntityGenerator
+ * @see RelationalEntityGenerator
*
* @version 2.5
* @author John Bracken
diff --git a/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/DynamicEntityGenerator.java b/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/RelationalEntityGenerator.java
similarity index 97%
rename from tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/DynamicEntityGenerator.java
rename to tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/RelationalEntityGenerator.java
index dc94d33..b2e8604 100644
--- a/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/DynamicEntityGenerator.java
+++ b/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/RelationalEntityGenerator.java
@@ -41,7 +41,7 @@
* @version 2.5
* @author John Bracken
*/
-public class DynamicEntityGenerator {
+public class RelationalEntityGenerator {
/**
* JPT database reference.
@@ -49,11 +49,11 @@
private Database database;
/**
- * Constructs a new {@link DynamicEntityGenerator} based on the provided db connection
+ * Constructs a new {@link RelationalEntityGenerator} based on the provided db connection
*
* @param database the provided database to use in this dynamic entity generator.
*/
- public DynamicEntityGenerator(Database database) {
+ public RelationalEntityGenerator(Database database) {
super();
this.database = database;
}
diff --git a/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/MappingFileGenerator.java b/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/MappingFileGenerator.java
index 37d4475..7d07c84 100644
--- a/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/MappingFileGenerator.java
+++ b/tools/org.eclipse.persistence.tools.gen.db/src/org/eclipse/persistence/tools/gen/internal/MappingFileGenerator.java
@@ -18,11 +18,9 @@
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
-import org.apache.velocity.runtime.log.JdkLogChute;
/**
* This generator will generate EclipseLink dynamic entities for a set of tables.
@@ -37,7 +35,6 @@
@SuppressWarnings("nls")
public class MappingFileGenerator {
- private static final String LOGGER_NAME = "org.eclipse.jpt.entities.gen.log";
private final ORMGenCustomizer customizer;
public static String generate(ORMGenCustomizer customizer) {
@@ -64,15 +61,10 @@
List<String> tableNames = this.customizer.getGenTableNames();
try {
- //JdkLogChute in this version of Velocity not allow to set log level
- //Workaround by preset the log level before Velocity is initialized
- Logger logger = Logger.getLogger(LOGGER_NAME);
- logger.setLevel(Level.SEVERE);
-
+
Properties vep = new Properties();
vep.setProperty("resource.loader", "class");
vep.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
- vep.setProperty(JdkLogChute.RUNTIME_LOG_JDK_LOGGER, LOGGER_NAME);
VelocityEngine ve = new VelocityEngine();
ve.init(vep);
diff --git a/tools/org.eclipse.persistence.tools.gen.nosql/.classpath b/tools/org.eclipse.persistence.tools.gen.nosql/.classpath
index 0b9079a..fe62b7f 100644
--- a/tools/org.eclipse.persistence.tools.gen.nosql/.classpath
+++ b/tools/org.eclipse.persistence.tools.gen.nosql/.classpath
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="templates/java_entities"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="owner.project.facets" value="java"/>
diff --git a/tools/org.eclipse.persistence.tools.gen.nosql/.settings/org.eclipse.wst.common.component b/tools/org.eclipse.persistence.tools.gen.nosql/.settings/org.eclipse.wst.common.component
index 4fd455f..1fd8eca 100644
--- a/tools/org.eclipse.persistence.tools.gen.nosql/.settings/org.eclipse.wst.common.component
+++ b/tools/org.eclipse.persistence.tools.gen.nosql/.settings/org.eclipse.wst.common.component
@@ -1,6 +1,6 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project-modules id="moduleCoreId" project-version="1.5.0">
+<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="org.eclipse.persistence.tools.gen.nosql">
<wb-resource deploy-path="/" source-path="/src"/>
+ <wb-resource deploy-path="/" source-path="/templates/java_entities"/>
</wb-module>
</project-modules>
diff --git a/tools/org.eclipse.persistence.tools.gen.nosql/META-INF/MANIFEST.MF b/tools/org.eclipse.persistence.tools.gen.nosql/META-INF/MANIFEST.MF
index df4abe3..c959b83 100644
--- a/tools/org.eclipse.persistence.tools.gen.nosql/META-INF/MANIFEST.MF
+++ b/tools/org.eclipse.persistence.tools.gen.nosql/META-INF/MANIFEST.MF
@@ -2,8 +2,13 @@
Export-Package:
org.eclipse.persistence.tools.gen.nosql.mongo
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Require-Bundle: org.eclipse.persistence.tools.utility;bundle-version="2.5.0",
- org.eclipse.persistence.tools.mapping;bundle-version="2.5.0"
+Require-Bundle: org.apache.velocity;bundle-version="1.5.0",
+ org.apache.commons.collections;bundle-version="3.2.0",
+ org.jdom;bundle-version="1.1.1",
+ org.apache.commons.lang;bundle-version="2.1.0",
+ org.eclipse.persistence.tools.utility;bundle-version="2.5.0",
+ org.eclipse.persistence.tools.mapping;bundle-version="2.5.0",
+ javax.persistence;bundle-version="2.0.4"
Bundle-SymbolicName: org.eclipse.persistence.tools.gen.nosql
Bundle-Name: EclipseLink Tools NoSql
Bundle-Vendor: Eclipse.org - EclipseLink Project
diff --git a/tools/org.eclipse.persistence.tools.gen.nosql/src/META-INF/persistence.xml b/tools/org.eclipse.persistence.tools.gen.nosql/src/META-INF/persistence.xml
deleted file mode 100644
index 92e3288..0000000
--- a/tools/org.eclipse.persistence.tools.gen.nosql/src/META-INF/persistence.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<persistence-unit name="mongo-example" transaction-type="RESOURCE_LOCAL">
- <provider>
- org.eclipse.persistence.jpa.PersistenceProvider
- </provider>
- <mapping-file>META-INF/test.xml</mapping-file>
- <properties>
- <property name="eclipselink.target-database" value="org.eclipse.persistence.nosql.adapters.mongo.MongoPlatform"/>
- <property name="eclipselink.nosql.connection-spec" value="org.eclipse.persistence.nosql.adapters.mongo.MongoConnectionSpec"/>
- <property name="eclipselink.nosql.property.mongo.port" value="27017"/>
- <property name="eclipselink.nosql.property.mongo.host" value="localhost"/>
- <property name="eclipselink.nosql.property.mongo.db" value="scratch"/>
- <property name="eclipselink.logging.level" value="FINEST"/>
- </properties>
-</persistence-unit>
\ No newline at end of file
diff --git a/tools/org.eclipse.persistence.tools.gen.nosql/src/org/eclipse/persistence/tools/gen/nosql/mongo/MongoDynamicEntityGenerator.java b/tools/org.eclipse.persistence.tools.gen.nosql/src/org/eclipse/persistence/tools/gen/nosql/mongo/MongoEntityGenerator.java
similarity index 81%
rename from tools/org.eclipse.persistence.tools.gen.nosql/src/org/eclipse/persistence/tools/gen/nosql/mongo/MongoDynamicEntityGenerator.java
rename to tools/org.eclipse.persistence.tools.gen.nosql/src/org/eclipse/persistence/tools/gen/nosql/mongo/MongoEntityGenerator.java
index f01c0e2..583abd9 100644
--- a/tools/org.eclipse.persistence.tools.gen.nosql/src/org/eclipse/persistence/tools/gen/nosql/mongo/MongoDynamicEntityGenerator.java
+++ b/tools/org.eclipse.persistence.tools.gen.nosql/src/org/eclipse/persistence/tools/gen/nosql/mongo/MongoEntityGenerator.java
@@ -13,15 +13,23 @@
* Oracle - initial API and implementation
*
******************************************************************************/
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.StringWriter;
import java.net.UnknownHostException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Properties;
import java.util.Set;
import java.util.Vector;
+import javax.persistence.AccessType;
+
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
import org.eclipse.persistence.tools.gen.nosql.mongo.meta.CollectionDescriptor;
import org.eclipse.persistence.tools.gen.nosql.mongo.meta.ColumnDescriptor;
import org.eclipse.persistence.tools.gen.nosql.mongo.meta.LeafColumnDescriptor;
@@ -37,6 +45,7 @@
import org.eclipse.persistence.tools.mapping.orm.ExternalORMConfiguration;
import org.eclipse.persistence.tools.mapping.orm.ORMDocumentType;
import org.eclipse.persistence.tools.mapping.orm.dom.ORMRepository;
+import org.eclipse.persistence.tools.utility.CollectionTools;
import org.eclipse.persistence.tools.utility.NameTools;
import com.mongodb.BasicDBList;
@@ -50,9 +59,9 @@
import com.mongodb.ServerAddress;
/**
- * This class is an entry point for dynamic entity generation for MongoDB.
- * It provides API for discovering metadata (table names, etc) and generating
- * EclipseLink JPA, NoSql, mapping files.
+ * This class is an entry point for dynamic entity xml and source generation for
+ * MongoDB. It also provides API for discovering metadata (table names, etc) and generating
+ * EclipseLink-JPA NoSql, mapping files.
* <p>
* Provisional API: This interface is part of an interim API that is still under development and
* expected to change significantly before reaching stability. It is available at this early stage
@@ -62,7 +71,7 @@
* @author John Bracken
* @version 2.5
*/
-public class MongoDynamicEntityGenerator {
+public class MongoEntityGenerator {
/** Mongo database connection to use in generation. */
private Mongo connection;
@@ -74,7 +83,7 @@
private int rowSampleSize;
/**
- * Constructs a new {@link MongoDynamicEntityGenerator} based on the provided
+ * Constructs a new {@link MongoEntityGenerator} based on the provided
* db connection information.
*
* @param host the MongoDB network host.
@@ -87,7 +96,7 @@
* @throws MongoException
* @throws UnknownHostException
*/
- public MongoDynamicEntityGenerator(String host, int port, String dbName, int rowSampleSize)
+ public MongoEntityGenerator(String host, int port, String dbName, int rowSampleSize)
throws MongoException, UnknownHostException {
super();
this.rowSampleSize = rowSampleSize;
@@ -137,18 +146,78 @@
}
/**
- * Creates an eclipselink-orm.xml descriptor mapping the provided <code>collectionNames</code>
- * as EclipseLink dynamic entities.
+ * Generates a set of EclipseLink, java entity files mapped to the underlying Mongo
+ * database for the given <code>collectionNames</code>.
*
- * @param collectionNames
- * @return a {@link String} representation of the eclipselink-orm.xml.
+ * @param collectionNames names of the Mongo collections to generate entities for.
+ * @param packageName java package to use for the generated code.
+ * @param baseDirectory the base directory to use for the generated code.
+ * @param type the access type to use (method versus field annotations).
+ *
+ * @throws Exception
*/
- public String generate(Collection<String> collectionNames) {
+ public void generateSource(Collection<String> collectionNames, String packageName,
+ File baseDirectory, AccessType type) throws Exception {
// Create metadata descriptors for the specified collections.
List<CollectionDescriptor> collectionDescriptors = buildCollectionDescriptors(collectionNames);
+ ExternalORMConfiguration config = generate(collectionDescriptors);
- // Generate an eclpselink-orm.xml from the collection descriptors
- return generateORMConfig(collectionDescriptors);
+ // Ensure that the provided gen directory and package folders exists
+ File packageDirectory = new File(baseDirectory, packageName.replace('.', '/') + "/");
+ packageDirectory.mkdirs();
+
+ // Build up the velocity generator
+ Properties vep = new Properties();
+ vep.setProperty("resource.loader", "class");
+ vep.setProperty("class.resource.loader.class",
+ "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
+ VelocityEngine ve = new VelocityEngine();
+ ve.init(vep);
+
+ // Generate source for entities
+ for (ExternalEntity entity : config.entities()) {
+ generateSource(entity, type, "entity.java.vm", packageName, packageDirectory, ve);
+ }
+
+ // Generate source for embeddables
+ for (ExternalEmbeddableEntity entity : config.embeddableEntities()) {
+ generateSource(entity, type, "embeddable.java.vm", packageName, packageDirectory, ve);
+ }
+ }
+
+ /**
+ * Generates the entity source file for the provided mapping metadata.
+ *
+ * @param entity the metadata representation of the entity.
+ * @param accessType the {@link AccessType} to use (method or field) for annotations.
+ * @param templateName the source gen template to use (embeddable, entity, etc).
+ * @param packageName the package name to use.
+ * @param packageDirectory the directory to generate the source file in.
+ * @param ve the velocity engine to use.
+ *
+ * @throws Exception
+ */
+ private void generateSource(ExternalEmbeddableEntity entity, AccessType accessType,
+ String templateName, String packageName,
+ File packageDirectory, VelocityEngine ve) throws Exception {
+ VelocityContext context = new VelocityContext();
+ context.put("entity", entity);
+ context.put("mappings", CollectionTools.list(entity.mappings()));
+ context.put("packageName", packageName);
+ context.put("accessType", accessType);
+ StringWriter w = new StringWriter();
+ ve.mergeTemplate(templateName, context, w);
+
+ String fileContent = w.toString();
+
+ File javaFile = new File(packageDirectory, entity.getClassName() + ".java");
+
+ byte[] content = fileContent.getBytes("UTF-8");
+ javaFile.createNewFile();
+ FileOutputStream writer = new FileOutputStream(javaFile);
+ writer.write(content);
+ writer.flush();
+ writer.close();
}
/**
@@ -245,6 +314,22 @@
}
/**
+ * Generates and adds a root level named query for each entity
+ * enumerate in the {@link ExternalORMConfiguration}.
+ *
+ * @param config the configuration to generate and add queries from.
+ */
+ private void generateQueries(ExternalORMConfiguration config) {
+ for (ExternalEntity entity : config.entities()) {
+ String entityName = entity.getClassName();
+ ExternalNamedQuery query = config.addNamedQuery(entityName + ".findAll");
+ char identifier = Character.toLowerCase(entityName.charAt(0));
+ query.setQuery("select " + identifier + " from " + entityName + " " + identifier);
+
+ }
+ }
+
+ /**
* Generates a {@link String} representation of an eclipselink-orm.xml descriptor based
* on the provided MongoDB {@link CollectionDescriptor} definitions.
*
@@ -252,7 +337,7 @@
*
* @return a {@link String} representation of the eclipselink-orm.xml.
*/
- private String generateORMConfig(List<CollectionDescriptor> collectionDescriptors) {
+ private ExternalORMConfiguration generate(List<CollectionDescriptor> collectionDescriptors) {
// Create a new orm.xml metadata model.
ExternalORMConfiguration config = new ORMRepository().buildORMConfiguration(ORMDocumentType.ECLIPELINK_2_4);
// track all entity names being used.
@@ -278,23 +363,22 @@
// Generate a default, read all query for all entities
generateQueries(config);
- return config.getXML();
+ return config;
}
/**
- * Generates and adds a root level named query for each entity
- * enumerate in the {@link ExternalORMConfiguration}.
+ * Creates an eclipselink-orm.xml descriptor mapping the provided <code>collectionNames</code>
+ * as EclipseLink dynamic entities.
*
- * @param config the configuration to generate and add queries from.
+ * @param collectionNames
+ * @return a {@link String} representation of the eclipselink-orm.xml.
*/
- private void generateQueries(ExternalORMConfiguration config) {
- for (ExternalEntity entity : config.entities()) {
- String entityName = entity.getClassName();
- ExternalNamedQuery query = config.addNamedQuery(entityName + ".findAll");
- char identifier = Character.toLowerCase(entityName.charAt(0));
- query.setQuery("select " + identifier + " from " + entityName + " " + identifier);
-
- }
+ public String generateXML(Collection<String> collectionNames) {
+ // Create metadata descriptors for the specified collections.
+ List<CollectionDescriptor> collectionDescriptors = buildCollectionDescriptors(collectionNames);
+
+ // Generate an eclpselink-orm.xml from the collection descriptors
+ return generate(collectionDescriptors).getXML();
}
/**
diff --git a/tools/org.eclipse.persistence.tools.gen.nosql/templates/java_entities/embeddable.java.vm b/tools/org.eclipse.persistence.tools.gen.nosql/templates/java_entities/embeddable.java.vm
new file mode 100644
index 0000000..06dec95
--- /dev/null
+++ b/tools/org.eclipse.persistence.tools.gen.nosql/templates/java_entities/embeddable.java.vm
@@ -0,0 +1,15 @@
+#if ($packageName != "")
+package ${packageName};
+#end
+
+import java.io.Serializable;
+import java.util.*;
+import javax.persistence.*;
+import org.eclipse.persistence.nosql.annotations.*;
+
+/**
+ * The persistent class generated for the "${entity.getClassName()}" nested
+ * column.
+ */
+@Embeddable
+#parse("mapped_class.java.vm")
\ No newline at end of file
diff --git a/tools/org.eclipse.persistence.tools.gen.nosql/templates/java_entities/entity.java.vm b/tools/org.eclipse.persistence.tools.gen.nosql/templates/java_entities/entity.java.vm
new file mode 100644
index 0000000..e618d86
--- /dev/null
+++ b/tools/org.eclipse.persistence.tools.gen.nosql/templates/java_entities/entity.java.vm
@@ -0,0 +1,17 @@
+#if ($packageName != "")
+package ${packageName};
+#end
+
+import java.io.Serializable;
+import java.util.*;
+import javax.persistence.*;
+import org.eclipse.persistence.nosql.annotations.*;
+import static org.eclipse.persistence.nosql.annotations.DataFormatType.*;
+
+/**
+ * The persistent class for the "${entity.getNoSql().getDataType()}" Mongo
+ * collection.
+ */
+@Entity
+@NoSql(dataFormat = MAPPED, dataType = "$entity.getNoSql().getDataType()")
+#parse("mapped_class.java.vm")
\ No newline at end of file
diff --git a/tools/org.eclipse.persistence.tools.gen.nosql/templates/java_entities/mapped_class.java.vm b/tools/org.eclipse.persistence.tools.gen.nosql/templates/java_entities/mapped_class.java.vm
new file mode 100644
index 0000000..546b361
--- /dev/null
+++ b/tools/org.eclipse.persistence.tools.gen.nosql/templates/java_entities/mapped_class.java.vm
@@ -0,0 +1,69 @@
+public class ${entity.getClassName()} implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+#####
+##### fields
+#####
+#foreach ($mapping in $mappings)
+#if ($accessType == "FIELD")
+
+#if ($mapping.isBasicMapping())
+ @Basic
+#elseif ($mapping.isIdMapping())
+ @Id
+ @GeneratedValue
+#elseif ($mapping.isEmbeddedMapping())
+ @Embedded
+#elseif ($mapping.isElementCollectionMapping())
+ @ElementCollection
+#end
+ @Field(name = "${mapping.getNoSqlField()}")
+#end
+#if ($mapping.isElementCollectionMapping())
+ private $mapping.getAttributeTypeShortName()<$mapping.getTargetClassShortName()> $mapping.getName();
+#else
+ private $mapping.getAttributeTypeShortName() $mapping.getName();
+#end
+#end
+
+ public ${entity.getClassName()}() {
+ super();
+ }
+#foreach ($mapping in $mappings)
+
+#if ($accessType == "PROPERTY")
+#if ($mapping.isBasicMapping())
+ @Basic
+#elseif ($mapping.isIdMapping())
+ @Id
+ @GeneratedValue
+#elseif ($mapping.isEmbeddedMapping())
+ @Embedded
+#elseif ($mapping.isElementCollectionMapping())
+ @ElementCollection
+#end
+ @Field(name = "${mapping.getNoSqlField()}")
+#end
+#if ($mapping.isElementCollectionMapping())
+ public $mapping.getAttributeTypeShortName()<$mapping.getTargetClassShortName()> $mapping.getGetMethodName()() {
+ return this.$mapping.getName();
+ }
+#else
+ public $mapping.getAttributeTypeShortName() $mapping.getGetMethodName()() {
+ return this.$mapping.getName();
+ }
+#end
+#end
+#foreach ($mapping in $mappings)
+
+#if ($mapping.isElementCollectionMapping())
+ public void $mapping.getSetMethodName()($mapping.getAttributeTypeShortName()<$mapping.getTargetClassShortName()> $mapping.getName()) {
+ this.$mapping.getName() = $mapping.getName();
+ }
+#else
+ public void $mapping.getSetMethodName()($mapping.getAttributeTypeShortName() $mapping.getName()) {
+ this.$mapping.getName() = $mapping.getName();
+ }
+#end
+#end
+}
\ No newline at end of file
diff --git a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/ExternalElementCollectionMapping.java b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/ExternalElementCollectionMapping.java
index 0872f1d..c5e14ff 100644
--- a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/ExternalElementCollectionMapping.java
+++ b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/ExternalElementCollectionMapping.java
@@ -101,6 +101,11 @@
* Returns the target class name for this mapping.
*/
String getTargetClassName();
+
+ /**
+ * Returns the target class short name for this mapping.
+ */
+ String getTargetClassShortName();
/**
* Indicates whether this basic mapping's column is a LOB.
diff --git a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/ExternalMapping.java b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/ExternalMapping.java
index 86eb74c..5e27acb 100644
--- a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/ExternalMapping.java
+++ b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/ExternalMapping.java
@@ -13,6 +13,11 @@
******************************************************************************/
package org.eclipse.persistence.tools.mapping.orm;
+import javax.persistence.Basic;
+import javax.persistence.ElementCollection;
+import javax.persistence.Embedded;
+import javax.persistence.Id;
+
/**
* This interface represents the basis for all mapping types defined by the JPA spec that are
* available for configuration via the ORM xml.
@@ -35,10 +40,53 @@
String getAttributeType();
/**
+ * Returns the short name of the attribute type
+ * of this mapping.
+ */
+ String getAttributeTypeShortName();
+
+ /**
* Returns the name of the mapping.
*/
String getName();
-
+
+ /**
+ * Indicates whether this mapping is of type
+ * {@link Basic}.
+ */
+ boolean isBasicMapping();
+
+ /**
+ * Indicates whether this mapping is of type
+ * {@link ElementCollection}.
+ */
+ boolean isElementCollectionMapping();
+
+ /**
+ * Indicates whether this mapping is of type
+ * {@link Embedded}.
+ */
+ boolean isEmbeddedMapping();
+
+
+ /**
+ * Derives a getter method name for this mapping's
+ * attribute.
+ */
+ String getGetMethodName();
+
+ /**
+ * Derives a setter method name for this mapping's
+ * attribute.
+ */
+ String getSetMethodName();
+
+ /**
+ * Indicates whether this mapping is of type
+ * {@link Id}.
+ */
+ boolean isIdMapping();
+
/**
* Sets the attribute type of this mapping.
*/
diff --git a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/BasicMapping.java b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/BasicMapping.java
index c0874e6..51ca0e2 100644
--- a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/BasicMapping.java
+++ b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/BasicMapping.java
@@ -284,6 +284,14 @@
* {@inheritDoc}
*/
@Override
+ public final boolean isBasicMapping() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public Boolean isLob() {
return getChildBooleanNode(LOB);
}
diff --git a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/ElementCollectionMapping.java b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/ElementCollectionMapping.java
index daf1e54..972be04 100644
--- a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/ElementCollectionMapping.java
+++ b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/ElementCollectionMapping.java
@@ -32,6 +32,7 @@
import org.eclipse.persistence.tools.mapping.orm.ExternalOrderColumn;
import org.eclipse.persistence.tools.mapping.orm.ExternalStructConverter;
import org.eclipse.persistence.tools.mapping.orm.ExternalTypeConverter;
+import org.eclipse.persistence.tools.utility.ClassName;
import org.eclipse.persistence.tools.utility.iterables.ListIterable;
import org.eclipse.persistence.tools.utility.iterables.ListListIterable;
import org.w3c.dom.Element;
@@ -624,6 +625,14 @@
public String getTargetClassName() {
return getAttribute(TARGET_CLASS);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getTargetClassShortName() {
+ return ClassName.getSimpleName(getTargetClassName());
+ }
/**
* {@inheritDoc}
@@ -632,6 +641,14 @@
public TemporalType getTemporalType() {
return getChildEnumNode(TEMPORAL, TemporalType.class);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isElementCollectionMapping() {
+ return true;
+ }
/**
* {@inheritDoc}
diff --git a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/EmbeddableEntity.java b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/EmbeddableEntity.java
index 8ce5870..c2d757c 100644
--- a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/EmbeddableEntity.java
+++ b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/EmbeddableEntity.java
@@ -41,6 +41,7 @@
import org.eclipse.persistence.tools.mapping.orm.ExternalStructConverter;
import org.eclipse.persistence.tools.mapping.orm.ExternalTransientMapping;
import org.eclipse.persistence.tools.mapping.orm.ExternalTypeConverter;
+import org.eclipse.persistence.tools.utility.CollectionTools;
import org.eclipse.persistence.tools.utility.Tools;
import org.eclipse.persistence.tools.utility.iterables.EmptyListIterable;
import org.eclipse.persistence.tools.utility.iterables.ListIterable;
@@ -719,6 +720,10 @@
return buildInstantiationCopyPolicy();
}
+
+ public final List<ExternalMapping> getMappings() {
+ return CollectionTools.list(mappings());
+ }
/**
* {@inheritDoc}
@@ -846,7 +851,7 @@
public final Boolean isMetadataComplete() {
return getBooleanAttribute(METADATA_COMPLETE);
}
-
+
/**
* {@inheritDoc}
*/
diff --git a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/EmbeddedMapping.java b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/EmbeddedMapping.java
index e73493b..c1e1339 100644
--- a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/EmbeddedMapping.java
+++ b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/EmbeddedMapping.java
@@ -210,6 +210,14 @@
ExternalNoSqlField field = buildNoSqlField();
return field.getName();
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final boolean isEmbeddedMapping() {
+ return true;
+ }
/**
* {@inheritDoc}
diff --git a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/IdMapping.java b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/IdMapping.java
index 831859f..4763c17 100644
--- a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/IdMapping.java
+++ b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/IdMapping.java
@@ -224,6 +224,14 @@
public TemporalType getTemporalType() {
return getChildEnumNode(TEMPORAL, TemporalType.class);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final boolean isIdMapping() {
+ return true;
+ }
/**
* {@inheritDoc}
diff --git a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/Mapping.java b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/Mapping.java
index e204c20..1eefe57 100644
--- a/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/Mapping.java
+++ b/tools/org.eclipse.persistence.tools.mapping/src/org/eclipse/persistence/tools/mapping/orm/dom/Mapping.java
@@ -17,6 +17,8 @@
import java.util.List;
import org.eclipse.persistence.tools.mapping.orm.ExternalMapping;
+import org.eclipse.persistence.tools.utility.ClassName;
+import org.eclipse.persistence.tools.utility.NameTools;
import org.w3c.dom.Element;
/**
@@ -106,6 +108,14 @@
public final String getAttributeType() {
return getAttribute(ATTRIBUTE_TYPE);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final String getAttributeTypeShortName() {
+ return ClassName.getSimpleName(getAttributeType());
+ }
/**
* {@inheritDoc}
@@ -121,6 +131,14 @@
return getChild(element, index);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final String getGetMethodName() {
+ return NameTools.javabeanAccessorName("get", getName(), "");
+ }
/**
* Returns the position of this external form within the list of children owned by the parent.
@@ -151,6 +169,46 @@
* {@inheritDoc}
*/
@Override
+ public final String getSetMethodName() {
+ return NameTools.javabeanAccessorName("set", getName(), "");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isBasicMapping() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isElementCollectionMapping() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isEmbeddedMapping() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isIdMapping() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public final void removeSelf() {
Element element = getChild(getParent(), ATTRIBUTES);
diff --git a/tools/org.eclipse.persistence.tools.utility/src/org/eclipse/persistence/tools/utility/NameTools.java b/tools/org.eclipse.persistence.tools.utility/src/org/eclipse/persistence/tools/utility/NameTools.java
index 82c8d81..0257aeb 100644
--- a/tools/org.eclipse.persistence.tools.utility/src/org/eclipse/persistence/tools/utility/NameTools.java
+++ b/tools/org.eclipse.persistence.tools.utility/src/org/eclipse/persistence/tools/utility/NameTools.java
@@ -200,7 +200,48 @@
*/
public static final SortedSet<String> JAVA_RESERVED_WORDS_SET =
Collections.unmodifiableSortedSet(CollectionTools.sortedSet(JAVA_RESERVED_WORDS));
+
+ /**
+ * Generates a javabean compliant method name based on the provided
+ * property name. Does not alter the case of the property name if the
+ * second character is capitalized, e.g.:
+ * <ul>
+ * <li>javabeanMethodName("get", "URL", "") produces "getURL"
+ * <li>javabeanMethodName("get", "fName", "") produces "getfName"
+ * <li>javabeanMethodName("get", "fname", "") produces "getFname"
+ * <li>javabeanMethodName("get", "firstName", "") produces "getFirstName"
+ * </ul>
+ *
+ * The "fName" example in particular may seem strange, but is required by
+ * JDev ADF interpretation of the JavaBean naming conventions.
+ * See bug #4572393.
+ *
+ * @param prefix - <code>String</code> representing the prefix for the
+ * method name (for example, "get" to produce a getter
+ * method).
+ * @param propertyName - <code>String</code> representing the name of the
+ * property for which an accessor name is being generated.
+ * @param suffix - <code>String</code> representing the suffix for the
+ * accessor being generated (for example, "Holder" for
+ * ValueHolder accessors).
+ */
+ public static String javabeanAccessorName(String prefix, String propertyName, String suffix) {
+ StringBuilder sb = new StringBuilder(propertyName.length() + 10);
+ sb.append(prefix);
+ if (propertyName.length() >= 2
+ && Character.isUpperCase(propertyName.charAt(1)))
+ {
+ sb.append(propertyName);
+ }
+ else
+ {
+ StringTools.capitalizeOn(propertyName, sb);
+ }
+ sb.append(suffix);
+ return sb.toString();
+ }
+
/**
* Generates a Java identifier name based on the provided database name.
* Camel-cases the Java identifier on _ characters and on characters that