Package org.synchronoss.cpo.core.meta
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 Summary
Modifier and TypeMethodDescriptionvoidaddCpoClass(CpoClass cpoClass) Adds aCpoClassto this descriptor's metadata.static voidRemoves all descriptors from the cache.Creates a new, emptyCpoArgument.Creates a new, emptyCpoAttribute.Creates a new, emptyCpoClassof the concrete type appropriate for this descriptor's case-sensitivity setting.Creates a new, emptyCpoFunction.Creates a new, emptyCpoFunctionGroup.final voidPerforms an export of the metadata to the specified Filefinal voidexport(OutputStream outputStream) Performs an export of the meta ata to the specified OutputStreamfinal voidPerforms an export of the metadata to the specified WriterGets the names of all native data types this meta adapter knows how to map.Returns a list of the cpo class objects that the meta adapter is aware of.static Collection<String> Gets the names of all meta descriptors currently loaded.intgetDataTypeInt(String dataTypeName) Gets the integer identifier for a named native data type.Class<?> getDataTypeJavaClass(CpoAttribute attribute) Gets the Java class that the given attribute's native data type maps to.getDataTypeMapEntry(int dataTypeInt) Gets the full data type mapping entry for a given native data type identifier.getDataTypeName(CpoAttribute attribute) Gets the Java class name that the given attribute's native data type maps to.Gets the default Java package name used by the CPO tooling (e.g.Gets the parser used to extract bind-marker/column information from this metadata source's native function expressions.static CpoMetaDescriptorgetInstance(String name) Gets the already-loaded descriptor registered under the given name.static CpoMetaDescriptorgetInstance(String name, String[] metaXmls, boolean caseSensitive) Gets the descriptor registered undername, creating and loading it from one or more meta XML documents if it does not already exist.static CpoMetaDescriptorgetInstance(String name, String metaXml, boolean caseSensitive) Gets the descriptor registered undername, creating and loading it from a single meta XML document if it does not already exist.static CpoMetaDescriptorgetInstance(String name, List<String> metaXmls, boolean caseSensitive) Gets the descriptor registered undername, creating and loading it from one or more meta XML documents if it does not already exist.<T> CpoClassgetMetaClass(T bean) Returns the metadata for the class that is contained within the metadata sourcegetName()Gets the name this descriptor is registered under.booleanGets whether this descriptor matches attribute data names case-sensitively.static booleanisValidMetaDescriptor(CpoMetaDescriptor metaDescriptor) Gets whethermetaDescriptoris registered in the descriptor cache under its own name.static voidrefreshDescriptorMeta(String name, List<String> metaXmls) Hot-reloads the descriptor registered undernameby merging in the given meta XML documents, if that descriptor is currently loaded.static voidrefreshDescriptorMeta(String name, List<String> metaXmls, boolean overwrite) Hot-reloads the descriptor registered undernameby merging in (or, ifoverwriteis set, replacing with) the given meta XML documents, if that descriptor is currently loaded.voidrefreshDescriptorMeta(List<String> metaXmls) Hot-reloads this descriptor by merging in the given meta XML documents.voidrefreshDescriptorMeta(List<String> metaXmls, boolean overwrite) Hot-reloads this descriptor by merging in (or, ifoverwriteis set, replacing with) the given meta XML documents.voidremoveCpoClass(CpoClass cpoClass) Removes aCpoClassfrom this descriptor's metadata.static voidremoveInstance(String name) Removes the descriptor registered under the given name from the cache.voidsetDefaultPackageName(String packageName) Sets the default Java package name used by the CPO tooling.
-
Method Details
-
isValidMetaDescriptor
Gets whethermetaDescriptoris registered in the descriptor cache under its own name.- Parameters:
metaDescriptor- the descriptor to check- Returns:
trueif a descriptor with the same name is currently cached,falseotherwise
-
getInstance
Gets the already-loaded descriptor registered under the given name.- Parameters:
name- the descriptor name- Returns:
- the cached descriptor, or
nullif none is registered undername - Throws:
CpoException- if the descriptor cannot be looked up
-
removeInstance
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
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 undername, creating and loading it from a single meta XML document if it does not already exist.- Parameters:
name- the descriptor namemetaXml- the meta XML document (or classpath/file reference) to loadcaseSensitive- 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 undername, 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 namemetaXmls- the meta XML documents (or classpath/file references) to load, in ordercaseSensitive- 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 undername, 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 namemetaXmls- the meta XML documents (or classpath/file references) to load, in ordercaseSensitive- 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
Gets the names of all meta descriptors currently loaded.- Returns:
- A collection of names of all meta descriptors currently loaded
-
refreshDescriptorMeta
Hot-reloads the descriptor registered undernameby merging in the given meta XML documents, if that descriptor is currently loaded. A no-op if no descriptor is registered undername.- Parameters:
name- the descriptor namemetaXmls- 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 undernameby merging in (or, ifoverwriteis set, replacing with) the given meta XML documents, if that descriptor is currently loaded. A no-op if no descriptor is registered undername.- Parameters:
name- the descriptor namemetaXmls- the meta XML documents (or classpath/file references) to (re)loadoverwrite- whether to discard the descriptor's existing classes before loading- Throws:
CpoException- if the meta XML cannot be parsed or loaded
-
refreshDescriptorMeta
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
Hot-reloads this descriptor by merging in (or, ifoverwriteis set, replacing with) the given meta XML documents.- Parameters:
metaXmls- the meta XML documents (or classpath/file references) to (re)loadoverwrite- whether to discard this descriptor's existing classes before loading- Throws:
CpoException- if the meta XML cannot be parsed or loaded
-
getMetaClass
Returns the metadata for the class that is contained within the metadata source- Specified by:
getMetaClassin interfaceCpoMetaAdapter- Type Parameters:
T- The bean Type- Parameters:
bean- The java bean whose metaclass is needed- Returns:
- the
CpoClassmetadata forbean's class - Throws:
CpoException- Thrown if there are errors accessing the datasource
-
getCpoClasses
Returns a list of the cpo class objects that the meta adapter is aware of.- Specified by:
getCpoClassesin interfaceCpoMetaAdapter- Returns:
- java.util.List of CpoClass
- Throws:
CpoException- Thrown if there are errors accessing the datasource
-
addCpoClass
Adds aCpoClassto this descriptor's metadata.- Parameters:
cpoClass- the class metadata to add- Throws:
CpoException- if the class cannot be added
-
removeCpoClass
Removes aCpoClassfrom this descriptor's metadata.- Parameters:
cpoClass- the class metadata to remove- Throws:
CpoException- if the class cannot be removed
-
getExpressionParser
Gets the parser used to extract bind-marker/column information from this metadata source's native function expressions.- Specified by:
getExpressionParserin interfaceCpoMetaAdapter- Returns:
- the expression parser for this meta adapter
- Throws:
CpoException- if the parser cannot be created
-
getDataTypeName
Gets the Java class name that the given attribute's native data type maps to.- Specified by:
getDataTypeNamein interfaceCpoMetaAdapter- Parameters:
attribute- the attribute whose data type is being resolved- Returns:
- the fully-qualified Java class name (array types are reported as
byte[]orchar[]) - Throws:
CpoException- if the data type cannot be resolved
-
getDataTypeJavaClass
Gets the Java class that the given attribute's native data type maps to.- Specified by:
getDataTypeJavaClassin interfaceCpoMetaAdapter- 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
Gets the integer identifier for a named native data type.- Specified by:
getDataTypeIntin interfaceCpoMetaAdapter- 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
Gets the full data type mapping entry for a given native data type identifier.- Specified by:
getDataTypeMapEntryin interfaceCpoMetaAdapter- Parameters:
dataTypeInt- the integer identifier of the native data type- Returns:
- the
DataTypeMapEntryregistered fordataTypeInt - Throws:
CpoException- if the data type identifier is not recognized
-
getAllowableDataTypes
Gets the names of all native data types this meta adapter knows how to map.- Specified by:
getAllowableDataTypesin interfaceCpoMetaAdapter- Returns:
- the list of allowable native data type names
- Throws:
CpoException- if the data types cannot be retrieved
-
createCpoClass
Creates a new, emptyCpoClassof 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
Creates a new, emptyCpoAttribute.- Returns:
- a new, unpopulated attribute metadata instance
- Throws:
CpoException- if the instance cannot be created
-
createCpoFunctionGroup
Creates a new, emptyCpoFunctionGroup.- Returns:
- a new, unpopulated function group metadata instance
- Throws:
CpoException- if the instance cannot be created
-
createCpoFunction
Creates a new, emptyCpoFunction.- Returns:
- a new, unpopulated function metadata instance
- Throws:
CpoException- if the instance cannot be created
-
createCpoArgument
Creates a new, emptyCpoArgument.- Returns:
- a new, unpopulated argument metadata instance
- Throws:
CpoException- if the instance cannot be created
-
getDefaultPackageName
Gets the default Java package name used by the CPO tooling (e.g.cpo-plugincode generation) when a meta XML document does not otherwise specify one.- Returns:
- the default package name, or
nullif none has been set
-
setDefaultPackageName
Sets the default Java package name used by the CPO tooling. Anullargument is ignored, leaving any previously set value unchanged.- Parameters:
packageName- the default package name
-
getName
Gets the name this descriptor is registered under.- Returns:
- the descriptor name
-
export
Performs an export of the metadata to the specified File- Specified by:
exportin interfaceCpoMetaExportable- Parameters:
file- The file to export to- Throws:
CpoException- An error has occurred
-
export
Performs an export of the metadata to the specified Writer- Specified by:
exportin interfaceCpoMetaExportable- Parameters:
writer- The writer to export to- Throws:
CpoException- An error has occurred
-
export
Performs an export of the meta ata to the specified OutputStream- Specified by:
exportin interfaceCpoMetaExportable- 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:
trueif data names are matched case-sensitively,falseotherwise
-