org.datanucleus.jdo.metadata
Class JDOMetaDataManager

java.lang.Object
  extended by org.datanucleus.metadata.MetaDataManager
      extended by org.datanucleus.jdo.metadata.JDOMetaDataManager

public class JDOMetaDataManager
extends MetaDataManager

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 OMFContext 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.


Field Summary
static int ALL_JDO_LOCATIONS
          MetaData files will be searched in all possible locations defined in JDO1.0, JDO1.0.1, JDO2.0 or later
protected  java.util.Map<java.lang.String,AbstractClassMetaData> classMetaDataByInterface
          Map of ClassMetaData, keyed by the interface class name (for "persistent-interface"s).
static int JDO_1_0_0_LOCATIONS
          MetaData files will be searched in all locations defined in JDO 1.0
static int JDO_1_0_1_LOCATIONS
          MetaData files will be searched in all locations defined in JDO 1.0.1
protected  int locationDefinition
          Definition of which locations we accept for MetaData files.
protected  java.util.Map<java.lang.String,AbstractClassMetaData> ormClassMetaDataByClass
          Map of ClassMetaData from ORM files, keyed by the class name.
protected  org.datanucleus.jdo.metadata.JDOMetaDataManager.MetaDataRegisterClassListener registerListener
          Listener for persistent class initialisations (since JDO uses a discovery process).
 
Fields inherited from class org.datanucleus.metadata.MetaDataManager
allowMetaDataLoad, annotationManager, classesWithoutPersistenceInfo, classMetaDataByAppIdClassName, classMetaDataByClass, classMetaDataByDiscriminatorName, classMetaDataByEntityName, directSubclassesByClass, fetchPlanMetaDataByName, fileMetaDataByURLString, listeners, LOCALISER, metaDataParser, omfContext, queryMetaDataByName, queryResultMetaDataByName, sequenceMetaDataByPackageSequence, supportsORM, tableGeneratorMetaDataByPackageSequence, userMetaDataNumber, utilisedFileMetaData, validateMetaData
 
Constructor Summary
JDOMetaDataManager(OMFContext ctxt)
          Constructor.
 
Method Summary
 void addORMDataToClass(java.lang.Class c, ClassLoaderResolver clr)
          Load up and add the O/R mapping info for the specified class to the stored JDO ClassMetaData.
 void close()
          Clear resources
 ClassMetaData getClassMetaDataForImplementationOfPersistentInterface(java.lang.String interfaceName)
          Accessor for the metadata for the implementation of the specified "persistent-interface".
 java.lang.String getImplementationNameForPersistentInterface(java.lang.String interfaceName)
          Accessor for the implementation name for the specified "persistent-interface".
 AbstractClassMetaData getMetaDataForClassInternal(java.lang.Class c, ClassLoaderResolver clr)
          Internal method for accessing the MetaData for a class.
 InterfaceMetaData getMetaDataForInterface(java.lang.Class c, ClassLoaderResolver clr)
          Main accessor for the MetaData for a "persistent-interface".
 QueryMetaData getMetaDataForQuery(java.lang.Class cls, ClassLoaderResolver clr, java.lang.String queryName)
          Accessor for the MetaData for a named query for a class.
 SequenceMetaData getMetaDataForSequence(ClassLoaderResolver clr, java.lang.String packageSequenceName)
          Accessor for the MetaData for a Sequence in a package.
 java.util.List getValidMetaDataLocationsForClass(java.lang.String fileExtension, java.lang.String fileModifier, java.lang.String className)
          Method to return the valid metadata locations to contain a particular class.
 java.util.List getValidMetaDataLocationsForPackage(java.lang.String fileExtension, java.lang.String fileModifier, java.lang.String packageName)
          Method to return the valid metadata locations to contain a particular package.
 boolean isPersistentDefinitionImplementation(java.lang.String implName)
          Convenience method to return if the passed class name is an implementation of a "persistent definition".
 boolean isPersistentInterface(java.lang.String name)
          Convenience method to return if the passed class name is a "persistent-interface".
 boolean isPersistentInterfaceImplementation(java.lang.String interfaceName, java.lang.String implName)
          Convenience method to return if the passed class name is an implementation of the passed "persistent-interface".
protected  FileMetaData loadMetaDataForClass(java.lang.Class pc_class, ClassLoaderResolver clr, java.lang.String mappingModifier, java.lang.String metadataFileExtension, MetadataFileType metadataType, boolean populate)
          Method to find the Meta-Data file for a specified class.
