Package org.datanucleus.metadata
Class MetaDataUtils
java.lang.Object
org.datanucleus.metadata.MetaDataUtils
Utilities needed for the processing of MetaData.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Protected constructor to prevent outside instantiation -
Method Summary
Modifier and TypeMethodDescriptionboolean
Convenience method to determine if an array is storable in a single column as a byte array.static boolean
getBooleanForString
(String str, boolean dflt) Convenience method to return a boolean from the String value.static FileMetaData[]
getFileMetaDataForInputFiles
(MetaDataManager metaDataMgr, ClassLoaderResolver clr, String[] inputFiles) Method to take the provided input files and returns the FileMetaData that they implies.String[]
getImplementationNamesForReferenceField
(AbstractMemberMetaData fmd, FieldRole fieldRole, ClassLoaderResolver clr, MetaDataManager mmgr) Convenience method to return the class names of the available implementation types for an interface/Object field, given its required role.static MetaDataUtils
Gets an instance of MetaDataUtilsstatic JdbcType
getJdbcTypeForEnum
(AbstractMemberMetaData mmd, FieldRole role, ClassLoaderResolver clr) static List
<AbstractClassMetaData> getMetaDataForCandidates
(Class cls, boolean subclasses, ExecutionContext ec) Convenience method to return the class metadata for the candidate and optionally its subclasses.static PersistenceUnitMetaData
getMetaDataForPersistenceUnit
(PluginManager pluginMgr, String persistenceFilename, String unitName, boolean validate, boolean namespaceAware, ClassLoaderResolver clr) Convenience method to parse the available persistence.xml file(s) and find the metadata for the specified persistence-unit.static Class
static String
getValueForExtensionRecursively
(MetaData metadata, String key) Searches the meta data tree upwards starting with the given leaf, stops as soon as it finds an extension with the given key.String[]
Convenience method that splits a comma-separated list of values into a String array (removing whitespace).static String[]
getValuesForExtensionRecursively
(MetaData metadata, String key) Searches the meta data tree upwards starting with the given leaf, stops as soon as it finds an extension with the given key.static boolean
isJdbcTypeFloatingPoint
(JdbcType jdbcType) Convenience method to return if a jdbc-type is floating point based.static boolean
isJdbcTypeNumeric
(JdbcType jdbcType) Convenience method to return if a jdbc-type is numeric.static boolean
isJdbcTypeString
(JdbcType jdbcType) Convenience method to return if a jdbc-type is character based.static boolean
isMemberEmbedded
(AbstractMemberMetaData mmd, RelationType relationType, ClassLoaderResolver clr, MetaDataManager mmgr) Convenience method to return whether a member is stored as embedded.boolean
isMemberEmbedded
(MetaDataManager mmgr, ClassLoaderResolver clr, AbstractMemberMetaData mmd, RelationType relationType, AbstractMemberMetaData ownerMmd) Convenience method to return if the specified member is embedded.static PersistenceFileMetaData[]
parsePersistenceFiles
(PluginManager pluginMgr, String persistenceFilename, boolean validate, boolean namespaceAware, ClassLoaderResolver clr) Method to parse the available "persistence.xml" files returning the metadata for all found.static boolean
Convenience method for whether to persist the provided column as numeric.static boolean
Convenience method for whether to persist the provided column as string-based.boolean
Convenience method that returns if a member stores a First-Class object (FCO).boolean
Convenience method that returns if a field stores a persistable object.
-
Field Details
-
instance
-
-
Constructor Details
-
MetaDataUtils
protected MetaDataUtils()Protected constructor to prevent outside instantiation
-
-
Method Details
-
getInstance
Gets an instance of MetaDataUtils- Returns:
- a singleton instance of MetaDataUtils
-
arrayStorableAsByteArrayInSingleColumn
Convenience method to determine if an array is storable in a single column as a byte array.- Parameters:
fmd
- The field- Returns:
- Whether this is an array that can be stored in a single column as non-serialised
-
storesPersistable
Convenience method that returns if a field stores a persistable object. Doesn't care if the persistable object is serialised or embedded, just that it is persistable.- Parameters:
mmd
- MetaData for the fieldec
- ExecutionContext- Returns:
- Whether it stores a persistable object
-
storesFCO
Convenience method that returns if a member stores a First-Class object (FCO). If a field object is serialised/embedded then doesn't count the object as FCO - use storesPersistable() if you want that not checking.- Parameters:
mmd
- MetaData for the memberec
- ExecutionContext- Returns:
- Whether it stores a FCO
-
getValuesForCommaSeparatedAttribute
Convenience method that splits a comma-separated list of values into a String array (removing whitespace).- Parameters:
attr
- The attribute value- Returns:
- The string components
-
getImplementationNamesForReferenceField
public String[] getImplementationNamesForReferenceField(AbstractMemberMetaData fmd, FieldRole fieldRole, ClassLoaderResolver clr, MetaDataManager mmgr) Convenience method to return the class names of the available implementation types for an interface/Object field, given its required role. Removes all duplicates from the list.- Parameters:
fmd
- MetaData for the fieldfieldRole
- The role of the fieldclr
- the ClassLoaderResolvermmgr
- MetaData manager- Returns:
- Names of the classes of the possible implementations of this interface/Object
- Throws:
NucleusUserException
- if no implementation types are found for the reference type field
-
getBooleanForString
Convenience method to return a boolean from the String value. If the string is null then dflt is returned.- Parameters:
str
- The string (should be "true", "false")dflt
- The default- Returns:
- The boolean to use
-
getValueForExtensionRecursively
Searches the meta data tree upwards starting with the given leaf, stops as soon as it finds an extension with the given key.- Parameters:
metadata
- Leaf of the meta data tree, where the search should startkey
- The key of the extension- Returns:
- The value of the extension (null if not existing)
-
getValuesForExtensionRecursively
Searches the meta data tree upwards starting with the given leaf, stops as soon as it finds an extension with the given key.- Parameters:
metadata
- Leaf of the meta data tree, where the search should startkey
- The key of the extension- Returns:
- The values of the extension (null if not existing)
-
isJdbcTypeNumeric
Convenience method to return if a jdbc-type is numeric.- Parameters:
jdbcType
- The type string- Returns:
- Whether it is numeric
-
isJdbcTypeFloatingPoint
Convenience method to return if a jdbc-type is floating point based.- Parameters:
jdbcType
- The type string- Returns:
- Whether it is floating point ased
-
isJdbcTypeString
Convenience method to return if a jdbc-type is character based.- Parameters:
jdbcType
- The type string- Returns:
- Whether it is character based
-
getJdbcTypeForEnum
public static JdbcType getJdbcTypeForEnum(AbstractMemberMetaData mmd, FieldRole role, ClassLoaderResolver clr) -
getMetaDataForCandidates
public static List<AbstractClassMetaData> getMetaDataForCandidates(Class cls, boolean subclasses, ExecutionContext ec) Convenience method to return the class metadata for the candidate and optionally its subclasses. Caters for the class being a persistent interface.- Parameters:
cls
- The classsubclasses
- Include subclasses?ec
- ExecutionContext- Returns:
- The metadata, starting with the candidate
- Throws:
NucleusUserException
- if candidate is an interface with no metadata (i.e not persistent)
-
getFileMetaDataForInputFiles
public static FileMetaData[] getFileMetaDataForInputFiles(MetaDataManager metaDataMgr, ClassLoaderResolver clr, String[] inputFiles) Method to take the provided input files and returns the FileMetaData that they implies. Loads the files into the provided MetaDataManager in the process.- Parameters:
metaDataMgr
- Manager for MetaDataclr
- ClassLoader resolverinputFiles
- Input metadata/class files- Returns:
- The FileMetaData for the input
- Throws:
NucleusException
- Thrown if error(s) occur in processing the input
-
parsePersistenceFiles
public static PersistenceFileMetaData[] parsePersistenceFiles(PluginManager pluginMgr, String persistenceFilename, boolean validate, boolean namespaceAware, ClassLoaderResolver clr) 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.- Parameters:
pluginMgr
- PluginManagerpersistenceFilename
- Name of persistence file (if null will use "persistence.xml")validate
- Whether to validate the persistence filenamespaceAware
- Whether to support namespacesclr
- ClassLoader resolver- Returns:
- The metadata for all "persistence.xml" files
-
getMetaDataForPersistenceUnit
public static PersistenceUnitMetaData getMetaDataForPersistenceUnit(PluginManager pluginMgr, String persistenceFilename, String unitName, boolean validate, boolean namespaceAware, ClassLoaderResolver clr) Convenience method to parse the available persistence.xml file(s) and find the metadata for the specified persistence-unit.- Parameters:
pluginMgr
- Plugin ManagerpersistenceFilename
- Filename of the persistence.xml (or null if using default "META-INF/persistence.xml")unitName
- Name of the persistence unitvalidate
- Whether to validate the XMLnamespaceAware
- Whether the XML is namespace awareclr
- ClassLoader resolver- Returns:
- Metadata for the persistence-unit (if found), or null (if not found)
-
persistColumnAsNumeric
Convenience method for whether to persist the provided column as numeric. Returns true if it has the jdbcType defined as "int"/"integer"- Parameters:
colmd
- Metadata for the column- Returns:
- Whether explicitly specified to use numeric, otherwise returns false.
-
persistColumnAsString
Convenience method for whether to persist the provided column as string-based. Returns true if it has the jdbcType defined as "varchar"/"char"- Parameters:
colmd
- Metadata for the column- Returns:
- Whether explicitly specified to use String, otherwise returns false.
-
getTypeOfDatastoreIdentity
-
isMemberEmbedded
public static boolean isMemberEmbedded(AbstractMemberMetaData mmd, RelationType relationType, ClassLoaderResolver clr, MetaDataManager mmgr) Convenience method to return whether a member is stored as embedded. This caters for not just "mmd.isEmbedded" returning true, but also the "embeddedOnly" of the related type, as well as whether there is <embedded> metadata for this member- Parameters:
mmd
- Metadata for the memberrelationType
- The relation type for this memberclr
- ClassLoader resolvermmgr
- MetaData manager- Returns:
- Whether it is embedded
-
isMemberEmbedded
public boolean isMemberEmbedded(MetaDataManager mmgr, ClassLoaderResolver clr, AbstractMemberMetaData mmd, RelationType relationType, AbstractMemberMetaData ownerMmd) Convenience method to return if the specified member is embedded. Only applies to relation fields, since all other fields are always "embedded". TODO Likely ought to change last arg to List<AbstractMemberMetaData> for multilevel of embedded- Parameters:
mmgr
- Metadata managerclr
- ClassLoader resolvermmd
- Metadata for the member we are interested inrelationType
- Relation type of the member we are interested inownerMmd
- Optional metadata for the owner member (for nested embeddeds only. Set to null if not relevant to the member in question).- Returns:
- Whether the member is embedded
-