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

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 isnt 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 PMFContext 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 JDO 1.0, JDO 1.0.1, JDO 2.0 or later
protected  java.util.Map 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 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
annotationManager, classesWithoutPersistenceInfo, classMetaDataByClass, classMetaDataByEntityName, directSubclassesByClass, fetchPlanMetaDataByName, fileMetaDataByURLString, initialised, listeners, LOCALISER, metaDataParser, omfContext, queryMetaDataByName, queryResultMetaDataByName, sequenceMetaDataByPackageSequence, supportsORM, tableGeneratorMetaDataByPackageSequence, 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".
 java.lang.String getJDOFileSuffix()
          Convenience accessor for the JDO file suffix.
 java.lang.String getJDOQueryFileSuffix()
          Convenience accessor for the JDOQuery file suffix.
 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.lang.String getORMFileSuffix()
          Convenience accessor for the ORM file suffix.
protected  java.lang.String getORMMappingName()
          Convenience accessor for the mapping name.
 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 hasMetaDataForClass(java.lang.String className)
          Convenience method to check if we have metadata present for the specified class.
 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 metadata_file_modifier, java.lang.String metadata_file_extension, boolean populate)
          Method to find the Meta-Data file for a specified class.
protected  void logConfiguration()
          Method to log the configuration of this manager.
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
getApiAdapter, getClassesImplementingInterface, getClassesWithMetaData, getFileMetaData, getListeners, getMetaDataFactory, getMetaDataForClass, getMetaDataForClass, getMetaDataForEntityName, getMetaDataForFetchPlan, getMetaDataForImplementationOfReference, getMetaDataForMember, getMetaDataForMember, getMetaDataForPersistenceUnit, getMetaDataForQueryResult, getMetaDataForTableGenerator, getOMFContext, getReferencedClassMetaData, getSubclassesForClass, initialise, initialise, initialise, initialiseAbstractClassMetaData, initialiseClassMetaData, initialiseFileMetaData, initialiseInterfaceMetaData, isClassPersistable, isClassWithoutPersistenceInfo, isEnhancing, loadAnnotationsForClass, parsePersistenceFiles, populateAbstractClassMetaData, populateFileMetaData, readMetaDataForClass, readMetaDataForMember, registerFetchPlansForFile, registerMetaDataForClass, registerQueriesForFile, registerQueryResultMetaDataForFile, registerSequencesForFile, registerTableGeneratorsForFile, setMetaDataFactory, 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 JDO 1.0, JDO 1.0.1, JDO 2.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 ormClassMetaDataByClass
Map of ClassMetaData from ORM files, keyed by the class name.


classMetaDataByInterface

protected java.util.Map 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

getORMMappingName

protected java.lang.String getORMMappingName()
Convenience accessor for the mapping name.

Returns:
ORM mapping name

getJDOFileSuffix

public java.lang.String getJDOFileSuffix()
Convenience accessor for the JDO file suffix.

Returns:
JDO file suffix

getORMFileSuffix

public java.lang.String getORMFileSuffix()
Convenience accessor for the ORM file suffix.

Returns:
ORM file suffix

getJDOQueryFileSuffix

public java.lang.String getJDOQueryFileSuffix()
Convenience accessor for the JDOQuery file suffix.

Returns:
JDOQuery file suffix

logConfiguration

protected void logConfiguration()
Method to log the configuration of this manager.

Overrides:
logConfiguration in class MetaDataManager

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

hasMetaDataForClass

public boolean hasMetaDataForClass(java.lang.String className)
Convenience method to check if we have metadata present for the specified class.

Overrides:
hasMetaDataForClass in class MetaDataManager
Parameters:
className - The name of the class to check
Returns:
Whether the metadata is already registered for this class

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 metadata_file_modifier,
                                            java.lang.String metadata_file_extension,
                                            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 Meta-Data file for
clr - the ClassLoaderResolver
metadata_file_modifier - Any modifier for the filename
metadata_file_extension - File extension of MetaData files (e.g "jdo")
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 © 2009. All Rights Reserved.