org.datanucleus.metadata
Class MetaDataManager

java.lang.Object
  extended by org.datanucleus.metadata.MetaDataManager
Direct Known Subclasses:
JDOMetaDataManager

public abstract class MetaDataManager
extends java.lang.Object

Manager of metadata information in DataNucleus having scope of an ObjectManagerFactory. Each PMF/EMF will effectively have a single MetaDataManager handling all XML/Annotations metadata.

Metadata can be loaded into the MetaDataManager in two ways

Acts as a registry of 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.

Maintains a list of all classes that have been checked for MetaData and don't have any available. This avoids the needs to look up MetaData multiple times finding the same result. Currently this list is for all ClassMetaData objects keyed by the class name.

Users can register interest in knowing when metadata for classes are loaded by registering a listener using the addListener method. This will then notify the listener when metadata for any class is initialised. This provides the opportunity to reject the metadata where particular features are not supported. For example a StoreManager could register a listener where it doesn't support datastore identity and throw an InvalidMetaDataException. This would then filter back out to the user for the operation they invoked


Field Summary
protected  boolean allowMetaDataLoad
          Flag defining if we allow metadata load currently.
protected  AnnotationManager annotationManager
          Manager for annotations.
protected  java.util.Collection<java.lang.String> classesWithoutPersistenceInfo
          Cache of class names that are known to not have MetaData/annotations.
protected  MultiMap classMetaDataByAppIdClassName
          Map of class metadata, keyed by the application-id object-id class name (not SingleField).
protected  java.util.Map<java.lang.String,AbstractClassMetaData> classMetaDataByClass
          Map of ClassMetaData, keyed by the class name.
protected  java.util.Map<java.lang.String,AbstractClassMetaData> classMetaDataByDiscriminatorName
          Map of ClassMetaData, keyed by the class discriminator name.
protected  java.util.Map<java.lang.String,AbstractClassMetaData> classMetaDataByEntityName
          Map of ClassMetaData, keyed by the JPA "entity name".
protected  java.util.Map<java.lang.String,java.util.Set<java.lang.String>> directSubclassesByClass
          Cache subclass information as that is expensive to compute, keyed by class name
protected  java.util.Map<java.lang.String,FetchPlanMetaData> fetchPlanMetaDataByName
          Map of FetchPlanMetaData, keyed by the fetch plan name.
protected  java.util.Map<java.lang.String,FileMetaData> fileMetaDataByURLString
          Map of FileMetaData for the parsed files, keyed by the URL string.
protected  java.util.Set<MetaDataListener> listeners
          Listeners for metadata load.
protected static Localiser LOCALISER
          Localiser for messages.
protected  MetaDataParser metaDataParser
          Parser for MetaData.
protected  OMFContext omfContext
          The ObjectManagerFactory Context that this metadata manager is operating in.
protected  java.util.Map<java.lang.String,QueryMetaData> queryMetaDataByName
          Map of QueryMetaData, keyed by the (class name + query name).
protected  java.util.Map<java.lang.String,QueryResultMetaData> queryResultMetaDataByName
          Map of QueryResultMetaData keyed by the name.
protected  java.util.Map<java.lang.String,SequenceMetaData> sequenceMetaDataByPackageSequence
          Map of SequenceMetaData, keyed by the package name and sequence name.
protected  boolean supportsORM
          Whether the metadata manager supports ORM concepts in metadata.
protected  java.util.Map<java.lang.String,TableGeneratorMetaData> tableGeneratorMetaDataByPackageSequence
          Map of TableGeneratorMetaData, keyed by the package name and generator name.
protected  int userMetaDataNumber
          Number of user metadata items.
protected  java.util.ArrayList<FileMetaData> utilisedFileMetaData
          Temporary list of the FileMetaData objects utilised in this call for metadata.
protected  boolean validateMetaData
          Flag whether we should validate the (XML) metadata files when parsing.
 
Constructor Summary
MetaDataManager(OMFContext ctxt)
          Constructor, specifying the OMFContext used.
 