protected  FileMetaData parseFile(java.net.URL fileURL)
          Utility to parse a file, using the "jdo" MetaData handler.
 void registerFile(java.lang.String fileURLString, FileMetaData filemd, ClassLoaderResolver clr)
          Method to take the FileMetaData and register the relevant parts of it with the assorted caches provided.
 void registerImplementationOfAbstractClass(ClassMetaData cmd, java.lang.Class implClass, ClassLoaderResolver clr)
          Method to register the metadata for an implementation of a persistent abstract class.
 void registerPersistentInterface(InterfaceMetaData imd, java.lang.Class implClass, ClassLoaderResolver clr)
          Method to register a persistent interface and its implementation with the MetaData system.
 
Methods inherited from class org.datanucleus.metadata.MetaDataManager
deregisterListener, getAllowMetaDataLoad, getApiAdapter, getClassesImplementingInterface, getClassesWithMetaData, getClassMetaDataWithApplicationId, getFileMetaData, getMetaDataForClass, getMetaDataForClass, getMetaDataForDiscriminator, getMetaDataForEntityName, getMetaDataForFetchPlan, getMetaDataForImplementationOfReference, getMetaDataForMember, getMetaDataForMember, getMetaDataForPersistenceUnit, getMetaDataForQueryResult, getMetaDataForTableGenerator, getOMFContext, getReferencedClasses, getReferencedClassMetaData, getSubclassesForClass, hasMetaDataForClass, initialiseAbstractClassMetaData, initialiseClassMetaData, initialiseFileMetaData, initialiseFileMetaDataForUse, initialiseInterfaceMetaData, isClassPersistable, isClassWithoutPersistenceInfo, isEnhancing, isFieldTypePersistable, loadAnnotationsForClass, loadClasses, loadFiles, loadJar, loadMetadataFiles, loadPersistenceUnit, loadUserMetaData, logConfiguration, parsePersistenceFiles, populateAbstractClassMetaData, populateFileMetaData, readMetaDataForClass, readMetaDataForMember, registerFetchPlansForFile, registerListener, registerMetaDataForClass, registerQueriesForFile, registerQueryResultMetaDataForFile, registerSequencesForFile, registerTableGeneratorsForFile, setAllowMetaDataLoad, setValidate, supportsORM
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALL_JDO_LOCATIONS

public static final int ALL_JDO_LOCATIONS
MetaData files will be searched in all possible locations defined in JDO1.0, JDO1.0.1, JDO2.0 or later

See Also:
Constant Field Values

JDO_1_0_0_LOCATIONS

public static final int JDO_1_0_0_LOCATIONS
MetaData files will be searched in all locations defined in JDO 1.0

See Also:
Constant Field Values

JDO_1_0_1_LOCATIONS

public static final int JDO_1_0_1_LOCATIONS
MetaData files will be searched in all locations defined in JDO 1.0.1

See Also:
Constant Field Values

locationDefinition

protected int locationDefinition
Definition of which locations we accept for MetaData files.


ormClassMetaDataByClass

protected java.util.Map<java.lang.String,AbstractClassMetaData> ormClassMetaDataByClass
Map of ClassMetaData from ORM files, keyed by the class name.


classMetaDataByInterface

protected java.util.Map<java.lang.String,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.jdo.metadata.JDOMetaDataManager.MetaDataRegisterClassListener registerListener
Listener for persistent class initialisations (since JDO uses a discovery process).

Constructor Detail

JDOMetaDataManager

public JDOMetaDataManager(OMFContext ctxt)
Constructor.

Parameters:
ctxt - ObjectManagerFactory Context that this metadata manager operates in
Method Detail

close

public void close()
Clear resources

Overrides:
close in class MetaDataManager

parseFile

protected FileMetaData parseFile(java.net.URL fileURL)
Utility to parse a file, using the "jdo" MetaData handler.

Specified by:
parseFile in class MetaDataManager
Parameters:
fileURL - URL of the file
Returns:
The FileMetaData for this file

registerFile

public void registerFile(java.lang.String fileURLString,
                         FileMetaData filemd,
                         ClassLoaderResolver clr)
Method to take the FileMetaData and register the relevant parts of it with the assorted caches provided.

Specified by:
registerFile in class MetaDataManager
Parameters:
fileURLString - URL of the metadata file
filemd - The File MetaData

getMetaDataForClassInternal

public AbstractClassMetaData getMetaDataForClassInternal(java.lang.Class c,
                                                         ClassLoaderResolver clr)
