Class CpoMetaDescriptor

java.lang.Object
org.synchronoss.cpo.core.cache.CpoMetaDescriptorCache
org.synchronoss.cpo.core.meta.CpoMetaDescriptor
All Implemented Interfaces:
CpoMetaAdapter, CpoMetaExportable
Direct Known Subclasses:
CassandraCpoMetaDescriptor, JdbcCpoMetaDescriptor

public class CpoMetaDescriptor extends CpoMetaDescriptorCache implements CpoMetaAdapter, CpoMetaExportable
CpoMetaDescriptor is the runtime, named handle on a loaded CPO metadata source: it owns the datastore-specific AbstractCpoMetaAdapter that holds the actual CpoClass metadata, and delegates the CpoMetaAdapter contract to it. Instances are singletons per name, cached in the inherited CpoMetaDescriptorCache and looked up/created via the static getInstance/createUpdateInstance factory methods rather than constructed directly.

A descriptor can be built up from one or more meta XML documents (via getInstance(String, List, boolean) and friends); loading multiple documents into the same named descriptor merges their CpoClass definitions, which is what enables the polymorphic override pattern described in the project documentation.

Author:
dberry
  • Method Details

    • isValidMetaDescriptor

      public static boolean isValidMetaDescriptor(CpoMetaDescriptor metaDescriptor)
      Gets whether metaDescriptor is registered in the descriptor cache under its own name.
      Parameters:
      metaDescriptor - the descriptor to check
      Returns:
      true if a descriptor with the same name is currently cached, false otherwise
    • getInstance

      public static CpoMetaDescriptor getInstance(String name) throws CpoException
      Gets the already-loaded descriptor registered under the given name.
      Parameters:
      name - the descriptor name
      Returns:
      the cached descriptor, or null if none is registered under name
      Throws:
      CpoException - if the descriptor cannot be looked up
    • removeInstance

      public static void removeInstance(String name) throws CpoException
      Removes the descriptor registered under the given name from the cache.
      Parameters:
      name - the descriptor name
      Throws:
      CpoException - if the descriptor cannot be removed
    • clearAllInstances

      public static void clearAllInstances() throws CpoException
      Removes all descriptors from the cache.
      Throws:
      CpoException - if the cache cannot be cleared
    • getInstance

      public static CpoMetaDescriptor getInstance(String name, String metaXml, boolean caseSensitive) throws CpoException
      Gets the descriptor registered under name, creating and loading it from a single meta XML document if it does not already exist.
      Parameters:
      name - the descriptor name
      metaXml - the meta XML document (or classpath/file reference) to load
      caseSensitive - whether attribute data names should be matched case-sensitively
      Returns:
      the loaded (or previously cached) descriptor
      Throws:
      CpoException - if the meta XML cannot be parsed or loaded
    • getInstance

      public static CpoMetaDescriptor getInstance(String name, List<String> metaXmls, boolean caseSensitive) throws CpoException
      Gets the descriptor registered under name, creating and loading it from one or more meta XML documents if it does not already exist. Loading multiple documents into the same descriptor merges their class definitions.
      Parameters:
      name - the descriptor name
      metaXmls - the meta XML documents (or classpath/file references) to load, in order
      caseSensitive - whether attribute data names should be matched case-sensitively
      Returns:
      the loaded (or previously cached) descriptor
      Throws:
      CpoException - if the meta XML cannot be parsed or loaded
    • getInstance

      public static CpoMetaDescriptor getInstance(String name, String[] metaXmls, boolean caseSensitive) throws CpoException
      Gets the descriptor registered under name, creating and loading it from one or more meta XML documents if it does not already exist. Loading multiple documents into the same descriptor merges their class definitions.
      Parameters:
      name - the descriptor name
      metaXmls - the meta XML documents (or classpath/file references) to load, in order
      caseSensitive - whether attribute data names should be matched case-sensitively
      Returns:
      the loaded (or previously cached) descriptor
      Throws:
      CpoException - if the meta XML cannot be parsed or loaded
    • getCpoMetaDescriptorNames

      public static Collection<String> getCpoMetaDescriptorNames()
      Gets the names of all meta descriptors currently loaded.
      Returns:
      A collection of names of all meta descriptors currently loaded
    • refreshDescriptorMeta

      public static void refreshDescriptorMeta(String name, List<String> metaXmls) throws CpoException
      Hot-reloads the descriptor registered under name by merging in the given meta XML documents, if that descriptor is currently loaded. A no-op if no descriptor is registered under name.
      Parameters:
      name - the descriptor name
      metaXmls - the meta XML documents (or classpath/file references) to (re)load
      Throws:
      CpoException - if the meta XML cannot be parsed or loaded
    • refreshDescriptorMeta

      public static void refreshDescriptorMeta(String name, List<String> metaXmls, boolean overwrite) throws CpoException
      Hot-reloads the descriptor registered under name by merging in (or, if overwrite is set, replacing with) the given meta XML documents, if that descriptor is currently loaded. A no-op if no descriptor is registered under name.
      Parameters:
      name - the descriptor name
      metaXmls - the meta XML documents (or classpath/file references) to (re)load
      overwrite - whether to discard the descriptor's existing classes before loading
      Throws:
      CpoException - if the meta XML cannot be parsed or loaded
    • refreshDescriptorMeta

      public void refreshDescriptorMeta(List<String> metaXmls) throws CpoException
      Hot-reloads this descriptor by merging in the given meta XML documents.
      Parameters:
      metaXmls - the meta XML documents (or classpath/file references) to (re)load
      Throws:
      CpoException - if the meta XML cannot be parsed or loaded
    • refreshDescriptorMeta

      public void refreshDescriptorMeta(List<String> metaXmls, boolean overwrite) throws CpoException
      Hot-reloads this descriptor by merging in (or, if overwrite is set, replacing with) the given meta XML documents.
      Parameters:
      metaXmls - the meta XML documents (or classpath/file references) to (re)load
      overwrite - whether to discard this descriptor's existing classes before loading
      Throws:
      CpoException - if the meta XML cannot be parsed or loaded
    • getMetaClass

      public <T> CpoClass getMetaClass(T bean) throws CpoException
      Returns the metadata for the class that is contained within the metadata source
      Specified by:
      getMetaClass in interface CpoMetaAdapter
      Type Parameters:
      T - The bean Type
      Parameters:
      bean - The java bean whose metaclass is needed
      Returns:
      the CpoClass metadata for bean's class
      Throws:
      CpoException - Thrown if there are errors accessing the datasource
    • getCpoClasses

      public List<CpoClass> getCpoClasses() throws CpoException
      Returns a list of the cpo class objects that the meta adapter is aware of.
      Specified by:
      getCpoClasses in interface CpoMetaAdapter
      Returns:
      java.util.List of CpoClass
      Throws:
      CpoException - Thrown if there are errors accessing the datasource
    • addCpoClass

      public void addCpoClass(CpoClass cpoClass) throws CpoException
      Adds a CpoClass to this descriptor's metadata.
      Parameters:
      cpoClass - the class metadata to add
      Throws:
      CpoException - if the class cannot be added
    • removeCpoClass

      public void removeCpoClass(CpoClass cpoClass) throws CpoException
      Removes a CpoClass from this descriptor's metadata.
      Parameters:
      cpoClass - the class metadata to remove
      Throws:
      CpoException - if the class cannot be removed
    • getExpressionParser

      public ExpressionParser getExpressionParser() throws CpoException
      Gets the parser used to extract bind-marker/column information from this metadata source's native function expressions.
      Specified by:
      getExpressionParser in interface CpoMetaAdapter
      Returns:
      the expression parser for this meta adapter
      Throws:
      CpoException - if the parser cannot be created
    • getDataTypeName

      public String getDataTypeName(CpoAttribute attribute) throws CpoException
      Gets the Java class name that the given attribute's native data type maps to.
      Specified by:
      getDataTypeName in interface CpoMetaAdapter
      Parameters:
      attribute - the attribute whose data type is being resolved
      Returns:
      the fully-qualified Java class name (array types are reported as byte[] or char[])
      Throws:
      CpoException - if the data type cannot be resolved
    • getDataTypeJavaClass

      public Class<?> getDataTypeJavaClass(CpoAttribute attribute) throws CpoException
      Gets the Java class that the given attribute's native data type maps to.
      Specified by:
      getDataTypeJavaClass in interface CpoMetaAdapter
      Parameters:
      attribute - the attribute whose data type is being resolved
      Returns:
      the Java class the attribute's value is represented as
      Throws:
      CpoException - if the data type cannot be resolved
    • getDataTypeInt

      public int getDataTypeInt(String dataTypeName) throws CpoException
      Gets the integer identifier for a named native data type.
      Specified by:
      getDataTypeInt in interface CpoMetaAdapter
      Parameters:
      dataTypeName - the native data type name
      Returns:
      the integer identifier registered for dataTypeName
      Throws:
      CpoException - if the data type name is not recognized
    • getDataTypeMapEntry

      public DataTypeMapEntry<?> getDataTypeMapEntry(int dataTypeInt) throws CpoException
      Gets the full data type mapping entry for a given native data type identifier.
      Specified by:
      getDataTypeMapEntry in interface CpoMetaAdapter
      Parameters:
      dataTypeInt - the integer identifier of the native data type
      Returns:
      the DataTypeMapEntry registered for dataTypeInt
      Throws:
      CpoException - if the data type identifier is not recognized
    • getAllowableDataTypes

      public List<String> getAllowableDataTypes() throws CpoException
      Gets the names of all native data types this meta adapter knows how to map.
      Specified by:
      getAllowableDataTypes in interface CpoMetaAdapter
      Returns:
      the list of allowable native data type names
      Throws:
      CpoException - if the data types cannot be retrieved
    • createCpoClass

      public CpoClass createCpoClass() throws CpoException
      Creates a new, empty CpoClass of the concrete type appropriate for this descriptor's case-sensitivity setting.
      Returns:
      a new, unpopulated class metadata instance
      Throws:
      CpoException - if the instance cannot be created
    • createCpoAttribute

      public CpoAttribute createCpoAttribute() throws CpoException
      Creates a new, empty CpoAttribute.
      Returns:
      a new, unpopulated attribute metadata instance
      Throws:
      CpoException - if the instance cannot be created
    • createCpoFunctionGroup

      public CpoFunctionGroup createCpoFunctionGroup() throws CpoException
      Creates a new, empty CpoFunctionGroup.
      Returns:
      a new, unpopulated function group metadata instance
      Throws:
      CpoException - if the instance cannot be created
    • createCpoFunction

      public CpoFunction createCpoFunction() throws CpoException
      Creates a new, empty CpoFunction.
      Returns:
      a new, unpopulated function metadata instance
      Throws:
      CpoException - if the instance cannot be created
    • createCpoArgument

      public CpoArgument createCpoArgument() throws CpoException
      Creates a new, empty CpoArgument.
      Returns:
      a new, unpopulated argument metadata instance
      Throws:
      CpoException - if the instance cannot be created
    • getDefaultPackageName

      public String getDefaultPackageName()
      Gets the default Java package name used by the CPO tooling (e.g. cpo-plugin code generation) when a meta XML document does not otherwise specify one.
      Returns:
      the default package name, or null if none has been set
    • setDefaultPackageName

      public void setDefaultPackageName(String packageName)
      Sets the default Java package name used by the CPO tooling. A null argument is ignored, leaving any previously set value unchanged.
      Parameters:
      packageName - the default package name
    • getName

      public String getName()
      Gets the name this descriptor is registered under.
      Returns:
      the descriptor name
    • export

      public final void export(File file) throws CpoException
      Performs an export of the metadata to the specified File
      Specified by:
      export in interface CpoMetaExportable
      Parameters:
      file - The file to export to
      Throws:
      CpoException - An error has occurred
    • export

      public final void export(Writer writer) throws CpoException
      Performs an export of the metadata to the specified Writer
      Specified by:
      export in interface CpoMetaExportable
      Parameters:
      writer - The writer to export to
      Throws:
      CpoException - An error has occurred
    • export

      public final void export(OutputStream outputStream) throws CpoException
      Performs an export of the meta ata to the specified OutputStream
      Specified by:
      export in interface CpoMetaExportable
      Parameters:
      outputStream - The output stream to export to
      Throws:
      CpoException - An error has occurred
    • isCaseSensitive

      public boolean isCaseSensitive()
      Gets whether this descriptor matches attribute data names case-sensitively.
      Returns:
      true if data names are matched case-sensitively, false otherwise