Class DefaultPolymorphicTypeMapper
- All Implemented Interfaces:
PolymorphicTypeMapper
Boiler-plate implementation of PolymorphicTypeMapper which requires
all mappings to be manually specified. This type mapper will not attempt to
do anything clever like caching or storing of mapping results. Rather, it
depends entirely upon the developer to explicitly specify the map values for
every polymorphic type in use.
If a type which has not been explicitly specified, this converter
will default to the fully qualified classname. Thus the inverse conversion
will also default to a Class.forName(String) invocation in case
of no valid mapping in the relevant class hierarchy.
You should not attempt to use the same instance of this class with more than
one instance of EntityManager. This is because EntityManager
performs some initialization on the mapper when it is set. While this initialization
is in fact thread-safe, it may cause undesired behavior if using two separate
entity managers with different table name converters.
- Author:
- Daniel Spiewak
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultPolymorphicTypeMapper(Class<? extends RawEntity<?>>... types) Convenience constructor which will construct a set of mappings on the fly based on the specified entity types.DefaultPolymorphicTypeMapper(Map<Class<? extends RawEntity<?>>, String> mappings) Creates a new instance with the specified {type => flag} mappings. -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the polymorphic type flag value which corresponds to the specified type.Retrieves the entity type which corresponds to the given polymorphic type flag value as a subtype of the specified parent entity type.
-
Constructor Details
-
DefaultPolymorphicTypeMapper
Convenience constructor which will construct a set of mappings on the fly based on the specified entity types. Actual construction of the mappings is delayed and invoked directly by the
EntityManagerinstance which receives the instance of this class. This is to allowEntityManagerto pass the relevant table name converter to be used in the initialization process.It is very important that an instance created using this constructor is not used with more than one
EntityManager.- Parameters:
types- The polymorphic types which must be mapped.
-
DefaultPolymorphicTypeMapper
Creates a new instance with the specified {type => flag} mappings.- Parameters:
mappings- The mappings from entity type to polymorphic flag value.
-
-
Method Details
-
convert
Description copied from interface:PolymorphicTypeMapperRetrieves the polymorphic type flag value which corresponds to the specified type. Return value must be repeatable given the same type as well as uniquely defined within the hierarchy of the given type.- Specified by:
convertin interfacePolymorphicTypeMapper- Parameters:
type- The type for which a polymorphic flag must be generated.- Returns:
- The polymorphic flag type value which corresponds to the given type.
- See Also:
-
invert
Description copied from interface:PolymorphicTypeMapperRetrieves the entity type which corresponds to the given polymorphic type flag value as a subtype of the specified parent entity type. Logically the inverse of thePolymorphicTypeMapper.convert(Class)method.- Specified by:
invertin interfacePolymorphicTypeMapper- Parameters:
parent- The parent interface of the type which must be retrieved.type- The polymorphic type flag value which corresponds to the type which must be retrieved.- Returns:
- The entity type corresponding uniquely to the supertype-flag pair.
-