Class JDOMetaDataManager

java.lang.Object
org.datanucleus.metadata.MetaDataManagerImpl
org.datanucleus.api.jdo.metadata.JDOMetaDataManager
All Implemented Interfaces:
Serializable, org.datanucleus.metadata.MetaDataManager

public class JDOMetaDataManager extends org.datanucleus.metadata.MetaDataManagerImpl
Manager of JDO MetaData information in DataNucleus.

Acts as a registry of JDO metadata so that metadata files don't need to be parsed multiple times. MetaData is stored as a FileMetaData, which contains PackageMetaData, which contains ClassMetaData, and so on. This maps exactly to the users model of their metadata. The users access point is getMetaDataForClass() which will check the known classes without metadata, then check the existing registered metadata, then check the valid locations for metadata files. This way, the metadata is managed from this single point.

When the MetaData is requested for a class, if it isn't already found, the valid file locations are checked for that class and the file containing it will be read. The MetaData for all classes, queries, sequences etc in that file are loaded at that point. In addition, all classes will be "populated" (meaning that their superclasses are assigned, and unspecified fields are added, and any related objects are linked). The MetaData of these classes are only initialised when they are absolutely needed - to avoid generating circular references in the initialisation process.

Each NucleusContext typically will have its own MetaDataManager so allowing Meta-Data to be for different datastores. In addition, each PMF can allow MetaData files to use a particular suffix, hence we allow the JDO/ORM file suffices to be specifiable at construction.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private class 
    Register to persistent class load
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
     
    private static final char
     
    protected Map<String,org.datanucleus.metadata.AbstractClassMetaData>
    Map of ClassMetaData, keyed by the interface class name (for "persistent-interface"s).
    private static final char
     
    private static final String
     
    private static final String
     
    private static final String
     
    protected Map<String,org.datanucleus.metadata.AbstractClassMetaData>
    Map of ClassMetaData from ORM files, keyed by the class name.
    private static final char
     
    Listener for persistent class initialisations (since JDO uses a discovery process).
    private static final long
     
    protected org.datanucleus.metadata.xml.XmlMetaDataParser
    Parser for XML MetaData.

    Fields inherited from class org.datanucleus.metadata.MetaDataManagerImpl

    allowAnnotations, allowMetaDataLoad, allowORM, allowXML, annotationManager, classesWithoutPersistenceInfo, classMetaDataByAppIdClassName, classMetaDataByClass, classMetaDataByDiscriminatorName, classMetaDataByEntityName, concreteSubclassNamesByClassName, defaultNullable, directSubclassesByClass, discriminatorLookupByRootClassName, fetchPlanMetaDataByName, fileMetaDataByURLString, listeners, nucleusContext, queryMetaDataByName, queryResultMetaDataByName, sequenceMetaDataByPackageSequence, storedProcQueryMetaDataByName, supportXMLNamespaces, tableGeneratorMetaDataByPackageSequence, updateLock, usableClassMetaDataByClass, userMetaDataNumber, utilisedFileMetaData, validateXML
  • Constructor Summary

    Constructors
    Constructor
    Description
    JDOMetaDataManager(org.datanucleus.NucleusContext ctxt)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addORMDataToClass(Class c, org.datanucleus.ClassLoaderResolver clr)
    Load up and add the O/R mapping info for the specified class to the stored JDO ClassMetaData.
    void
    Clear resources
    org.datanucleus.metadata.ClassMetaData
    Accessor for the metadata for the implementation of the specified "persistent-interface".
    Accessor for the implementation name for the specified "persistent-interface".
    private String
    Convenience accessor for the JDO file suffix.
    private String
    Convenience accessor for the JDOQuery file suffix.
    org.datanucleus.metadata.InterfaceMetaData
    getMetaDataForInterface(Class c, org.datanucleus.ClassLoaderResolver clr)
    Main accessor for the MetaData for a "persistent-interface".
    org.datanucleus.metadata.QueryMetaData
    getMetaDataForQuery(Class cls, org.datanucleus.ClassLoaderResolver clr, String queryName)
    Accessor for the MetaData for a named query for a class.
    org.datanucleus.metadata.SequenceMetaData
    getMetaDataForSequence(org.datanucleus.ClassLoaderResolver clr, String packageSequenceName)
    Accessor for the MetaData for a Sequence in a package.
    private String
    Convenience accessor for the ORM file suffix.
    private String
    Convenience accessor for the mapping name.
    getValidMetaDataLocationsForClass(String fileExtension, String fileModifier, String className)
    Method to return the valid metadata locations to contain a particular class.
    (package private) List<String>
    getValidMetaDataLocationsForItem(String fileExtension, String fileModifier, String itemName, boolean isClass)
    Method to return the valid metadata locations to contain a particular item.
    getValidMetaDataLocationsForPackage(String fileExtension, String fileModifier, String packageName)
    Method to return the valid metadata locations to contain a particular package.
    private List<String>
    getValidMetaDataLocationsForSingleExtension(String fileExtension, String fileModifier, String itemName, boolean isClass)
    Method to return the valid metadata locations to contain a particular item.
    boolean
    Convenience method to return if the passed class name is a "persistent-interface".
    boolean
    Convenience method to return if the passed class name is an implementation of the passed "persistent-interface".
    protected org.datanucleus.metadata.AbstractClassMetaData
    loadMetaDataForClass(Class c, org.datanucleus.ClassLoaderResolver clr)
    Load the metadata for the specified class (if available).
    protected org.datanucleus.metadata.FileMetaData
    loadXMLMetaDataForClass(Class pc_class, org.datanucleus.ClassLoaderResolver clr, String mappingModifier, String metadataFileExtension, org.datanucleus.metadata.MetaDataFileType metadataType, boolean populate)
    Method to find the Meta-Data file for a specified class.
    protected org.datanucleus.metadata.FileMetaData
    parseXmlFile(URL fileURL)
    Utility to parse an XML file, using the "jdo" MetaData handler.
    void
    registerFile(String fileURLString, org.datanucleus.metadata.FileMetaData filemd, org.datanucleus.ClassLoaderResolver clr)
     
    void
    registerImplementationOfAbstractClass(org.datanucleus.metadata.ClassMetaData cmd, Class implClass, org.datanucleus.ClassLoaderResolver clr)
    Method to register the metadata for an implementation of a persistent abstract class.
    void
    registerPersistentInterface(org.datanucleus.metadata.InterfaceMetaData imd, Class implClass, org.datanucleus.ClassLoaderResolver clr)
    Method to register a persistent interface and its implementation with the MetaData system.
    void
     

    Methods inherited from class org.datanucleus.metadata.MetaDataManagerImpl

    abstractClassMetaDataInitialised, addAnnotationsDataToClass, deregisterListener, getAnnotationManager, getApiAdapter, getClassesImplementingInterface, getClassesWithMetaData, getClassMetaDataWithApplicationId, getClassNameForDiscriminatorValueWithRoot, getClassNameFromDiscriminatorValue, getConcreteSubclassesForClass, getDiscriminatorValueForClass, getEnhancedMethodNamePrefix, getFileMetaData, getMetaDataForClass, getMetaDataForClass, getMetaDataForClassInternal, getMetaDataForDiscriminator, getMetaDataForEntityName, getMetaDataForFetchPlan, getMetaDataForImplementationOfReference, getMetaDataForQueryResult, getMetaDataForStoredProcQuery, getMetaDataForTableGenerator, getNamedQueryNames, getNucleusContext, getReferencedClasses, getReferencedClassMetaData, getScanner, getSubclassesForClass, hasMetaDataForClass, initialiseAbstractClassMetaData, initialiseClassMetaData, initialiseFileMetaData, initialiseFileMetaDataForUse, initialiseInterfaceMetaData, isClassPersistable, isClassWithoutPersistenceInfo, isDefaultNullable, isEnhancerField, isEnhancing, isFieldTypePersistable, loadAnnotationsForClass, loadClasses, loadFiles, loadJar, loadMetaDataFiles, loadPersistenceUnit, loadUserMetaData, populateAbstractClassMetaData, populateFileMetaData, postProcessClassMetaData, processListenerLoadingCall, readMetaDataForClass, readMetaDataForMember, registerDiscriminatorValueForClass, registerFetchPlansForFile, registerListener, registerMetaDataForClass, registerNamedQuery, registerQueriesForFile, registerQueryResultMetaDataForFile, registerSequencesForFile, registerStoredProcQueriesForFile, registerTableGeneratorsForFile, setAllowAnnotations, setAllowMetaDataLoad, setAllowXML, setDefaultNullable, setValidate, setXmlNamespaceAware, supportsORM

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • allowXmlLocationsFromJDO1_0

      protected boolean allowXmlLocationsFromJDO1_0
    • xmlMetaDataParser

      protected org.datanucleus.metadata.xml.XmlMetaDataParser xmlMetaDataParser
      Parser for XML MetaData.
    • ormClassMetaDataByClass

      protected Map<String,org.datanucleus.metadata.AbstractClassMetaData> ormClassMetaDataByClass
      Map of ClassMetaData from ORM files, keyed by the class name.
    • classMetaDataByInterface

      protected Map<String,org.datanucleus.metadata.AbstractClassMetaData> classMetaDataByInterface
      Map of ClassMetaData, keyed by the interface class name (for "persistent-interface"s). Keyed by the persistent-interface name.
    • registerListener

      Listener for persistent class initialisations (since JDO uses a discovery process).
    • CLASS_SEPARATOR

      private static final char CLASS_SEPARATOR
      See Also:
    • PATH_SEPARATOR

      private static final char PATH_SEPARATOR
      See Also:
    • EXTENSION_SEPARATOR

      private static final char EXTENSION_SEPARATOR
      See Also:
    • METADATA_PACKAGE

      private static final String METADATA_PACKAGE
      See Also:
    • METADATA_LOCATION_METAINF

      private static final String METADATA_LOCATION_METAINF
      See Also:
    • METADATA_LOCATION_WEBINF

      private static final String METADATA_LOCATION_WEBINF
      See Also:
  • Constructor Details

    • JDOMetaDataManager

      public JDOMetaDataManager(org.datanucleus.NucleusContext ctxt)
      Constructor.
      Parameters:
      ctxt - NucleusContext that this metadata manager operates in
  • Method Details

    • close

      public void close()
      Clear resources
      Specified by:
      close in interface org.datanucleus.metadata.MetaDataManager
      Overrides:
      close in class org.datanucleus.metadata.MetaDataManagerImpl
    • unloadMetaDataForClass

      public void unloadMetaDataForClass(String className)
      Specified by:
      unloadMetaDataForClass in interface org.datanucleus.metadata.MetaDataManager
      Overrides:
      unloadMetaDataForClass in class org.datanucleus.metadata.MetaDataManagerImpl
    • parseXmlFile

      protected org.datanucleus.metadata.FileMetaData parseXmlFile(URL fileURL)
      Utility to parse an XML file, using the "jdo" MetaData handler.
      Specified by:
      parseXmlFile in class org.datanucleus.metadata.MetaDataManagerImpl
      Parameters:
      fileURL - URL of the file
      Returns:
      The FileMetaData for this file
    • registerFile

      public void registerFile(String fileURLString, org.datanucleus.metadata.FileMetaData filemd, org.datanucleus.ClassLoaderResolver clr)
      Specified by:
      registerFile in interface org.datanucleus.metadata.MetaDataManager
      Specified by:
      registerFile in class org.datanucleus.metadata.MetaDataManagerImpl
    • loadMetaDataForClass

      protected org.datanucleus.metadata.AbstractClassMetaData loadMetaDataForClass(Class c, org.datanucleus.ClassLoaderResolver clr)
      Load the metadata for the specified class (if available). With JDO we check for XML metadata for the class (in one of the standard locations), or annotations on the class itself.
      Specified by:
      loadMetaDataForClass in class org.datanucleus.metadata.MetaDataManagerImpl
      Parameters:
      c - The class
      clr - ClassLoader resolver
      Returns:
      The metadata for this class (if found)
    • getMetaDataForQuery

      public org.datanucleus.metadata.QueryMetaData getMetaDataForQuery(Class cls, org.datanucleus.ClassLoaderResolver clr, String queryName)
      Accessor for the MetaData for a named query for a class. If the query is not found, will check all valid JDO file locations and try to load it.
      Specified by:
      getMetaDataForQuery in interface org.datanucleus.metadata.MetaDataManager
      Overrides:
      getMetaDataForQuery in class org.datanucleus.metadata.MetaDataManagerImpl
      Parameters:
      cls - The class which has the query defined for it
      clr - the ClassLoaderResolver
      queryName - Name of the query
      Returns:
      The QueryMetaData for the query for this class
    • getMetaDataForSequence

      public org.datanucleus.metadata.SequenceMetaData getMetaDataForSequence(org.datanucleus.ClassLoaderResolver clr, String packageSequenceName)
      Accessor for the MetaData for a Sequence in a package. If the sequence is not yet known will search the valid locations for the passed name.
      Specified by:
      getMetaDataForSequence in interface org.datanucleus.metadata.MetaDataManager
      Overrides:
      getMetaDataForSequence in class org.datanucleus.metadata.MetaDataManagerImpl
      Parameters:
      clr - the ClassLoaderResolver
      packageSequenceName - Fully qualified name of the sequence (inc package name)
      Returns:
      The SequenceMetaData for this named sequence
    • addORMDataToClass

      public void addORMDataToClass(Class c, org.datanucleus.ClassLoaderResolver clr)
      Load up and add the O/R mapping info for the specified class to the stored JDO ClassMetaData.
      Specified by:
      addORMDataToClass in interface org.datanucleus.metadata.MetaDataManager
      Overrides:
      addORMDataToClass in class org.datanucleus.metadata.MetaDataManagerImpl
      Parameters:
      c - The class
      clr - the ClassLoaderResolver
    • loadXMLMetaDataForClass

      protected org.datanucleus.metadata.FileMetaData loadXMLMetaDataForClass(Class pc_class, org.datanucleus.ClassLoaderResolver clr, String mappingModifier, String metadataFileExtension, org.datanucleus.metadata.MetaDataFileType metadataType, boolean populate)
      Method to find the Meta-Data file for a specified class. Checks the locations one-by-one, and checks for existence of the specified class in the file. If a valid file is found it is loaded no matter if the file contains the actual class. When a file is found containing the class the process stops and the FileMetaData for that file (containing the class) returned.

      Allows 2 variations on the naming above. The first is a modifier which caters for a JDO 2.0 requirement whereby the user can specify a modifier such as "mysql", which would mean that this should search for filenames "package-mysql.jdo". The second variation is the suffix of the file. This is "jdo" by default, but JDO 2.0 has situations where "orm", or "jdoquery" are required as a suffix.

      Parameters:
      pc_class - The class/interface to retrieve the metadata file for
      clr - the ClassLoaderResolver
      mappingModifier - Any modifier for the filename for mapping
      metadataFileExtension - File extension of metadata files (e.g "jdo")
      metadataType - Type of metadata file to load
      populate - Whether to populate any loaded MetaData classes
      Returns:
      FileMetaData for the file containing the class
    • getValidMetaDataLocationsForPackage

      public List<String> getValidMetaDataLocationsForPackage(String fileExtension, String fileModifier, String packageName)
      Method to return the valid metadata locations to contain a particular package.
      Parameters:
      fileExtension - File extension (e.g "jdo")
      fileModifier - Any modifier (for use when using ORM files package-mysql.orm, this is the "mysql" part)
      packageName - The package name to look for
      Returns:
      The list of valid locations
    • getValidMetaDataLocationsForClass

      public List<String> getValidMetaDataLocationsForClass(String fileExtension, String fileModifier, String className)
      Method to return the valid metadata locations to contain a particular class.
      Parameters:
      fileExtension - File extension (e.g "jdo")
      fileModifier - Any modifier (for use when using ORM files package-mysql.orm, this is the "mysql" part)
      className - The class name to look for
      Returns:
      The list of valid locations
    • getValidMetaDataLocationsForItem

      List<String> getValidMetaDataLocationsForItem(String fileExtension, String fileModifier, String itemName, boolean isClass)
      Method to return the valid metadata locations to contain a particular item. The "item" can be a package or a class. Will look in the locations appropriate for the setting of "locationDefintion".
      Parameters:
      fileExtension - File extension (e.g "jdo") accepts comma separated list
      fileModifier - Any modifier (for use when using ORM files package-mysql.orm, this is the "mysql" part)
      itemName - The name of the item (package or class)
      isClass - Whether this is a class
      Returns:
      The list of valid locations
    • getValidMetaDataLocationsForSingleExtension

      private List<String> getValidMetaDataLocationsForSingleExtension(String fileExtension, String fileModifier, String itemName, boolean isClass)
      Method to return the valid metadata locations to contain a particular item. The "item" can be a package or a class. Will look in the locations appropriate for the setting of "locationDefintion".
      Parameters:
      fileExtension - File extension (e.g "jdo")
      fileModifier - Any modifier (for use when using ORM files package-mysql.orm, this is the "mysql" part)
      itemName - The name of the item (package or class)
      isClass - Whether this is a class
      Returns:
      The list of valid locations
    • getORMMappingName

      private String getORMMappingName()
      Convenience accessor for the mapping name.
      Returns:
      ORM mapping name
    • getJDOFileSuffix

      private String getJDOFileSuffix()
      Convenience accessor for the JDO file suffix.
      Returns:
      JDO file suffix
    • getORMFileSuffix

      private String getORMFileSuffix()
      Convenience accessor for the ORM file suffix.
      Returns:
      ORM file suffix
    • getJDOQueryFileSuffix

      private String getJDOQueryFileSuffix()
      Convenience accessor for the JDOQuery file suffix.
      Returns:
      JDOQuery file suffix
    • getMetaDataForInterface

      public org.datanucleus.metadata.InterfaceMetaData getMetaDataForInterface(Class c, org.datanucleus.ClassLoaderResolver clr)
      Main accessor for the MetaData for a "persistent-interface". All MetaData returned from this method will be initialised and ready for full use.
      Specified by:
      getMetaDataForInterface in interface org.datanucleus.metadata.MetaDataManager
      Overrides:
      getMetaDataForInterface in class org.datanucleus.metadata.MetaDataManagerImpl
      Parameters:
      c - The interface to find MetaData for
      clr - the ClassLoaderResolver
      Returns:
      The InterfaceMetaData for this interface (or null if not found)
    • isPersistentInterface

      public boolean isPersistentInterface(String name)
      Convenience method to return if the passed class name is a "persistent-interface".
      Specified by:
      isPersistentInterface in interface org.datanucleus.metadata.MetaDataManager
      Overrides:
      isPersistentInterface in class org.datanucleus.metadata.MetaDataManagerImpl
      Parameters:
      name - Name if the interface
      Returns:
      Whether it is a "persistent-interface"
    • isPersistentInterfaceImplementation

      public boolean isPersistentInterfaceImplementation(String interfaceName, String implName)
      Convenience method to return if the passed class name is an implementation of the passed "persistent-interface".
      Specified by:
      isPersistentInterfaceImplementation in interface org.datanucleus.metadata.MetaDataManager
      Overrides:
      isPersistentInterfaceImplementation in class org.datanucleus.metadata.MetaDataManagerImpl
      Parameters:
      interfaceName - Name of the persistent interface
      implName - The implementation name
      Returns:
      Whether it is a (generated) impl of the persistent interface
    • getImplementationNameForPersistentInterface

      public String getImplementationNameForPersistentInterface(String interfaceName)
      Accessor for the implementation name for the specified "persistent-interface".
      Specified by:
      getImplementationNameForPersistentInterface in interface org.datanucleus.metadata.MetaDataManager
      Overrides:
      getImplementationNameForPersistentInterface in class org.datanucleus.metadata.MetaDataManagerImpl
      Parameters:
      interfaceName - The name of the persistent interface
      Returns:
      The name of the implementation class
    • getClassMetaDataForImplementationOfPersistentInterface

      public org.datanucleus.metadata.ClassMetaData getClassMetaDataForImplementationOfPersistentInterface(String interfaceName)
      Accessor for the metadata for the implementation of the specified "persistent-interface".
      Overrides:
      getClassMetaDataForImplementationOfPersistentInterface in class org.datanucleus.metadata.MetaDataManagerImpl
      Parameters:
      interfaceName - The name of the persistent interface
      Returns:
      The ClassMetaData of the implementation class
    • registerPersistentInterface

      public void registerPersistentInterface(org.datanucleus.metadata.InterfaceMetaData imd, Class implClass, org.datanucleus.ClassLoaderResolver clr)
      Method to register a persistent interface and its implementation with the MetaData system.
      Specified by:
      registerPersistentInterface in interface org.datanucleus.metadata.MetaDataManager
      Overrides:
      registerPersistentInterface in class org.datanucleus.metadata.MetaDataManagerImpl
      Parameters:
      imd - MetaData for the interface
      implClass - The implementation class
      clr - ClassLoader Resolver to use
    • registerImplementationOfAbstractClass

      public void registerImplementationOfAbstractClass(org.datanucleus.metadata.ClassMetaData cmd, Class implClass, org.datanucleus.ClassLoaderResolver clr)
      Method to register the metadata for an implementation of a persistent abstract class.
      Specified by:
      registerImplementationOfAbstractClass in interface org.datanucleus.metadata.MetaDataManager
      Overrides:
      registerImplementationOfAbstractClass in class org.datanucleus.metadata.MetaDataManagerImpl
      Parameters:
      cmd - MetaData for the abstract class
      implClass - The implementation class
      clr - ClassLoader resolver