Method Summary
protected  void addORMDataToClass(java.lang.Class c, ClassLoaderResolver clr)
          Load up and add any O/R mapping info for the specified class to the stored ClassMetaData (if supported).
 void close()
          Clear resources
 void deregisterListener(MetaDataListener listener)
          Method to deregister a listener from being notified when metadata for a class/interface is initialised.
 boolean getAllowMetaDataLoad()
          Accessor for whether we allow metadata load currently.
 ApiAdapter getApiAdapter()
          Accessor for the API adapter being used by this MetaDataManager.
 java.lang.String[] getClassesImplementingInterface(java.lang.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).
 java.util.Collection getClassesWithMetaData()
          Accessor for the names of the classes with MetaData currently registered with this manager.
 ClassMetaData getClassMetaDataForImplementationOfPersistentInterface(java.lang.String interfaceName)
          Accessor for the metadata for the implementation of the specified "persistent-interface".
 java.util.Collection<AbstractClassMetaData> getClassMetaDataWithApplicationId(java.lang.String objectIdClassName)
          Accessor for the metadata for the class(es) with the specified object-id class name as PK.
 FileMetaData[] getFileMetaData()
          Accessor for all FileMetaData currently managed here.
 java.lang.String getImplementationNameForPersistentInterface(java.lang.String interfaceName)
          Accessor for the implementation name for the specified "persistent-interface".
 AbstractClassMetaData getMetaDataForClass(java.lang.Class c, ClassLoaderResolver clr)
          Main accessor for the MetaData for a class.
 AbstractClassMetaData getMetaDataForClass(java.lang.String className, ClassLoaderResolver clr)
          Accessor for the MetaData for a class given the name and a loader.
abstract  AbstractClassMetaData getMetaDataForClassInternal(java.lang.Class c, ClassLoaderResolver clr)
          Internal convenience method for accessing the MetaData for a class.
 AbstractClassMetaData getMetaDataForDiscriminator(java.lang.String discriminator)
          Accessor for the MetaData for a class given the "discriminator".
 AbstractClassMetaData getMetaDataForEntityName(java.lang.String entityName)
          Accessor for the MetaData for a class given the "entity-name".
 FetchPlanMetaData getMetaDataForFetchPlan(java.lang.String name)
          Accessor for the MetaData for a named fetch plan.
 ClassMetaData getMetaDataForImplementationOfReference(java.lang.Class referenceClass, java.lang.Object implValue, ClassLoaderResolver clr)
          Accessor for the MetaData for an implementation of a reference type.
 InterfaceMetaData getMetaDataForInterface(java.lang.Class c, ClassLoaderResolver clr)
          Accessor for the MetaData for an interface.
 AbstractMemberMetaData getMetaDataForMember(java.lang.Class c, ClassLoaderResolver clr, java.lang.String memberName)
          Accessor for the MetaData for a field/property of a class.
 AbstractMemberMetaData getMetaDataForMember(java.lang.String className, java.lang.String memberName, ClassLoaderResolver clr)
          Accessor for the MetaData for a field/property of a class.
 PersistenceUnitMetaData getMetaDataForPersistenceUnit(java.lang.String unitName)
          Method to parse all available "persistence.xml" files and return the metadata for the persistence unit with the specified name.
 QueryMetaData getMetaDataForQuery(java.lang.Class cls, ClassLoaderResolver clr, java.lang.String queryName)
          Accessor for the MetaData for a named query for a class.
 QueryResultMetaData getMetaDataForQueryResult(java.lang.String name)
          Accessor for the MetaData for a QueryResult.
 SequenceMetaData getMetaDataForSequence(ClassLoaderResolver clr, java.lang.String seqName)
          Accessor for the MetaData for a Sequence in a package.
 TableGeneratorMetaData getMetaDataForTableGenerator(ClassLoaderResolver clr, java.lang.String genName)
          Accessor for the MetaData for a TableGenerator in a package.
 OMFContext getOMFContext()
          Accessor for the ObjectManagerFactory Context that this manager is running in.
 java.util.List<AbstractClassMetaData> getReferencedClasses(java.lang.String[] classNames, ClassLoaderResolver clr)
          Convenience method to get the MetaData for all referenced classes with the passed set of classes as root.
protected  java.util.List<AbstractClassMetaData> getReferencedClassMetaData(AbstractClassMetaData cmd, ClassLoaderResolver clr)
          Utility to return all ClassMetaData that is referenced from the supplier class.
 java.lang.String[] getSubclassesForClass(java.lang.String className, boolean includeDescendents)
          Accessor for the subclasses of a particular class
 boolean hasMetaDataForClass(java.lang.String className)
          Convenience method to check if we have metadata present for the specified class.
