public final class DefaultPolymorphicTypeMapper extends Object implements 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.
Constructor and Description |
---|
DefaultPolymorphicTypeMapper(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.
|
Modifier and Type | Method and Description |
---|---|
String |
convert(Class<? extends RawEntity<?>> type)
Retrieves the polymorphic type flag value which corresponds to the
specified type.
|
Class<? extends RawEntity<?>> |
invert(Class<? extends RawEntity<?>> parent,
String type)
Retrieves the entity type which corresponds to the given polymorphic type
flag value as a subtype of the specified parent entity type.
|
public DefaultPolymorphicTypeMapper(Class<? extends RawEntity<?>>... types)
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 EntityManager
instance which receives the
instance of this class. This is to allow EntityManager
to 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
.
types
- The polymorphic types which must be mapped.public String convert(Class<? extends RawEntity<?>> type)
PolymorphicTypeMapper
convert
in interface PolymorphicTypeMapper
type
- The type for which a polymorphic flag must be generated.PolymorphicTypeMapper.invert(Class, String)
public Class<? extends RawEntity<?>> invert(Class<? extends RawEntity<?>> parent, String type)
PolymorphicTypeMapper
PolymorphicTypeMapper.convert(Class)
method.invert
in interface PolymorphicTypeMapper
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.Copyright © 2007–2019 Atlassian. All rights reserved.