Class ClassMetaData

java.lang.Object
org.apache.openjpa.meta.Extensions
org.apache.openjpa.meta.ClassMetaData
All Implemented Interfaces:
Serializable, Comparable<ClassMetaData>, ValueListener, SourceTracker, Commentable, MetaDataContext, MetaDataModes
Direct Known Subclasses:
ClassMapping

Contains metadata about a persistent type. This metadata is available both at enhancement time and runtime. Note that this class employs aggressive caching, and therefore it is important to finalize the configuration of field metadatas before invoking methods that depend on that configuration, such as getPrimaryKeyFields().
Author:
Abe White
See Also:
  • Field Details

    • ID_UNKNOWN

      public static final int ID_UNKNOWN
      Unknown identity type.
      See Also:
    • ID_DATASTORE

      public static final int ID_DATASTORE
      Datastore identity type.
      See Also:
    • ID_APPLICATION

      public static final int ID_APPLICATION
      Application identity type.
      See Also:
    • ACCESS_UNKNOWN

      public static final int ACCESS_UNKNOWN
      Unknown access type.
    • ACCESS_FIELD

      public static final int ACCESS_FIELD
      Persistent attributes are accessed via direct field access. Bit flag.
    • ACCESS_PROPERTY

      public static final int ACCESS_PROPERTY
      Persistent attributes are accessed via setters and getters. Bit flag.
    • ACCESS_EXPLICIT

      public static final int ACCESS_EXPLICIT
      Persistent class has explicitly defined an access type. This will allow the attributes to use mixed access i.e. some field may use ACCESS_FIELD while others ACCESS_PROPERTY.
    • SYNTHETIC

      public static final String SYNTHETIC
      Value for using a synthetic detached state field, which is the default.
      See Also:
    • DEFAULT_STRING

      protected static final String DEFAULT_STRING
      See Also:
  • Constructor Details

    • ClassMetaData

      protected ClassMetaData(Class<?> type, MetaDataRepository repos)
      Constructor. Supply described type and repository.
    • ClassMetaData

      protected ClassMetaData(ValueMetaData owner)
      Embedded constructor. Supply embedding value.
  • Method Details

    • getRepository

      public MetaDataRepository getRepository()
      Return the owning repository.
      Specified by:
      getRepository in interface MetaDataContext
      Specified by:
      getRepository in class Extensions
    • getEmbeddingMetaData

      public ValueMetaData getEmbeddingMetaData()
      If this metadata is for an embedded object, returning the owning value.
    • getDescribedType

      public Class<?> getDescribedType()
      The persistence capable class described by this metadata.
    • getDescribedTypeString

      public String getDescribedTypeString()
      The persistence capable stringified class described by this metadata.
    • setDescribedType

      protected void setDescribedType(Class<?> type)
      Set the class described by this metadata. The type may be reset when an embedded value changes its declared type.
    • getEnvClassLoader

      public ClassLoader getEnvClassLoader()
      The environmental loader used when loading this metadata. The class metadata should use this loader when loading metadata for its superclass and field types.
    • setEnvClassLoader

      public void setEnvClassLoader(ClassLoader loader)
      The class environmental loader used when loading this metadata. The class metadata should use this loader when loading metadata for its superclass and field types.
    • getPCSuperclass

      public Class<?> getPCSuperclass()
      The persistence capable superclass of the described type.
    • setPCSuperclass

      public void setPCSuperclass(Class<?> pc)
      The persistence capable superclass of the described type.
    • getPCSuperclassMetaData

      public ClassMetaData getPCSuperclassMetaData()
      The metadata for this class' superclass.
    • setPCSuperclassMetaData

      public void setPCSuperclassMetaData(ClassMetaData meta)
      The metadata for this class' superclass.
    • isMapped

      public boolean isMapped()
      Whether this class is mapped to the datastore. By default, only returns false if class is embedded-only, but subclasses might override to allow unmapped other types.
    • getMappedPCSuperclassMetaData

      public ClassMetaData getMappedPCSuperclassMetaData()
      Return the closest mapped superclass.
    • getPCSubclasses

      public Class<?>[] getPCSubclasses()
      Return the known persistence capable subclasses of the described type, or empty array if none or if this is embedded metadata.
    • getPCSubclassMetaDatas

      public ClassMetaData[] getPCSubclassMetaDatas()
      Return the metadata for the known persistence capable subclasses of the described type, or empty array if none or if this is embedded metadata.
    • getMappedPCSubclassMetaDatas

      public ClassMetaData[] getMappedPCSubclassMetaDatas()
      Return all mapped subclasses.
    • getIdentityType

      public int getIdentityType()
      The type of identity being used. This will be one of:
      • ID_UNKNOWN: unknown identity type
      • ID_DATASTORE: identity managed by the data store and independent of the fields of the instance
      • ID_APPLICATION: identity managed by the application and defined by one or more fields of the instance
      If unspecified, defaults to ID_DATASTORE if there are no primary key fields, and ID_APPLICATION otherwise.
    • setIdentityType

      public void setIdentityType(int type)
      The type of identity being used. This will be one of:
      • ID_UNKNOWN: unknown identity type
      • ID_DATASTORE: identity managed by the data store and independent of the fields of the instance
      • ID_APPLICATION: identity managed by the application and defined by one or more fields of the instance
      If unspecified, defaults to ID_DATASTORE if there are no primary key fields, and ID_APPLICATION otherwise.
    • getObjectIdType

      public Class<?> getObjectIdType()
      The metadata-specified class to use for the object ID.
    • setObjectIdType

      public void setObjectIdType(Class<?> cls, boolean shared)
      The metadata-specified class to use for the object ID. When there is IdClass annotation, AnnotationMetaDataParser will call this method to set ObjectId type. However, if this is a derived identity in the child entity where a relation field (parent entity) is used as an id, and this relation field has an IdClass, the IdClass annotation in the child entity can be ignored as Openjpa will automatically wrap parent's IdClass as child's IdClass.
    • isObjectIdTypeShared

      public boolean isObjectIdTypeShared()
      Whether this type uses an application identity class that is shared with other classes, and is therefore wrapped in an ObjectId.
    • isOpenJPAIdentity

      public boolean isOpenJPAIdentity()
      Whether this type uses OpenJPA identity.
    • getIdentityStrategy

      public int getIdentityStrategy()
      The strategy to use for datastore identity generation. One of the constants from ValueStrategies.
    • setIdentityStrategy

      public void setIdentityStrategy(int strategy)
      The strategy to use for datastore identity generation. One of the constants from ValueStrategies.
    • getIdentitySequenceName

      public String getIdentitySequenceName()
      The datastore identity sequence name, or null for none.
    • setIdentitySequenceName

      public void setIdentitySequenceName(String seqName)
      The datastore identity sequence name, or null for none.
    • getIdentitySequenceMetaData

      public SequenceMetaData getIdentitySequenceMetaData()
      Metadata for the datastore identity sequence.
    • getLifecycleMetaData

      public LifecycleMetaData getLifecycleMetaData()
      Information about lifecycle callbacks for this class.
    • getTypeAlias

      public String getTypeAlias()
      Returns the alias for the described type, or null if none has been set.
      See Also:
    • setTypeAlias

      public void setTypeAlias(String alias)
      Sets the alias for the described type. The alias can be any arbitrary string that the implementation can later use to refer to the class. Note that at runtime, only the alias computed when the persistent type was enhanced is used.
      Parameters:
      alias - the alias name to apply to the described type
    • getAccessType

      public int getAccessType()
      The access type used by this class.
    • setAccessType

      public void setAccessType(int type)
      Sets the access type.
    • isExplicitAccess

      public boolean isExplicitAccess()
      Affirms if access style is explicitly defined.
    • isMixedAccess

      public boolean isMixedAccess()
      Affirms if attributes of this class use mixed access types.
    • getRequiresExtent

      public boolean getRequiresExtent()
      Whether the type requires extent management.
    • setRequiresExtent

      public void setRequiresExtent(boolean req)
      Whether the type requires extent management.
    • isEmbeddedOnly

      public boolean isEmbeddedOnly()
      Whether the type can only be used as an embedded object.
    • setEmbeddedOnly

      public void setEmbeddedOnly(boolean embed)
      Whether the type can only be used as an embedded object.
    • isEmbeddable

      public boolean isEmbeddable()
    • setEmbeddable

      public void setEmbeddable()
    • isIntercepting

      public boolean isIntercepting()
      Whether the type's fields are actively intercepted, either by redefinition or enhancement.
    • setIntercepting

      public void setIntercepting(boolean intercepting)
      Whether the type's fields are actively intercepted, either by redefinition or enhancement.
    • isManagedInterface

      public boolean isManagedInterface()
      Whether the type is a managed interface.
    • setManagedInterface

      public void setManagedInterface(boolean managedInterface)
      Whether the type is a managed interface
    • getInterfaceImpl

      public Class<?> getInterfaceImpl()
      Return the managed interface implementor if any.
    • setInterfaceImpl

      public void setInterfaceImpl(Class<?> impl)
      Set the managed interface implementor class.
    • getDeclaredInterfaces

      public Class<?>[] getDeclaredInterfaces()
      Return all explicitly declared interfaces this class implements.
    • addDeclaredInterface

      public void addDeclaredInterface(Class<?> iface)
      Explicitly declare the given interface among the ones this class implements.
    • removeDeclaredInterface

      public boolean removeDeclaredInterface(Class<?> iface)
      Remove the given interface from the declared list.
    • setInterfacePropertyAlias

      public void setInterfacePropertyAlias(Class<?> iface, String orig, String local)
      Alias properties from the given interface during queries to the local field.
    • getInterfacePropertyAlias

      public String getInterfacePropertyAlias(Class<?> iface, String orig)
      Get local field alias for the given interface property.
    • getInterfaceAliasedProperties

      public String[] getInterfaceAliasedProperties(Class<?> iface)
      Return all aliases property named for the given interface.
    • getExtraFieldDataLength

      public int getExtraFieldDataLength()
      Return the number of fields that use impl or intermediate data, in order to create a compacted array for storage of said data.
    • getExtraFieldDataIndex

      public int getExtraFieldDataIndex(int field)
      Return the intermediate field data index of the given field in the compacted array, or -1 if the field does not use extra data.
      See Also:
    • isAccessibleField

      public boolean isAccessibleField(String field)
      Return whether the given name represents a managed or static field of this class, including superclass fields.
    • getProxyFields

      public FieldMetaData[] getProxyFields()
      Return all fields that are types that need to be wrappered by a proxy. The types that need to be proxied are:

    • org.apache.openjpa.meta.JavaTypes.CALENDAR
    • org.apache.openjpa.meta.JavaTypes.COLLECTION
    • org.apache.openjpa.meta.JavaTypes.DATE
    • org.apache.openjpa.meta.JavaTypes.MAP
    • org.apache.openjpa.meta.JavaTypes.OBJECT
    • getLrsFields

      public FieldMetaData[] getLrsFields()
      Return all large result set fields. Will never return null.
    • getFields

      public FieldMetaData[] getFields()
      Return all field metadata, including superclass fields.
    • getSuperclassField

      protected FieldMetaData getSuperclassField(FieldMetaData supField)
      Return the superclass copy of the given field.
    • getDeclaredFields

      public FieldMetaData[] getDeclaredFields()
      Return only the fields for this class, without superclass fields.
    • getPrimaryKeyFields

      public FieldMetaData[] getPrimaryKeyFields()
      Return primary key fields, or empty array if none. The order in which the keys are returned will be the order in which the fields are declared, starting at the least-derived superclass and ending with the primary key fields of the most-derived subclass.
    • getDefaultFetchGroupFields

      public FieldMetaData[] getDefaultFetchGroupFields()
      Return the list of fields in the default fetch group, including superclass fields, or an empty array if none.
    • getVersionField

      public FieldMetaData getVersionField()
      Return the version field for this class, if any.
    • getField

      public FieldMetaData getField(int index)
      Return the metadata for the persistent or transactional field with the given absolute index.
      Returns:
      the field's metadata, or null if not found
    • getDeclaredField

      public FieldMetaData getDeclaredField(int index)
      Return the metadata for the persistent or transactional field with the given relative index.
      Returns:
      the field's metadata, or null if not found
    • getField

      public FieldMetaData getField(String name)
      Return the metadata for the persistent or transactional field with the given name.
      Returns:
      the field's metadata, or null if not found
    • getDeclaredField

      public FieldMetaData getDeclaredField(String name)
      Return the metadata for the persistent or transactional field with the given name, without including superclass fields.
      Returns:
      the field's metadata, or null if not found
    • getDeclaredUnmanagedFields

      public FieldMetaData[] getDeclaredUnmanagedFields()
      Return any fields that were added as non-managed. All other methods to get fields return only those that are managed.
    • addDeclaredField

      public FieldMetaData addDeclaredField(String name, Class<?> type)
      Add a new field metadata to this class.
    • removeDeclaredField

      public boolean removeDeclaredField(FieldMetaData field)
      Remove the given field from management.
      Returns:
      true if the field was removed, false otherwise
    • getDefinedSuperclassField

      public FieldMetaData getDefinedSuperclassField(String name)
      Return the defined superclass field with the given name, or null if none.
    • addDefinedSuperclassField

      public FieldMetaData addDefinedSuperclassField(String name, Class<?> type, Class<?> sup)
      Add a new defined superclass field metadata to this class.
    • removeDefinedSuperclassField

      public boolean removeDefinedSuperclassField(FieldMetaData field)
      Remove the given field from management.
      Returns:
      true if the field was removed, false otherwise
    • defineSuperclassFields

      public void defineSuperclassFields(boolean force)
      Incorporate superclass fields redefined in this subclass into this metadata. This method is generally called after metadata is resolved and mapping information is loaded, but before mapping resolve.
      Parameters:
      force - whether to force re-mapping of even mapped superclass fields
    • getDefinedFields

      public FieldMetaData[] getDefinedFields()
      Returns an array of all the fields defined by this class. This includes mapped declared fields and any concrete mapping of unmapped superclass fields performed by this class.
    • getFieldsInListingOrder

      public FieldMetaData[] getFieldsInListingOrder()
      Returns all fields in the order they are listed in the metadata file. Unlisted fields are placed after listed ones.
    • getDefinedFieldsInListingOrder

      public FieldMetaData[] getDefinedFieldsInListingOrder()
      Returns all fields defined by this class in the order they are listed in the metadata file. Unlisted fields are placed after listed ones. This array includes declared transactional and unmanaged fields.
    • getDataCacheName

      public String getDataCacheName()
      The name of the data cache that stores the managed instance of this class, by default. This can be overwritten by per-instance basis cache distribution policy.
      Returns:
      null if this class is disabled from cache by @DataCache(enabled=false). default if @DataCache(enabled=true) without a name. Otherwise, data cache name set by the user via @DataCache name attribute.
    • setDataCacheName

      public void setDataCacheName(String name)
      Set the cache name for this class.
      Parameters:
      name - can be null to disable cache.
    • getDataCacheEnabled

      public boolean getDataCacheEnabled()
      Affirms true if this receiver is annotated with @DataCache and is not disabled. A separate state variable is necessary besides the name of the cache defaulted to a special string.
    • getDataCacheTimeout

      public int getDataCacheTimeout()
      The cache timeout for this class. -1 indicates no timeout.
    • setDataCacheTimeout

      public void setDataCacheTimeout(int timeout)
      The cache timeout for this class. -1 indicates no timeout.
    • getDataCache

      public DataCache getDataCache()
      Return the data cache for this class, or null if it is not cachable.
    • isDetachable

      public boolean isDetachable()
      Whether instances are detachable.
    • setDetachable

      public void setDetachable(boolean detachable)
      Whether instances are detachable.
    • getDetachedState

      public String getDetachedState()
      The name of the detach state field, or null if none.
    • setDetachedState

      public void setDetachedState(String field)
      The name of the detach state field, or null if none.
    • getDetachedStateField

      public Field getDetachedStateField()
      Return the detach state field, or null if none.
    • usesDetachedState

      public Boolean usesDetachedState()
      Whether an instance of this type has detached state.
      Returns:
      true if a detached instance must have detached state, false if it does not, and null if it may use a manually-constructed instance without detached state
    • clearAllFieldCache

      protected void clearAllFieldCache()
      Clear cached field data.
    • clearDefinedFieldCache

      protected void clearDefinedFieldCache()
      Clear defined field data.
    • clearFieldCache

      protected void clearFieldCache()
      Clear cached field data.
    • clearSubclassCache

      protected void clearSubclassCache()
      Clear cached subclass data.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • compareTo

      public int compareTo(ClassMetaData other)
      Specified by:
      compareTo in interface Comparable<ClassMetaData>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getResolve

      public int getResolve()
      The resolve mode for this metadata.
    • setResolve

      public void setResolve(int mode)
      The resolve mode for this metadata.
    • setResolve

      public void setResolve(int mode, boolean on)
      The resolve mode for this metadata.
    • resolve

      public boolean resolve(int mode)
      Resolve and validate metadata. Return true if already resolved.
    • resolveMeta

      protected void resolveMeta(boolean runtime)
      Resolve metadata.
    • validateMeta

      protected void validateMeta(boolean runtime)
      Validate resolved metadata.
    • resolveMapping

      protected void resolveMapping(boolean runtime)
      Resolve mapping data. Logs resolve message and resolves super by default.
    • validateMapping

      protected void validateMapping(boolean runtime)
      Validate mapping data.
    • initializeMapping

      protected void initializeMapping()
      Initialize mapping. Logs init message by default.
    • useIdClassFromParent

      public boolean useIdClassFromParent()
      Return true if this class uses IdClass derived from idClass of the parent entity which annotated as id in the child class. In this case, there are no key fields in the child entity corresponding to the fields in the IdClass.
    • getDeclaredFetchGroups

      public FetchGroup[] getDeclaredFetchGroups()
      Return the fetch groups declared explicitly in this type.
    • getCustomFetchGroups

      public FetchGroup[] getCustomFetchGroups()
      Return all fetch groups for this type, including superclass groups but excluding the standard groups such as "default" or "all".
    • getFetchGroup

      public FetchGroup getFetchGroup(String name)
      Gets a named fetch group. If not available in this receiver then looks up the inheritance hierarchy.
      Parameters:
      name - name of a fetch group.
      Returns:
      an existing fetch group of the given name if known to this receiver or any of its superclasses. Otherwise null.
    • addDeclaredFetchGroup

      public FetchGroup addDeclaredFetchGroup(String name)
      Adds fetch group of the given name, or returns existing instance.
      Parameters:
      name - a non-null, non-empty name. Must be unique within this receiver's scope. The super class may have a group with the same name.
    • removeDeclaredFetchGroup

      public boolean removeDeclaredFetchGroup(FetchGroup fg)
      Remove a declared fetch group.
    • getSourceFile

      public File getSourceFile()
      Description copied from interface: SourceTracker
      Return the file from which this instance was parsed.
      Specified by:
      getSourceFile in interface SourceTracker
    • getSourceScope

      public Object getSourceScope()
      Description copied from interface: SourceTracker
      Return the domain-dependent scope of this instance within its file.
      Specified by:
      getSourceScope in interface SourceTracker
    • getSourceType

      public int getSourceType()
      Description copied from interface: SourceTracker
      Return the type of source.
      Specified by:
      getSourceType in interface SourceTracker
    • setSource

      public void setSource(File file, int srcType, String srcName)
    • getResourceName

      public String getResourceName()
      Description copied from interface: SourceTracker
      Return the domain-meaningful name of the resource that was loaded from this source. I.e., if we had loaded the source for a Java class, this would return the name of the class.
      Specified by:
      getResourceName in interface SourceTracker
    • getLineNumber

      public int getLineNumber()
      Description copied from interface: SourceTracker
      Return the line number of the file at which this instance was parsed.
      Specified by:
      getLineNumber in interface SourceTracker
    • setLineNumber

      public void setLineNumber(int lineNum)
    • getColNumber

      public int getColNumber()
      Description copied from interface: SourceTracker
      Return the column number in the line of the file at which this instance was parsed.
      Specified by:
      getColNumber in interface SourceTracker
    • setColNumber

      public void setColNumber(int colNum)
    • getSourceMode

      public int getSourceMode()
      The source mode this metadata has been loaded under.
    • setSourceMode

      public void setSourceMode(int mode)
      The source mode this metadata has been loaded under.
    • setSourceMode

      public void setSourceMode(int mode, boolean on)
      The source mode this metadata has been loaded under.
    • getListingIndex

      public int getListingIndex()
      The index in which this class was listed in the metadata. Defaults to -1 if this class was not listed in the metadata.
    • setListingIndex

      public void setListingIndex(int index)
      The index in which this field was listed in the metadata. Defaults to -1 if this class was not listed in the metadata.
    • getComments

      public String[] getComments()
      Description copied from interface: Commentable
      Return comments, or empty array if none.
      Specified by:
      getComments in interface Commentable
    • setComments

      public void setComments(String[] comments)
      Description copied from interface: Commentable
      Set comments.
      Specified by:
      setComments in interface Commentable
    • copy

      public void copy(ClassMetaData meta)
      Copy the metadata from the given instance to this one. Do not copy mapping information.
    • addExtensionKeys

      protected void addExtensionKeys(Collection exts)
      Description copied from class: Extensions
      Add all the known extension keys to the specified collection; any implementation that utilized new extensions should override this method to include both the known extensions of its superclass as well as its own extension keys.
      Overrides:
      addExtensionKeys in class Extensions
    • registerForValueUpdate

      public void registerForValueUpdate(String... values)
    • valueChanged

      public void valueChanged(Value val)
      Description copied from interface: ValueListener
      Callback used by Value objects to notify listener of change.
      Specified by:
      valueChanged in interface ValueListener
    • getFieldNames

      public String[] getFieldNames()
      Utility method to get names of all fields including the superclasses' sorted in lexical order.
    • getDeclaredFieldNames

      public String[] getDeclaredFieldNames()
      Utility method to get names of all declared fields excluding the superclasses' sorted in lexical order.
    • isAbstract

      public boolean isAbstract()
    • setAbstract

      public void setAbstract(boolean flag)
    • hasAbstractPKField

      public boolean hasAbstractPKField()
      Convenience method to determine if the pcType modeled by this ClassMetaData object is both abstract and declares PKFields. This method is used by the PCEnhancer to determine if special handling is required.
    • hasPKFieldsFromAbstractClass

      public boolean hasPKFieldsFromAbstractClass()
      Convenience method to determine if this type is a direct decendent of an abstract type declaring PKFields. Returns true if there are no pcTypes mapped to a table between this type and an abstract pcType declaring PKFields. Returns false if there no such abstract pcTypes in the inheritance hierarchy or if there are any pcTypes mapped to tables in between the type represented by this ClassMetaData object and the abstract pcType declaring PKFields.
    • setCacheEnabled

      public void setCacheEnabled(boolean enabled)
      Sets the eligibility status of this class for cache.
    • getCacheEnabled

      public Boolean getCacheEnabled()
      Returns tri-state status on whether this class has been enabled for caching.
      Returns:
      TRUE or FALSE denote this class has been explicitly enabled or disabled for caching. If no status has been explicitly set, then the status of the persistent super class, if any, is returned.
    • getSourceName

      public String getSourceName()
    • getPkAndNonPersistentManagedFmdIndexes

      public int[] getPkAndNonPersistentManagedFmdIndexes()
    • hasInverseManagedFields

      public boolean hasInverseManagedFields()
    • getMappyedByIdFields

      public List<FieldMetaData> getMappyedByIdFields()
    • getUseSchemaElement

      public boolean getUseSchemaElement()
      Set whether to include schema name in generated class files
    • setUseSchemaElement

      public void setUseSchemaElement(boolean useSchemaElement)
      Get whether to include schema name in generated class files
    • getIdClass

      public Class<?> getIdClass()
      The class specified with the @IdClass annotation if used