protected  void initialiseAbstractClassMetaData(AbstractClassMetaData acmd, ClassLoaderResolver clr)
          Convenience method to initialise the MetaData for the specified class/interface.
protected  void initialiseClassMetaData(ClassMetaData cmd, java.lang.Class cls, ClassLoaderResolver clr)
          Utility to initialise the MetaData for a class, using the specified class.
protected  void initialiseFileMetaData(FileMetaData filemd, ClassLoaderResolver clr, java.lang.ClassLoader primary)
          Initialise all classes/interfaces in a Meta-Data file.
protected  void initialiseFileMetaDataForUse(java.util.Collection fileMetaData, ClassLoaderResolver clr)
          Method to initialise the provided FileMetaData, ready for use.
protected  void initialiseInterfaceMetaData(InterfaceMetaData imd, ClassLoaderResolver clr, java.lang.ClassLoader primary)
          Utility to initialise the MetaData for a interface, using the specified class.
 boolean isClassPersistable(java.lang.String className)
          Convenience method to return if the specified class is a known persistable class.
protected  boolean isClassWithoutPersistenceInfo(java.lang.String className)
          Accessor for whether a class doesn't have MetaData or annotations.
 boolean isEnhancing()
          Accessor for whether we are managing the enhancement process.
 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 loadAnnotationsForClass(java.lang.Class cls, ClassLoaderResolver clr, boolean register, boolean populate)
          Method to load the annotations for the specified class and return the FileMetaData containing the class.
 FileMetaData[] loadClasses(java.lang.String[] classNames, java.lang.ClassLoader loader)
          Method to load up all metadata for the specified classes.
 java.util.Collection<FileMetaData> loadFiles(java.lang.String[] metadataFiles, ClassLoaderResolver clr)
          Method to load the metadata from the specified files.
 FileMetaData[] loadJar(java.lang.String jarFileName, java.lang.ClassLoader loader)
          Initialisation method to load the metadata provided by the specified jar.
 FileMetaData[] loadMetadataFiles(java.lang.String[] metadataFiles, java.lang.ClassLoader loader)
          Method to load up all metadata defined by the specified metadata files.
 FileMetaData[] loadPersistenceUnit(PersistenceUnitMetaData pumd, java.lang.ClassLoader loader)
          Initialisation method to to load all class metadata defined by the "persistence-unit".
 void loadUserMetaData(FileMetaData fileMetaData, java.lang.ClassLoader loader)
          Method to load user-provided metadata.
protected  void logConfiguration()
          Method to log the configuration of this manager.
protected abstract  FileMetaData parseFile(java.net.URL file_url)
          Utility to parse a MetaData file.
 PersistenceFileMetaData[] parsePersistenceFiles()
          Method to parse the available "persistence.xml" files returning the metadata for all found.
protected  void populateAbstractClassMetaData(AbstractClassMetaData acmd, ClassLoaderResolver clr, java.lang.ClassLoader loader)
          Convenience method to populate the MetaData for the specified class/interface.
protected  void populateFileMetaData(FileMetaData filemd, ClassLoaderResolver clr, java.lang.ClassLoader primary)
          Convenience method to populate all classes/interfaces in a Meta-Data file.
 AbstractClassMetaData readMetaDataForClass(java.lang.String className)
          Method to access the (already known) metadata for the specified class.
 AbstractMemberMetaData readMetaDataForMember(java.lang.String className, java.lang.String memberName)
          Method to access the (already known) metadata for the field/property of the specified class.
protected  void registerFetchPlansForFile(FileMetaData filemd)
          Convenience method to register all FetchPlans found in the passed file.
abstract  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 registerListener(MetaDataListener listener)
          Method to register a listener to be notified when metadata for a class/interface is initialised.
protected  void registerMetaDataForClass(java.lang.String fullClassName, AbstractClassMetaData cmd)
          Internal method called when we want to register the metadata for a class/interface.
 void registerPersistentInterface(InterfaceMetaData imd, java.lang.Class implClass, ClassLoaderResolver clr)
          Method to register a persistent interface and its implementation with the MetaData system.
