Package org.datanucleus.store.types
Class TypeManagerImpl
- java.lang.Object
-
- org.datanucleus.store.types.TypeManagerImpl
-
- All Implemented Interfaces:
Serializable,TypeManager
public class TypeManagerImpl extends Object implements TypeManager, Serializable
Implementation of registry of java type support. Provides information applicable to all datastores for how a field of a class is treated; whether it is by default persistent, whether it is by default embedded, whether it is in the DFG, and if it has a wrapper for SCO operations. Also stores whether the type can be converted to/from a String (for datastores that don't provide storage natively). Uses the plugin mechanism extension-point "org.datanucleus.java_type".- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,TypeConverter>autoApplyConvertersByTypeMap of TypeConverter keyed by type name that we should default to for this type (user-defined).protected ClassLoaderResolverclrprotected Map<Class,? super ContainerHandler>containerHandlersByClassMap of ContainerHandlers, keyed by the container type class name.protected Map<String,org.datanucleus.store.types.TypeManagerImpl.JavaType>javaTypesMap of java types, keyed by the class name.protected NucleusContextnucCtxprotected Map<String,TypeConverter>typeConverterByNameMap of TypeConverter keyed by their symbolic name.protected Map<TypeConverter,Class>typeConverterDatastoreTypeByConverterCache of TypeConverter datastore type, keyed by the converter.protected Map<Class,Map<Class,TypeConverter>>typeConverterMapMap of (Map of TypeConverter keyed by the datastore type), keyed by the member type.protected Map<TypeConverter,Class>typeConverterMemberTypeByConverterCache of TypeConverter member type, keyed by the converter.
-
Constructor Summary
Constructors Constructor Description TypeManagerImpl(NucleusContext nucCtx)Constructor, loading support for type mappings using the plugin mechanism.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()SCOcreateSCOInstance(ObjectProvider ownerOP, AbstractMemberMetaData mmd, Class instantiatedType, Object value, boolean replaceField)Method to create a new SCO wrapper for the specified member.String[]filterOutSupportedSecondClassNames(String[] inputClassNames)Convenience method to filter out any supported classes from a list.protected org.datanucleus.store.types.TypeManagerImpl.JavaTypefindJavaTypeForClass(Class cls)Convenience method to return the JavaType for the specified class.protected org.datanucleus.store.types.TypeManagerImpl.JavaTypefindJavaTypeForCollectionClass(Class cls, Class genericType)Convenience method to return the JavaType for the specified class.TypeConvertergetAutoApplyTypeConverterForType(Class memberType)Method to return a TypeConverter that should be applied by default for the specified java (member) type.ContainerAdaptergetContainerAdapter(Object container)Convenience method to obtain the ContainerAdapter using the container object instance<H extends ContainerHandler>
HgetContainerHandler(Class containerClass)Obtains the registered ContainerHandler for the given containerClass.ClassgetDatastoreTypeForTypeConverter(TypeConverter conv, Class memberType)Method to return the datastore type for the specified TypeConverter.TypeConvertergetDefaultTypeConverterForType(Class memberType)Accessor for the default type converter for the provided Java type.ClassgetMemberTypeForTypeConverter(TypeConverter conv, Class datastoreType)Method to return the member type for the specified TypeConverter.Set<String>getSupportedSecondClassTypes()Accessor for the supported second-class Types.TypeConvertergetTypeConverterForName(String converterName)Accessor for the type converter with the provided name.TypeConvertergetTypeConverterForType(Class memberType, Class datastoreType)Accessor for the type converter for the provided Java type and its datastore type.Collection<TypeConverter>getTypeConvertersForType(Class memberType)Accessor for the available type converters for the provided Java type.ClassgetTypeForSecondClassWrapper(String className)Accessor for a java type that the supplied class is a SCO wrapper for.ClassgetWrappedTypeBackedForType(String className)Accessor for the backing-store Second Class Wrapper class for the supplied class.ClassgetWrapperTypeForType(String className)Accessor for the SCO wrapper for the typebooleanisDefaultEmbeddedType(Class c)Accessor for whether the type is by default embedded.booleanisDefaultFetchGroup(Class c)Accessor for whether the type is by default in the DFG.booleanisDefaultFetchGroupForCollection(Class c, Class genericType)Accessor for whether the generic collection type is by default in the DFG.booleanisDefaultPersistent(Class c)Accessor for whether the type is by default persistent.booleanisSecondClassMutableType(String className)Accessor for whether the type is SCO mutable.booleanisSecondClassWrapper(String className)Accessor for whether the type is a SCO wrapper itself.booleanisSupportedSecondClassType(String className)Accessor for whether a class is supported as being second class.voidregisterConverter(String name, TypeConverter converter, Class memberType, Class dbType, boolean autoApply, String autoApplyType)Register a TypeConverter with the TypeManager process for specific attribute/db types.voidsetDefaultTypeConverterForType(Class memberType, String converterName)Method providing the ability for a datastore plugin to override the default converter type for the specified java type.ObjectwrapAndReplaceSCOField(ObjectProvider ownerOP, int memberNumber, Object newValue, Object oldValue, boolean replaceFieldIfChanged)Method to create a new SCO wrapper for the specified field replacing the old value with the new value.
-
-
-
Field Detail
-
nucCtx
protected NucleusContext nucCtx
-
clr
protected transient ClassLoaderResolver clr
-
javaTypes
protected Map<String,org.datanucleus.store.types.TypeManagerImpl.JavaType> javaTypes
Map of java types, keyed by the class name.
-
containerHandlersByClass
protected Map<Class,? super ContainerHandler> containerHandlersByClass
Map of ContainerHandlers, keyed by the container type class name.
-
typeConverterByName
protected Map<String,TypeConverter> typeConverterByName
Map of TypeConverter keyed by their symbolic name.
-
autoApplyConvertersByType
protected Map<String,TypeConverter> autoApplyConvertersByType
Map of TypeConverter keyed by type name that we should default to for this type (user-defined).
-
typeConverterMap
protected Map<Class,Map<Class,TypeConverter>> typeConverterMap
Map of (Map of TypeConverter keyed by the datastore type), keyed by the member type.
-
typeConverterDatastoreTypeByConverter
protected Map<TypeConverter,Class> typeConverterDatastoreTypeByConverter
Cache of TypeConverter datastore type, keyed by the converter.
-
typeConverterMemberTypeByConverter
protected Map<TypeConverter,Class> typeConverterMemberTypeByConverter
Cache of TypeConverter member type, keyed by the converter.
-
-
Constructor Detail
-
TypeManagerImpl
public TypeManagerImpl(NucleusContext nucCtx)
Constructor, loading support for type mappings using the plugin mechanism.- Parameters:
nucCtx- NucleusContext
-
-
Method Detail
-
close
public void close()
- Specified by:
closein interfaceTypeManager
-
getSupportedSecondClassTypes
public Set<String> getSupportedSecondClassTypes()
Description copied from interface:TypeManagerAccessor for the supported second-class Types. This may or may not be a complete list, just that it provides the principal ones.- Specified by:
getSupportedSecondClassTypesin interfaceTypeManager- Returns:
- Set of supported types (fully qualified class names).
-
isSupportedSecondClassType
public boolean isSupportedSecondClassType(String className)
Description copied from interface:TypeManagerAccessor for whether a class is supported as being second class.- Specified by:
isSupportedSecondClassTypein interfaceTypeManager- Parameters:
className- The class name- Returns:
- Whether the class is supported (to some degree)
-
filterOutSupportedSecondClassNames
public String[] filterOutSupportedSecondClassNames(String[] inputClassNames)
Description copied from interface:TypeManagerConvenience method to filter out any supported classes from a list.- Specified by:
filterOutSupportedSecondClassNamesin interfaceTypeManager- Parameters:
inputClassNames- Names of the classes- Returns:
- Names of the classes (omitting supported types)
-
isDefaultPersistent
public boolean isDefaultPersistent(Class c)
Description copied from interface:TypeManagerAccessor for whether the type is by default persistent. TODO Support use of apiAdapter.isMemberDefaultPersistent to get strict JDO/JPA behaviour.- Specified by:
isDefaultPersistentin interfaceTypeManager- Parameters:
c- The type- Returns:
- Whether persistent
-
isDefaultFetchGroup
public boolean isDefaultFetchGroup(Class c)
Description copied from interface:TypeManagerAccessor for whether the type is by default in the DFG.- Specified by:
isDefaultFetchGroupin interfaceTypeManager- Parameters:
c- The type- Returns:
- Whether in the DFG
-
isDefaultFetchGroupForCollection
public boolean isDefaultFetchGroupForCollection(Class c, Class genericType)
Description copied from interface:TypeManagerAccessor for whether the generic collection type is by default in the DFG.- Specified by:
isDefaultFetchGroupForCollectionin interfaceTypeManager- Parameters:
c- The typegenericType- The element generic type- Returns:
- Whether in the DFG
-
isDefaultEmbeddedType
public boolean isDefaultEmbeddedType(Class c)
Description copied from interface:TypeManagerAccessor for whether the type is by default embedded.- Specified by:
isDefaultEmbeddedTypein interfaceTypeManager- Parameters:
c- The type- Returns:
- Whether embedded
-
isSecondClassMutableType
public boolean isSecondClassMutableType(String className)
Description copied from interface:TypeManagerAccessor for whether the type is SCO mutable.- Specified by:
isSecondClassMutableTypein interfaceTypeManager- Parameters:
className- The type- Returns:
- Whether SCO mutable
-
getWrapperTypeForType
public Class getWrapperTypeForType(String className)
Description copied from interface:TypeManagerAccessor for the SCO wrapper for the type- Specified by:
getWrapperTypeForTypein interfaceTypeManager- Parameters:
className- The type- Returns:
- SCO wrapper
-
getWrappedTypeBackedForType
public Class getWrappedTypeBackedForType(String className)
Description copied from interface:TypeManagerAccessor for the backing-store Second Class Wrapper class for the supplied class. A type will have a SCO wrapper if it is SCO supported and is mutable. If there is no backed wrapper provided returns the simple wrapper.- Specified by:
getWrappedTypeBackedForTypein interfaceTypeManager- Parameters:
className- The class name- Returns:
- The second class wrapper
-
isSecondClassWrapper
public boolean isSecondClassWrapper(String className)
Description copied from interface:TypeManagerAccessor for whether the type is a SCO wrapper itself.- Specified by:
isSecondClassWrapperin interfaceTypeManager- Parameters:
className- The type- Returns:
- Whether is SCO wrapper
-
createSCOInstance
public SCO createSCOInstance(ObjectProvider ownerOP, AbstractMemberMetaData mmd, Class instantiatedType, Object value, boolean replaceField)
Description copied from interface:TypeManagerMethod to create a new SCO wrapper for the specified member. The SCO wrapper will be appropriate for the passed value (which represents the instantiated type of the field) unless it is null when the wrapper will be appropriate for the declared type of the field. While the "instantiated type" and the type of "value" should be the same when value is non-null, there are situations where we need to create a List based collection yet have no value so pass in the declaredType as Collection, instantiatedType as ArrayList, and value as null.- Specified by:
createSCOInstancein interfaceTypeManager- Parameters:
ownerOP- ObjectProvider managing the instancemmd- Metadata for the member in questioninstantiatedType- The instantiated typevalue- The value to wrapreplaceField- Whether to replace the field in the owner object- Returns:
- The SCO wrapper
-
wrapAndReplaceSCOField
public Object wrapAndReplaceSCOField(ObjectProvider ownerOP, int memberNumber, Object newValue, Object oldValue, boolean replaceFieldIfChanged)
Method to create a new SCO wrapper for the specified field replacing the old value with the new value. If the member value is a SCO already will just return the (new) value.- Specified by:
wrapAndReplaceSCOFieldin interfaceTypeManager- Parameters:
ownerOP- The ObjectProvider of the owner objectmemberNumber- The member number in the ownernewValue- The value to initialise the wrapper with (if any) for this memberoldValue- The previous value that we are replacing with this valuereplaceFieldIfChanged- Whether to replace the member in the object if wrapping the value- Returns:
- The wrapper (or original value if not wrappable)
-
getTypeForSecondClassWrapper
public Class getTypeForSecondClassWrapper(String className)
Description copied from interface:TypeManagerAccessor for a java type that the supplied class is a SCO wrapper for. If the supplied class is not a SCO wrapper for anything then returns null.- Specified by:
getTypeForSecondClassWrapperin interfaceTypeManager- Parameters:
className- Name of the class- Returns:
- The java class that this is a wrapper for (or null)
-
getContainerAdapter
public ContainerAdapter getContainerAdapter(Object container)
Description copied from interface:TypeManagerConvenience method to obtain the ContainerAdapter using the container object instance- Specified by:
getContainerAdapterin interfaceTypeManager- Parameters:
container- The container instance- Returns:
- The ContainerAdapter for the respective container or null if it's not a supported container
-
getContainerHandler
public <H extends ContainerHandler> H getContainerHandler(Class containerClass)
Description copied from interface:TypeManagerObtains the registered ContainerHandler for the given containerClass. ContainerHandler are specified via the plugin mechanism using the container-handler attribute of the java-type element.- Specified by:
getContainerHandlerin interfaceTypeManager- Type Parameters:
H- Handler type- Parameters:
containerClass- The class of the container.- Returns:
- The respective ContainerHandler if registered or null if no ContainerHandler is found for the containerClass.
-
getTypeConverterForName
public TypeConverter getTypeConverterForName(String converterName)
Description copied from interface:TypeManagerAccessor for the type converter with the provided name. This is used when the user has specified metadata for a field to use a particular named converter.- Specified by:
getTypeConverterForNamein interfaceTypeManager- Parameters:
converterName- Name of the converter- Returns:
- The converter
-
registerConverter
public void registerConverter(String name, TypeConverter converter, Class memberType, Class dbType, boolean autoApply, String autoApplyType)
Description copied from interface:TypeManagerRegister a TypeConverter with the TypeManager process for specific attribute/db types. TypeConverters are registered either from the contents of "plugin.xml" (i.e the builtin types) where the name is of the form "dn.*", or from user-registered metadata (e.g JPA Annotations) where the name is the class name of the converter or a user supplied name.- Specified by:
registerConverterin interfaceTypeManager- Parameters:
name- The name to register the converter underconverter- The convertermemberType- Type of the java memberdbType- Type of the database columnautoApply- Whether this should be used as an auto-apply converterautoApplyType- Java type to auto apply this for
-
getAutoApplyTypeConverterForType
public TypeConverter getAutoApplyTypeConverterForType(Class memberType)
Description copied from interface:TypeManagerMethod to return a TypeConverter that should be applied by default for the specified java (member) type. Will return null if the java type has no autoApply type defined for it (the default).- Specified by:
getAutoApplyTypeConverterForTypein interfaceTypeManager- Parameters:
memberType- The java (member) type- Returns:
- The converter to use by default
-
setDefaultTypeConverterForType
public void setDefaultTypeConverterForType(Class memberType, String converterName)
Description copied from interface:TypeManagerMethod providing the ability for a datastore plugin to override the default converter type for the specified java type.- Specified by:
setDefaultTypeConverterForTypein interfaceTypeManager- Parameters:
memberType- Member typeconverterName- The converter to use by default. This is assumed to exist.
-
getDefaultTypeConverterForType
public TypeConverter getDefaultTypeConverterForType(Class memberType)
Description copied from interface:TypeManagerAccessor for the default type converter for the provided Java type.- Specified by:
getDefaultTypeConverterForTypein interfaceTypeManager- Parameters:
memberType- Java type for the member- Returns:
- The default converter (if any)
-
getTypeConverterForType
public TypeConverter getTypeConverterForType(Class memberType, Class datastoreType)
Description copied from interface:TypeManagerAccessor for the type converter for the provided Java type and its datastore type.- Specified by:
getTypeConverterForTypein interfaceTypeManager- Parameters:
memberType- Java type for the memberdatastoreType- Java type for the datastore- Returns:
- The converter (if any)
-
getTypeConvertersForType
public Collection<TypeConverter> getTypeConvertersForType(Class memberType)
Description copied from interface:TypeManagerAccessor for the available type converters for the provided Java type.- Specified by:
getTypeConvertersForTypein interfaceTypeManager- Parameters:
memberType- The java type- Returns:
- The available Type Converters
-
getDatastoreTypeForTypeConverter
public Class getDatastoreTypeForTypeConverter(TypeConverter conv, Class memberType)
Method to return the datastore type for the specified TypeConverter.- Specified by:
getDatastoreTypeForTypeConverterin interfaceTypeManager- Parameters:
conv- The convertermemberType- The member type- Returns:
- The datastore type
-
getMemberTypeForTypeConverter
public Class getMemberTypeForTypeConverter(TypeConverter conv, Class datastoreType)
Method to return the member type for the specified TypeConverter.- Specified by:
getMemberTypeForTypeConverterin interfaceTypeManager- Parameters:
conv- The converterdatastoreType- The datastore type for this converter- Returns:
- The member type
-
findJavaTypeForClass
protected org.datanucleus.store.types.TypeManagerImpl.JavaType findJavaTypeForClass(Class cls)
Convenience method to return the JavaType for the specified class. If this class has a defined JavaType then returns it. If not then tries to find a superclass that is castable to the specified type.- Parameters:
cls- The class required- Returns:
- The JavaType
-
findJavaTypeForCollectionClass
protected org.datanucleus.store.types.TypeManagerImpl.JavaType findJavaTypeForCollectionClass(Class cls, Class genericType)
Convenience method to return the JavaType for the specified class. If this class has a defined JavaType then returns it. If not then tries to find a superclass that is castable to the specified type.- Parameters:
cls- The class requiredgenericType- Any generic type specified for the element- Returns:
- The JavaType
-
-