Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormtaal2007-03-29 15:00:51 +0000
committermtaal2007-03-29 15:00:51 +0000
commit4048efca7249c9215c0093fbc2b20c43039df323 (patch)
tree118dae4b46fada6bf3a1791a88c5f86600f58c03
parent9f450b24fd410fba75cf1041a21837b0912ab8d1 (diff)
downloadorg.eclipse.emf.teneo-4048efca7249c9215c0093fbc2b20c43039df323.tar.gz
org.eclipse.emf.teneo-4048efca7249c9215c0093fbc2b20c43039df323.tar.xz
org.eclipse.emf.teneo-4048efca7249c9215c0093fbc2b20c43039df323.zip
[177370]
[179446] [177369]
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/ERuntime.java25
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/PersistenceOptions.java58
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/ecore/DefaultEClassNameStrategy.java191
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/util/StoreUtil.java6
4 files changed, 168 insertions, 112 deletions
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/ERuntime.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/ERuntime.java
index 48d109a05..0218ece52 100644
--- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/ERuntime.java
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/ERuntime.java
@@ -12,7 +12,7 @@
*
* </copyright>
*
- * $Id: ERuntime.java,v 1.6 2007/02/08 23:14:41 mtaal Exp $
+ * $Id: ERuntime.java,v 1.7 2007/03/29 15:00:51 mtaal Exp $
*/
package org.eclipse.emf.teneo;
@@ -44,7 +44,7 @@ import org.eclipse.emf.teneo.util.StoreUtil;
* contained computations.
*
* @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
- * @version $Revision: 1.6 $
+ * @version $Revision: 1.7 $
*/
public class ERuntime {
@@ -313,6 +313,11 @@ public class ERuntime {
return (EPackage[]) epackages.toArray(new EPackage[epackages.size()]);
}
+ /** Returns true if the epackage is registered here */
+ public boolean isRegistered(EPackage epackage) {
+ return epackages.contains(epackage);
+ }
+
/** Convenience method to easily determine which packages should be ignored */
private static boolean ignorePackage(EPackage epack) {
if (epack instanceof XMLTypePackageImpl)
@@ -338,6 +343,11 @@ public class ERuntime {
}
return (Class<?>) eclassToConcrete.get(eclass);
}
+
+ /** Returns the interface class for a passed eclass */
+ public Class<?> getInterfaceClass(EClass eclass) {
+ return eclass.getInstanceClass();
+ }
/** Get the eclass for a certain class */
public EClass getEClass(Class<?> clazz) {
@@ -346,6 +356,17 @@ public class ERuntime {
}
return (EClass) concreteToEClass.get(clazz);
}
+
+ /** Get the eclass for a certain class name */
+ public EClass getEClass(String classname) {
+ try {
+ return getEClass(Class.forName(classname));
+ } catch (ClassNotFoundException e) {
+ log.debug("Failed to retreive ECLass for name: " + classname);
+
+ return null;
+ }
+ }
/**
* Returns the structural feature for a certain field and object comby. Null
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/PersistenceOptions.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/PersistenceOptions.java
index 76eb321f0..fe283dedd 100644
--- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/PersistenceOptions.java
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/PersistenceOptions.java
@@ -12,7 +12,7 @@
*
* </copyright>
*
- * $Id: PersistenceOptions.java,v 1.23 2007/03/21 15:45:26 mtaal Exp $
+ * $Id: PersistenceOptions.java,v 1.24 2007/03/29 15:00:51 mtaal Exp $
*/
package org.eclipse.emf.teneo;
@@ -39,7 +39,7 @@ import org.eclipse.emf.teneo.util.SQLCaseStrategyImpl;
* As a convenience, this class offers type-safe property accessor wrappers.
*
* @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
- * @version $Revision: 1.23 $
+ * @version $Revision: 1.24 $
*/
public class PersistenceOptions {
@@ -113,13 +113,6 @@ public class PersistenceOptions {
public static final String MAP_ALL_LISTS_AS_IDBAG = MAPPING_PREFIX
+ "map_all_lists_as_idbag";
- /** The proxy strategy, can be none (no proxies, default), emf, hibernate */
- public static final String PROXY_STRATEGY = MAPPING_PREFIX
- + "proxy_strategy";
- public static final String PROXY_STRATEGY_NONE = "none";
- public static final String PROXY_STRATEGY_EMF = "emf";
- public static final String PROXY_STRATEGY_HIBERNATE = "hibernate";
-
/** Use static hibernate mapping file */
public static final String USE_MAPPING_FILE = MAPPING_PREFIX
+ "hibernate_mapping_file";
@@ -162,7 +155,7 @@ public class PersistenceOptions {
+ "ignore_eannotations";
/**
- * Map als emaps as true hibernate maps, default is false. In EMF an EMap is
+ * Map all emaps as true hibernate maps, default is false. In EMF an EMap is
* in fact an EList with Map entries. Originally Teneo maps this as a
* hibernate list. In the new behavior hibernate can map the emap as a real
* map. The default is false (to support previous behavior).
@@ -171,6 +164,27 @@ public class PersistenceOptions {
+ "emap_as_true_map";
/**
+ * This option controls if in case of hibernate also a name attribute should be added
+ * to the class/subclass tag. By adding this a class is mapped as an entity as well as a normal class.
+ * Also mapping as a normal class has the advantage that proxies can be used and that queries can use
+ * actual class names and interface names.
+ * This option is really there for backward compatibility. There are no apparent dis-advantages of
+ * adding a name attribute so the default of this option is true.
+ * Note that an eclass must have an implementation class otherwise this option has no effect.
+ * Interfaces are for example always mapped as an entity.
+ */
+ public static final String ALSO_MAP_AS_CLASS = MAPPING_PREFIX
+ + "also_map_as_class";
+
+ /**
+ * This option controls if as a default all classes should be proxied (for hibernate). This means that you
+ * don't need to add a @Proxy annotation to each eclass. As a default Teneo will use the
+ * eclass interface as the proxy class.
+ * When this is set to true then the option ALSO_MAP_AS_CLASS should also be true.
+ */
+ public static final String SET_PROXY = MAPPING_PREFIX + "set_proxy";
+
+ /**
* Truncate the column name if the length is larger than this property. In
* case of concatenating property names for foreign keys
*/
@@ -232,7 +246,6 @@ public class PersistenceOptions {
props.setProperty(UPDATE_SCHEMA, "true");
props.setProperty(FETCH_CONTAINMENT_EAGERLY, "false");
props.setProperty(USE_IMPLEMENTATION_CLASSES_AS_ENTITYNAME, "false");
- props.setProperty(PROXY_STRATEGY, PROXY_STRATEGY_NONE);
props.setProperty(SET_ENTITY_AUTOMATICALLY, "true");
props.setProperty(VERSION_COLUMN_NAME, "e_version");
props.setProperty(SQL_CASE_STRATEGY, "lowercase");
@@ -248,6 +261,8 @@ public class PersistenceOptions {
props.setProperty(ID_FEATURE_AS_PRIMARY_KEY, "true");
props.setProperty(EMAP_AS_TRUE_MAP, "true");
props.setProperty(ALWAYS_MAP_LIST_AS_BAG, "false");
+ props.setProperty(ALSO_MAP_AS_CLASS, "true");
+ props.setProperty(SET_PROXY, "false");
props.setProperty(MAP_ALL_LISTS_AS_IDBAG, "false");
props.setProperty(IDBAG_ID_COLUMN_NAME, "ID");
return props;
@@ -333,6 +348,22 @@ public class PersistenceOptions {
}
/**
+ * Returns the value of the ALSO_MAP_AS_CLASS option, default is false
+ */
+ public boolean isAlsoMapAsClass() {
+ return Boolean.valueOf(properties.getProperty(ALSO_MAP_AS_CLASS))
+ .booleanValue();
+ }
+
+ /**
+ * Returns true if the proxy annotation should be added automatically
+ */
+ public boolean isSetProxy() {
+ return Boolean.valueOf(properties.getProperty(SET_PROXY))
+ .booleanValue();
+ }
+
+ /**
* Returns the value of the ALWAYS_MAP_LIST_AS_BAG option, default is false
*/
public boolean alwaysMapListAsBag() {
@@ -387,11 +418,6 @@ public class PersistenceOptions {
}
/** Returns the value of the UpdateSchema option, default is true */
- public String getProxyStrategy() {
- return properties.getProperty(PROXY_STRATEGY);
- }
-
- /** Returns the value of the UpdateSchema option, default is true */
public boolean isUpdateSchema() {
return Boolean.valueOf(properties.getProperty(UPDATE_SCHEMA))
.booleanValue();
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/ecore/DefaultEClassNameStrategy.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/ecore/DefaultEClassNameStrategy.java
index 0dead35b4..248a3ead7 100644
--- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/ecore/DefaultEClassNameStrategy.java
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/ecore/DefaultEClassNameStrategy.java
@@ -1,92 +1,99 @@
-package org.eclipse.emf.teneo.ecore;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EcorePackage;
-
-/**
- * This implementation assumes that EClass names are unique. It will (de)Resolve
- * using the EClass name.
- * <p>
- * TODO: Should be moved to Teneo project.
- *
- * @author <a href="lmfridael@elver.org">Laurens Fridael</a>
- * @author <a href="mtaal@elver.org">Martin Taal</a>
- */
-public class DefaultEClassNameStrategy implements EClassNameStrategy {
-
- /** The singleton instance as it is thread safe */
- public static final DefaultEClassNameStrategy INSTANCE = new DefaultEClassNameStrategy();
-
- /*
- * (non-Javadoc)
- *
- * @see org.elver.ecore.spring.EClassResolver#deResolve(org.eclipse.emf.ecore.EClass)
- */
- public String toUniqueName(EClass eClass) {
- if (eClass == EOBJECT_ECLASS) {
- return EOBJECT_ECLASS_NAME;
- }
-
- if (eClass == null) {
- throw new IllegalArgumentException(
- "Passed eclass is null."
- + "This can occur if epackages which refer to eachother are placed in different ecore/xsd files "
- + "and they are not read using one resource set. The reference from one epackage to another must be "
- + "resolvable by EMF.");
- }
-
- if (eClass.getName() == null) {
- throw new IllegalArgumentException(
- "EClass "
- + eClass.toString()
- + " has a null name."
- + "This can occur if epackages which refer to eachother are placed in different ecore/xsd files "
- + "and they are not read using one resource set. The reference from one epackage to another must be "
- + "resolvable by EMF.");
- }
- return eClass.getName();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.elver.ecore.spring.EClassResolver#resolve(java.lang.String)
- */
- public EClass toEClass(String eClassName, EPackage[] epackages) {
- if (eClassName == null) {
- throw new IllegalArgumentException("eClassName may not be null");
- }
-
- if (eClassName.compareTo(EOBJECT_ECLASS_NAME) == 0) {
- return EcorePackage.eINSTANCE.getEObject();
- }
-
- // now try all epackages
- EClass eClass = null;
- for (int i = 0; i < epackages.length; i++) {
- final EPackage ePackage = epackages[i];
- final EClassifier eClassifier = ePackage.getEClassifier(eClassName);
- if (eClassifier instanceof EClass) {
- if (eClass != null) {
- // doubly entry! Actually require different resolver
- throw new IllegalArgumentException(
- "There is more than one EClass with the same name ("
- + eClassName
- + " in EPackage "
- + eClass.getEPackage().getName()
- + " and "
- + ePackage.getName()
- + ". A different EClassResolver should be used.");
- }
- eClass = (EClass) eClassifier;
- }
- }
- if (eClass == null) {
- throw new IllegalArgumentException("No EClass found using "
- + eClassName);
- }
- return eClass;
- }
-}
+package org.eclipse.emf.teneo.ecore;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.teneo.ERuntime;
+
+/**
+ * This implementation assumes that EClass names are unique. It will (de)Resolve
+ * using the EClass name.
+ * <p>
+ * TODO: Should be moved to Teneo project.
+ *
+ * @author <a href="lmfridael@elver.org">Laurens Fridael</a>
+ * @author <a href="mtaal@elver.org">Martin Taal</a>
+ */
+public class DefaultEClassNameStrategy implements EClassNameStrategy {
+
+ /** The singleton instance as it is thread safe */
+ public static final DefaultEClassNameStrategy INSTANCE = new DefaultEClassNameStrategy();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.elver.ecore.spring.EClassResolver#deResolve(org.eclipse.emf.ecore.EClass)
+ */
+ public String toUniqueName(EClass eClass) {
+ if (eClass == EOBJECT_ECLASS) {
+ return EOBJECT_ECLASS_NAME;
+ }
+
+ if (eClass == null) {
+ throw new IllegalArgumentException(
+ "Passed eclass is null."
+ + "This can occur if epackages which refer to eachother are placed in different ecore/xsd files "
+ + "and they are not read using one resource set. The reference from one epackage to another must be "
+ + "resolvable by EMF.");
+ }
+
+ if (eClass.getName() == null) {
+ throw new IllegalArgumentException(
+ "EClass "
+ + eClass.toString()
+ + " has a null name."
+ + "This can occur if epackages which refer to eachother are placed in different ecore/xsd files "
+ + "and they are not read using one resource set. The reference from one epackage to another must be "
+ + "resolvable by EMF.");
+ }
+ return eClass.getName();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.elver.ecore.spring.EClassResolver#resolve(java.lang.String)
+ */
+ public EClass toEClass(String eClassName, EPackage[] epackages) {
+ if (eClassName == null) {
+ throw new IllegalArgumentException("eClassName may not be null");
+ }
+
+ if (eClassName.compareTo(EOBJECT_ECLASS_NAME) == 0) {
+ return EcorePackage.eINSTANCE.getEObject();
+ }
+
+ // now try all epackages
+ EClass eClass = null;
+ for (int i = 0; i < epackages.length; i++) {
+ final EPackage ePackage = epackages[i];
+ final EClassifier eClassifier = ePackage.getEClassifier(eClassName);
+ if (eClassifier instanceof EClass) {
+ if (eClass != null) {
+ // doubly entry! Actually require different resolver
+ throw new IllegalArgumentException(
+ "There is more than one EClass with the same name ("
+ + eClassName
+ + " in EPackage "
+ + eClass.getEPackage().getName()
+ + " and "
+ + ePackage.getName()
+ + ". A different EClassResolver should be used.");
+ }
+ eClass = (EClass) eClassifier;
+ }
+ }
+
+ // we didn'y find it, perhaps it is fully qualified, lets try by full class name
+ if (eClass == null) {
+ eClass = ERuntime.INSTANCE.getEClass(eClassName);
+ }
+
+ if (eClass == null) {
+ throw new IllegalArgumentException("No EClass found using "
+ + eClassName);
+ }
+ return eClass;
+ }
+}
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/util/StoreUtil.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/util/StoreUtil.java
index f4753d254..f45ee977d 100644
--- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/util/StoreUtil.java
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/util/StoreUtil.java
@@ -12,7 +12,7 @@
*
* </copyright>
*
- * $Id: StoreUtil.java,v 1.13 2007/03/18 19:18:25 mtaal Exp $
+ * $Id: StoreUtil.java,v 1.14 2007/03/29 15:00:51 mtaal Exp $
*/
package org.eclipse.emf.teneo.util;
@@ -51,7 +51,7 @@ import org.eclipse.emf.teneo.StoreException;
* Contains different util methods.
*
* @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
- * @version $Revision: 1.13 $
+ * @version $Revision: 1.14 $
*/
public class StoreUtil {
@@ -584,6 +584,8 @@ public class StoreUtil {
// walk through all the classnames
final ArrayList<String> newPackagePathList = new ArrayList<String>();
newPackagePathList.add(File.pathSeparator); // add the root package
+
+ // TODO: move this to the EModelResolver!
final ArrayList<Class<?>> allClasses = new ArrayList<Class<?>>(
ERuntime.INSTANCE.getAllInterfaces());
allClasses.addAll(ERuntime.INSTANCE.getAllConcreteClasses());

Back to the top