protected  void registerQueriesForFile(FileMetaData filemd)
          Convenience method to register all queries found in the passed file.
protected  void registerQueryResultMetaDataForFile(FileMetaData filemd)
          Convenience method to register all table generators found in the passed file.
protected  void registerSequencesForFile(FileMetaData filemd)
          Convenience method to register all sequences found in the passed file.
protected  void registerTableGeneratorsForFile(FileMetaData filemd)
          Convenience method to register all table generators found in the passed file.
 void setAllowMetaDataLoad(boolean allow)
          Method to set whether to allow metadata load from this point.
 void setValidate(boolean validate)
          Mutator for whether to validate the MetaData files for XML compliance.
 boolean supportsORM()
          Accessor for whether the MetaData manager supports ORM concepts and metadata.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER

protected static final Localiser LOCALISER
Localiser for messages.


omfContext

protected final OMFContext omfContext
The ObjectManagerFactory Context that this metadata manager is operating in.


annotationManager

protected final AnnotationManager annotationManager
Manager for annotations.


metaDataParser

protected MetaDataParser metaDataParser
Parser for MetaData.


validateMetaData

protected boolean validateMetaData
Flag whether we should validate the (XML) metadata files when parsing.


classesWithoutPersistenceInfo

protected java.util.Collection<java.lang.String> classesWithoutPersistenceInfo
Cache of class names that are known to not have MetaData/annotations.


fileMetaDataByURLString

protected java.util.Map<java.lang.String,FileMetaData> fileMetaDataByURLString
Map of FileMetaData for the parsed files, keyed by the URL string.


classMetaDataByClass

protected java.util.Map<java.lang.String,AbstractClassMetaData> classMetaDataByClass
Map of ClassMetaData, keyed by the class name.


classMetaDataByEntityName

protected java.util.Map<java.lang.String,AbstractClassMetaData> classMetaDataByEntityName
Map of ClassMetaData, keyed by the JPA "entity name".


classMetaDataByDiscriminatorName

protected java.util.Map<java.lang.String,AbstractClassMetaData> classMetaDataByDiscriminatorName
Map of ClassMetaData, keyed by the class discriminator name.


directSubclassesByClass

protected java.util.Map<java.lang.String,java.util.Set<java.lang.String>> directSubclassesByClass
Cache subclass information as that is expensive to compute, keyed by class name


queryMetaDataByName

protected java.util.Map<java.lang.String,QueryMetaData> queryMetaDataByName
Map of QueryMetaData, keyed by the (class name + query name).


fetchPlanMetaDataByName

protected java.util.Map<java.lang.String,FetchPlanMetaData> fetchPlanMetaDataByName
Map of FetchPlanMetaData, keyed by the fetch plan name.


sequenceMetaDataByPackageSequence

protected java.util.Map<java.lang.String,SequenceMetaData> sequenceMetaDataByPackageSequence
Map of SequenceMetaData, keyed by the package name and sequence name.


tableGeneratorMetaDataByPackageSequence

protected java.util.Map<java.lang.String,TableGeneratorMetaData> tableGeneratorMetaDataByPackageSequence
Map of TableGeneratorMetaData, keyed by the package name and generator name.


queryResultMetaDataByName

protected java.util.Map<java.lang.String,QueryResultMetaData> queryResultMetaDataByName
Map of QueryResultMetaData keyed by the name.


classMetaDataByAppIdClassName

protected MultiMap classMetaDataByAppIdClassName
Map of class metadata, keyed by the application-id object-id class name (not SingleField).


listeners

protected java.util.Set<MetaDataListener> listeners
Listeners for metadata load.


userMetaDataNumber

protected int userMetaDataNumber
Number of user metadata items.


supportsORM

protected boolean supportsORM
Whether the metadata manager supports ORM concepts in metadata.


allowMetaDataLoad

protected boolean allowMetaDataLoad
Flag defining if we allow metadata load currently. If false then we only allow access to currently loaded metadata.


utilisedFileMetaData

protected java.util.ArrayList<FileMetaData> utilisedFileMetaData
Temporary list of the FileMetaData objects utilised in this call for metadata.

Constructor Detail

MetaDataManager

public MetaDataManager(OMFContext ctxt)
Constructor, specifying the OMFContext used.

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

