public class DefaultPropertyMapper extends Object implements PropertyMapper
PropertyMapper
used by the mapper.
This mapper can be configured to scan for fields, getters and setters, or both.
The default is to scan for both.
This mapper can also be configured to skip transient properties.
By default, all properties will be mapped (non-transient),
unless explicitly marked with @Transient
.
This mapper recognizes standard getter and setter methods
(as defined by the Java Beans specification),
and also "relaxed" setter methods, i.e., setter methods
whose return type are not void
.DefaultMappedProperty
Constructor and Description |
---|
DefaultPropertyMapper() |
Modifier and Type | Method and Description |
---|---|
DefaultPropertyMapper |
addTransientPropertyNames(Collection<String> transientPropertyNames)
Adds new values to the existing set of transient property names.
|
DefaultPropertyMapper |
addTransientPropertyNames(String... transientPropertyNames)
Adds new values to the existing set of transient property names.
|
protected MappedProperty<?> |
createMappedProperty(Class<?> mappedClass,
String propertyName,
String mappedName,
Field field,
Method getter,
Method setter,
Map<Class<? extends Annotation>,Annotation> annotations)
Creates a
MappedProperty instance. |
protected String |
inferMappedName(Class<?> mappedClass,
String propertyName,
Map<Class<? extends Annotation>,Annotation> annotations)
Infers the Cassandra object name corresponding to given the property name.
|
protected boolean |
isTransient(String propertyName,
Field field,
Method getter,
Method setter,
Map<Class<? extends Annotation>,Annotation> annotations)
Returns
true if the given property is transient,
false otherwise. |
protected Method |
locateGetter(Class<?> mappedClass,
PropertyDescriptor property)
Locates a getter method for the given mapped class and given property.
|
protected Method |
locateSetter(Class<?> mappedClass,
PropertyDescriptor property)
Locates a setter method for the given mapped class and given property.
|
Set<? extends MappedProperty<?>> |
mapTable(Class<?> tableClass)
Maps the given table class.
|
Set<? extends MappedProperty<?>> |
mapUdt(Class<?> udtClass)
Maps the given UDT class.
|
DefaultPropertyMapper |
setHierarchyScanStrategy(HierarchyScanStrategy hierarchyScanStrategy)
Sets the
hierarchy scan strategy to use. |
DefaultPropertyMapper |
setNamingStrategy(NamingStrategy namingStrategy)
Sets the
naming strategy to use. |
DefaultPropertyMapper |
setPropertyAccessStrategy(PropertyAccessStrategy propertyAccessStrategy)
Sets the
property access strategy to use. |
DefaultPropertyMapper |
setPropertyTransienceStrategy(PropertyTransienceStrategy propertyTransienceStrategy)
Sets the
property transience strategy to use. |
DefaultPropertyMapper |
setTransientPropertyNames(Set<String> transientPropertyNames)
Sets transient property names.
|
public DefaultPropertyMapper setPropertyAccessStrategy(PropertyAccessStrategy propertyAccessStrategy)
property access strategy
to use.
The default is PropertyAccessStrategy.BOTH
.propertyAccessStrategy
- the property access strategy
to use; may not be null
.DefaultPropertyMapper
instance (to allow for fluent builder pattern).public DefaultPropertyMapper setPropertyTransienceStrategy(PropertyTransienceStrategy propertyTransienceStrategy)
property transience strategy
to use.
The default is PropertyTransienceStrategy.OPT_OUT
.propertyTransienceStrategy
- the property transience strategy
to use; may not be null
.DefaultPropertyMapper
instance (to allow for fluent builder pattern).public DefaultPropertyMapper setHierarchyScanStrategy(HierarchyScanStrategy hierarchyScanStrategy)
hierarchy scan strategy
to use.
The default is DefaultHierarchyScanStrategy
.hierarchyScanStrategy
- the hierarchy scan strategy
to use; may not be null
.DefaultPropertyMapper
instance (to allow for fluent builder pattern).public DefaultPropertyMapper setNamingStrategy(NamingStrategy namingStrategy)
naming strategy
to use.
The default is DefaultNamingStrategy
.namingStrategy
- the naming strategy
to use; may not be null
.DefaultPropertyMapper
instance (to allow for fluent builder pattern).public DefaultPropertyMapper setTransientPropertyNames(Set<String> transientPropertyNames)
class
and metaClass
.
These properties pertain to the Object
class –
metaClass
being specific to the Groovy language.
Property names provided here will always be considered transient;
if a more fine-grained tuning is required, it is also possible
to use the @Transient
annotation
on a specific property.
Subclasses can also override isTransient(String, Field, Method, Method, Map)
to gain
complete control over which properties should be considered transient.transientPropertyNames
- a set of property names to exclude from mapping; may not be null
. This
will completely replace any names already configured for this object.public DefaultPropertyMapper addTransientPropertyNames(String... transientPropertyNames)
class
and metaClass
.
These properties pertain to the Object
class –
metaClass
being specific to the Groovy language.
Property names provided here will always be considered transient;
if a more fine-grained tuning is required, it is also possible
to use the @Transient
annotation
on a specific property.
Subclasses can also override isTransient(String, Field, Method, Method, Map)
to gain
complete control over which properties should be considered transient.transientPropertyNames
- the values to add; may not be null
.public DefaultPropertyMapper addTransientPropertyNames(Collection<String> transientPropertyNames)
class
and metaClass
.
These properties pertain to the Object
class –
metaClass
being specific to the Groovy language.
Property names provided here will always be considered transient;
if a more fine-grained tuning is required, it is also possible
to use the @Transient
annotation
on a specific property.
Subclasses can also override isTransient(String, Field, Method, Method, Map)
to gain
complete control over which properties should be considered transient.transientPropertyNames
- the values to add; may not be null
.public Set<? extends MappedProperty<?>> mapTable(Class<?> tableClass)
PropertyMapper
mapTable
in interface PropertyMapper
tableClass
- the table class.public Set<? extends MappedProperty<?>> mapUdt(Class<?> udtClass)
PropertyMapper
mapUdt
in interface PropertyMapper
udtClass
- the UDT class.protected boolean isTransient(String propertyName, Field field, Method getter, Method setter, Map<Class<? extends Annotation>,Annotation> annotations)
true
if the given property is transient,
false
otherwise.
If this method returns true
the given property will not be mapped.
The implementation provided here relies on the
transience strategy
and the transient property names
configured on this mapper.
Subclasses may override this method to take full control of which properties
should be mapped and which should be considered transient.propertyName
- the property name; may not be null
.field
- the property field; may be null
.getter
- the getter method for this property; may be null
.setter
- the setter method for this property; may be null
.annotations
- the annotations found on this property; may be empty but never null
.true
if the given property is transient (i.e., non-mapped), false
otherwise.protected Method locateGetter(Class<?> mappedClass, PropertyDescriptor property)
hasAccount
":
one could then return the non-standard method boolean hasAccount()
as its getter.
This method is never called if PropertyAccessStrategy.isGetterSetterScanAllowed()
returns false
.
Besides, implementors are free to return null
if access to the property through reflection is not required
(in which case, they will likely have to provide a custom implementation of MappedProperty
).mappedClass
- The mapped class; this is necessarily a class annotated with
either @Table
or
@UDT
.property
- The property to locate a getter for; never null
.null
if no getter was found, or reflection is not required.protected Method locateSetter(Class<?> mappedClass, PropertyDescriptor property)
PropertyAccessStrategy.isGetterSetterScanAllowed()
returns false
.
Besides, implementors are free to return null
if access to the property through reflection is not required
(in which case, they will likely have to provide a custom implementation of MappedProperty
).mappedClass
- The mapped class; this is necessarily a class annotated with
either @Table
or
@UDT
.property
- The property to locate a setter for; never null
.null
if no setter was found, or reflection is not required.protected String inferMappedName(Class<?> mappedClass, String propertyName, Map<Class<? extends Annotation>,Annotation> annotations)
NamingStrategy
configured on this mapper.
Subclasses may override this method if they need full control
over generating Cassandra object names.mappedClass
- The mapped class; this is necessarily a class annotated with
either @Table
or
@UDT
.propertyName
- The property name; may not be null
nor empty.annotations
- The property annotations (found on its field and getter method); may not be null
but can be empty.protected MappedProperty<?> createMappedProperty(Class<?> mappedClass, String propertyName, String mappedName, Field field, Method getter, Method setter, Map<Class<? extends Annotation>,Annotation> annotations)
MappedProperty
instance.
Instances returned by the implementation below will use the Java reflection API to read and write values. Subclasses may override this method if they are capable of accessing properties without incurring the cost of reflection.
mappedClass
- The mapped class; this is necessarily a class annotated with
either @Table
or
@UDT
.propertyName
- The property name; may not be null
nor empty.mappedName
- The mapped name; may not be null
nor empty.field
- The property field; may be null
.getter
- The property getter method; may be null
.setter
- The property setter method; may be null
.annotations
- The property annotations (found on its field and getter method); may not be null
but can be empty.MappedProperty
instance.Copyright © 2012–2017. All rights reserved.