org.apache.jdo.impl.model.jdo.caching
Class JDOClassImplCaching

java.lang.Object
  extended byorg.apache.jdo.impl.model.jdo.JDOElementImpl
      extended byorg.apache.jdo.impl.model.jdo.JDOMemberImpl
          extended byorg.apache.jdo.impl.model.jdo.JDOClassImplDynamic
              extended byorg.apache.jdo.impl.model.jdo.caching.JDOClassImplCaching
All Implemented Interfaces:
java.lang.Comparable, JDOClass, JDOElement, JDOMember

public class JDOClassImplCaching
extends 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.

Since:
1.1
Version:
2.0
Author:
Michael Bouschen

Field Summary
private  JDOField[] declaredManagedFields
          Array of declared managed fields, sorted by name (see JDO spec).
private  JDOField[] defaultFetchGroupFields
          Default fetch group fields.
private  boolean fieldNumbersCalculated
          Flag indicating wthere field numbers are calculated already.
private  int inheritedManagedFieldCount
          Number of inherited fields.
private  int[] managedFieldNumbers
          Field numbers of managed fields.
private  JDOField[] managedFields
          Array of managed fields, incluing inherited fields.
private  int[] nonPrimaryKeyFieldNumbers
          Field numbers of managed non primaryKey fields.
private  boolean objectIdClassResolved
          Flag indicating whether the objectIdClass is resolved already.
private  boolean pcSuperclassResolved
          Flag indicating whether the pcSuperclass is resolved already.
private  int[] persistentFieldNumbers
          Field numbers of PERSISTENT fields.
private  JDOField[] persistentFields
          Array of persistent fields, incluing inherited fields.
private  int[] persistentNonPrimaryKeyFieldNumbers
          Field numbers of persistent non primaryKey fields.
private  int[] persistentRelationshipFieldNumbers
          Field numbers of persistent relationship fields.
private  JDOField[] persistentRelationshipFields
          Persistent relationship fields.
private  int[] persistentSerializableFieldNumbers
          Field numbers of persistent, serializable fields.
private  int[] primaryKeyFieldNumbers
          Field numbers of primaryKey fields.
private  JDOField[] primaryKeyFields
          Primary key fields.
 
Fields inherited from class org.apache.jdo.impl.model.jdo.JDOClassImplDynamic
identityType, javaType, msg, objectIdClass, pcSuperclass, shortName
 
Fields inherited from class org.apache.jdo.impl.model.jdo.JDOMemberImpl
 
Fields inherited from class org.apache.jdo.impl.model.jdo.JDOElementImpl
 
Constructor Summary
protected JDOClassImplCaching(java.lang.String name)
          Constructor.
protected JDOClassImplCaching(java.lang.String name, JDOClass declaringClass)
          Constructor for inner classes.
 
Method Summary
protected  void calculateFieldNumbers()
          This method calculates the relative field number of the declared managed fields of this JDOClass and uddates the relativeFieldNumber property of the JDOField instance.
 JDOField createJDOField(java.lang.String name)
          This method returns a JDOField instance for the field with the specified name.
 JDOField[] getDeclaredManagedFields()
          Returns the collection of managed JDOField instances declared by this JDOClass in the form of an array.
 JDOField[] getDefaultFetchGroupFields()
          Returns the collection of default fetch group fields of this JDOClass in the form of an array.
 int getIdentityType()
          Get the JDO identity type of this JDOClass.
 int getInheritedManagedFieldCount()
          Returns the number of inherited managed fields for this class.
 JavaType getJavaType()
          Provides the JavaType representaion corresponding to this JDOClass.
 int[] getManagedFieldNumbers()
          Returns an array of absolute field numbers of the managed fields of this JDOClass.
 JDOField[] getManagedFields()
          Returns the collection of managed JDOField instances of this JDOClass in the form of an array.
 JavaType getObjectIdClass()
          Get the JavaType representation of the object identity class (primary key class) for this JDOClass.
 JDOClass getPersistenceCapableSuperclass()
          Returns the JDOClass instance for the persistence-capable superclass of this JDOClass.
 int[] getPersistentFieldNumbers()
          Returns an array of absolute field numbers of the persistent fields of this JDOClass.
 JDOField[] getPersistentFields()
          Returns the collection of persistent JDOField instances of this JDOClass in the form of an array.
 int[] getPersistentNonPrimaryKeyFieldNumbers()
          Returns an array of absolute field numbers of the non identifying, persistent fields of this JDOClass.
 int[] getPersistentRelationshipFieldNumbers()
          Returns an array of absolute field numbers of persistent relationship fields of this JDOClass.
 JDOField[] getPersistentRelationshipFields()
          Returns the collection of persistent relationship fields of this JDOClass in the form of an array.
 int[] getPersistentSerializableFieldNumbers()
          Returns an array of absolute field numbers of persistent, serializable fields of this JDOClass.
 int[] getPrimaryKeyFieldNumbers()
          Returns an array of absolute field numbers of the identifying fields of this JDOClass.
 JDOField[] getPrimaryKeyFields()
          Returns the collection of identifying fields of this JDOClass in the form of an array.
 java.lang.String getShortName()
          Get the short name of this JDOClass.
