public final class PropertyHelper
extends java.lang.Object
Maps are threadsafe and are cached to avoid redundant introspection using reflection.
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.reflect.Method,java.lang.String>> |
g2lCache
Cache of getter method to property name maps, by DMO interface, for legacy fields only
|
private static java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.reflect.Method,java.lang.String>> |
g2pCache
Cache of getter method to property name maps, by DMO interface, for POJO methods only
|
private static java.lang.String[] |
getterPrefix
Method name prefix(es) for getter methods
|
private static java.util.Map<java.lang.Class<?>,java.util.List<java.lang.reflect.Method>> |
i2ltCache
Cache of methods to trigger lazy collection init, by DMO interface
|
private static java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> |
p2agCache
Cache of property name to getter method maps, by DMO interface, POJO and legacy methods
|
private static java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> |
p2asCache
Cache of property name to setter method maps, by DMO interface, POJO and legacy methods
|
private static java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> |
p2lgCache
Cache of property name to getter method maps, by DMO interface, for legacy fields only
|
private static java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> |
p2lsCache
Cache of property name to setter method maps, by DMO interface, for legacy fields only
|
private static java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> |
p2pgCache
Cache of property name to getter method maps, by DMO interface, for POJO methods only
|
private static java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> |
p2psCache
Cache of property name to setter method maps, by DMO interface, for POJO methods only
|
private static java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.reflect.Method>> |
p2seCache
Cache of property name to setter method maps, by DMO entity name, for POJO methods only
|
private static java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.Integer>> |
p2xCache
Cache of property name to extent maps, by DMO interface
|
private static java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.reflect.Method,java.lang.String>> |
s2lCache
Cache of setter method to property name maps, by DMO interface, for legacy fields only
|
private static java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.reflect.Method,java.lang.String>> |
s2pCache
Cache of setter method to property name maps, by DMO interface, for POJO methods only
|
private static java.lang.String[] |
setterPrefix
Method name prefix(es) for setter methods
|
Modifier | Constructor and Description |
---|---|
private |
PropertyHelper()
Private constructor; all access is via static methods.
|
Modifier and Type | Method and Description |
---|---|
static java.util.Map<java.lang.String,java.lang.reflect.Method> |
allGettersByProperty(java.lang.Class<?> dmoIface)
Get a map of DMO property names to all legacy and POJO getter methods for the given DMO
type.
|
private static java.util.Map<java.lang.String,java.lang.reflect.Method> |
allMethodsByProperty(java.lang.Class<?> dmoIface,
java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> allCache,
java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> legacyCache,
java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> pojoCache,
java.lang.String[] methodPrefixes)
Get a map of DMO property names to all legacy and POJO getter or setter methods, for the
given DMO type.
|
static java.util.Map<java.lang.String,java.lang.reflect.Method> |
allSettersByProperty(java.lang.Class<?> dmoIface)
Get a map of DMO property names to all legacy and POJO setter methods for the given DMO
type.
|
(package private) static java.util.Map<java.lang.String,java.lang.Integer> |
extentsByProperty(java.lang.Class<?> dmoIface)
Get an immutable map of DMO property names to extent values (if any) for the given DMO type,
keyed by DMO interface.
|
private static <K,V> java.util.Map<K,V> |
getMapFailOnNull(java.lang.Class<?> dmoIface,
java.util.Map<java.lang.Class<?>,java.util.Map<K,V>> cache)
Retrieve a map from a cache of maps, keyed by DMO interface.
|
static java.lang.String |
getPropertyName(java.lang.reflect.Method method)
Get the property name for the given getter or setter method.
|
private static java.lang.Class<?> |
getRootPojoInterface(java.lang.Class<?> dmoIface)
Given a top-level DMO interface, inspect its hierarchy of super-interfaces and return the
furthest ancestor interface from the given interface (the "root"), which is still a DMO
interface.
|
private static <K,V> java.util.Map<V,K> |
invertMap(java.util.Map<K,V> original,
java.util.Map<V,K> inverted)
Make a copy of the given map where the values of the original are the keys of the copy,
and the keys of the original are the values of the copy.
|
(package private) static boolean |
isJavaBeanMethod(java.lang.reflect.Method method)
Report whether the given method is getter or setter.
|
(package private) static java.util.List<java.lang.reflect.Method> |
lazyExtentTriggersForInterface(java.lang.Class<?> dmoIface,
java.lang.Class<?> dmoClass)
Get a list of methods which, when invoked, will trigger Hibernate to initialize the lazily
initialized persistent lists which are used to manage extent fields for a DMO.
|
(package private) static java.util.Map<java.lang.String,java.lang.reflect.Method> |
legacyGettersByProperty(java.lang.Class<?> dmoIface)
Get an immutable map of DMO property names to legacy getter methods for the given DMO type,
keyed by DMO interface.
|
(package private) static java.util.Map<java.lang.reflect.Method,java.lang.String> |
legacyPropertiesByGetter(java.lang.Class<?> dmoIface)
Get an map of legacy getter names to their corresponding property names for the given DMO
type.
|
(package private) static java.util.Map<java.lang.reflect.Method,java.lang.String> |
legacyPropertiesBySetter(java.lang.Class<?> dmoIface)
Get an map of legacy setter names to their corresponding property names for the given DMO
type.
|
(package private) static java.util.Map<java.lang.String,java.lang.reflect.Method> |
legacySettersByProperty(java.lang.Class<?> dmoIface)
Get an immutable map of DMO property names to setter methods for the given DMO type, keyed
by DMO interface.
|
(package private) static java.lang.String |
makePropertyName(java.lang.String methodName,
int index)
Given a method name ending in a property name, extract the property
name by trimming off the prefix and decapitalizing the root name, using
java.beans.Introspector.decapitalize() . |
(package private) static java.util.Map<java.lang.String,java.lang.reflect.Method> |
methodsByProperty(java.lang.reflect.Method[] methods,
java.lang.String[] prefix)
Build a map of all methods in the given array, whose names begin with any of the given
prefixes.
|
static java.util.Map<java.lang.String,java.lang.reflect.Method> |
pojoGettersByProperty(java.lang.Class<?> dmoIface)
Get a map of DMO property names to POJO getter methods for the given DMO type.
|
private static java.util.Map<java.lang.String,java.lang.reflect.Method> |
pojoMethodsByProperty(java.lang.Class<?> dmoIface,
java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> cache,
java.lang.String[] methodPrefixes)
Get a map of DMO property names to POJO getter/setter methods for the given DMO type.
|
(package private) static java.util.Map<java.lang.reflect.Method,java.lang.String> |
pojoPropertiesByGetter(java.lang.Class<?> dmoIface)
Get an map of POJO getter names to their corresponding property names for the given DMO
type.
|
(package private) static java.util.Map<java.lang.reflect.Method,java.lang.String> |
pojoPropertiesBySetter(java.lang.Class<?> dmoIface)
Get an map of POJO setter names to their corresponding property names for the given DMO
type.
|
static java.util.Map<java.lang.String,java.lang.reflect.Method> |
pojoSettersByProperty(java.lang.Class<?> dmoIface)
Get a map of DMO property names to POJO setter methods for the given DMO type.
|
static java.util.Map<java.lang.String,java.lang.reflect.Method> |
pojoSettersByProperty(java.lang.String entity)
Given a DMO implementation class entity name, get the map of DMO property names to setter
methods.
|
private static java.util.Map<java.lang.reflect.Method,java.lang.String> |
propertiesByMethod(java.lang.Class<?> dmoIface,
java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.reflect.Method,java.lang.String>> cache,
java.util.function.Function<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> worker)
Get a map of DMO methods to the property names with which they are associated.
|
(package private) static void |
putExtentsByProperty(java.lang.Class<?> dmoIface,
java.util.Map<java.lang.String,java.lang.Integer> map)
Cache an immutable map of DMO property names to extent values (if any) for the given DMO
type, keyed by DMO interface.
|
(package private) static void |
putLegacyGettersByProperty(java.lang.Class<?> dmoIface,
java.util.Map<java.lang.String,java.lang.reflect.Method> map)
Cache an immutable map of DMO property names to getter methods for the given DMO type,
keyed by DMO interface.
|
(package private) static void |
putLegacySettersByProperty(java.lang.Class<?> dmoIface,
java.util.Map<java.lang.String,java.lang.reflect.Method> map)
Cache an immutable map of DMO property names to setter methods for the given DMO type,
keyed by DMO interface.
|
private static <K,V> java.util.Map<K,V> |
storableMap(java.util.Map<K,V> map)
Get a map that is suitable for storing in one of this class' caches, given an existing map.
|
private static final java.lang.String[] getterPrefix
private static final java.lang.String[] setterPrefix
private static final java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> p2lgCache
private static final java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> p2lsCache
private static final java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> p2pgCache
private static final java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> p2psCache
private static final java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> p2agCache
private static final java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> p2asCache
private static final java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.Integer>> p2xCache
private static final java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.reflect.Method,java.lang.String>> g2lCache
private static final java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.reflect.Method,java.lang.String>> s2lCache
private static final java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.reflect.Method,java.lang.String>> g2pCache
private static final java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.reflect.Method,java.lang.String>> s2pCache
private static final java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.reflect.Method>> p2seCache
private static final java.util.Map<java.lang.Class<?>,java.util.List<java.lang.reflect.Method>> i2ltCache
private PropertyHelper()
public static java.util.Map<java.lang.String,java.lang.reflect.Method> pojoGettersByProperty(java.lang.Class<?> dmoIface)
dmoIface
- DMO interface (top level) for which the map is desired.public static java.util.Map<java.lang.String,java.lang.reflect.Method> pojoSettersByProperty(java.lang.Class<?> dmoIface)
dmoIface
- DMO interface (top level) for which the map is desired.public static java.util.Map<java.lang.String,java.lang.reflect.Method> allGettersByProperty(java.lang.Class<?> dmoIface)
dmoIface
- DMO interface (top level) for which the map is desired.legacyGettersByProperty(Class)
,
pojoGettersByProperty(Class)
public static java.util.Map<java.lang.String,java.lang.reflect.Method> allSettersByProperty(java.lang.Class<?> dmoIface)
dmoIface
- DMO interface (top level) for which the map is desired.legacyGettersByProperty(Class)
,
pojoGettersByProperty(Class)
public static java.util.Map<java.lang.String,java.lang.reflect.Method> pojoSettersByProperty(java.lang.String entity)
entity
- DMO implementation class entity name.public static java.lang.String getPropertyName(java.lang.reflect.Method method)
get
, set
, or is
. If the method name begins with none
of these prefixes, an error is raised.method
- Method.java.lang.IllegalArgumentException
- if method is not getter or setter.static java.util.Map<java.lang.String,java.lang.Integer> extentsByProperty(java.lang.Class<?> dmoIface)
WARNING: a mapping for any given DMO type is only available after the first time a record buffer is defined for that DMO type. The information is collected and stored when a DMO interface is first proxied, so this method must not be invoked before that occurs. To do so represents a programming error and will raise an exception.
dmoIface
- DMO interface.java.lang.IllegalStateException
- if this method is invoked before the given DMO interface has been proxied.static void putExtentsByProperty(java.lang.Class<?> dmoIface, java.util.Map<java.lang.String,java.lang.Integer> map)
This method is only intended to be called once per DMO interface. The map for a given DMO interface can only be stored once. Further requests to store a new map for that interface will fail silently and the original mapping will remain.
dmoIface
- DMO interface.map
- A map as described above.static java.util.Map<java.lang.String,java.lang.reflect.Method> legacyGettersByProperty(java.lang.Class<?> dmoIface)
WARNING: a mapping for any given DMO type is only available after the first time a record buffer is defined for that DMO type. The information is collected and stored when a DMO interface is first proxied, so this method must not be invoked before that occurs. To do so represents a programming error and will raise an exception.
dmoIface
- DMO interface.java.lang.IllegalStateException
- if this method is invoked before the given DMO interface has been proxied.static void putLegacyGettersByProperty(java.lang.Class<?> dmoIface, java.util.Map<java.lang.String,java.lang.reflect.Method> map)
This method is only intended to be called once per DMO interface. The map for a given DMO interface can only be stored once. Further requests to store a new map for that interface will fail silently and the original mapping will remain.
dmoIface
- DMO interface.map
- A map as described above.static java.util.Map<java.lang.String,java.lang.reflect.Method> legacySettersByProperty(java.lang.Class<?> dmoIface)
WARNING: a mapping for any given DMO type is only available after the first time a record buffer is defined for that DMO type. The information is collected and stored when a DMO interface is first proxied, so this method must not be invoked before that occurs. To do so represents a programming error and will raise an exception.
dmoIface
- DMO interface.java.lang.IllegalStateException
- if this method is invoked before the given DMO interface has been proxied.static void putLegacySettersByProperty(java.lang.Class<?> dmoIface, java.util.Map<java.lang.String,java.lang.reflect.Method> map)
This method is only intended to be called once per DMO interface. The map for a given DMO interface can only be stored once. Further requests to store a new map for that interface will fail silently and the original mapping will remain.
dmoIface
- DMO interface.map
- A map as described above.static java.util.Map<java.lang.reflect.Method,java.lang.String> legacyPropertiesByGetter(java.lang.Class<?> dmoIface)
legacyGettersByProperty(Class)
.
WARNING: a mapping for any given DMO type is only available after the first time a record buffer is defined for that DMO type. The information is collected and stored when a DMO interface is first proxied, so this method must not be invoked before that occurs. To do so represents a programming error and will raise an exception.
dmoIface
- DMO interface for which the map is desired.static java.util.Map<java.lang.reflect.Method,java.lang.String> legacyPropertiesBySetter(java.lang.Class<?> dmoIface)
legacySettersByProperty(Class)
.
WARNING: a mapping for any given DMO type is only available after the first time a record buffer is defined for that DMO type. The information is collected and stored when a DMO interface is first proxied, so this method must not be invoked before that occurs. To do so represents a programming error and will raise an exception.
dmoIface
- DMO interface for which the map is desired.static java.util.Map<java.lang.reflect.Method,java.lang.String> pojoPropertiesByGetter(java.lang.Class<?> dmoIface)
pojoGettersByProperty(Class)
.dmoIface
- DMO interface for which the map is desired.static java.util.Map<java.lang.reflect.Method,java.lang.String> pojoPropertiesBySetter(java.lang.Class<?> dmoIface)
pojoSettersByProperty(Class)
.dmoIface
- DMO interface for which the map is desired.static java.util.Map<java.lang.String,java.lang.reflect.Method> methodsByProperty(java.lang.reflect.Method[] methods, java.lang.String[] prefix)
methods
- Methods to be tested.prefix
- Array of prefix strings which are used to identify matching methods.static java.util.List<java.lang.reflect.Method> lazyExtentTriggersForInterface(java.lang.Class<?> dmoIface, java.lang.Class<?> dmoClass)
dmoIface
- DMO interface to introspect.dmoClass
- DMO implementation class.static java.lang.String makePropertyName(java.lang.String methodName, int index)
java.beans.Introspector.decapitalize()
. Note that this
method will not decapitalize the first letter of the name if both the
first letter and the second letter (if any) are both uppercase. This
quirk is necessary for compatibility with Hibernate's internal property
name conversions.methodName
- Method name ending in the property name.index
- Index of first character of property name.static boolean isJavaBeanMethod(java.lang.reflect.Method method)
method
- Method.true
if method is getter or setter otherwise false
.private static java.util.Map<java.lang.String,java.lang.reflect.Method> pojoMethodsByProperty(java.lang.Class<?> dmoIface, java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> cache, java.lang.String[] methodPrefixes)
dmoIface
- DMO interface (top level) for which the map is desired. If no mapping is found in
the cache
and this interface has a DMO interface as a superinterface,
the hierarchy is walked up to the furthest ancestor, and that interface is used.cache
- Cache which is searched for the map first, and to which the new map is added if
built.methodPrefixes
- One or more method name prefixes which will identify the method as a getter or a
setter.private static java.util.Map<java.lang.String,java.lang.reflect.Method> allMethodsByProperty(java.lang.Class<?> dmoIface, java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> allCache, java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> legacyCache, java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> pojoCache, java.lang.String[] methodPrefixes)
dmoIface
- DMO interface (top level) for which the map is desired. If no mapping is found in
the allCache
and this interface has a DMO interface as a
superinterface, the hierarchy is walked up to the furthest ancestor, and that
interface is used.allCache
- Cache which is searched for the map first, and to which the new map is added if
built.legacyCache
- Cache which is searched for the legacy method elements of the map.pojoCache
- Cache which is searched for the POJO method elements of the map.allGettersByProperty(Class)
,
allSettersByProperty(Class)
private static java.lang.Class<?> getRootPojoInterface(java.lang.Class<?> dmoIface)
For purposes of this algorithm, a DMO interface is defined as one which directly extends
Temporary
or DataModelObject
. Note that the starting interface may already
be the root.
dmoIface
- Starting DMO interface.private static java.util.Map<java.lang.reflect.Method,java.lang.String> propertiesByMethod(java.lang.Class<?> dmoIface, java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.reflect.Method,java.lang.String>> cache, java.util.function.Function<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.reflect.Method>> worker)
dmoIface
- DMO interface with which the map is associated and cached.cache
- Cache containing maps of the desired type, keyed by DMO interface.worker
- Worker method which can be used to get a map of DMO properties to methods of the
desired type. The returned map will be inverted
and
the inverted copy cached.private static <K,V> java.util.Map<K,V> getMapFailOnNull(java.lang.Class<?> dmoIface, java.util.Map<java.lang.Class<?>,java.util.Map<K,V>> cache)
dmoIface
- DMO interface, which is the key to the desired map.cache
- Cache from which to retrieve the map.java.lang.IllegalStateException
- if this method is invoked before the given DMO interface has been proxied.private static <K,V> java.util.Map<K,V> storableMap(java.util.Map<K,V> map)
null
or empty, return a singleton empty map; otherwise,
return an unmodifiable view of the given map.map
- Original map, or null
.private static <K,V> java.util.Map<V,K> invertMap(java.util.Map<K,V> original, java.util.Map<V,K> inverted)
original
- Original map.inverted
- Copy map with keys and values of the original inverted.