close

public void close()
Clear resources


registerListener

public 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

public 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

public void setAllowMetaDataLoad(boolean allow)
Method to set whether to allow metadata load from this point.

Parameters:
allow - Whether to allow it

getAllowMetaDataLoad

public boolean getAllowMetaDataLoad()
Accessor for whether we allow metadata load currently.

Returns:
Whether to allow any further loading.

supportsORM

public 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

isEnhancing

public boolean isEnhancing()
Accessor for whether we are managing the enhancement process.

Returns:
Whether we are enhancing

setValidate

public void setValidate(boolean validate)
Mutator for whether to validate the MetaData files for XML compliance.

Parameters:
validate - Whether to validate

getOMFContext

public OMFContext getOMFContext()
Accessor for the ObjectManagerFactory Context that this manager is running in.

Returns:
The ObjectManagerFactory Context

getApiAdapter

public ApiAdapter getApiAdapter()
Accessor for the API adapter being used by this MetaDataManager.

Returns:
API adapter.

logConfiguration

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


loadMetadataFiles

public FileMetaData[] loadMetadataFiles(java.lang.String[] metadataFiles,
                                        java.lang.ClassLoader loader)
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

public FileMetaData[] loadClasses(java.lang.String[] classNames,
                                  java.lang.ClassLoader loader)
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