protected  JDOClass newJDOClassInstance(java.lang.String name)
          Returns a new instance of the JDOClass implementation class.
protected  JDOField newJDOFieldInstance(java.lang.String name)
          Returns a new instance of the JDOField implementation class.
protected  JDOProperty newJDOPropertyInstance(java.lang.String name)
          Returns a new instance of the JDOProperty implementation class.
protected  JDOProperty newJDOPropertyInstance(java.lang.String name, JDOField associatedJDOField)
          Returns a new instance of the JDOProperty implementation class.
 void removeDeclaredMember(JDOMember member)
          Remove the supplied member from the collection of members maintained by this JDOClass.
 
Methods inherited from class org.apache.jdo.impl.model.jdo.JDOClassImplDynamic
createJDOClass, createJDOProperty, createJDOProperty, getAssociatedProperty, getAssociatedProperty, getDeclaredClasses, getDeclaredField, getDeclaredFields, getDeclaredManagedFieldCount, getDeclaredMembers, getDeclaredObjectIdClassName, getDeclaredPrimaryKeyFields, getDeclaringModel, getField, getField, getFieldInternal, getJDOPackage, getManagedField, getManagedFieldCount, getPackagePrefix, getPersistenceCapableRootClass, getPersistenceCapableSuperclassName, isXMLMetadataLoaded, requiresExtent, setDeclaredObjectIdClassName, setDeclaringModel, setIdentityType, setJavaType, setJDOPackage, setObjectIdClass, setPersistenceCapableSuperclass, setPersistenceCapableSuperclassName, setRequiresExtent, setShortName, setXMLMetadataLoaded
 
Methods inherited from class org.apache.jdo.impl.model.jdo.JDOMemberImpl
compareTo, equals, getDeclaringClass, getName, hashCode, toString
 
Methods inherited from class org.apache.jdo.impl.model.jdo.JDOElementImpl
addPropertyChangeListener, addVetoableChangeListener, createJDOExtension, firePropertyChange, fireVetoableChange, getJDOExtensions, removeJDOExtension, removePropertyChangeListener, removeVetoableChangeListener
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.jdo.model.jdo.JDOMember
getDeclaringClass, getName
 
Methods inherited from interface org.apache.jdo.model.jdo.JDOElement
addPropertyChangeListener, addVetoableChangeListener, createJDOExtension, getJDOExtensions, removeJDOExtension, removePropertyChangeListener, removeVetoableChangeListener
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Field Detail

objectIdClassResolved

private boolean objectIdClassResolved
Flag indicating whether the objectIdClass is resolved already.


pcSuperclassResolved

private boolean pcSuperclassResolved
Flag indicating whether the pcSuperclass is resolved already.


declaredManagedFields

private JDOField[] declaredManagedFields
Array of declared managed fields, sorted by name (see JDO spec).


managedFields

private JDOField[] managedFields
Array of managed fields, incluing inherited fields. The fields are sorted by name (see JDO Spec) per class in the inheritance hierarchy.


persistentFields

private JDOField[] persistentFields
Array of persistent fields, incluing inherited fields. The fields are sorted by name (see JDO Spec) per class in the inheritance hierarchy.


primaryKeyFields

private JDOField[] primaryKeyFields
Primary key fields.


persistentRelationshipFields

private JDOField[] persistentRelationshipFields
Persistent relationship fields.


defaultFetchGroupFields

private JDOField[] defaultFetchGroupFields
Default fetch group fields.


inheritedManagedFieldCount

private int inheritedManagedFieldCount
Number of inherited fields.


managedFieldNumbers

private int[] managedFieldNumbers
Field numbers of managed fields.


persistentFieldNumbers

private int[] persistentFieldNumbers
Field numbers of PERSISTENT fields.


primaryKeyFieldNumbers

private int[] primaryKeyFieldNumbers
Field numbers of primaryKey fields.


nonPrimaryKeyFieldNumbers

private int[] nonPrimaryKeyFieldNumbers
Field numbers of managed non primaryKey fields.


persistentNonPrimaryKeyFieldNumbers

private int[] persistentNonPrimaryKeyFieldNumbers
Field numbers of persistent non primaryKey fields.


persistentRelationshipFieldNumbers

private int[] persistentRelationshipFieldNumbers
Field numbers of persistent relationship fields.


