Interface MetaDataManager

  • All Known Implementing Classes:
    MetaDataManagerImpl

    public interface MetaDataManager
    Manager for metadata in DataNucleus. The MetaDataManager manages the metadata for classes/members. MetaData can be derived from annotations, or XML, or via an API, or a mixture of all. MetaData from different sources is merged using MetaDataMerger

    persistence.xml

    This class does not handle the parsing of a persistence-unit metadata from a "persistence.xml" file. That is handled by MetaDataUtils.getMetaDataForPersistenceUnit which returns the PersistenceUnitMetaData and by MetaDataUtils.parsePersistenceFiles which parses all PersistenceFileMetaData from the available "persistence.xml" file(s).
    • Method Detail

      • close

        void close()
      • getEnhancedMethodNamePrefix

        String getEnhancedMethodNamePrefix()
        Method to return the prefix applied to all enhancer method names
        Returns:
        The enhancer method name prefix (e.g "dn")
      • isEnhancerField

        boolean isEnhancerField​(String memberName)
        Method to return whether the specified member is an enhancer-provided member.
        Parameters:
        memberName - Name of the member
        Returns:
        Whether it was added by the enhancer (e.g prefix "dn")
      • registerListener

        void registerListener​(MetaDataListener listener)
        Method to register a listener to be notified when metadata for a class/interface is initialised.
        Parameters:
        listener - The listener
      • deregisterListener

        void deregisterListener​(MetaDataListener listener)
        Method to deregister a listener from being notified when metadata for a class/interface is initialised.
        Parameters:
        listener - The listener
      • setAllowMetaDataLoad

        void setAllowMetaDataLoad​(boolean allow)
      • setAllowXML

        void setAllowXML​(boolean allow)
      • setDefaultNullable

        void setDefaultNullable​(boolean nullable)
      • setAllowAnnotations

        void setAllowAnnotations​(boolean allow)
      • setValidate

        void setValidate​(boolean validate)
        Mutator for whether to validate the MetaData files for XML compliance.
        Parameters:
        validate - Whether to validate
      • setXmlNamespaceAware

        void setXmlNamespaceAware​(boolean aware)
        Mutator for whether to support XML namespaces.
        Parameters:
        aware - Whether to be XML namespace aware
      • supportsORM

        boolean supportsORM()
        Accessor for whether the MetaData manager supports ORM concepts and metadata. With object datastores this will return false.
        Returns:
        Whether we support ORM
      • isDefaultNullable

        boolean isDefaultNullable()
        Acessor for the default nullability of fields.
        Returns:
        true if fields should be null by default and false whether it should be not-null.
      • isEnhancing

        boolean isEnhancing()
        Accessor for whether we are managing the enhancement process.
        Returns:
        Whether we are enhancing
      • loadMetaDataFiles

        FileMetaData[] loadMetaDataFiles​(String[] metadataFiles,
                                         ClassLoader loader)
        Initialisation method to load up all metadata defined by the specified metadata files. Metadata files can be absolute/relative filenames, or can be resources in the CLASSPATH.
        Parameters:
        metadataFiles - The metadata files
        loader - ClassLoader to use in loading the metadata (if any)
        Returns:
        Array of the FileMetaData that is managed
        Throws:
        NucleusUserException - (with nested exceptions) if an error occurs parsing the files
      • loadClasses

        FileMetaData[] loadClasses​(String[] classNames,
                                   ClassLoader loader)
        Initialisation method to load up all metadata for the specified classes.
        Parameters:
        classNames - The class names
        loader - ClassLoader to use in loading the classes (if any)
        Returns:
        Array of the FileMetaData that is managed
        Throws:
        NucleusUserException - (with nested exceptions) if an error occurs parsing the files
      • loadJar

        FileMetaData[] loadJar​(String jarFileName,
                               ClassLoader loader)
        Initialisation method to load the metadata provided by the specified jar.
        Parameters:
        jarFileName - Name of the jar file
        loader - ClassLoader to use in loading of the jar (if any)
        Returns:
        Array of the FileMetaData that is managed
        Throws:
        NucleusUserException - if an error occurs parsing the jar info
      • loadPersistenceUnit

        FileMetaData[] loadPersistenceUnit​(PersistenceUnitMetaData pumd,
                                           ClassLoader loader)
        Initialisation method to to load all class metadata defined by the "persistence-unit".
        Parameters:
        pumd - The MetaData for this "persistence-unit"
        loader - ClassLoader to use in loading of the persistence unit (if any)
        Returns:
        Array of the FileMetaData that is managed
        Throws:
        NucleusUserException - if an error occurs parsing the persistence-unit info
      • loadUserMetaData

        void loadUserMetaData​(FileMetaData fileMetaData,
                              ClassLoader loader)
        Method to load user-provided (dynamic) metadata (from the JDO MetaData API).
        Parameters:
        fileMetaData - FileMetaData to register/populate/initialise
        loader - ClassLoader to use in loading the metadata (if any)
      • loadFiles

        Collection<FileMetaData> loadFiles​(String[] metadataFiles,
                                           ClassLoaderResolver clr)
        Method to load the metadata from the specified files. Supports absolute/relative file names, or CLASSPATH resources.
        Parameters:
        metadataFiles - array of MetaData files
        clr - ClassLoader resolver
        Returns:
        List of FileMetaData
      • unloadMetaDataForClass

        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.
        Parameters:
        className - Name of the class
      • isClassPersistable

        boolean isClassPersistable​(String className)
        Convenience method to return if the specified class is a known persistable class.
        Parameters:
        className - Name of the class
        Returns:
        Whether it is persistable
      • getFileMetaData

        FileMetaData[] getFileMetaData()
        Accessor for all FileMetaData currently managed here.
        Returns:
        FileMetaData managed here currently
      • getClassesWithMetaData

        Collection<String> getClassesWithMetaData()
        Accessor for the names of the classes with MetaData currently registered with this manager.
        Returns:
        Names of classes with MetaData
      • hasMetaDataForClass

        boolean hasMetaDataForClass​(String className)
        Convenience method to check if we have metadata present for the specified class.
        Parameters:
        className - The name of the class to check
        Returns:
        Whether the metadata is already registered for this class
      • getClassMetaDataWithApplicationId

        Collection<AbstractClassMetaData> getClassMetaDataWithApplicationId​(String objectIdClassName)
        Accessor for the metadata for the class(es) with the specified object-id class name as PK. This only works for user-provided object-id classes (not SingleFieldIdentity).
        Parameters:
        objectIdClassName - The object-id class name
        Returns:
        Collection of AbstractClassMetaData for the classes using this PK
      • getMetaDataForClass

        AbstractClassMetaData getMetaDataForClass​(String className,
                                                  ClassLoaderResolver clr)
        Accessor for the MetaData for a class given the name and a loader. All MetaData returned from this method will be initialised and ready for full use. If the class can't be loaded, null will be returned.
        Parameters:
        className - Name of the class to find MetaData for
        clr - ClassLoaderResolver resolver for use in loading the class.
        Returns:
        The ClassMetaData for this class (or null if not found)
      • getMetaDataForClass

        AbstractClassMetaData getMetaDataForClass​(Class c,
                                                  ClassLoaderResolver clr)
        Primary accessor for the MetaData for a class. All MetaData returned from this method will be initialised and ready for full use.
        Parameters:
        c - The class to find MetaData for
        clr - the ClassLoaderResolver
        Returns:
        The ClassMetaData for this class (or null if not found)
      • getMetaDataForEntityName

        AbstractClassMetaData getMetaDataForEntityName​(String entityName)
        Accessor for the MetaData for a class given the "entity-name".
        Parameters:
        entityName - The entity name to find MetaData for
        Returns:
        The ClassMetaData for this entity name (or null if not found)
      • getMetaDataForDiscriminator

        AbstractClassMetaData getMetaDataForDiscriminator​(String discriminator)
        Accessor for the MetaData for a class given the "discriminator".
        Parameters:
        discriminator - The discriminator name to find MetaData for
        Returns:
        The ClassMetaData for this discriminator (or null if not found)
      • readMetaDataForClass

        AbstractClassMetaData readMetaDataForClass​(String className)
        Method to access the (already known) metadata for the specified class. If the class is not yet known about it returns null. Only used by org.datanucleus.metadata classes.
        Parameters:
        className - Name of the class
        Returns:
        MetaData for the class
      • readMetaDataForMember

        AbstractMemberMetaData readMetaDataForMember​(String className,
                                                     String memberName)
        Method to access the (already known) metadata for the field/property of the specified class. If the class (or this field/property) is not yet known about it returns null. Only used by org.datanucleus.metadata classes.
        Parameters:
        className - Name of the class
        memberName - Name of the field/property
        Returns:
        MetaData for the field/property
      • getMetaDataForClassInternal

        AbstractClassMetaData getMetaDataForClassInternal​(Class c,
                                                          ClassLoaderResolver clr)
        Internal convenience method for accessing the MetaData for a class. MetaData returned by this method may be uninitialised so should only really be used in initialisation processes. To be implemented by the implementing class.
        Parameters:
        c - The class to find MetaData for
        clr - ClassLoader resolver
        Returns:
        The ClassMetaData for this class (or null if not found)
      • getSubclassesForClass

        String[] getSubclassesForClass​(String className,
                                       boolean includeDescendents)
        Accessor for the subclasses of a particular class
        Parameters:
        className - Name of the class that we want the known subclasses for.
        includeDescendents - Whether to include subclasses of subclasses etc
        Returns:
        Names of the subclasses. return null if there are no subclasses
      • getConcreteSubclassesForClass

        String[] getConcreteSubclassesForClass​(String className)
        Accessor for the names of all concrete subclasses of the provided class.
        Parameters:
        className - Name of the class that we want the known concrete subclasses for.
        Returns:
        Names of the subclasses. Returns null if there are no subclasses
      • getClassesImplementingInterface

        String[] getClassesImplementingInterface​(String interfaceName,
                                                 ClassLoaderResolver clr)
        Accessor for the list of names of classes that are declared to implement the specified interface (using <implements> in the MetaData). This will include subclasses of declared classes. Ignore abstract classes. The array of implementation class names will have the initial implementations first followed by the subclass implementations etc. So for example if we look for all implementations of I and A implements I and B extends A, then it will return [A, B] in that order.
        Parameters:
        interfaceName - Name of the interface
        clr - The ClassLoaderResolver
        Returns:
        The names of the classes declared as implementing that interface. return null if no classes
      • getMetaDataForImplementationOfReference

        ClassMetaData getMetaDataForImplementationOfReference​(Class referenceClass,
                                                              Object implValue,
                                                              ClassLoaderResolver clr)
        Accessor for the MetaData for an implementation of a reference type. Finds the metadata for the implementation of this reference.
        Parameters:
        referenceClass - The reference class to find MetaData for
        implValue - Object of an implementation class, to return if possible (null=ignore)
        clr - ClassLoader resolver
        Returns:
        The ClassMetaData for an implementation of a reference type
      • getMetaDataForQuery

        QueryMetaData getMetaDataForQuery​(Class cls,
                                          ClassLoaderResolver clr,
                                          String queryName)
        Accessor for the MetaData for a named query for a class. If the class is not specified, searches for the query with this name for any class. Will only return metadata for queries already registered in this implementation.
        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
      • getNamedQueryNames

        Set<String> getNamedQueryNames()
        Convenience method to access the names of named queries that are registered with this manager.
        Returns:
        Names of the named queries
      • registerNamedQuery

        void registerNamedQuery​(QueryMetaData qmd)
        Method to register a named query.
        Parameters:
        qmd - The definition of the query, with its name
      • getMetaDataForStoredProcQuery

        StoredProcQueryMetaData getMetaDataForStoredProcQuery​(Class cls,
                                                              ClassLoaderResolver clr,
                                                              String queryName)
        Accessor for the MetaData for a named stored procedure query for a class. If the class is not specified, searches for the query with this name for any class. Will only return metadata for queries already registered in this implementation.
        Parameters:
        cls - The class which has the query defined for it
        clr - the ClassLoaderResolver
        queryName - Name of the (stored proc) query
        Returns:
        The StoredProcQueryMetaData for the query for this class
      • getMetaDataForFetchPlan

        FetchPlanMetaData getMetaDataForFetchPlan​(String name)
        Accessor for the MetaData for a named fetch plan.
        Parameters:
        name - Name of the fetch plan
        Returns:
        The FetchPlanMetaData for this name (if any)
      • getMetaDataForSequence

        SequenceMetaData getMetaDataForSequence​(ClassLoaderResolver clr,
                                                String seqName)
        Accessor for the MetaData for a Sequence in a package. This implementation simply checks what is already loaded and returns if found
        Parameters:
        clr - the ClassLoaderResolver
        seqName - Name of the package (fully qualified if necessary)
        Returns:
        The SequenceMetaData for this named sequence
      • getMetaDataForTableGenerator

        TableGeneratorMetaData getMetaDataForTableGenerator​(ClassLoaderResolver clr,
                                                            String genName)
        Accessor for the MetaData for a TableGenerator in a package. This implementation simply checks what is already loaded and returns if found
        Parameters:
        clr - the ClassLoaderResolver
        genName - Name of the package (fully qualified if necessary)
        Returns:
        The TableGenerator for this named generator
      • getMetaDataForQueryResult

        QueryResultMetaData getMetaDataForQueryResult​(String name)
        Accessor for the MetaData for a QueryResult.
        Parameters:
        name - Name of the query result
        Returns:
        The QueryResultMetaData under this name
      • getMetaDataForInterface

        InterfaceMetaData getMetaDataForInterface​(Class c,
                                                  ClassLoaderResolver clr)
        Accessor for the MetaData for an interface. Part of the support for "persistent-interface". This defaults to returning null since interfaces are only supported by JDO.
        Parameters:
        c - The interface to find MetaData for
        clr - the ClassLoaderResolver
        Returns:
        The InterfaceMetaData for this interface (or null if not found)
      • isPersistentInterface

        boolean isPersistentInterface​(String name)
        Convenience method to return if the passed class name is a "persistent-interface".
        Parameters:
        name - Name if the interface
        Returns:
        Whether it is a "persistent-interface"
      • isPersistentInterfaceImplementation

        boolean isPersistentInterfaceImplementation​(String interfaceName,
                                                    String implName)
        Convenience method to return if the passed class name is an implementation of the passed "persistent-interface".
        Parameters:
        interfaceName - Name of the persistent interface
        implName - The implementation name
        Returns:
        Whether it is a (DataNucleus-generated) impl of the persistent interface
      • getImplementationNameForPersistentInterface

        String getImplementationNameForPersistentInterface​(String interfaceName)
        Accessor for the implementation name for the specified "persistent-interface".
        Parameters:
        interfaceName - The name of the persistent interface
        Returns:
        The name of the implementation class
      • registerFile

        void registerFile​(String fileURLString,
                          FileMetaData filemd,
                          ClassLoaderResolver clr)
        Method to take the FileMetaData and register the relevant parts of it with the assorted caches provided. Note : this is only public to allow enhancer tests to load up metadata manually.
        Parameters:
        fileURLString - URL of the metadata file
        filemd - The File MetaData
        clr - ClassLoader resolver
      • getClassNameForDiscriminatorValueWithRoot

        String getClassNameForDiscriminatorValueWithRoot​(AbstractClassMetaData rootCmd,
                                                         String discrimValue)
        Method to return the class name that uses the provided discriminator value using the specified root class to search from.
        Parameters:
        rootCmd - The root class
        discrimValue - The discriminator value
        Returns:
        The class using this value
      • getDiscriminatorValueForClass

        String getDiscriminatorValueForClass​(AbstractClassMetaData cmd)
        Method to return the discriminator value used by the specified class.
        Parameters:
        cmd - Class to search for
        Returns:
        The discriminator value used by this class
      • getClassNameFromDiscriminatorValue

        String getClassNameFromDiscriminatorValue​(String discrimValue,
                                                  DiscriminatorMetaData dismd)
        Method to return the class name that uses the specified discriminator value for the specified discriminator.
        Parameters:
        discrimValue - Discriminator value
        dismd - The discriminator metadata
        Returns:
        The class name (or null if not found)
      • getReferencedClasses

        List<AbstractClassMetaData> getReferencedClasses​(String[] classNames,
                                                         ClassLoaderResolver clr)
        Convenience method to get the MetaData for all referenced classes with the passed set of classes as root.
        Parameters:
        classNames - Names of the root classes
        clr - ClassLoader resolver
        Returns:
        List of AbstractClassMetaData objects for the referenced classes
        Throws:
        NoPersistenceInformationException - thrown when one of the classes has no metadata.
      • isFieldTypePersistable

        boolean isFieldTypePersistable​(Class type)
        Utility to return if this field is of a persistable type.
        Parameters:
        type - Type of the field (for when "type" is not yet set)
        Returns:
        Whether the field type is persistable.
      • registerPersistentInterface

        void registerPersistentInterface​(InterfaceMetaData imd,
                                         Class implClass,
                                         ClassLoaderResolver clr)
        Method to register a persistent interface and its implementation with the MetaData system. This is called by the JDO ImplementationCreator.
        Parameters:
        imd - MetaData for the interface
        implClass - The implementation class
        clr - ClassLoader Resolver to use
      • registerImplementationOfAbstractClass

        void registerImplementationOfAbstractClass​(ClassMetaData cmd,
                                                   Class implClass,
                                                   ClassLoaderResolver clr)
        Method to register the metadata for an implementation of a persistent abstract class. This is called by the JDO ImplementationCreator.
        Parameters:
        cmd - MetaData for the abstract class
        implClass - The implementation class
        clr - ClassLoader resolver
      • addORMDataToClass

        void addORMDataToClass​(Class c,
                               ClassLoaderResolver clr)
        Load up and add any O/R mapping info for the specified class to the stored ClassMetaData (if supported). Only to be invoked by ClassMetaData, InterfaceMetaData.
        Parameters:
        c - The class
        clr - ClassLoader resolver
      • addAnnotationsDataToClass

        void addAnnotationsDataToClass​(Class c,
                                       AbstractClassMetaData cmd,
                                       ClassLoaderResolver clr)
        Load up and add any annotations mapping info for the specified class to the stored ClassMetaData. Only to be invoked by ClassMetaData, InterfaceMetaData.
        Parameters:
        c - The class
        cmd - the metadata to add annotation to
        clr - ClassLoader resolver
      • abstractClassMetaDataInitialised

        void abstractClassMetaDataInitialised​(AbstractClassMetaData cmd)
        Method called (by AbstractClassMetaData.initialise()) when a class/interface has its metadata initialised. Only to be invoked by ClassMetaData, InterfaceMetaData.
        Parameters:
        cmd - Metadata that has been initialised
      • registerSequencesForFile

        void registerSequencesForFile​(FileMetaData filemd)
        Convenience method to register all sequences found in the passed file.
        Parameters:
        filemd - MetaData for the file
      • registerTableGeneratorsForFile

        void registerTableGeneratorsForFile​(FileMetaData filemd)
        Convenience method to register all table generators found in the passed file.
        Parameters:
        filemd - MetaData for the file
      • registerDiscriminatorValueForClass

        void registerDiscriminatorValueForClass​(AbstractClassMetaData cmd,
                                                String discrimValue)
        Convenience method to register the discriminator value used by the specified class for easy lookup.
        Parameters:
        cmd - Metadata for the class
        discrimValue - The discriminator value