db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r178637 - in /incubator/jdo/trunk/core20/src/java/org/apache/jdo: impl/model/jdo/ impl/model/jdo/caching/ model/jdo/
Date Thu, 26 May 2005 14:17:11 GMT
Author: mbo
Date: Thu May 26 07:17:09 2005
New Revision: 178637

URL: http://svn.apache.org/viewcvs?rev=178637&view=rev
Log:
Add support for short names in JDOModel

Modified:
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/JDOClassImplDynamic.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/JDOModelImplDynamic.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/caching/JDOClassImplCaching.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelImplCaching.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/jdo/JDOClass.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/jdo/JDOModel.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/jdo/JDOModel.jpg
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/jdo/JDOModel.mdl

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/JDOClassImplDynamic.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/JDOClassImplDynamic.java?rev=178637&r1=178636&r2=178637&view=diff
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/JDOClassImplDynamic.java
(original)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/JDOClassImplDynamic.java
Thu May 26 07:17:09 2005
@@ -32,6 +32,7 @@
 import org.apache.jdo.model.jdo.JDOPackage;
 
 import org.apache.jdo.util.I18NHelper;
+import org.apache.jdo.util.StringHelper;
 
 /**
  * An instance of this class represents the JDO metadata of a persistence 
@@ -47,12 +48,15 @@
  *
  * @author Michael Bouschen
  * @since 1.1
- * @version 1.1
+ * @version 2.0
  */
 public class JDOClassImplDynamic
     extends JDOMemberImpl
     implements JDOClass
 {
+    /** Property shortName. It defaults to the unqualified class name. */
+    protected String shortName;
+
     /** Property identityType. Default see {@link #getIdentityType}. */
     protected int identityType = JDOIdentityType.UNSPECIFIED;
 
@@ -102,6 +106,28 @@
     protected final static I18NHelper msg =  
         I18NHelper.getInstance(JDOClassImplDynamic.class);
 
+    /** 
+     * Get the short name of this JDOClass. The short name defaults to the
+     * unqualified class name, if not explicitly set by method
+     * {@link #setShortName(String shortName)}.
+     * @return the short name of this JDOClass.
+     */
+    public String getShortName() {
+        if (shortName != null)
+            // return short name, if explicitly set by the setter
+            return shortName;
+
+        return StringHelper.getShortClassName(getName());
+    }
+    
+    /** 
+     * Set the short name of this JDOClass.
+     * @param shortName the short name.
+     */
+    public void setShortName(String shortName) {
+        this.shortName = shortName;
+    }
+    
     /** 
      * Get the JDO identity type of this JDOClass.
      * The identity type of the least-derived persistence-capable class defines

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/JDOModelImplDynamic.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/JDOModelImplDynamic.java?rev=178637&r1=178636&r2=178637&view=diff
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/JDOModelImplDynamic.java
(original)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/JDOModelImplDynamic.java
Thu May 26 07:17:09 2005
@@ -47,7 +47,9 @@
 import org.apache.jdo.model.jdo.JDOModel;
 import org.apache.jdo.model.jdo.JDOModelFactory;
 import org.apache.jdo.model.jdo.JDOPackage;
+
 import org.apache.jdo.util.I18NHelper;
+import org.apache.jdo.util.StringHelper;
 
 import org.xml.sax.SAXException;
 import org.xml.sax.InputSource;
@@ -88,7 +90,7 @@
  *
  * @author Michael Bouschen
  * @since 1.1
- * @version 1.1
+ * @version 2.0
  */
 public class JDOModelImplDynamic extends JDOElementImpl implements JDOModel {
 
@@ -190,7 +192,7 @@
      * the existing instance is returned. Otherwise, it creates a new JDOClass 
      * instance, sets its declaringModel and returns the new instance.
      * <p>
-     * Whether this method reads XML metatdata or not is deteremined at
+     * Whether this method reads XML metatdata or not is determined at
      * JDOModel creation time (see flag <code>loadXMLMetadataDefault</code> 
      * in {@link JDOModelFactory#getJDOModel(JavaModel javaModel, boolean
      * loadXMLMetadataDefault)}). Invoking this method is method is equivalent
@@ -241,9 +243,9 @@
      * qualified class name if present. The method returns <code>null</code>

      * if it cannot find a JDOClass instance for the specified name. 
      * <p>
-     * Whether this method reads XML metatdata or not is deteremined at
+     * Whether this method reads XML metatdata or not is determined at
      * JDOModel creation time (see flag <code>loadXMLMetadataDefault</code> 
-     * in {@link JDOModelFactory#getJDOModel(JavaModel javaModel, boolean
+     * in {@link JDOModelFactory#getJDOModel(JavaModel javaModel, boolean 
      * loadXMLMetadataDefault)}). Invoking this method is method is equivalent
      * to <code>createJDOClass(className, loadXMLMetadataDefault)</code>.
      * @param className the fully qualified class name of the JDOClass
@@ -301,6 +303,38 @@
         }
 
         return jdoClass;