persistentSerializableFieldNumbers

private int[] persistentSerializableFieldNumbers
Field numbers of persistent, serializable fields.


fieldNumbersCalculated

private boolean fieldNumbersCalculated
Flag indicating wthere field numbers are calculated already.

Constructor Detail

JDOClassImplCaching

protected JDOClassImplCaching(java.lang.String name)
Constructor.


JDOClassImplCaching

protected JDOClassImplCaching(java.lang.String name,
                              JDOClass declaringClass)
Constructor for inner classes.

Method Detail

getShortName

public java.lang.String getShortName()
Get the short name of this JDOClass. The short name defaults to the unqualified class name, if not explicitly set by method JDOClassImplDynamic.setShortName(String shortName).

Specified by:
getShortName in interface JDOClass
Overrides:
getShortName in class JDOClassImplDynamic
Returns:
the short name of this JDOClass.

getIdentityType

public int getIdentityType()
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 JDOIdentityType.APPLICATION if objectid-class is specified, and JDOIdentityType.DATASTORE, if not.

Specified by:
getIdentityType in interface JDOClass
Overrides:
getIdentityType in class JDOClassImplDynamic
Returns:
the JDO identity type, one of JDOIdentityType.APPLICATION, JDOIdentityType.DATASTORE, or JDOIdentityType.NONDURABLE

getObjectIdClass

public JavaType getObjectIdClass()
Get the JavaType representation of the object identity class (primary key class) for this JDOClass.

Specified by:
getObjectIdClass in interface JDOClass
Overrides:
getObjectIdClass in class JDOClassImplDynamic
Returns:
the JavaType representation of the object identity class.

getPersistenceCapableSuperclass

public JDOClass getPersistenceCapableSuperclass()
Returns the JDOClass instance for the persistence-capable superclass of this JDOClass. If this class does not have a persistence-capable superclass then null is returned.

Specified by:
getPersistenceCapableSuperclass in interface JDOClass
Overrides:
getPersistenceCapableSuperclass in class JDOClassImplDynamic
Returns:
the JDClass instance of the persistence-capable superclass or null if there is no persistence-capable superclass

getJavaType

public JavaType getJavaType()
Provides the JavaType representaion corresponding to this JDOClass.

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.

Specified by:
getJavaType in interface JDOClass
Overrides:
getJavaType in class JDOClassImplDynamic
Returns:
the JavaType object corresponding to this JDOClass.

removeDeclaredMember

public void removeDeclaredMember(JDOMember member)
                          throws ModelException
Remove the supplied member from the collection of members maintained by this JDOClass.

Specified by:
removeDeclaredMember in interface JDOClass
Overrides:
removeDeclaredMember in class JDOClassImplDynamic
Parameters:
member - the member to be removed
Throws:
ModelException - if impossible

createJDOField

public JDOField createJDOField(java.lang.String name)
                        throws ModelException
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.

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

Specified by:
createJDOField in interface JDOClass
Overrides:
createJDOField in class JDOClassImplDynamic
Parameters:
name - the name of the field
Throws:
ModelException - if impossible

getDeclaredManagedFields

public JDOField[] getDeclaredManagedFields()
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 PersistenceModifier.PERSISTENT or PersistenceModifier.TRANSACTIONAL. The position of the fields in the returned array equals their relative field number as returned by JDOField.getRelativeFieldNumber(). The following holds true for any field in the returned array:

Specified by:
getDeclaredManagedFields in interface JDOClass
Overrides:
getDeclaredManagedFields in class JDOClassImplDynamic
Returns:
the managed fields declared by this JDOClass

getManagedFields

public JDOField[] getManagedFields()
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 PersistenceModifier.PERSISTENT or PersistenceModifier.TRANSACTIONAL. The position of the fields in the returned array equals their absolute field number as returned by JDOField.getFieldNumber(). The following holds true for any field in the returned array:

Specified by:
getManagedFields in interface JDOClass
Overrides:
getManagedFields in class JDOClassImplDynamic
Returns:
the managed fields of this JDOClass

getPersistentFields

public JDOField[] getPersistentFields()
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 PersistenceModifier.PERSISTENT. Please note, the position of the fields in the returned array might not equal their absolute field number as returned by JDOField.getFieldNumber().

Specified by:
getPersistentFields in interface JDOClass
Overrides:
getPersistentFields in class JDOClassImplDynamic
Returns:
the persistent fields of this JDOClass

getPrimaryKeyFields

public JDOField[] getPrimaryKeyFields()
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 JDOField.isPrimaryKey()).

Specified by:
getPrimaryKeyFields in interface JDOClass
Overrides:
getPrimaryKeyFields in class JDOClassImplDynamic
Returns:
the identifying fields of this JDOClass

getPersistentRelationshipFields

