Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Taal2012-05-31 07:33:40 -0400
committerMartin Taal2012-05-31 07:33:40 -0400
commitf398d8eb045d1c26221ca89b16596018166a3a9d (patch)
treec50558ad014aedb9ccd821b6e7149d0b2162be9b /generator/org.eclipse.emf.texo.orm
parente94fb64274d0aa2ff51ce77d100fa1a2e9b180d7 (diff)
downloadorg.eclipse.emf.texo-f398d8eb045d1c26221ca89b16596018166a3a9d.tar.gz
org.eclipse.emf.texo-f398d8eb045d1c26221ca89b16596018166a3a9d.tar.xz
org.eclipse.emf.texo-f398d8eb045d1c26221ca89b16596018166a3a9d.zip
Implemented integration between project properties and code generation
Diffstat (limited to 'generator/org.eclipse.emf.texo.orm')
-rw-r--r--generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/GenerateModelJPACode.java2
-rwxr-xr-xgenerator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMGenerator.java19
-rw-r--r--generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMMappingOptions.java9
-rw-r--r--generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMUtils.java63
-rw-r--r--generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/reserved-sql-words.txt1
-rwxr-xr-xgenerator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/ormannotations/EPackageORMAnnotation.java32
6 files changed, 110 insertions, 16 deletions
diff --git a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/GenerateModelJPACode.java b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/GenerateModelJPACode.java
index a1b1130d..ca882a0c 100644
--- a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/GenerateModelJPACode.java
+++ b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/GenerateModelJPACode.java
@@ -34,9 +34,11 @@ public class GenerateModelJPACode extends GenerateCode {
@Override
protected void generateFromUris(IProgressMonitor monitor, IProject project, List<URI> uris) {
try {
+ ORMUtils.setORMMappingOptionsFromProjectProperties(project);
AnnotationManager.enableAnnotationSystem(AnnotationManager.JPA_ANNOTATION_SYSTEM_ID);
super.generateFromUris(monitor, project, uris);
} finally {
+ ORMMappingOptions.setDefaultOptions(null);
AnnotationManager.removeEnabledAnnotationSystem(AnnotationManager.JPA_ANNOTATION_SYSTEM_ID);
}
}
diff --git a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMGenerator.java b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMGenerator.java
index 5847a63d..6c5b27b5 100755
--- a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMGenerator.java
+++ b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMGenerator.java
@@ -174,13 +174,20 @@ public class ORMGenerator extends BaseGenerateAction {
}
protected void generateFromURI(IProgressMonitor monitor, IProject project, java.net.URI uri) {
- // always start with a fresh epackage registry
- final List<EPackage> ePackages = GeneratorUtils.readEPackages(Collections.singletonList(uri),
- GeneratorUtils.createEPackageRegistry());
- final URI parentUri = URI.createURI(uri.toString()).trimSegments(1);
- final URI ormUri = parentUri.appendSegment(ORM_FILE_NAME);
- generateStoreORM(ePackages, ormUri);
+ ORMUtils.setORMMappingOptionsFromProjectProperties(project);
+
+ try {
+ // always start with a fresh epackage registry
+ final List<EPackage> ePackages = GeneratorUtils.readEPackages(Collections.singletonList(uri),
+ GeneratorUtils.createEPackageRegistry());
+
+ final URI parentUri = URI.createURI(uri.toString()).trimSegments(1);
+ final URI ormUri = parentUri.appendSegment(ORM_FILE_NAME);
+ generateStoreORM(ePackages, ormUri);
+ } finally {
+ ORMMappingOptions.setDefaultOptions(null);
+ }
}
public ModelController generateStoreORM(List<EPackage> ePackages, URI ormUri) {
diff --git a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMMappingOptions.java b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMMappingOptions.java
index 384e6d17..53976a91 100644
--- a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMMappingOptions.java
+++ b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMMappingOptions.java
@@ -34,6 +34,7 @@ public class ORMMappingOptions {
ORMMappingOptions.defaultOptions = defaultOptions;
}
+ private boolean testRun = false;
private boolean addOrderColumnToListMappings = false;
private boolean enforceUniqueNames = false;
private boolean renameSQLReservedNames = false;
@@ -80,4 +81,12 @@ public class ORMMappingOptions {
this.maximumSqlNameLength = maximumSqlNameLength;
}
+ public boolean isTestRun() {
+ return testRun;
+ }
+
+ public void setTestRun(boolean testRun) {
+ this.testRun = testRun;
+ }
+
} \ No newline at end of file
diff --git a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMUtils.java b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMUtils.java
new file mode 100644
index 00000000..c483ae53
--- /dev/null
+++ b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMUtils.java
@@ -0,0 +1,63 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2012 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: GenerateModelJPACode.java,v 1.1 2011/10/26 05:29:39 mtaal Exp $
+ */
+package org.eclipse.emf.texo.orm.annotator;
+
+import java.util.Properties;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.texo.component.ComponentProvider;
+import org.eclipse.emf.texo.eclipse.ProjectPropertyUtil;
+import org.eclipse.emf.texo.orm.ormannotations.EPackageORMAnnotation;
+
+/**
+ * ORM utility methods
+ *
+ * @author mtaal
+ */
+public class ORMUtils {
+
+ /**
+ * Reads project properties and creates a {@link ORMMappingOptions} object and sets it in the
+ * {@link ORMMappingOptions#setDefaultOptions(ORMMappingOptions)}. This is picked up during ORM and JPA code
+ * generation if there is no {@link EPackageORMAnnotation} for an {@link EPackage}.
+ */
+ public static void setORMMappingOptionsFromProjectProperties(IProject project) {
+ final Properties props = ProjectPropertyUtil.getProjectProperties(project);
+ final ORMMappingOptions options = ComponentProvider.getInstance().newInstance(ORMMappingOptions.class);
+ options.setAddOrderColumnToListMappings(isTrue(props.getProperty(ProjectPropertyUtil.ORM_ADD_ORDER_COLUMN)));
+ options.setEnforceUniqueNames(isTrue(props.getProperty(ProjectPropertyUtil.ORM_ENFORCE_UNIQUE_NAMES)));
+ options.setGenerateFullDbSchemaNames(isTrue(props
+ .getProperty(ProjectPropertyUtil.ORM_GENERATE_FULL_DB_SCHEMA_NAMES)));
+ options.setRenameSQLReservedNames(isTrue(props.getProperty(ProjectPropertyUtil.ORM_RENAME_SQL_RESERVED_NAMES)));
+ if (props.getProperty(ProjectPropertyUtil.ORM_MAX_SQL_NAME_LENGTH) != null) {
+ try {
+ int val = Integer.parseInt(props.getProperty(ProjectPropertyUtil.ORM_MAX_SQL_NAME_LENGTH));
+ if (val > 0) {
+ options.setMaximumSqlNameLength(val);
+ }
+ } catch (NumberFormatException e) {
+ // do nothing
+ }
+ }
+ ORMMappingOptions.setDefaultOptions(options);
+ }
+
+ private static boolean isTrue(String value) {
+ return value != null && value.equals("true");
+ }
+}
diff --git a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/reserved-sql-words.txt b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/reserved-sql-words.txt
index 57d012c4..f9e7c561 100644
--- a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/reserved-sql-words.txt
+++ b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/reserved-sql-words.txt
@@ -1,4 +1,3 @@
-
A
ABORT
ABS
diff --git a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/ormannotations/EPackageORMAnnotation.java b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/ormannotations/EPackageORMAnnotation.java
index 1f1d8661..bd5fefc6 100755
--- a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/ormannotations/EPackageORMAnnotation.java
+++ b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/ormannotations/EPackageORMAnnotation.java
@@ -344,22 +344,36 @@ public class EPackageORMAnnotation extends EPackageAnnotation implements ENamedE
// set some defaults which help to run
// different testcases or are read from the project
// properties
- if (ORMMappingOptions.getDefaultOptions() != null) {
+ if (ORMMappingOptions.getDefaultOptions() != null && ORMMappingOptions.getDefaultOptions().isTestRun()) {
final ORMMappingOptions options = ORMMappingOptions.getDefaultOptions();
- // otherwise order of lists is not maintained
- addOrderColumnToListMappings = options.isAddOrderColumnToListMappings();
- enforceUniqueNames = options.isEnforceUniqueNames();
- renameSQLReservedNames = options.isRenameSQLReservedNames();
- generateFullDbSchemaNames = options.isGenerateFullDbSchemaNames();
- if (options.getMaximumSqlNameLength() > 0) {
- maximumSqlNameLength = options.getMaximumSqlNameLength();
- }
+ applyMappingOptions(options);
}
namingStrategy = ORMNamingStrategyProvider.getInstance().createORMNamingStrategy(this);
generateJavaAnnotations = AnnotationManager.isAnnotationSystemEnabled("jpa"); //$NON-NLS-1$
}
+ @Override
+ public void setGenerated(boolean newGenerated) {
+ if (newGenerated && ORMMappingOptions.getDefaultOptions() != null) {
+ final ORMMappingOptions options = ORMMappingOptions.getDefaultOptions();
+ applyMappingOptions(options);
+ }
+
+ super.setGenerated(newGenerated);
+ }
+
+ public void applyMappingOptions(ORMMappingOptions options) {
+ // otherwise order of lists is not maintained
+ addOrderColumnToListMappings = options.isAddOrderColumnToListMappings();
+ enforceUniqueNames = options.isEnforceUniqueNames();
+ renameSQLReservedNames = options.isRenameSQLReservedNames();
+ generateFullDbSchemaNames = options.isGenerateFullDbSchemaNames();
+ if (options.getMaximumSqlNameLength() > 0) {
+ maximumSqlNameLength = options.getMaximumSqlNameLength();
+ }
+ }
+
public ORMNamingStrategy getNamingStrategy() {
return namingStrategy;
}

Back to the top