Class 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 metdata, then check the valid locations for metdata 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:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean allowXmlLocationsFromJDO1_0  
      protected Map<String,​org.datanucleus.metadata.AbstractClassMetaData> classMetaDataByInterface
      Map of ClassMetaData, keyed by the interface class name (for "persistent-interface"s).
      protected org.datanucleus.metadata.xml.MetaDataParser metaDataParser
      Parser for XML MetaData.
      protected Map<String,​org.datanucleus.metadata.AbstractClassMetaData> ormClassMetaDataByClass
      Map of ClassMetaData from ORM files, keyed by the class name.
      protected org.datanucleus.api.jdo.metadata.JDOMetaDataManager.MetaDataRegisterClassListener registerListener
      Listener for persistent class initialisations (since JDO uses a discovery process).
      • 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

      All Methods Instance Methods Concrete Methods 
      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 close()
      Clear resources
      org.datanucleus.metadata.ClassMetaData getClassMetaDataForImplementationOfPersistentInterface​(String interfaceName)
      Accessor for the metadata for the implementation of the specified "persistent-interface".
      String getImplementationNameForPersistentInterface​(String interfaceName)
      Accessor for the implementation name for the specified "persistent-interface".
      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.
      List<String> getValidMetaDataLocationsForClass​(String fileExtension, String fileModifier, String className)
      Method to return the valid metadata locations to contain a particular class.
      List<String> getValidMetaDataLocationsForPackage​(String fileExtension, String fileModifier, String packageName)
      Method to return the valid metadata locations to contain a particular package.
      boolean isPersistentDefinitionImplementation​(String implName)
      Convenience method to return if the passed class name is an implementation of a "persistent definition".
      boolean isPersistentInterface​(String name)
      Convenience method to return if the passed class name is a "persistent-interface".
      boolean isPersistentInterfaceImplementation​(String interfaceName, String implName)
      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 parseFile​(URL fileURL)
      Utility to parse a file, using the "jdo" MetaData handler.
      void registerFile​(String fileURLString, org.datanucleus.metadata.FileMetaData filemd, org.datanucleus.ClassLoaderResolver clr)
      Method to take the FileMetaData and register the relevant parts of it with the assorted caches provided.
      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 unloadMetaDataForClass​(String className)
      Convenience method to allow the unloading of metadata, for example where the user wants to reload a class definition and that class maybe has different metadata with the new definition.
      • 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
    • Field Detail

      • allowXmlLocationsFromJDO1_0

        protected boolean allowXmlLocationsFromJDO1_0
      • metaDataParser

        protected org.datanucleus.metadata.xml.MetaDataParser metaDataParser
        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

        protected org.datanucleus.api.jdo.metadata.JDOMetaDataManager.MetaDataRegisterClassListener registerListener
        Listener for persistent class initialisations (since JDO uses a discovery process).
    • Constructor Detail

      • JDOMetaDataManager

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

      • 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)
        Convenience method to allow the unloading of metadata, for example where the user wants to reload a class definition and that class maybe has different metadata with the new definition.
        Specified by:
        unloadMetaDataForClass in interface org.datanucleus.metadata.MetaDataManager
        Overrides:
        unloadMetaDataForClass in class org.datanucleus.metadata.MetaDataManagerImpl
        Parameters:
        className - Name of the class
      • parseFile

        protected org.datanucleus.metadata.FileMetaData parseFile​(URL fileURL)
        Utility to parse a file, using the "jdo" MetaData handler.
        Specified by:
        parseFile 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)
        Method to take the FileMetaData and register the relevant parts of it with the assorted caches provided.
        Specified by:
        registerFile in interface org.datanucleus.metadata.MetaDataManager
        Specified by:
        registerFile in class org.datanucleus.metadata.MetaDataManagerImpl
        Parameters:
        fileURLString - URL of the metadata file
        filemd - The File MetaData
      • 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
      • 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
      • isPersistentDefinitionImplementation

        public boolean isPersistentDefinitionImplementation​(String implName)
        Convenience method to return if the passed class name is an implementation of a "persistent definition".
        Specified by:
        isPersistentDefinitionImplementation in interface org.datanucleus.metadata.MetaDataManager
        Overrides:
        isPersistentDefinitionImplementation in class org.datanucleus.metadata.MetaDataManagerImpl
        Parameters:
        implName - The implementation name
        Returns:
        Whether it is a (generated) impl of the persistent interface or abstract class
      • 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".
        Specified by:
        getClassMetaDataForImplementationOfPersistentInterface in interface org.datanucleus.metadata.MetaDataManager
        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