db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r158176 [39/79] - in incubator/jdo/trunk/ri11: ./ src/ src/conf/ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/jdo/ src/java/org/apache/jdo/ejb/ src/java/org/apache/jdo/enhancer/ src/java/org/apache/jdo/impl/ src/java/org/apache/jdo/impl/enhancer/ src/java/org/apache/jdo/impl/enhancer/classfile/ src/java/org/apache/jdo/impl/enhancer/core/ src/java/org/apache/jdo/impl/enhancer/generator/ src/java/org/apache/jdo/impl/enhancer/meta/ src/java/org/apache/jdo/impl/enhancer/meta/model/ src/java/org/apache/jdo/impl/enhancer/meta/prop/ src/java/org/apache/jdo/impl/enhancer/meta/util/ src/java/org/apache/jdo/impl/enhancer/util/ src/java/org/apache/jdo/impl/fostore/ src/java/org/apache/jdo/impl/jdoql/ src/java/org/apache/jdo/impl/jdoql/jdoqlc/ src/java/org/apache/jdo/impl/jdoql/scope/ src/java/org/apache/jdo/impl/jdoql/tree/ src/java/org/apache/jdo/impl/model/ src/java/org/apache/jdo/impl/model/java/ src/java/org/apache/jdo/impl/model/java/runtime/ src/java/org/apache/jdo/impl/model/jdo/ src/java/org/apache/jdo/impl/model/jdo/caching/ src/java/org/apache/jdo/impl/model/jdo/util/ src/java/org/apache/jdo/impl/model/jdo/xml/ src/java/org/apache/jdo/impl/pm/ src/java/org/apache/jdo/impl/sco/ src/java/org/apache/jdo/impl/state/ src/java/org/apache/jdo/jdoql/ src/java/org/apache/jdo/jdoql/tree/ src/java/org/apache/jdo/model/ src/java/org/apache/jdo/model/java/ src/java/org/apache/jdo/model/jdo/ src/java/org/apache/jdo/pm/ src/java/org/apache/jdo/sco/ src/java/org/apache/jdo/state/ src/java/org/apache/jdo/store/ src/java/org/apache/jdo/util/ test/ test/conf/ test/enhancer/ test/enhancer/sempdept/ test/enhancer/sempdept/src/ test/enhancer/sempdept/src/empdept/ test/fsuid2/ test/fsuid2/org/ test/fsuid2/org/apache/ test/fsuid2/org/apache/jdo/ test/fsuid2/org/apache/jdo/pc/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/jdo/ test/java/org/apache/jdo/impl/ test/java/org/apache/jdo/impl/fostore/ test/java/org/apache/jdo/pc/ test/java/org/apache/jdo/pc/appid/ test/java/org/apache/jdo/pc/empdept/ test/java/org/apache/jdo/pc/serializable/ test/java/org/apache/jdo/pc/xempdept/ test/java/org/apache/jdo/test/ test/java/org/apache/jdo/test/query/ test/java/org/apache/jdo/test/util/ test/jdo/ test/jdo/org/ test/jdo/org/apache/ test/jdo/org/apache/jdo/ test/jdo/org/apache/jdo/pc/ test/jdo/org/apache/jdo/pc/appid/ test/jdo/org/apache/jdo/pc/empdept/ test/jdo/org/apache/jdo/pc/serializable/ test/jdo/org/apache/jdo/pc/xempdept/ xdocs/
Date Sat, 19 Mar 2005 01:06:07 GMT
Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOClassImplCaching.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOClassImplCaching.java?view=auto&rev=158176
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOClassImplCaching.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOClassImplCaching.java Fri Mar 18 17:02:29 2005
@@ -0,0 +1,443 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.jdo.impl.model.jdo.caching;
+
+import org.apache.jdo.model.java.JavaType;
+import org.apache.jdo.model.ModelException;
+import org.apache.jdo.model.jdo.JDOClass;
+import org.apache.jdo.model.jdo.JDOField;
+import org.apache.jdo.model.jdo.JDOIdentityType;
+import org.apache.jdo.model.jdo.JDOMember;
+
+import org.apache.jdo.impl.model.jdo.JDOClassImplDynamic;
+
+/**
+ * An instance of this class represents the JDO metadata of a persistence 
+ * capable class. This caching implementation caches any calulated
+ * value to avoid re-calculating it if it is requested again.
+ *
+ * @author Michael Bouschen
+ * @since 1.1
+ * @version 1.1
+ */
+public class JDOClassImplCaching extends JDOClassImplDynamic
+{
+
+    /** Flag indicating whether the objectIdClass is resolved already. */
+    private boolean objectIdClassResolved = false;
+
+    /** Flag indicating whether the pcSuperclass is resolved already. */
+    private boolean pcSuperclassResolved = false;
+
+    /** Array of declared managed fields, sorted by name (see JDO spec).  */
+    private JDOField[] declaredManagedFields;
+
+    /** 
+     * Array of managed fields, incluing inherited fields. The fields are 
+     * sorted by name (see JDO Spec) per class in the inheritance hierarchy.
+     */
+    private JDOField[] managedFields;
+
+    /** 
+     * Array of persistent fields, incluing inherited fields. The fields are 
+     * sorted by name (see JDO Spec) per class in the inheritance hierarchy.
+     */
+    private JDOField[] persistentFields;
+
+    /** Primary key fields. */
+    private JDOField[] primaryKeyFields;
+
+    /** Persistent relationship fields. */
+    private JDOField[] persistentRelationshipFields;
+    
+    /** Default fetch group fields. */
+    private JDOField[] defaultFetchGroupFields;
+    
+    /** Number of inherited fields. */
+    private int inheritedManagedFieldCount = -1;
+    
+    /** Field numbers of managed fields. */
+    private int[] managedFieldNumbers;
+
+    /** Field numbers of PERSISTENT fields. */
+    private int[] persistentFieldNumbers;
+
+    /** Field numbers of primaryKey fields. */
+    private int[] primaryKeyFieldNumbers;
+
+    /** Field numbers of managed non primaryKey fields. */
+    private int[] nonPrimaryKeyFieldNumbers;
+
+    /** Field numbers of persistent non primaryKey fields. */
+    private int[] persistentNonPrimaryKeyFieldNumbers;
+
+    /** Field numbers of persistent relationship fields. */
+    private int[] persistentRelationshipFieldNumbers;
+
+    /** Field numbers of persistent, serializable fields. */
+    private int[] persistentSerializableFieldNumbers;
+
+    /** Flag indicating wthere field numbers are calculated already. */
+    private boolean fieldNumbersCalculated = false;
+
+    /** 
+     * Get the JDO identity type of this JDOClass.
+     * The identity type of the least-derived persistence-capable class defines
+     * the identity type for all persistence-capable classes that extend it.
+     * The identity type of the least-derived persistence-capable class is
+     * defaulted to {@link JDOIdentityType#APPLICATION} if objectid-class is 
+     * specified, and {@link JDOIdentityType#DATASTORE}, if not. 
+     * @return the JDO identity type, one of 
+     * {@link JDOIdentityType#APPLICATION}, 
+     * {@link JDOIdentityType#DATASTORE}, or 
+     * {@link JDOIdentityType#NONDURABLE}
+     */
+    public int getIdentityType() {
+        if (identityType == JDOIdentityType.UNSPECIFIED) {
+            identityType = super.getIdentityType();
+        }
+        return identityType;
+    }
+
+    /** 
+     * Get the JavaType representation of the object identity class 
+     * (primary key class) for this JDOClass. 
+     * @return the JavaType representation of the object identity class.
+     */
+    public JavaType getObjectIdClass() {
+        if (!objectIdClassResolved) {
+            objectIdClassResolved = true;
+            objectIdClass = super.getObjectIdClass();
+        }
+        return objectIdClass;
+    }
+
+    /**
+     * Returns the JDOClass instance for the persistence-capable superclass 
+     * of this JDOClass. If this class does not have a persistence-capable 
+     * superclass then <code>null</code> is returned.
+     * @return the JDClass instance of the persistence-capable superclass
+     * or <code>null</code> if there is no persistence-capable superclass 
+     */
+    public JDOClass getPersistenceCapableSuperclass() {
+        if(!pcSuperclassResolved) {
+            pcSuperclass = super.getPersistenceCapableSuperclass();
+        }
+        return pcSuperclass;
+    }
+
+    /**
+     * Provides the JavaType representaion corresponding to this JDOClass.
+     * <p>
+     * Note the difference between Object.getClass() and this method. The
+     * former returns the class of the object in hand, this returns the class
+     * of the object represented by this meta data.
+     * @return the JavaType object corresponding to this JDOClass.
+     */
+    public JavaType getJavaType() {
+        if (javaType == null) {
+            javaType = super.getJavaType();
+        }
+        return javaType;
+    }
+
+    /** 
+     * Remove the supplied member from the collection of members maintained by
+     * this JDOClass.
+     * @param member the member to be removed
+     * @exception ModelException if impossible
+     */
+    public void removeDeclaredMember(JDOMember member) throws ModelException {
+        if ((member instanceof JDOField) && fieldNumbersCalculated) {
+            throw new ModelException(
+                msg.msg("EXC_CannotRemoveJDOField")); //NOI18N
+        }
+        super.removeDeclaredMember(member);
+    }
+
+    /**
+     * This method returns a JDOField instance for the field with the specified 
+     * name. If this JDOClass already declares such a field, the existing 
+     * JDOField instance is returned. Otherwise, it creates a new JDOField 
+     * instance, sets its declaringClass and returns the new instance.
+     * <P> 
+     * Note, if the field numbers for the managed fields of this JDOClass are 
+     * calculated, this methid will fail to create a new JDOField. Any new field
+     * would possibly invalidate existing field number 
+     * @param name the name of the field
+     * @exception ModelException if impossible
+     */
+    public JDOField createJDOField(String name) throws ModelException {
+        if ((getDeclaredField(name) == null) && fieldNumbersCalculated) {
+            throw new ModelException(
+                msg.msg("EXC_CannotCreateJDOField")); //NOI18N
+        }
+        return super.createJDOField(name);
+    }
+
+    /**
+     * Returns the collection of managed JDOField instances declared by this
+     * JDOClass in the form of an array. The returned array does not include 
+     * inherited fields. A field is a managed field, if it has the 
+     * persistence-modifier 
+     * {@link org.apache.jdo.model.jdo.PersistenceModifier#PERSISTENT} or 
+     * {@link org.apache.jdo.model.jdo.PersistenceModifier#TRANSACTIONAL}. 
+     * The position of the fields in the returned array equals their
+     * relative field number as returned by 
+     * {@link JDOField#getRelativeFieldNumber()}. The following holds
+     * true for any field in the returned array: 
+     * <ul>
+     * <li> <code>getDeclaredManagedFields()[i].getRelativeFieldNumber() 
+     * == i</code>
+     * <li> <code>getDeclaredManagedFields()[field.getRelativeFieldNumber()] 
+     * == field</code>
+     * </ul> 
+     * @return the managed fields declared by this JDOClass
+     */
+    public JDOField[] getDeclaredManagedFields() {
+        if (declaredManagedFields == null) {
+            declaredManagedFields = super.getDeclaredManagedFields();
+        }
+        return declaredManagedFields;
+    }
+            
+    /**
+     * Returns the collection of managed JDOField instances of this JDOClass 
+     * in the form of an array. The returned array includes inherited fields.
+     * A field is a managed field, if it has the persistence-modifier 
+     * {@link org.apache.jdo.model.jdo.PersistenceModifier#PERSISTENT} or 
+     * {@link org.apache.jdo.model.jdo.PersistenceModifier#TRANSACTIONAL}. 
+     * The position of the fields in the returned array equals their
+     * absolute field number as returned by 
+     * {@link JDOField#getFieldNumber()}. The following holds true for
+     * any field in the returned array: 
+     * <ul>
+     * <li> <code>getManagedFields()[i].getFieldNumber() == i</code>
+     * <li> <code>getManagedFields()[field.getFieldNumber()] == field</code>
+     * </ul> 
+     * @return the managed fields of this JDOClass
+     */
+    public JDOField[] getManagedFields() {
+        if (managedFields == null) {
+            managedFields = super.getManagedFields();
+        }
+        return managedFields;
+    }
+    
+    /**
+     * Returns the collection of persistent JDOField instances of this JDOClass 
+     * in the form of an array. The returned array includes inherited fields.
+     * A field is a persistent field, if it has the persistence-modifier 
+     * {@link org.apache.jdo.model.jdo.PersistenceModifier#PERSISTENT}.
+     * Please note, the position of the fields in the returned array might not 
+     * equal their absolute field number as returned by 
+     * {@link JDOField#getFieldNumber()}.
+     * @return the persistent fields of this JDOClass
+     */
+    public JDOField[] getPersistentFields() {
+        if (persistentFields == null) {
+            persistentFields = super.getPersistentFields();
+        }
+        return persistentFields;
+    }
+
+    /**
+     * Returns the collection of identifying fields of this JDOClass in the form
+     * of an array. The method returns the JDOField instances defined as 
+     * primary key fields (see {@link JDOField#isPrimaryKey}).
+     * @return the identifying fields of this JDOClass
+     */
+    public JDOField[] getPrimaryKeyFields() {
+        if (primaryKeyFields == null) {
+            primaryKeyFields = super.getPrimaryKeyFields();
+        }
+        return primaryKeyFields;
+    }
+
+    /**
+     * Returns the collection of persistent relationship fields of this JDOClass
+     * in the form of an array. The method returns the JDOField instances 
+     * defined as relationship (method {@link JDOField#getRelationship} returns
+     * a non null value) and having the persistence-modifier 
+     * {@link org.apache.jdo.model.jdo.PersistenceModifier#PERSISTENT}.
+     * @return the persistent relationship fields of this JDOClass
+     */
+    public JDOField[] getPersistentRelationshipFields() {
+        if (persistentRelationshipFields == null) {
+            persistentRelationshipFields = 
+                super.getPersistentRelationshipFields();
+        }
+        return persistentRelationshipFields;
+    }
+
+    /**
+     * Returns the collection of default fetch group fields of this JDOClass
+     * in the form of an array. The method returns the JDOField instances 
+     * defined as part of the default fetch group 
+     * (method {@link JDOField#isDefaultFetchGroup} returns <code>true</code>.
+     * @return the default fetch group fields of this JDOClass
+     * @since 1.1
+     */
+    public JDOField[] getDefaultFetchGroupFields() {
+        if (defaultFetchGroupFields == null) {
+            defaultFetchGroupFields = super.getDefaultFetchGroupFields();
+        }
+        return defaultFetchGroupFields;
+    }
+
+    /**
+     * Returns an array of absolute field numbers of the managed fields of this
+     * JDOClass. The returned array includes field numbers of inherited fields.
+     * A field is a managed field, if it has the persistence-modifier 
+     * {@link org.apache.jdo.model.jdo.PersistenceModifier#PERSISTENT} or 
+     * {@link org.apache.jdo.model.jdo.PersistenceModifier#TRANSACTIONAL}. 
+     * Only managed fields have a valid field number, thus the field number in 
+     * the returned array equals its index:
+     * <br>
+     *  <code>getManagedFields()[i] == i</code>
+     */
+    public int[] getManagedFieldNumbers() {
+        if (managedFieldNumbers == null) {
+            managedFieldNumbers = super.getManagedFieldNumbers();
+        }
+        return managedFieldNumbers;
+    }
+
+    /**
+     * Returns an array of absolute field numbers of the persistent fields of 
+     * this JDOClass. The returned array includes field numbers of inherited 
+     * fields. A persistent field has the persistence-modifier 
+     * {@link org.apache.jdo.model.jdo.PersistenceModifier#PERSISTENT}.
+     */
+    public int[] getPersistentFieldNumbers()
+    {
+        if (persistentFieldNumbers == null) {
+            persistentFieldNumbers = super.getPersistentFieldNumbers();
+        }
+        return persistentFieldNumbers;
+    }
+    
+    /**
+     * Returns an array of absolute field numbers of the identifying fields 
+     * of this JDOClass. A field number is included in the returned array, 
+     * iff the corresponding JDOField instance is defined as primary  key field
+     * (see {@link JDOField#isPrimaryKey}).
+     * @return array of numbers of the identifying fields
+     */
+    public int[] getPrimaryKeyFieldNumbers() {
+        if (primaryKeyFieldNumbers == null) {
+            primaryKeyFieldNumbers = super.getPrimaryKeyFieldNumbers();
+        }
+        return primaryKeyFieldNumbers;
+    }
+
+    /**
+     * Returns an array of absolute field numbers of the non identifying, 
+     * persistent fields of this JDOClass. A field number is included in the 
+     * returned array, iff the corresponding JDOField instance is persistent and 
+     * not a not a primary key field (see {@link JDOField#isPrimaryKey}).
+     * A field is a persistent field, if it has the persistence-modifier 
+     * {@link org.apache.jdo.model.jdo.PersistenceModifier#PERSISTENT} or 
+     * (see {@link JDOField#getPersistenceModifier}). 
+     * @return array of numbers of the non identifying, persistent fields
+     */
+    public int[] getPersistentNonPrimaryKeyFieldNumbers() {
+        if (persistentNonPrimaryKeyFieldNumbers == null) {
+            persistentNonPrimaryKeyFieldNumbers = 
+                super.getPersistentNonPrimaryKeyFieldNumbers();
+        }
+        return persistentNonPrimaryKeyFieldNumbers;
+    }
+    
+    /**
+     * Returns an array of absolute field numbers of persistent relationship 
+     * fields of this JDOClass. A field number is included in the returned 
+     * array, iff the corresponding JDOField instance is a relationship (method 
+     * {@link JDOField#getRelationship} returns a non null value) and has the 
+     * persistence-modifier 
+     * {@link org.apache.jdo.model.jdo.PersistenceModifier#PERSISTENT}.
+     * @return the field numbers of the persistent relationship fields
+     */
+    public int[] getPersistentRelationshipFieldNumbers() {
+        if (persistentRelationshipFieldNumbers == null) {
+            persistentRelationshipFieldNumbers = 
+                super.getPersistentRelationshipFieldNumbers();
+        }
+        return persistentRelationshipFieldNumbers;
+    }
+
+    /**
+     * Returns an array of absolute field numbers of persistent, serializable 
+     * fields of this JDOClass. A field number is included in the returned 
+     * array, iff the corresponding JDOField instance is serializable (method 
+     * {@link JDOField#isSerializable} returns <code>true</code>) and has the 
+     * persistence-modifier 
+     * {@link org.apache.jdo.model.jdo.PersistenceModifier#PERSISTENT}.
+     * @return the field numbers of serializable fields
+     */
+    public int[] getPersistentSerializableFieldNumbers() {
+        if (persistentSerializableFieldNumbers == null) {
+            persistentSerializableFieldNumbers = 
+                super.getPersistentSerializableFieldNumbers();
+        }
+        return persistentSerializableFieldNumbers;
+    }
+
+    /**
+     * Returns the number of inherited managed fields for this class.  
+     * @return number of inherited fields
+     */
+    public synchronized int getInheritedManagedFieldCount() {
+        // inheritedManagedFieldCount < 0 indicates check is not done yet.
+        if (inheritedManagedFieldCount < 0) {
+            inheritedManagedFieldCount = super.getInheritedManagedFieldCount();
+        }
+        return inheritedManagedFieldCount;
+    }    
+
+    //========= Internal helper methods ==========
+
+    /**
+     * This method calculates the relative field number of the
+     * declared managed fields of this JDOClass and uddates the
+     * relativeFieldNumber property of the JDOField instance.
+     */
+    protected void calculateFieldNumbers() {
+        if (!fieldNumbersCalculated) {
+            fieldNumbersCalculated = true;
+            JDOField[] fields = getDeclaredManagedFields();
+            // now set the relativeFieldNumber of the JDOField
+            for (int i = 0; i < fields.length; i++) {
+                ((JDOFieldImplCaching)fields[i]).setRelativeFieldNumber(i);
+            }
+        }
+    }
+
+    /**
+     * Returns a new instance of the JDOClass implementation class.
+     */
+    protected JDOClass newJDOClassInstance() {
+        return new JDOClassImplCaching();
+    }
+
+    /**
+     * Returns a new instance of the JDOField implementation class.
+     */
+    protected JDOField newJDOFieldInstance() {
+        return new JDOFieldImplCaching();
+    }
+}

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOCollectionImplCaching.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOCollectionImplCaching.java?view=auto&rev=158176
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOCollectionImplCaching.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOCollectionImplCaching.java Fri Mar 18 17:02:29 2005
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.jdo.impl.model.jdo.caching;
+
+import org.apache.jdo.impl.model.jdo.JDOCollectionImplDynamic;
+import org.apache.jdo.model.java.JavaType;
+
+/**
+ * An instance of this class represents the JDO relationship metadata 
+ * of a collection relationship field. This caching implementation
+ * caches any calulated value to avoid re-calculating it if it is
+ * requested again. 
+ *
+ * @author Michael Bouschen
+ * @since 1.1
+ * @version 1.1
+ */
+public class JDOCollectionImplCaching extends JDOCollectionImplDynamic {
+    
+    /**
+     * Determines whether the values of the elements should be stored if 
+     * possible as part of the instance instead of as their own instances 
+     * in the datastore.
+     * @return <code>true</code> if the elements should be stored as part of 
+     * the instance; <code>false</code> otherwise
+     */
+    public boolean isEmbeddedElement() {
+        if (embeddedElement == null) {
+            embeddedElement = 
+                super.isEmbeddedElement() ? Boolean.TRUE : Boolean.FALSE;
+        }
+        return (embeddedElement == null) ? false : 
+            embeddedElement.booleanValue();
+    }
+    
+    /** 
+     * Get the type representation of the collection elements. 
+     * @return the element type
+     */
+    public JavaType getElementType()
+    {
+        if (elementType == null) {
+            elementType = super.getElementType();
+        }
+        return elementType;
+    }
+
+}

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOFieldImplCaching.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOFieldImplCaching.java?view=auto&rev=158176
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOFieldImplCaching.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOFieldImplCaching.java Fri Mar 18 17:02:29 2005
@@ -0,0 +1,243 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.jdo.impl.model.jdo.caching;
+
+import org.apache.jdo.model.ModelException;
+import org.apache.jdo.model.jdo.JDOArray;
+import org.apache.jdo.model.jdo.JDOCollection;
+import org.apache.jdo.model.jdo.JDOMap;
+import org.apache.jdo.model.jdo.JDOReference;
+import org.apache.jdo.model.jdo.JDORelationship;
+import org.apache.jdo.model.jdo.PersistenceModifier;
+import org.apache.jdo.impl.model.jdo.JDOFieldImplDynamic;
+
+/**
+ * An instance of this class represents the JDO metadata of a managed
+ * field of a persistence capable class. This caching implementation
+ * caches any calulated value to avoid re-calculating it if it is
+ * requested again. 
+ * <p>
+ * Please note, this implementation does not support
+ * changing the relationship property once it is defined (either
+ * explicitly by the setter or internally calculated by the
+ * getter). The second attempt to define the relationship will result
+ * in an exception.
+ *
+ * @author Michael Bouschen
+ * @since 1.1
+ * @version 1.1
+ */
+public class JDOFieldImplCaching extends JDOFieldImplDynamic {
+
+    /** Relative field number. */
+    private int relativeFieldNumber = -1;
+
+    /**
+     * Get the persistence modifier of this JDOField.
+     * @return the persistence modifier, one of 
+     * {@link PersistenceModifier#NONE}, 
+     * {@link PersistenceModifier#PERSISTENT},
+     * {@link PersistenceModifier#TRANSACTIONAL}, or
+     * {@link PersistenceModifier#POSSIBLY_PERSISTENT}.
+     */
+    public int getPersistenceModifier() {
+        if (persistenceModifier == PersistenceModifier.UNSPECIFIED) {
+            persistenceModifier = super.getPersistenceModifier();
+        }
+        return persistenceModifier;
+    }
+
+    /**
+     * Returns the relative field number of this JDOField.
+     * @return the relative field number
+     */
+    public int getRelativeFieldNumber() {
+        ((JDOClassImplCaching)getDeclaringClass()).calculateFieldNumbers();
+        return relativeFieldNumber;
+    }
+
+    /**
+     * Determines whether this JDOField is part of the default fetch group or 
+     * not.
+     * @return <code>true</code> if the field is part of the default fetch 
+     * group, <code>false</code> otherwise
+     */
+    public boolean isDefaultFetchGroup() {
+        if (defaultFetchGroup == null) {
+            defaultFetchGroup = 
+                super.isDefaultFetchGroup() ? Boolean.TRUE : Boolean.FALSE;
+        }
+        return (defaultFetchGroup == null) ? 
+            false : defaultFetchGroup.booleanValue();
+    }
+
+    /**
+     * Determines whether the field should be stored if possible as part of
+     * the instance instead of as its own instance in the datastore.
+     * @return <code>true</code> if the field is stored as part of the instance;
+     * <code>false</code> otherwise
+     */
+    public boolean isEmbedded() {
+        if (embedded == null) {
+            embedded = super.isEmbedded() ? Boolean.TRUE : Boolean.FALSE;
+        }
+        return (embedded == null) ? false : embedded.booleanValue();
+    }
+    
+    /**
+     * Get the relationship information for this JDOField. The method 
+     * returns null if the field is not part of a relationship 
+     * (e.g. it is a primitive type field).
+     * @return relationship info of this JDOField or <code>null</code> if 
+     * this JDOField is not a relationship
+     */
+    public JDORelationship getRelationship() {
+        if (relationship == null) {
+            relationship = super.getRelationship();
+        }
+        return relationship;
+    }
+    
+    /**
+     * Creates and returns a new JDOReference instance. 
+     * This method automatically binds the new JDOReference to this JDOField. 
+     * It throws a ModelException, if this JDOField is already bound to 
+     * another JDORelationship instance. Otherwise the following holds true:
+     * <ul>
+     * <li> Method {@link #getRelationship} returns the new created instance
+     * <li> <code>this.getRelationship().getDeclaringField() == this</code>
+     * </ul> 
+     * @return a new JDOReference instance bound to this JDOField
+     * @exception ModelException if impossible
+     */
+    public JDOReference createJDOReference() throws ModelException {
+        if (relationship != null)
+            throw new ModelException(
+                msg.msg("EXC_RelationshipAlreadyDefined", //NOI18N
+                        getName(), relationship));
+        return super.createJDOReference();
+    }
+
+    /**
+     * Creates and returns a new JDOCollection instance. 
+     * This method automatically binds the new JDOCollection to this JDOField. 
+     * It throws a ModelException, if this JDOField is already bound to 
+     * another JDORelationship instance. Otherwise the following holds true:
+     * <ul>
+     * <li> Method {@link #getRelationship} returns the new created instance
+     * <li> <code>this.getRelationship().getDeclaringField() == this</code>
+     * </ul> 
+     * @return a new JDOCollection instance bound to this JDOField
+     * @exception ModelException if impossible
+     */
+    public JDOCollection createJDOCollection() throws ModelException {
+        if (relationship != null)
+            throw new ModelException(
+                msg.msg("EXC_RelationshipAlreadyDefined", //NOI18N
+                        getName(), relationship));
+        return super.createJDOCollection();
+    }
+
+    /**
+     * Creates and returns a new JDOArray instance. 
+     * This method automatically binds the new JDOArray to this JDOField. 
+     * It throws a ModelException, if this JDOField is already bound to 
+     * another JDORelationship instance. Otherwise the following holds true:
+     * <ul>
+     * <li> Method {@link #getRelationship} returns the new created instance
+     * <li> <code>this.getRelationship().getDeclaringField() == this</code>
+     * </ul> 
+     * @return a new JDOArray instance bound to this JDOField
+     * @exception ModelException if impossible
+     */
+    public JDOArray createJDOArray() throws ModelException {
+        if (relationship != null)
+            throw new ModelException(
+                msg.msg("EXC_RelationshipAlreadyDefined", //NOI18N
+                        getName(), relationship));
+        return super.createJDOArray();
+    }
+
+    /**
+     * Creates and returns a new JDOMap instance. 
+     * This method automatically binds the new JDOMap to this JDOField. 
+     * It throws a ModelException, if this JDOField is already bound to 
+     * another JDORelationship instance. Otherwise the following holds true:
+     * <ul>
+     * <li> Method {@link #getRelationship} returns the new created instance
+     * <li> <code>this.getRelationship().getDeclaringField() == this</code>
+     * </ul> 
+     * @return a new JDOMap instance bound to this JDOField
+     * @exception ModelException if impossible
+     */
+    public JDOMap createJDOMap() throws ModelException {
+        if (relationship != null)
+            throw new ModelException(
+                msg.msg("EXC_RelationshipAlreadyDefined", //NOI18N
+                        getName(), relationship));
+        return super.createJDOMap();
+    }
+
+    //========= Internal helper methods ==========
+
+    /**
+     * Creates and returns a new JDOCollection instance. 
+     * This method automatically this JDOField as the declarinmg field of 
+     * the returned instance.
+     * @return a new JDOCollection instance bound to this JDOField
+     */
+    protected JDOCollection createJDOCollectionInternal() {
+        JDOCollectionImplCaching collection = new JDOCollectionImplCaching();
+        // update relationship JDORelationship->JDOField
+        collection.setDeclaringField(this);
+        return collection;
+    }
+
+    /**
+     * Creates and returns a new JDOArray instance. 
+     * This method automatically this JDOField as the declarinmg field of 
+     * the returned instance.
+     * @return a new JDOArray instance bound to this JDOField
+     */
+    protected JDOArray createJDOArrayInternal() {
+        JDOArrayImplCaching array = new JDOArrayImplCaching();
+        // update relationship JDORelationship->JDOField
+        array.setDeclaringField(this);
+        return array;
+    }
+
+    /**
+     * Creates and returns a new JDOMap instance. 
+     * This method automatically this JDOField as the declarinmg field of 
+     * the returned instance.
+     * @return a new JDOMap instance bound to this JDOField
+     */
+    protected JDOMap createJDOMapInternal() {
+        JDOMapImplCaching map = new JDOMapImplCaching();
+        // update relationship JDORelationship->JDOField
+        map.setDeclaringField(this);
+        return map;
+    }
+
+    /**
+     * Sets the relative field number of this JDOField.
+     * @param number the relative field number
+     */
+    void setRelativeFieldNumber(int number) {
+        this.relativeFieldNumber = number;
+    }
+}

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOMapImplCaching.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOMapImplCaching.java?view=auto&rev=158176
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOMapImplCaching.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOMapImplCaching.java Fri Mar 18 17:02:29 2005
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.jdo.impl.model.jdo.caching;
+
+import org.apache.jdo.model.java.JavaType;
+import org.apache.jdo.impl.model.jdo.JDOMapImplDynamic;
+
+/**
+ * An instance of this class represents the JDO relationship metadata 
+ * (the treatment of keys and values) of a map relationship field.  
+ * This caching implementation caches any calulated value to avoid
+ * re-calculating it if it is requested again. 
+ *
+ * @author Michael Bouschen
+ * @since 1.1
+ * @version 1.1
+ */
+public class JDOMapImplCaching extends JDOMapImplDynamic {
+    
+    /**
+     * Determines whether the keys of the map should be stored if possible as 
+     * part of the instance instead of as their own instances in the datastore.
+     * @return <code>true</code> if the keys are stored as part of this instance;
+     * <code>false</code> otherwise
+     */
+    public boolean isEmbeddedKey() {
+        if (embeddedKey == null) {
+            embeddedKey =
+                super.isEmbeddedKey() ? Boolean.TRUE : Boolean.FALSE;
+        }
+        return embeddedKey.booleanValue();
+    }
+    
+    /**
+     * Get the type representation of the keys for this JDOMap.
+     * @return the type of the keys of this JDOMap  
+     */
+    public JavaType getKeyType() {
+        if (keyType == null) {
+            keyType = super.getKeyType();
+        }
+        return keyType;
+    }
+
+    /**
+     * Determines whether the values of the map should be stored if possible as 
+     * part of the instance instead of as their own instances in the datastore.
+     * @return <code>true</code> if the values are stored as part of this 
+     * instance; <code>false</code> otherwise
+     */
+    public boolean isEmbeddedValue() {
+        if (embeddedValue == null) {
+            embeddedValue = 
+                super.isEmbeddedValue() ? Boolean.TRUE : Boolean.FALSE;
+        }
+        return embeddedValue.booleanValue();
+    }
+    
+    /**
+     * Get the type representation of the values for this JDOMap.
+     * @return the type of the values of this JDOMap  
+     */
+    public JavaType getValueType() {
+        if (valueType == null) {
+            valueType = super.getValueType();
+        }
+        return valueType;
+    }
+
+}

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelFactoryImplCaching.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelFactoryImplCaching.java?view=auto&rev=158176
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelFactoryImplCaching.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelFactoryImplCaching.java Fri Mar 18 17:02:29 2005
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.jdo.impl.model.jdo.caching;
+
+import org.apache.jdo.model.java.JavaModel;
+import org.apache.jdo.model.jdo.JDOModel;
+import org.apache.jdo.model.jdo.JDOModelFactory;
+
+import org.apache.jdo.impl.model.jdo.JDOModelFactoryImplDynamic;
+
+/**
+ * Factory for caching JDOModel instances.
+ *
+ * @author Michael Bouschen
+ * @since 1.1
+ * @version 1.1
+ */
+public class JDOModelFactoryImplCaching extends JDOModelFactoryImplDynamic {
+
+    /** The singleton JDOModelFactory instance. */    
+    private static JDOModelFactory jdoModelFactory = 
+        new JDOModelFactoryImplCaching();
+
+    /**
+     * Creates new JDOModelFactoryImplCaching. This constructor
+     * should not be called directly; instead, the singleton access
+     * method  {@link #getInstance} should be used.
+     */
+    protected JDOModelFactoryImplCaching() {}
+
+    /** 
+     * Get an instance of JDOModelFactoryImpl.
+     * @return an instance of JDOModelFactoryImpl
+     */    
+    public static JDOModelFactory getInstance() {
+        return jdoModelFactory;
+    }
+    
+    /**
+     * Creates a new empty JDOModel instance.
+     */
+    public JDOModel createJDOModel(JavaModel javaModel) {
+        return new JDOModelImplCaching(javaModel);
+    }
+    
+}

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelImplCaching.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelImplCaching.java?view=auto&rev=158176
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelImplCaching.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelImplCaching.java Fri Mar 18 17:02:29 2005
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.jdo.impl.model.jdo.caching;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.jdo.model.java.JavaModel;
+import org.apache.jdo.model.jdo.JDOClass;
+import org.apache.jdo.impl.model.jdo.JDOModelImplDynamic;
+import org.apache.jdo.model.java.JavaType;
+
+/**
+ * A JDOModel instance bundles a number of JDOClass instances used by an 
+ * application. It provides factory methods to create and retrieve JDOClass 
+ * instances. A fully qualified class name must be unique within a JDOModel 
+ * instance. The model supports multiple classes having the same fully qualified 
+ * name by different JDOModel instances.
+ * <p>
+ * The caching JDOModel implementation caches any caclulated value to
+ * avoid re-calculating it if it is requested again. It is intended to
+ * be used in an environment where JDO metadata does NOT change
+ * (e.g. at runtime).
+ *
+ * @author Michael Bouschen
+ * @since 1.1
+ * @version 1.1
+ */
+public class JDOModelImplCaching extends JDOModelImplDynamic {
+
+    /** 
+     * 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();
+
+    /** 
+     * Set of fully qualified names of classes known to be 
+     * non persistence-capable. 
+     */
+    private Set nonPCClasses = new HashSet();
+
+    /** 
+     * Constructor. 
+     * JDOModel instances are created using the JDOModelFactory only.
+     */
+    protected JDOModelImplCaching(JavaModel javaModel) {
+        super(javaModel);
+    }
+
+    /**
+     * 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 
+     * {@link JDOClass#getPersistenceCapableSuperclass}).
+     * @param objectIdClass the type representation of the ObjectId class
+     * @return the JDOClass defining the specified class as ObjectId class
+     */
+    public JDOClass getJDOClassForObjectIdClass(JavaType objectIdClass)
+    {
+        // Note, method getJDOClassForObjectIdClass is not synchronized to
+        // avoid a deadlock with PC class registration.
+        if (objectIdClass == null)
+            return null;
+
+        synchronized (jdoClassesByObjectIdClasses) {
+            // First check the cache
+            JDOClass jdoClass = 
+                (JDOClass)jdoClassesByObjectIdClasses.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);
+                }
+            }
+            
+            return jdoClass;
+        }
+    }
+
+    /** Returns a new instance of the JDOClass implementation class. */
+    protected JDOClass newJDOClassInstance() {
+        return new JDOClassImplCaching();
+    }
+
+    /**
+     * Checks whether the type with the specified name does NOT denote a
+     * persistence-capable class.
+     * @param typeName name of the type to be checked
+     * @return <code>true</code> if types is a name of a primitive type; 
+     * <code>false</code> otherwise
+     */
+    protected boolean isKnownNonPC(String typeName) {
+        return super.isKnownNonPC(typeName) || nonPCClasses.contains(typeName);
+    }
+
+    /** 
+     * Hook called when a class is known to be non persistence
+     * capable.
+     * @param className the name of the non-pc class
+     */
+    protected void knownNonPC(String className) {
+        nonPCClasses.add(className);
+    }
+}

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/package.html
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/package.html?view=auto&rev=158176
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/package.html (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/package.html Fri Mar 18 17:02:29 2005
@@ -0,0 +1,27 @@
+<!--
+ Copyright 2005 The Apache Software Foundation.
+ 
+ Licensed 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.
+-->
+
+<html>
+<head>
+<title>JDOModel implementation package.</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+
+<body bgcolor="#FFFFFF">
+<p>This package contains classes that implement the JDO model interfaces 
+and provide access to JDO metadata. 
+</body>
+</html>

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/util/Assertion.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/util/Assertion.java?view=auto&rev=158176
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/util/Assertion.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/util/Assertion.java Fri Mar 18 17:02:29 2005
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.jdo.impl.model.jdo.util;
+
+import javax.jdo.JDOFatalInternalException;
+
+import org.apache.jdo.util.I18NHelper;
+
+
+/**
+ * Support for signalling internal implementation errors.
+ */
+public class Assertion 
+{
+    /** I18N support */
+    private final static I18NHelper msg = I18NHelper.getInstance(
+        "org.apache.jdo.impl.model.jdo.Bundle", Assertion.class.getClassLoader()); //NOI18N
+
+    /** */
+    public static final void affirm(boolean condition, String text) 
+    {
+        if (!condition) {
+            Thread.dumpStack();
+            throw new JDOFatalInternalException(
+                msg.msg("ERR_AssertionFailed", text)); //NOI18N
+        }
+    }
+    
+    /** */
+    public static final void affirm(Object object, String text) 
+    {
+        if (object == null) {
+            Thread.dumpStack();
+            throw new JDOFatalInternalException(
+                msg.msg("ERR_AssertionFailed", text)); //NOI18N
+        }
+    }
+}

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/util/PrintSupport.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/util/PrintSupport.java?view=auto&rev=158176
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/util/PrintSupport.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/util/PrintSupport.java Fri Mar 18 17:02:29 2005
@@ -0,0 +1,294 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.
+ */
+
+/**
+ * PrintSupport.java
+ *
+ */
+
+package org.apache.jdo.impl.model.jdo.util;
+
+import java.util.*;
+
+import org.apache.jdo.model.jdo.JDOArray;
+import org.apache.jdo.model.jdo.JDOClass;
+import org.apache.jdo.model.jdo.JDOCollection;
+import org.apache.jdo.model.jdo.JDOExtension;
+import org.apache.jdo.model.jdo.JDOField;
+import org.apache.jdo.model.jdo.JDOIdentityType;
+import org.apache.jdo.model.jdo.JDOMap;
+import org.apache.jdo.model.jdo.JDOModel;
+import org.apache.jdo.model.jdo.JDOReference;
+import org.apache.jdo.model.jdo.JDORelationship;
+import org.apache.jdo.model.jdo.NullValueTreatment;
+import org.apache.jdo.model.jdo.PersistenceModifier;
+
+public class PrintSupport 
+{
+    public static void printJDOModel(JDOModel jdoModel) 
+    {
+        JDOClass[] jdoClasses = jdoModel.getDeclaredClasses();
+        for (int i = 0; i < jdoClasses.length; i++) {
+            printJDOClass(0, jdoClasses[i]);
+        }
+    }
+    
+    public static void printJDOClass(JDOClass jdoClass)
+    {
+        printJDOClass(0, jdoClass);
+    }
+    
+    public static void printJDOFields(JDOField[] jdoFields)
+    {
+        printJDOFields(0, jdoFields);
+    }
+
+    public static void printJDOField(JDOField jdoField) 
+    {
+        printJDOField(0, jdoField);
+    }
+    
+    public static void printJDORelationship(JDORelationship jdoRelationship) 
+    {
+        printJDORelationship(0, jdoRelationship);
+    }
+
+    public static void printJDOExtensions(JDOExtension[] jdoExtensions)
+    {
+        printJDOExtensions(0, jdoExtensions);
+    }
+
+    public static void printJDOExtension(JDOExtension jdoExtension) 
+    {
+        printJDOExtension(0, jdoExtension);
+    }
+
+    // ----- methods taking indent level -----
+
+    private static void printJDOClass(int indent, JDOClass jdoClass) 
+    {
+        if (jdoClass == null)
+            return;
+
+        println(indent, "--> JDOClass "); //NOI18N
+        println(indent+1, "name                       = " + jdoClass.getName()); //NOI18N
+        println(indent+1, "packagePrefix              = " + jdoClass.getPackagePrefix()); //NOI18N
+        println(indent+1, "identityType               = " + JDOIdentityType.toString(jdoClass.getIdentityType())); //NOI18N
+        println(indent+1, "objectIdClass              = " + jdoClass.getObjectIdClass()); //NOI18N
+        println(indent+1, "declaredObjectIdClassName  = " + jdoClass.getDeclaredObjectIdClassName()); //NOI18N
+        println(indent+1, "requiresExtent             = " + jdoClass.requiresExtent()); //NOI18N
+        println(indent+1, "pcSuperclassName           = " + jdoClass.getPersistenceCapableSuperclassName()); //NOI18N
+        println(indent+1, "pcSuperclass               = " + jdoClass.getPersistenceCapableSuperclass()); //NOI18N
+        println(indent+1, "pcRootClass                = " + jdoClass.getPersistenceCapableRootClass()); //NOI18N
+        println(indent+1, "javaType                   = " + jdoClass.getJavaType()); //NOI18N
+        println(indent+1, "declaredManagedFieldCount  = " + jdoClass.getDeclaredManagedFieldCount()); //NOI18N
+        println(indent+1, "inheritedManagedFieldCount = " + jdoClass.getInheritedManagedFieldCount());  //NOI18N
+        println(indent+1, "managedFields              = " + Arrays.asList(jdoClass.getManagedFields())); //NOI18N
+        println(indent+1, "managedFieldNumbers        = " + asList(jdoClass.getManagedFieldNumbers()));  //NOI18N
+        println(indent+1, "persistentFieldNumbers     = " + asList(jdoClass.getPersistentFieldNumbers())); //NOI18N
+        println(indent+1, "primaryKeyFieldNumbers     = " + asList(jdoClass.getPrimaryKeyFieldNumbers())); //NOI18N
+        println(indent+1, "persistentNonPKFieldNs     = " + asList(jdoClass.getPersistentNonPrimaryKeyFieldNumbers())); //NOI18N
+        println(indent+1, "persistentRelshipFieldNs   = " + asList(jdoClass.getPersistentRelationshipFieldNumbers())); //NOI18N
+        println(indent+1, "persistentSerializableFNs  = " + asList(jdoClass.getPersistentSerializableFieldNumbers())); //NOI18N
+        println(indent+1, "declaredFields"); //NOI18N
+        printJDOFields(indent+1, jdoClass.getDeclaredFields());
+        printJDOExtensions(indent+1, jdoClass.getJDOExtensions());
+        println(0, "<-- JDOClass\n "); //NOI18N
+    }
+    
+    private static void printJDOFields(int indent, JDOField[] jdoFields) {
+        if ((jdoFields != null) && (jdoFields.length > 0)) {
+            TreeSet sorted = new TreeSet(new Comparator() {
+                    public int compare(Object o1, Object o2) {
+                        return (((JDOField)o1).getFieldNumber()
+                                - ((JDOField)o2).getFieldNumber());
+                    }
+                    public boolean equals(Object obj) {
+                        return obj.equals(this);
+                    }
+                });
+
+            for (int i = 0; i < jdoFields.length; i++) {
+                sorted.add(jdoFields[i]);
+            }
+
+            for (Iterator i = sorted.iterator(); i.hasNext();) {
+                printJDOField(indent, (JDOField)i.next());
+            }
+        }
+    }
+    
+    private static void printJDOField(int indent, JDOField jdoField) 
+    {
+        if (jdoField == null)
+            return;
+
+        println(indent, "--> JDOField "); //NOI18N
+        println(indent+1, "name                = " + jdoField.getName()); //NOI18N
+        println(indent+1, "declaringClass      = " + jdoField.getDeclaringClass().getName()); //NOI18N
+        println(indent+1, "persistenceModifier = " + PersistenceModifier.toString(jdoField.getPersistenceModifier())); //NOI18N
+        println(indent+1, "primaryKey          = " + jdoField.isPrimaryKey()); //NOI18N
+        println(indent+1, "nullValue           = " + NullValueTreatment.toString(jdoField.getNullValueTreatment())); //NOI18N
+        println(indent+1, "defaultFetchGroup   = " + jdoField.isDefaultFetchGroup()); //NOI18N
+        println(indent+1, "embedded            = " + jdoField.isEmbedded()); //NOI18N
+        println(indent+1, "type                = " + jdoField.getType()); //NOI18N
+        //println(indent+1, "typeName            = " + jdoField.getTypeName()); //NOI18N
+        println(indent+1, "javaField           = " + jdoField.getJavaField()); //NOI18N
+        println(indent+1, "serializable        = " + jdoField.isSerializable()); //NOI18N
+        println(indent+1, "fieldNumber         = " + jdoField.getFieldNumber()); //NOI18N
+        println(indent+1, "relativeFieldNumber = " + jdoField.getRelativeFieldNumber()); //NOI18N
+        printJDORelationship(indent+1, jdoField.getRelationship()); //NOI18N
+        printJDOExtensions(indent+1, jdoField.getJDOExtensions()); //NOI18N
+        println(indent, "<-- JDOField "); //NOI18N
+    }
+    
+    private static void printJDORelationship(int indent, 
+                                            JDORelationship jdoRelationship) 
+    {
+        if (jdoRelationship == null) 
+            return;
+
+        if (jdoRelationship instanceof JDOReference)
+            printJDOReference(indent, (JDOReference)jdoRelationship);
+        else if (jdoRelationship instanceof JDOCollection)
+            printJDOCollection(indent, (JDOCollection)jdoRelationship);
+        else if (jdoRelationship instanceof JDOArray)
+            printJDOArray(indent, (JDOArray)jdoRelationship);
+        else if (jdoRelationship instanceof JDOMap)
+            printJDOMap(indent, (JDOMap)jdoRelationship);
+    }
+    
+    private static void printJDORelationshipHelper(int indent, JDORelationship jdoRelationship) 
+    {
+        if (jdoRelationship == null)
+            return;
+
+        JDORelationship inverse = jdoRelationship.getInverseRelationship();
+        println(indent+1, "declaringField  = " + jdoRelationship.getDeclaringField().getName()); //NOI18N
+        println(indent+1, "bounds          = " + jdoRelationship.getLowerBound() + " / " +  jdoRelationship.getUpperBound()); //NOI18N
+        println(indent+1, "inverse         = " + ((inverse==null) ? "null" : //NOI18N
+            inverse.getDeclaringField().getDeclaringClass().getName() + "." + //NOI18N
+            inverse.getDeclaringField().getName()));
+    }
+    
+    private static void printJDOReference(int indent, JDOReference jdoReference) 
+    {
+        if (jdoReference == null)
+            return;
+
+        println(indent, "--> JDOReference"); //NOI18N
+        printJDORelationshipHelper(indent, jdoReference);
+        printJDOExtensions(indent+1, jdoReference.getJDOExtensions());
+        println(indent, "<-- JDOReference"); //NOI18N
+    }
+    
+    private static void printJDOCollection(int indent, JDOCollection jdoCollection) 
+    {
+        if (jdoCollection == null)
+            return;
+
+        println(indent, "--> JDOCollection"); //NOI18N
+        printJDORelationshipHelper(indent, jdoCollection);
+        println(indent+1, "embeddedElement = " + jdoCollection.isEmbeddedElement()); //NOI18N
+        println(indent+1, "elementType     = " + jdoCollection.getElementType()); //NOI18N
+        println(indent+1, "elementTypeName = " + jdoCollection.getElementTypeName()); //NOI18N
+        printJDOExtensions(indent+1, jdoCollection.getJDOExtensions()); //NOI18N
+        println(indent, "<-- JDOCollection"); //NOI18N
+    }
+    
+    private static void printJDOArray(int indent, JDOArray jdoArray) 
+    {
+        if (jdoArray == null)
+            return;
+
+        println(indent, "--> JDOArray"); //NOI18N
+        printJDORelationshipHelper(indent, jdoArray);
+        println(indent+1, "embeddedElement = " + jdoArray.isEmbeddedElement()); //NOI18N
+        printJDOExtensions(indent+1, jdoArray.getJDOExtensions());
+        println(indent, "<-- JDOArray"); //NOI18N
+    }
+    
+    private static void printJDOMap(int indent, JDOMap jdoMap) 
+    {
+        if (jdoMap == null)
+            return;
+
+        println(indent, "--> JDOMap"); //NOI18N
+        printJDORelationshipHelper(indent, jdoMap);
+        println(indent+1, "embeddedKey     = " + jdoMap.isEmbeddedKey()); //NOI18N
+        println(indent+1, "keyType         = " + jdoMap.getKeyType()); //NOI18N
+        println(indent+1, "keyTypeName     = " + jdoMap.getKeyTypeName()); //NOI18N
+        println(indent+1, "embeddedValue   = " + jdoMap.isEmbeddedValue()); //NOI18N
+        println(indent+1, "valueType       = " + jdoMap.getValueType()); //NOI18N
+        println(indent+1, "valueTypeName   = " + jdoMap.getValueTypeName()); //NOI18N
+        printJDOExtensions(indent+1, jdoMap.getJDOExtensions());
+        println(indent, "<-- JDOMap"); //NOI18N
+    }
+    
+    private static void printJDOExtensions(int indent, JDOExtension[] jdoExtensions) 
+    {
+        if ((jdoExtensions != null) && (jdoExtensions.length > 0)) {
+            TreeSet sorted = new TreeSet(new Comparator() {
+                    public int compare(Object o1, Object o2) {
+                        return ((JDOExtension)o1).getKey().compareTo(
+                          ((JDOExtension)o2).getKey());
+                    }
+                    public boolean equals(Object obj) {
+                        return obj.equals(this);
+                    }
+                });
+
+            for (int i = 0; i < jdoExtensions.length; i++) {
+                sorted.add(jdoExtensions[i]);
+            }
+
+            for (Iterator i = sorted.iterator(); i.hasNext();) {
+                printJDOExtension(indent, (JDOExtension)i.next());
+            }
+        }
+    }
+    
+    private static void printJDOExtension(int indent, JDOExtension jdoExtension) 
+    {
+        if (jdoExtension == null)
+            return;
+        
+        println(indent, "--> JDOExtension"); //NOI18N
+        println(indent+1, "vendorName = " + jdoExtension.getVendorName()); //NOI18N
+        println(indent+1, "key        = " + jdoExtension.getKey()); //NOI18N
+        println(indent+1, "value      = " + jdoExtension.getValue()); //NOI18N
+        println(indent, "<-- JDOExtension"); //NOI18N
+    }
+    
+    // ----- helper methods -----
+    
+    static void println(int indent, String text) {
+        for (int i = 0; i < indent; i++) {
+            System.out.print("    "); //NOI18N
+        }
+        System.out.println(text);
+    }
+
+    public static List asList(int[] array) 
+    {
+        int length = (array == null) ? 0 : array.length;
+        List list = new ArrayList(length);
+        for (int i = 0; i < length; i++) {
+            list.add(new Integer(array[i]));
+        }
+        return list;
+    }
+}

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/util/TypeSupport.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/util/TypeSupport.java?view=auto&rev=158176
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/util/TypeSupport.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/util/TypeSupport.java Fri Mar 18 17:02:29 2005
@@ -0,0 +1,170 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.
+ */
+
+/**
+ * TypeSupport.java
+ *
+ */
+
+package org.apache.jdo.impl.model.jdo.util;
+
+import java.util.Set;
+import java.util.HashSet;
+
+import org.apache.jdo.model.java.JavaModel;
+import org.apache.jdo.model.java.JavaType;
+import org.apache.jdo.model.jdo.JDOModel;
+
+
+/**
+ *
+ */
+public class TypeSupport
+{
+    /** */
+    private static Set primitiveTypeNames = new HashSet();
+
+    static 
+    {
+        // initialize set of names of primitive types
+        primitiveTypeNames.add("byte");
+        primitiveTypeNames.add("short");
+        primitiveTypeNames.add("int");
+        primitiveTypeNames.add("long");
+        primitiveTypeNames.add("char");
+        primitiveTypeNames.add("float");
+        primitiveTypeNames.add("double");
+        primitiveTypeNames.add("boolean");
+    }
+    
+
+    /** 
+     * Returns <code>true</code> if the persistence-modifier of a field
+     * having the specified type defaults to <code>true</code>. 
+     * @param type the type to be checked
+     * @return <code>true</code> if type is a value type; 
+     * <code>false</code> otherwise
+     */
+    public static boolean isPersistenceFieldType(JavaType type)
+    {
+        return type.isValue() ||
+               type.isJDOSupportedCollection() ||
+               type.isJDOSupportedMap() ||
+               type.isPersistenceCapable() ||
+               isPersistenceArrayType(type);
+    }
+     
+    /** 
+     * Returns <code>true</code> if the embedded-element property of a field 
+     * having the specified type defaults to <code>true</code>.
+     * @param type the type to be checked
+     * @return <code>true</code> if type is a embedded-element type; 
+     * <code>false</code> otherwise
+     */
+    public static boolean isEmbeddedElementType(JavaType type)
+    {
+        return !type.isPersistenceCapable() && !type.isInterface();
+    }
+
+    /** 
+     * Returns <code>true</code> if the embedded property of a field having 
+     * the specified type defaults to <code>true</code>.
+     * @param type the type to be checked
+     * @return <code>true</code> if type is a embedded type; 
+     * <code>false</code> otherwise
+     */
+    public static boolean isEmbeddedFieldType(JavaType type)
+    {
+        return type.isValue() ||
+               isPersistenceArrayType(type);
+    }
+
+    /**
+     * Returns a JavaType representation for the specified type name. 
+     * The method delegates the request to the JavaModel attached to the
+     * specified JDOModel. An unqualified name is qualified using first the 
+     * specified packagePrefix and then "java.lang.", but only if the type
+     * name is the the name of a primitive type. If the method still does
+     * not find a valid type, then it returns <code>null</code>.
+     * @param jdoModel the owning JDOModel
+     * @param typeName the name of the type to be checked
+     * @param packagePrefix the package prefix used to qualify the type name
+     * @return the JavaType representation of the specified type name or
+     * <code>null</code> if it cannot be resolved.
+     */
+    public static JavaType resolveType(JDOModel jdoModel, String typeName, 
+                                       String packagePrefix)
+    {
+        JavaType type = null;
+        JavaModel javaModel = jdoModel.getJavaModel();
+        if (primitiveTypeNames.contains(typeName) ||
+            (typeName.indexOf('.') != -1) || 
+            (packagePrefix == null) || (packagePrefix.length() == 0)) {
+            // Take the typeName as specified, 
+            // if typeName denotes a primitive type or is a qualified name
+            // or if there is no packagePrefix (default package)
+            type = javaModel.getJavaType(typeName);
+        }
+        else {
+            // Not a primitive type and not qualified and packagePrefix
+            // specified => qualify using packagePrefix
+            type = javaModel.getJavaType(packagePrefix + typeName);
+            if (type == null) {
+                // If type could not be resolved => 
+                // use java.lang. package prefix as qualifier 
+                type = javaModel.getJavaType("java.lang." + typeName); //NOI18N
+            }
+        }
+        return type;
+    }
+
+    /**
+     * Returns <code>true</code> if the specified type represents an array
+     * and its element type is a value type.
+     * @param type the JavaType to be checked
+     * @return <code>true</code> if type is a value array; 
+     * <code>false</code> otherwise.
+     */
+    public static boolean isValueArrayType(JavaType type)
+    {
+        if (type.isArray()) {
+            JavaType elementType = type.getArrayComponentType();
+            return elementType.isValue();
+        }
+        return false;
+    }
+    
+    
+    //========= Internal helper methods ==========
+    
+    /**
+     * Returns <code>true</code> if the specified type represents an array
+     * and its element type is a persistence capable class.
+     * @param type the JavaType to be checked
+     * @return <code>true</code> if type is a persistent array; 
+     * <code>false</code> otherwise.
+     */
+    private static boolean isPersistenceArrayType(JavaType type)
+    {
+         if (type.isArray()) {
+            JavaType elementType = type.getArrayComponentType();
+            return elementType.isValue() ||
+                   elementType.isPersistenceCapable();
+        }
+        return false;
+    }
+    
+}

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/JDOHandler.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/JDOHandler.java?view=auto&rev=158176
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/JDOHandler.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/JDOHandler.java Fri Mar 18 17:02:29 2005
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.
+ */
+
+/*
+ * File:           JDOHandler.java
+ * Date:           July 3, 2001  2:16 PM
+ *
+ * @author  michael
+ * @version generated by FFJ XML module
+ */
+package org.apache.jdo.impl.model.jdo.xml;
+
+import java.util.Collection;
+import org.xml.sax.*;
+
+public interface JDOHandler 
+{
+    
+    /**
+     * A container element start event handling method.
+     * @param meta attributes
+     */
+    public void start_jdo(final Attributes meta)
+        throws SAXException;
+    
+    /**
+     * A container element end event handling method.
+     */
+    public void end_jdo() 
+        throws SAXException;
+    
+    /**
+     * A container element start event handling method.
+     * @param meta attributes
+     */
+    public void start_package(final Attributes meta) 
+        throws SAXException;
+    
+    /**
+     * A container element end event handling method.
+     */
+    public void end_package() 
+        throws SAXException;
+    
+    /**
+     * A container element start event handling method.
+     * @param meta attributes
+     */
+    public void start_class(final Attributes meta) 
+        throws SAXException;
+    
+    /**
+     * A container element end event handling method.
+     */
+    public void end_class() 
+        throws SAXException;
+    
+    /**
+     * A container element start event handling method.
+     * @param meta attributes
+     */
+    public void start_field(final Attributes meta) 
+        throws SAXException;
+    
+    /**
+     * A container element end event handling method.
+     */
+    public void end_field() 
+        throws SAXException;
+    
+    /**
+     * A container element start event handling method.
+     * @param meta attributes
+     */
+    public void start_collection(final Attributes meta) 
+        throws SAXException;
+    
+    /**
+     * A container element end event handling method.
+     */
+    public void end_collection() 
+        throws SAXException;
+       
+    /**
+     * A container element start event handling method.
+     * @param meta attributes
+     */
+    public void start_array(final Attributes meta) 
+        throws SAXException;
+    
+    /**
+     * A container element end event handling method.
+     */
+    public void end_array() 
+        throws SAXException;
+    
+    /**
+     * A container element start event handling method.
+     * @param meta attributes
+     */
+    public void start_map(final Attributes meta) 
+        throws SAXException;
+    
+    /**
+     * A container element end event handling method.
+     */
+    public void end_map()   
+        throws SAXException;
+    
+    /**
+     * A container element start event handling method.
+     * @param meta attributes
+     */
+    public void start_extension(final Attributes meta) 
+        throws SAXException;
+    
+    /**
+     * A container element end event handling method.
+     */
+    public void end_extension() 
+        throws SAXException;
+
+    /**
+     *
+     */
+    public Collection handledJDOClasses();
+}



Mime
View raw message