Interface TypeManager

  • All Known Implementing Classes:
    TypeManagerImpl

    public interface TypeManager
    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".
    • Method Detail

      • close

        void close()
      • getSupportedSecondClassTypes

        java.util.Set<java.lang.String> getSupportedSecondClassTypes()
        Accessor for the supported second-class Types. This may or may not be a complete list, just that it provides the principal ones.
        Returns:
        Set of supported types (fully qualified class names).
      • isSupportedSecondClassType

        boolean isSupportedSecondClassType​(java.lang.String className)
        Accessor for whether a class is supported as being second class.
        Parameters:
        className - The class name
        Returns:
        Whether the class is supported (to some degree)
      • filterOutSupportedSecondClassNames

        java.lang.String[] filterOutSupportedSecondClassNames​(java.lang.String[] inputClassNames)
        Convenience method to filter out any supported classes from a list.
        Parameters:
        inputClassNames - Names of the classes
        Returns:
        Names of the classes (omitting supported types)
      • isDefaultPersistent

        boolean isDefaultPersistent​(java.lang.Class c)
        Accessor for whether the type is by default persistent. TODO Support use of apiAdapter.isMemberDefaultPersistent to get strict JDO/JPA behaviour.
        Parameters:
        c - The type
        Returns:
        Whether persistent
      • isDefaultFetchGroup

        boolean isDefaultFetchGroup​(java.lang.Class c)
        Accessor for whether the type is by default in the DFG.
        Parameters:
        c - The type
        Returns:
        Whether in the DFG
      • isDefaultFetchGroupForCollection

        boolean isDefaultFetchGroupForCollection​(java.lang.Class c,
                                                 java.lang.Class genericType)
        Accessor for whether the generic collection type is by default in the DFG.
        Parameters:
        c - The type
        genericType - The element generic type
        Returns:
        Whether in the DFG
      • isDefaultEmbeddedType

        boolean isDefaultEmbeddedType​(java.lang.Class c)
        Accessor for whether the type is by default embedded.
        Parameters:
        c - The type
        Returns:
        Whether embedded
      • isSecondClassMutableType

        boolean isSecondClassMutableType​(java.lang.String className)
        Accessor for whether the type is SCO mutable.
        Parameters:
        className - The type
        Returns:
        Whether SCO mutable
      • getWrapperTypeForType

        java.lang.Class<? extends SCO> getWrapperTypeForType​(java.lang.String className)
        Accessor for the SCO wrapper for the type
        Parameters:
        className - The type
        Returns:
        SCO wrapper type
      • getWrappedTypeBackedForType

        java.lang.Class getWrappedTypeBackedForType​(java.lang.String className)
        Accessor 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.
        Parameters:
        className - The class name
        Returns:
        The second class wrapper
      • createSCOWrapper

        <T> SCO<T> createSCOWrapper​(DNStateManager ownerSM,
                                    AbstractMemberMetaData mmd,
                                    java.lang.Class<T> instantiatedType)
        Method to create a new SCO wrapper for member type. Will find a wrapper suitable for the instantiated type (if provided), otherwise suitable for the member metadata type.
        Type Parameters:
        T - Type of the object that we are creating a wrapper for
        Parameters:
        ownerSM - StateManager for the owning object
        mmd - The MetaData for the related member.
        instantiatedType - Type to instantiate the member as (if known), otherwise falls back to the type from metadata
        Returns:
        The wrapper object of the required type
        Throws:
        NucleusUserException - if an error occurred when creating the SCO instance
      • isSecondClassWrapper

        boolean isSecondClassWrapper​(java.lang.String className)
        Accessor for whether the type is a SCO wrapper itself.
        Parameters:
        className - The type
        Returns:
        Whether is SCO wrapper
      • getTypeForSecondClassWrapper

        java.lang.Class getTypeForSecondClassWrapper​(java.lang.String className)
        Accessor 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.
        Parameters:
        className - Name of the class
        Returns:
        The java class that this is a wrapper for (or null)
      • getContainerHandler

        <H extends ContainerHandler> H getContainerHandler​(java.lang.Class containerClass)
        Obtains the registered ContainerHandler for the given containerClass. ContainerHandler are specified via the plugin mechanism using the container-handler attribute of the java-type element.
        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.
      • getContainerAdapter

        ContainerAdapter getContainerAdapter​(java.lang.Object container)
        Convenience method to obtain the ContainerAdapter using the container object instance
        Parameters:
        container - The container instance
        Returns:
        The ContainerAdapter for the respective container or null if it's not a supported container
      • getTypeConverterForName

        TypeConverter getTypeConverterForName​(java.lang.String converterName)
        Accessor 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.
        Parameters:
        converterName - Name of the converter
        Returns:
        The converter
      • registerConverter

        void registerConverter​(java.lang.String name,
                               TypeConverter converter,
                               java.lang.Class memberType,
                               java.lang.Class dbType,
                               boolean autoApply,
                               java.lang.String autoApplyType)
        Register 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.
        Parameters:
        name - The name to register the converter under
        converter - The converter
        memberType - Type of the java member
        dbType - Type of the database column
        autoApply - Whether this should be used as an auto-apply converter
        autoApplyType - Java type to auto apply this for
      • getAutoApplyTypeConverterForType

        TypeConverter getAutoApplyTypeConverterForType​(java.lang.Class memberType)
        Method 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).
        Parameters:
        memberType - The java (member) type
        Returns:
        The converter to use by default
      • getDefaultTypeConverterForType

        TypeConverter getDefaultTypeConverterForType​(java.lang.Class memberType)
        Accessor for the default type converter for the provided Java type.
        Parameters:
        memberType - Java type for the member
        Returns:
        The default converter (if any)
      • setDefaultTypeConverterForType

        void setDefaultTypeConverterForType​(java.lang.Class memberType,
                                            java.lang.String converterName)
        Method providing the ability for a datastore plugin to override the default converter type for the specified java type.
        Parameters:
        memberType - Member type
        converterName - The converter to use by default. This is assumed to exist.
      • getTypeConverterForType

        TypeConverter getTypeConverterForType​(java.lang.Class memberType,
                                              java.lang.Class datastoreType)
        Accessor for the type converter for the provided Java type and its datastore type.
        Parameters:
        memberType - Java type for the member
        datastoreType - Java type for the datastore
        Returns:
        The converter (if any)
      • getTypeConvertersForType

        java.util.Collection<TypeConverter> getTypeConvertersForType​(java.lang.Class memberType)
        Accessor for the available type converters for the provided Java type.
        Parameters:
        memberType - The java type
        Returns:
        The available Type Converters
      • getDatastoreTypeForTypeConverter

        java.lang.Class getDatastoreTypeForTypeConverter​(TypeConverter conv,
                                                         java.lang.Class memberType)
        Method to return the datastore type for the specified TypeConverter.
        Parameters:
        conv - The converter
        memberType - The member type
        Returns:
        The datastore type
      • getMemberTypeForTypeConverter

        java.lang.Class getMemberTypeForTypeConverter​(TypeConverter conv,
                                                      java.lang.Class datastoreType)
        Method to return the member type for the specified TypeConverter.
        Parameters:
        conv - The converter
        datastoreType - The datastore type for this converter
        Returns:
        The member type