Class MetaDataUtils

java.lang.Object
org.datanucleus.metadata.MetaDataUtils

public class MetaDataUtils extends Object
Utilities needed for the processing of MetaData.
  • Field Details

  • Constructor Details

    • MetaDataUtils

      protected MetaDataUtils()
      Protected constructor to prevent outside instantiation
  • Method Details

    • getInstance

      public static MetaDataUtils getInstance()
      Gets an instance of MetaDataUtils
      Returns:
      a singleton instance of MetaDataUtils
    • arrayStorableAsByteArrayInSingleColumn

      public boolean arrayStorableAsByteArrayInSingleColumn(AbstractMemberMetaData fmd)
      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

      public boolean storesPersistable(AbstractMemberMetaData mmd, ExecutionContext ec)
      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 field
      ec - ExecutionContext
      Returns:
      Whether it stores a persistable object
    • storesFCO

      public boolean storesFCO(AbstractMemberMetaData mmd, ExecutionContext ec)
      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 member
      ec - ExecutionContext
      Returns:
      Whether it stores a FCO
    • getValuesForCommaSeparatedAttribute

      public String[] getValuesForCommaSeparatedAttribute(String attr)
      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 field
      fieldRole - The role of the field
      clr - the ClassLoaderResolver
      mmgr - 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

      public static boolean getBooleanForString(String str, boolean dflt)
      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

      public 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.
      Parameters:
      metadata - Leaf of the meta data tree, where the search should start
      key - The key of the extension
      Returns:
      The value of the extension (null if not existing)
    • getValuesForExtensionRecursively

      public 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.
      Parameters:
      metadata - Leaf of the meta data tree, where the search should start
      key - The key of the extension
      Returns:
      The values of the extension (null if not existing)
    • isJdbcTypeNumeric

      public static boolean isJdbcTypeNumeric(JdbcType jdbcType)
      Convenience method to return if a jdbc-type is numeric.
      Parameters:
      jdbcType - The type string
      Returns:
      Whether it is numeric
    • isJdbcTypeFloatingPoint

      public static boolean isJdbcTypeFloatingPoint(JdbcType jdbcType)
      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

      public static boolean isJdbcTypeString(JdbcType jdbcType)
      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 class
      subclasses - 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 MetaData
      clr - ClassLoader resolver
      inputFiles - 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 - PluginManager
      persistenceFilename - Name of persistence file (if null will use "persistence.xml")
      validate - Whether to validate the persistence file
      namespaceAware - Whether to support namespaces
      clr - 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 Manager
      persistenceFilename - Filename of the persistence.xml (or null if using default "META-INF/persistence.xml")
      unitName - Name of the persistence unit
      validate - Whether to validate the XML
      namespaceAware - Whether the XML is namespace aware
      clr - ClassLoader resolver
      Returns:
      Metadata for the persistence-unit (if found), or null (if not found)
    • persistColumnAsNumeric

      public static boolean persistColumnAsNumeric(ColumnMetaData colmd)
      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

      public static boolean persistColumnAsString(ColumnMetaData colmd)
      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

      public static Class getTypeOfDatastoreIdentity(DatastoreIdentityMetaData dimd)
    • 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 member
      relationType - The relation type for this member
      clr - ClassLoader resolver
      mmgr - 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 manager
      clr - ClassLoader resolver
      mmd - Metadata for the member we are interested in
      relationType - Relation type of the member we are interested in
      ownerMmd - 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