public JDOField[] getPersistentRelationshipFields()
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 JDOField.getRelationship() returns a non null value) and having the persistence-modifier PersistenceModifier.PERSISTENT.

Specified by:
getPersistentRelationshipFields in interface JDOClass
Overrides:
getPersistentRelationshipFields in class JDOClassImplDynamic
Returns:
the persistent relationship fields of this JDOClass

getDefaultFetchGroupFields

public JDOField[] getDefaultFetchGroupFields()
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 JDOField.isDefaultFetchGroup() returns true.

Specified by:
getDefaultFetchGroupFields in interface JDOClass
Overrides:
getDefaultFetchGroupFields in class JDOClassImplDynamic
Returns:
the default fetch group fields of this JDOClass
Since:
1.1

getManagedFieldNumbers

public int[] getManagedFieldNumbers()
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 PersistenceModifier.PERSISTENT or PersistenceModifier.TRANSACTIONAL. Only managed fields have a valid field number, thus the field number in the returned array equals its index:
getManagedFields()[i] == i

Specified by:
getManagedFieldNumbers in interface JDOClass
Overrides:
getManagedFieldNumbers in class JDOClassImplDynamic

getPersistentFieldNumbers

public int[] getPersistentFieldNumbers()
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 PersistenceModifier.PERSISTENT.

Specified by:
getPersistentFieldNumbers in interface JDOClass
Overrides:
getPersistentFieldNumbers in class JDOClassImplDynamic

getPrimaryKeyFieldNumbers

public int[] getPrimaryKeyFieldNumbers()
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 JDOField.isPrimaryKey()).

Specified by:
getPrimaryKeyFieldNumbers in interface JDOClass
Overrides:
getPrimaryKeyFieldNumbers in class JDOClassImplDynamic
Returns:
array of numbers of the identifying fields

getPersistentNonPrimaryKeyFieldNumbers

public int[] getPersistentNonPrimaryKeyFieldNumbers()
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 JDOField.isPrimaryKey()). A field is a persistent field, if it has the persistence-modifier PersistenceModifier.PERSISTENT or (see JDOField.getPersistenceModifier()).

Specified by:
getPersistentNonPrimaryKeyFieldNumbers in interface JDOClass
Overrides:
getPersistentNonPrimaryKeyFieldNumbers in class JDOClassImplDynamic
Returns:
array of numbers of the non identifying, persistent fields

getPersistentRelationshipFieldNumbers

public int[] getPersistentRelationshipFieldNumbers()
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 JDOField.getRelationship() returns a non null value) and has the persistence-modifier PersistenceModifier.PERSISTENT.

Specified by:
getPersistentRelationshipFieldNumbers in interface JDOClass
Overrides:
getPersistentRelationshipFieldNumbers in class JDOClassImplDynamic
Returns:
the field numbers of the persistent relationship fields

getPersistentSerializableFieldNumbers

public int[] getPersistentSerializableFieldNumbers()
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 JDOField.isSerializable() returns true) and has the persistence-modifier PersistenceModifier.PERSISTENT.

Specified by:
getPersistentSerializableFieldNumbers in interface JDOClass
Overrides:
getPersistentSerializableFieldNumbers in class JDOClassImplDynamic
Returns:
the field numbers of serializable fields

getInheritedManagedFieldCount

public int getInheritedManagedFieldCount()
Returns the number of inherited managed fields for this class.

Specified by:
getInheritedManagedFieldCount in interface JDOClass
Overrides:
getInheritedManagedFieldCount in class JDOClassImplDynamic
Returns:
number of inherited fields

calculateFieldNumbers

protected void calculateFieldNumbers()
This method calculates the relative field number of the declared managed fields of this JDOClass and uddates the relativeFieldNumber property of the JDOField instance.


newJDOClassInstance

protected JDOClass newJDOClassInstance(java.lang.String name)
Returns a new instance of the JDOClass implementation class.

Overrides:
newJDOClassInstance in class JDOClassImplDynamic

newJDOFieldInstance

protected JDOField newJDOFieldInstance(java.lang.String name)
Returns a new instance of the JDOField implementation class.

Overrides:
newJDOFieldInstance in class JDOClassImplDynamic

newJDOPropertyInstance

protected JDOProperty newJDOPropertyInstance(java.lang.String name)
Returns a new instance of the JDOProperty implementation class.

Overrides:
newJDOPropertyInstance in class JDOClassImplDynamic

newJDOPropertyInstance

protected JDOProperty newJDOPropertyInstance(java.lang.String name,
                                             JDOField associatedJDOField)
                                      throws ModelException
Returns a new instance of the JDOProperty implementation class.

Overrides:
newJDOPropertyInstance in class JDOClassImplDynamic
Throws:
ModelException