Internal method for accessing the MetaData for a class. The MetaData returned can be uninitialised. Runs through the following process
  1. Checks if the class is known not to have metata
  2. Check if we have metadata for the class in one of the files that has been parsed.
  3. If we have metadata, check that it is initialised
  4. If we don't have metadata, find the file for this class.
  5. If we cant find a file for it, add it to the list of classes known to have no metadata

Specified by:
getMetaDataForClassInternal in class MetaDataManager
Parameters:
c - The class to find MetaData for
Returns:
The ClassMetaData for this class (or null if not found)

getMetaDataForQuery

public QueryMetaData getMetaDataForQuery(java.lang.Class cls,
                                         ClassLoaderResolver clr,
                                         java.lang.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.

Overrides:
getMetaDataForQuery in class MetaDataManager
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 SequenceMetaData getMetaDataForSequence(ClassLoaderResolver clr,
                                               java.lang.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.

Overrides:
getMetaDataForSequence in class MetaDataManager
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(java.lang.Class c,
                              ClassLoaderResolver clr)
Load up and add the O/R mapping info for the specified class to the stored JDO ClassMetaData.

Overrides:
addORMDataToClass in class MetaDataManager
Parameters:
c - The class
clr - the ClassLoaderResolver

loadMetaDataForClass

protected FileMetaData loadMetaDataForClass(java.lang.Class pc_class,
                                            ClassLoaderResolver clr,
                                            java.lang.String mappingModifier,
                                            java.lang.String metadataFileExtension,
                                            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 java.util.List getValidMetaDataLocationsForPackage(java.lang.String fileExtension,
                                                          java.lang.String fileModifier,
                                                          java.lang.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 java.util.List getValidMetaDataLocationsForClass(java.lang.String fileExtension,
                                                        java.lang.String fileModifier,
                                                        java.lang.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 InterfaceMetaData getMetaDataForInterface(java.lang.Class c,
                                                 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.

Overrides:
getMetaDataForInterface in class MetaDataManager
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(java.lang.String name)
Convenience method to return if the passed class name is a "persistent-interface".

Overrides:
isPersistentInterface in class MetaDataManager
Parameters:
name - Name if the interface
Returns:
Whether it is a "persistent-interface"

isPersistentInterfaceImplementation

public boolean isPersistentInterfaceImplementation(java.lang.String interfaceName,
                                                   java.lang.String implName)
Convenience method to return if the passed class name is an implementation of the passed "persistent-interface".

Overrides:
isPersistentInterfaceImplementation in class MetaDataManager
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(java.lang.String implName)
Convenience method to return if the passed class name is an implementation of a "persistent definition".

Overrides:
isPersistentDefinitionImplementation in class MetaDataManager
Parameters:
implName - The implementation name
Returns:
Whether it is a (generated) impl of the persistent interface or abstract class

getImplementationNameForPersistentInterface

public java.lang.String getImplementationNameForPersistentInterface(java.lang.String interfaceName)
Accessor for the implementation name for the specified "persistent-interface".

Overrides:
getImplementationNameForPersistentInterface in class MetaDataManager
Parameters:
interfaceName - The name of the persistent interface
Returns:
The name of the implementation class

getClassMetaDataForImplementationOfPersistentInterface

public ClassMetaData getClassMetaDataForImplementationOfPersistentInterface(java.lang.String interfaceName)
Accessor for the metadata for the implementation of the specified "persistent-interface".

Overrides:
getClassMetaDataForImplementationOfPersistentInterface in class MetaDataManager
Parameters:
interfaceName - The name of the persistent interface
Returns:
The ClassMetaData of the implementation class

registerPersistentInterface

public void registerPersistentInterface(InterfaceMetaData imd,
                                        java.lang.Class implClass,
                                        ClassLoaderResolver clr)
Method to register a persistent interface and its implementation with the MetaData system.

Overrides:
registerPersistentInterface in class MetaDataManager
Parameters:
imd - MetaData for the interface
implClass - The implementation class
clr - ClassLoader Resolver to use

registerImplementationOfAbstractClass

public void registerImplementationOfAbstractClass(ClassMetaData cmd,
                                                  java.lang.Class implClass,
                                                  ClassLoaderResolver clr)
Method to register the metadata for an implementation of a persistent abstract class.

Overrides:
registerImplementationOfAbstractClass in class MetaDataManager
Parameters:
cmd - MetaData for the abstract class
implClass - The implementation class
clr - ClassLoader resolver


Copyright © 2011. All Rights Reserved.