public FileMetaData[] loadJar(java.lang.String jarFileName,
                              java.lang.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

public FileMetaData[] loadPersistenceUnit(PersistenceUnitMetaData pumd,
                                          java.lang.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

public void loadUserMetaData(FileMetaData fileMetaData,
                             java.lang.ClassLoader loader)
Method to load user-provided metadata.

Parameters:
fileMetaData - FileMetaData to register/populate/initialise
loader - ClassLoader to use in loading the metadata (if any)

initialiseFileMetaDataForUse

protected void initialiseFileMetaDataForUse(java.util.Collection fileMetaData,
                                            ClassLoaderResolver clr)
Method to initialise the provided FileMetaData, ready for use.

Parameters:
fileMetaData - Collection of FileMetaData
clr - ClassLoader resolver
Throws:
NucleusUserException - thrown if an error occurs during the populate/initialise of the supplied metadata.

loadFiles

public java.util.Collection<FileMetaData> loadFiles(java.lang.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

isClassPersistable

public boolean isClassPersistable(java.lang.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

public FileMetaData[] getFileMetaData()
Accessor for all FileMetaData currently managed here.

Returns:
FileMetaData managed here currently

getClassesWithMetaData

public java.util.Collection getClassesWithMetaData()
Accessor for the names of the classes with MetaData currently registered with this manager.

Returns:
Names of classes with MetaData

hasMetaDataForClass

public boolean hasMetaDataForClass(java.lang.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

isClassWithoutPersistenceInfo

protected boolean isClassWithoutPersistenceInfo(java.lang.String className)
Accessor for whether a class doesn't have MetaData or annotations.

Parameters:
className - Name of the class
Returns:
Whether it has no metadata and annotations

getClassMetaDataWithApplicationId

public java.util.Collection<AbstractClassMetaData> getClassMetaDataWithApplicationId(java.lang.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

public AbstractClassMetaData getMetaDataForClass(java.lang.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

public AbstractClassMetaData getMetaDataForClass(java.lang.Class c,
                                                 ClassLoaderResolver clr)
Main 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

public AbstractClassMetaData getMetaDataForEntityName(java.lang.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

public AbstractClassMetaData getMetaDataForDiscriminator(java.lang.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

public AbstractClassMetaData readMetaDataForClass(java.lang.String className)
Method to access the (already known) metadata for the specified class. If the class is not yet known about it returns null.

Parameters:
className - Name of the class
Returns:
MetaData for the class

readMetaDataForMember

public AbstractMemberMetaData readMetaDataForMember(java.lang.String className,
                                                    java.lang.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.

Parameters:
className - Name of the class
memberName - Name of the field/property
Returns:
MetaData for the field/property

getMetaDataForClassInternal

public abstract AbstractClassMetaData getMetaDataForClassInternal(java.lang.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
Returns:
The ClassMetaData for this class (or null if not found)

registerMetaDataForClass

protected void registerMetaDataForClass(java.lang.String fullClassName,
                                        AbstractClassMetaData cmd)
Internal method called when we want to register the metadata for a class/interface.

Parameters:
fullClassName - Name of the class
cmd - The metadata

getSubclassesForClass

public java.lang.String[] getSubclassesForClass(java.lang.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

getClassesImplementingInterface

public java.lang.String[] getClassesImplementingInterface(java.lang.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

addORMDataToClass

protected void addORMDataToClass(java.lang.Class c,
                                 ClassLoaderResolver clr)
Load up and add any O/R mapping info for the specified class to the stored ClassMetaData (if supported). This implementation does nothing so if ORM files are supported then this should be overridden by subclasses. Is package-access so that is only accessable by MetaData classes

Parameters:
c - The class
clr - ClassLoader resolver

getMetaDataForImplementationOfReference

public ClassMetaData getMetaDataForImplementationOfReference(java.lang.Class referenceClass,
                                                             java.lang.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

getMetaDataForMember

public AbstractMemberMetaData getMetaDataForMember(java.lang.String className,
                                                   java.lang.String memberName,
                                                   ClassLoaderResolver clr)
Accessor for the MetaData for a field/property of a class. Utilises getMetaDataForClass, and then finds the relevant field/property.

Parameters:
className - The name of the class owning the field/property
memberName - The name of the field to find MetaData for
clr - ClassLoaderResolver resolver for any loading of classes
Returns:
The metadata for this field/property (or null if not found)

getMetaDataForMember

public AbstractMemberMetaData getMetaDataForMember(java.lang.Class c,
                                                   ClassLoaderResolver clr,
                                                   java.lang.String memberName)
Accessor for the MetaData for a field/property of a class. Utilises getMetaDataForClass, and then finds the relevant field/property.

Parameters:
c - The class owning the field/property
clr - the ClassLoaderResolver
memberName - The name of the field/property to find MetaData for
Returns:
The metadata for this field/property (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 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

getMetaDataForFetchPlan

public FetchPlanMetaData getMetaDataForFetchPlan(java.lang.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

public SequenceMetaData getMetaDataForSequence(ClassLoaderResolver clr,
                                               java.lang.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

public TableGeneratorMetaData getMetaDataForTableGenerator(ClassLoaderResolver clr,
                                                           java.lang.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

public QueryResultMetaData getMetaDataForQueryResult(java.lang.String name)
Accessor for the MetaData for a QueryResult.

Parameters:
name - Name of the query result
Returns:
The QueryResultMetaData under this name

getMetaDataForInterface

public InterfaceMetaData getMetaDataForInterface(java.lang.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

public boolean isPersistentInterface(java.lang.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

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

Parameters:
interfaceName - Name of the persistent interface
implName - The implementation name
Returns:
Whether it is a (DataNucleus-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".

Parameters:
implName - The implementation name
Returns:
Whether it is a (DataNucleus-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".

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

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.

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.

Parameters:
cmd - MetaData for the abstract class
implClass - The implementation class
clr - ClassLoader resolver

getMetaDataForPersistenceUnit

public PersistenceUnitMetaData getMetaDataForPersistenceUnit(java.lang.String unitName)
Method to parse all available "persistence.xml" files and return the metadata for the persistence unit with the specified name.

Parameters:
unitName - Name of the persistence-unit
Returns:
MetaData for the persistence-unit of the specified name (or null if not found)
Throws:
NucleusUserException - if no "persistence.xml" files are found

parsePersistenceFiles

public PersistenceFileMetaData[] parsePersistenceFiles()
Method to parse the available "persistence.xml" files returning the metadata for all found. Searches for all files "META-INF/persistence.xml" in the CLASSPATH of the current thread.

Returns:
The metadata for all "persistence.xml" files

parseFile

protected abstract FileMetaData parseFile(java.net.URL file_url)
Utility to parse a MetaData file.

Parameters:
file_url - URL of the file
Returns:
The FileMetaData for this file

registerFile

public abstract 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.

Parameters:
fileURLString - URL of the metadata file
filemd - The File MetaData

registerSequencesForFile

protected void registerSequencesForFile(FileMetaData filemd)
Convenience method to register all sequences found in the passed file.

Parameters:
filemd - MetaData for the file

registerTableGeneratorsForFile

protected void registerTableGeneratorsForFile(FileMetaData filemd)
Convenience method to register all table generators found in the passed file.

Parameters:
filemd - MetaData for the file

registerQueryResultMetaDataForFile

protected void registerQueryResultMetaDataForFile(FileMetaData filemd)
Convenience method to register all table generators found in the passed file.

Parameters:
filemd - MetaData for the file

registerQueriesForFile

protected void registerQueriesForFile(FileMetaData filemd)
Convenience method to register all queries found in the passed file.

Parameters:
filemd - MetaData for the file

registerFetchPlansForFile

protected void registerFetchPlansForFile(FileMetaData filemd)
Convenience method to register all FetchPlans found in the passed file.

Parameters:
filemd - MetaData for the file

populateFileMetaData

protected void populateFileMetaData(FileMetaData filemd,
                                    ClassLoaderResolver clr,
                                    java.lang.ClassLoader primary)
Convenience method to populate all classes/interfaces in a Meta-Data file.

Parameters:
filemd - The MetaData file
clr - Class Loader to use in population
primary - the primary ClassLoader to use (or null)

initialiseFileMetaData

protected void initialiseFileMetaData(FileMetaData filemd,
                                      ClassLoaderResolver clr,
                                      java.lang.ClassLoader primary)
Initialise all classes/interfaces in a Meta-Data file.

Parameters:
filemd - the FileMetaData
clr - ClassLoader resolver to use
primary - the primary ClassLoader to use (or null)

initialiseClassMetaData

protected void initialiseClassMetaData(ClassMetaData cmd,
                                       java.lang.Class cls,
                                       ClassLoaderResolver clr)
Utility to initialise the MetaData for a class, using the specified class. This assigns defaults to tags that haven't been assigned. If the class that is being used to populate the MetaData is not enhanced, this will throw a NucleusUserException informing them of this.

Parameters:
cmd - The classes metadata
cls - The class to use as a basis for initialisation
clr - ClassLoader resolver to use
Throws:
NucleusUserException - if the class is not enhanced

initialiseInterfaceMetaData

protected void initialiseInterfaceMetaData(InterfaceMetaData imd,
                                           ClassLoaderResolver clr,
                                           java.lang.ClassLoader primary)
Utility to initialise the MetaData for a interface, using the specified class. This assigns defaults to tags that haven't been assigned. If the class that is being used to populate the MetaData is not enhanced, this will throw a NucleusUserException informing them of this.

Parameters:
imd - The interface metadata
clr - The loader of the interface
primary - the primary ClassLoader to use (or null)

loadAnnotationsForClass

protected FileMetaData loadAnnotationsForClass(java.lang.Class cls,
                                               ClassLoaderResolver clr,
                                               boolean register,
                                               boolean populate)
Method to load the annotations for the specified class and return the FileMetaData containing the class. The FileMetaData, PackageMetaData will be dummy records.

Parameters:
cls - The class
clr - ClassLoader resolver
register - Whether to register the data
populate - Whether to populate the data
Returns:
The FileMetaData

populateAbstractClassMetaData

protected void populateAbstractClassMetaData(AbstractClassMetaData acmd,
                                             ClassLoaderResolver clr,
                                             java.lang.ClassLoader loader)
Convenience method to populate the MetaData for the specified class/interface.

Parameters:
acmd - MetaData
clr - ClassLoader resolver
loader - The primary class loader

initialiseAbstractClassMetaData

protected void initialiseAbstractClassMetaData(AbstractClassMetaData acmd,
                                               ClassLoaderResolver clr)
Convenience method to initialise the MetaData for the specified class/interface.

Parameters:
acmd - MetaData
clr - ClassLoaderResolver

getReferencedClasses

public java.util.List<AbstractClassMetaData> getReferencedClasses(java.lang.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.

getReferencedClassMetaData

protected java.util.List<AbstractClassMetaData> getReferencedClassMetaData(AbstractClassMetaData cmd,
                                                                           ClassLoaderResolver clr)
Utility to return all ClassMetaData that is referenced from the supplier class.

Parameters:
cmd - The origin class's MetaData.
clr - ClassLoaderResolver resolver for loading any classes.
Returns:
List of ClassMetaData referenced by the origin


Copyright © 2010. All Rights Reserved.