+    }
+
+    /**
+     * The method returns the JDOClass instance for the specified short name
+     * (see {@link JDOClass#getShortName()}) or <code>null</code> if it cannot
+     * find a JDOClass instance with the specified short name. 
+     * <p>
+     * The method searches the list of JDOClasses currently managed by this
+     * JDOModel instance. It does not attempt to load any metadata if it
+     * cannot find a JDOClass instance with the specified short name. The
+     * metadata for a JDOClass returned by this method must have been loaded
+     * before by any of the methods
+     * {@link #createJDOClass(String className)},
+     * {@link #createJDOClass(String className, boolean loadXMLMetadataDefault)},
+     * {@link #getJDOClass(String className)}, or
+     * {@link #getJDOClass(String className, boolean loadXMLMetadataDefault)}.
+     * @param shortName the short name of the JDOClass instance to be returned
+     * @return a JDOClass instance for the specified short name 
+     * or <code>null</code> if not present
+     */
+    public synchronized JDOClass getJDOClassForShortName(String shortName) {
+        if (StringHelper.isEmpty(shortName))
+            return null;
+
+        for (Iterator i = jdoClasses.values().iterator(); i.hasNext();) {
+            JDOClass jdoClass = (JDOClass)i.next();
+            if (shortName.equals(jdoClass.getShortName()))
+                // found => return
+                return jdoClass;
+        }
+
+        return null;
     }
 
     /**

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/caching/JDOClassImplCaching.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/caching/JDOClassImplCaching.java?rev=178637&r1=178636&r2=178637&view=diff
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/caching/JDOClassImplCaching.java
(original)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/caching/JDOClassImplCaching.java
Thu May 26 07:17:09 2005
@@ -32,7 +32,7 @@
  *
  * @author Michael Bouschen
  * @since 1.1
- * @version 1.1
+ * @version 2.0
  */
 public class JDOClassImplCaching extends JDOClassImplDynamic
 {
@@ -93,6 +93,19 @@
 
     /** Flag indicating wthere field numbers are calculated already. */
     private boolean fieldNumbersCalculated = false;
+
+     /** 
+     * Get the short name of this JDOClass. The short name defaults to the
+     * unqualified class name, if not explicitly set by method
+     * {@link #setShortName(String shortName)}.
+     * @return the short name of this JDOClass.
+     */
+    public String getShortName() {
+        if (shortName == null) {
+            shortName = super.getShortName();
+        }
+        return shortName;
+    }
 
     /** 
      * Get the JDO identity type of this JDOClass.

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelImplCaching.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelImplCaching.java?rev=178637&r1=178636&r2=178637&view=diff
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelImplCaching.java
(original)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelImplCaching.java
Thu May 26 07:17:09 2005
@@ -26,6 +26,8 @@
 import org.apache.jdo.impl.model.jdo.JDOModelImplDynamic;
 import org.apache.jdo.model.java.JavaType;
 
+import org.apache.jdo.util.StringHelper;
+
 /**
  * A JDOModel instance bundles a number of JDOClass instances used by an 
  * application. It provides factory methods to create and retrieve JDOClass 
@@ -40,17 +42,23 @@
  *
  * @author Michael Bouschen
  * @since 1.1
- * @version 1.1
+ * @version 2.0
  */
 public class JDOModelImplCaching extends JDOModelImplDynamic {
 
+    /**
+     * This is a mapping from short names to JDOClass instances. Key is the
+     * JDOClass short name, value is the corresponding JDOClass instance.  
+     */
+    private Map jdoClassesForShortNames = new HashMap();
+
     /** 
      * This is a mapping from ObjectId classes to its JDOClass instances.
      * Key is the type representation of the ObjectId class, value is the 
      * corresponding JDOClass instance. Note, in the case of inheritance
      * the top most persistence-capable class is stored.
      */
-    private Map jdoClassesByObjectIdClasses = new HashMap();
+    private Map jdoClassesForObjectIdClasses = new HashMap();
 
     /** 
      * Set of fully qualified names of classes known to be 
@@ -68,6 +76,43 @@
     }
 
     /**
+     * The method returns the JDOClass instance for the specified short name
+     * (see {@link JDOClass#getShortName()}) or <code>null</code> if it cannot
+     * find a JDOClass instance with the specified short name. 
+     * <p>
+     * The method searches the list of JDOClasses currently managed by this
+     * JDOModel instance. It does not attempt to load any metadata if it
+     * cannot find a JDOClass instance with the specified short name. The
+     * metadata for a JDOClass returned by this method must have been loaded
+     * before by any of the methods
+     * {@link #createJDOClass(String className)},
+     * {@link #createJDOClass(String className, boolean loadXMLMetadataDefault)},
+     * {@link #getJDOClass(String className)}, or
+     * {@link #getJDOClass(String className, boolean loadXMLMetadataDefault)}.
+     * @param shortName the short name of the JDOClass instance to be returned
+     * @return a JDOClass instance for the specified short name 
+     * or <code>null</code> if not present
+     */
+    public synchronized JDOClass getJDOClassForShortName(String shortName) {
+        if (StringHelper.isEmpty(shortName))
+            return null;
+
+        // First check the cache
+        JDOClass jdoClass = 
+            (JDOClass)jdoClassesForShortNames.get(shortName);
+        if (jdoClass == null) {
+            // not found in the cache => call super
+            jdoClass = super.getJDOClassForShortName(shortName);
+            if (jdoClass != null) {
+                // found => update the cache
+                jdoClassesForShortNames.put(shortName, jdoClass);
+            }
+        }
+        
+        return jdoClass;
+    }
+
+    /**
      * This method returns the JDOClass instance that defines the specified type
      * as its objectId class. In the case of an inheritance hierarchy it returns 
      * the top most persistence-capable class of the hierarchy (see 
@@ -82,16 +127,16 @@
         if (objectIdClass == null)
             return null;
 
-        synchronized (jdoClassesByObjectIdClasses) {
+        synchronized (jdoClassesForObjectIdClasses) {
             // First check the cache
             JDOClass jdoClass = 
-                (JDOClass)jdoClassesByObjectIdClasses.get(objectIdClass);
+                (JDOClass)jdoClassesForObjectIdClasses.get(objectIdClass);
             if (jdoClass == null) {
                 // not found in the cache => call super
                 jdoClass = super.getJDOClassForObjectIdClass(objectIdClass);
                 if (jdoClass != null) {
                     // found => update the cache
-                    jdoClassesByObjectIdClasses.put(objectIdClass, jdoClass);
+                    jdoClassesForObjectIdClasses.put(objectIdClass, jdoClass);
                 }
             }
             

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/jdo/JDOClass.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/jdo/JDOClass.java?rev=178637&r1=178636&r2=178637&view=diff
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/jdo/JDOClass.java (original)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/jdo/JDOClass.java Thu May 26
07:17:09 2005
@@ -25,11 +25,27 @@
  * class.
  *
  * @author Michael Bouschen
- * @version 1.1
+ * @version 2.0
  */
 public interface JDOClass 
     extends JDOMember 
 {
+    /** 
+     * Get the short name of this JDOClass. The short name defaults to the
+     * unqualified class name, if not explicitly set by method
+     * {@link #setShortName(String shortName)}.
+     * @return the short name of this JDOClass.
+     */
+    public String getShortName();
+    
+    /** 
+     * Set the short name of this JDOClass.
+     * @param shortName the short name.
+     * @exception ModelException if impossible
+     */
+    public void setShortName(String shortName)
+        throws ModelException;
+
     /** 
      * Get the JDO identity type of this JDOClass.
      * The identity type of the least-derived persistence-capable class defines

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/jdo/JDOModel.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/jdo/JDOModel.java?rev=178637&r1=178636&r2=178637&view=diff
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/jdo/JDOModel.java (original)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/jdo/JDOModel.java Thu May 26
07:17:09 2005
@@ -29,6 +29,7 @@
  * name by different JDOModel instances.
  *
  * @author Michael Bouschen
+ * @version 2.0
  */
 public interface JDOModel
     extends JDOElement
@@ -70,7 +71,7 @@
      * the existing instance is returned. Otherwise, it creates a new JDOClass 
      * instance, sets its declaringModel and returns the new instance.
      * <p>
-     * Whether this method reads XML metatdata or not is deteremined at
+     * Whether this method reads XML metatdata or not is determined at
      * JDOModel creation time (see flag <code>loadXMLMetadataDefault</code> 
      * in {@link JDOModelFactory#getJDOModel(JavaModel javaModel, boolean
      * loadXMLMetadataDefault)}). Invoking this method is method is equivalent
@@ -105,7 +106,7 @@
      * qualified class name if present. The method returns <code>null</code>

      * if it cannot find a JDOClass instance for the specified name. 
      * <p>
-     * Whether this method reads XML metatdata or not is deteremined at
+     * Whether this method reads XML metatdata or not is determined at
      * JDOModel creation time (see flag <code>loadXMLMetadataDefault</code> 
      * in {@link JDOModelFactory#getJDOModel(JavaModel javaModel, boolean
      * loadXMLMetadataDefault)}). Invoking this method is method is equivalent
@@ -130,6 +131,26 @@
      * or <code>null</code> if not present
      */
     public JDOClass getJDOClass(String className, boolean loadXMLMetadata);
+
+    /**
+     * The method returns the JDOClass instance for the specified short name
+     * (see {@link JDOClass#getShortName()}) or <code>null</code> if it cannot
+     * find a JDOClass instance with the specified short name. 
+     * <p>
+     * The method searches the list of JDOClasses currently managed by this
+     * JDOModel instance. It does not attempt to load any metadata if it
+     * cannot find a JDOClass instance with the specified short name. The
+     * metadata for a JDOClass returned by this method must have been loaded
+     * before by any of the methods
+     * {@link #createJDOClass(String className)},
+     * {@link #createJDOClass(String className, boolean loadXMLMetadataDefault)},
+     * {@link #getJDOClass(String className)}, or
+     * {@link #getJDOClass(String className, boolean loadXMLMetadataDefault)}.
+     * @param shortName the short name of the JDOClass instance to be returned
+     * @return a JDOClass instance for the specified short name 
+     * or <code>null</code> if not present
+     */
+    public JDOClass getJDOClassForShortName(String shortName);
 
     /**
      * Returns the collection of JDOClass instances declared by this JDOModel 

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/jdo/JDOModel.jpg
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/jdo/JDOModel.jpg?rev=178637&r1=178636&r2=178637&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/jdo/JDOModel.mdl
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/jdo/JDOModel.mdl?rev=178637&r1=178636&r2=178637&view=diff
==============================================================================
Binary files - no diff available.



Mime
View raw message