public class PropertyWrapper extends Object
Provides access to the meta-data defined on a single java property of a class, and provides methods for reading and writing the value of the property on a single bound object, given a specified database definition.
DB properties can be seen to have the types and values in the table that
follows. This class provides a virtual view over the property whereby the
DBv-centric type and value are easily accessible via the
getQueryableDatatype() and
setQueryableDatatype(QueryableDatatype) methods.
Note: instances of this class are cheap to create and do not need to be cached.
This class is thread-safe.
This class is not serializable. References to it within serializable classes
should be marked as transient.
| Constructor and Description |
|---|
PropertyWrapper(RowDefinitionInstanceWrapper instanceWrapper,
PropertyWrapperDefinition classProperty,
RowDefinition target) |
| Modifier and Type | Method and Description |
|---|---|
String |
columnName()
Gets the annotated column name.
|
boolean |
equals(Object obj)
Equality of this property wrapper definition, based on the java property it
wraps in a specific class, plus the underlying object reference containing
the wrapped property.
|
Class<?> |
getAutoFillingClass()
Returns the class provided to the
AutoFillDuringQueryIfPossible
annotation. |
String[] |
getColumnAlias(DBDefinition defn)
The alias to the column for use in the select clause and during value
retrieval
|
List<PropertyWrapperDefinition.ColumnAspects> |
getColumnAspects(DBDefinition db)
The names and aliases of this property as it will appear in a SELECT and
WHERE clauses.
|
DBExpression[] |
getColumnExpression()
Returns the Column Expression, if any, defined on this property.
|
Class<?> |
getEnumCodeType()
Gets the type of the code supplied by enum values.
|
Class<? extends Enum<?>> |
getEnumType()
Gets the enum type, or null if not appropriate
Support DBvolution at Patreon |
PropertyWrapperDefinition |
getPropertyWrapperDefinition()
Gets the definition of the property, independent of any DBRow instance.
|
<A extends QueryableDatatype<?>> |
getQueryableDatatype()
Gets the DBvolution-centric value of the property.
|
Class<?> |
getRawJavaType()
Gets the declared type of the property in the end-user's target object,
prior to type conversion to the DBvolution-centric type.
|
RowDefinitionInstanceWrapper |
getRowDefinitionInstanceWrapper()
Gets the wrapper for the DBRow instance containing this property.
|
boolean |
hasColumnExpression()
Indicates whether this property has a ColumnExpression.
|
int |
hashCode()
Generates a hash-code of this property wrapper definition, based on the
java property it wraps and the referenced target object.
|
boolean |
isAutoFilling()
Returns true if the property wrapped is an auto-filling field.
|
boolean |
isAutoIncrement()
Returns true if the property wrapped is an auto-incrementing column.
|
boolean |
isColumn()
Indicates whether this property is a column.
|
boolean |
isForeignKey()
Indicates whether this property is a foreign key.
|
boolean |
isForeignKeyTo(DBRow table)
Returns TRUE if the property wrapped is a foreign key reference to the
table supplied
|
boolean |
isInstanceOf(Class<? extends QueryableDatatype<?>> refType)
Convenience method for testing the type of the QueryableDatatype.
|
boolean |
isInstanceOfLargeObject()
Convenience method for testing the type of the QueryableDatatype.
|
boolean |
isPrimaryKey()
Indicates whether this property is a primary key.
|
boolean |
isReadable()
Indicates whether the value of the property can be retrieved.
|
boolean |
isSpatial2DType()
Returns true if the property wrapped is a Spatial2D column.
|
boolean |
isTypeAdapted()
Indicates whether the property's type is adapted by an explicit or implicit
type adaptor.
|
boolean |
isWritable()
Indicates whether the value of the property can be modified.
|
String |
javaName()
Gets the name of the java property, without the containing class name.
|
String |
qualifiedJavaName()
Gets the fully qualified name of the underlying java property, including
the fully qualified name of the containing class.
|
Object |
rawJavaValue()
Gets the value of the declared property in the end-user's target object,
prior to type conversion to the DBvolution-centric type.
|
Class<? extends DBRow> |
referencedClass()
Gets the class referenced by this property, if this property is a foreign
key.
|
String |
referencedColumnName()
Gets the column name in the foreign table referenced by this property.
|
PropertyWrapperDefinition |
referencedPropertyDefinitionIdentity()
Gets information for the referenced property in the referenced table.
|
String |
referencedTableName()
Gets the table referenced by this property, if this property is a foreign
key.
|
void |
setQueryableDatatype(QueryableDatatype<?> value)
Sets the DBvolution-centric value of the property.
|
void |
setRawJavaValue(Object value)
Set the value of the declared property in the end-user's target object,
without type conversion to/from the DBvolution-centric type.
|
String |
shortQualifiedJavaName()
Gets the partially qualified name of the underlying java property, using
the short-name of the containing class.
|
String |
tableName()
Gets the annotated table name of the table this property belongs to.
|
String |
toString()
Gets a string representation of the wrapped property, suitable for
debugging and logging.
|
Class<? extends QueryableDatatype<?>> |
type()
Gets the DBvolution-centric type of the property.
|
public PropertyWrapper(RowDefinitionInstanceWrapper instanceWrapper, PropertyWrapperDefinition classProperty, RowDefinition target)
instanceWrapper - instanceWrapperclassProperty - the class-level wrappertarget - the target object containing the given propertypublic String toString()
For example:
"DBInteger nz.co.mycompany.myproject.Vehicle.fkSpecOptionColour<fk_17> = [15241672]"
Support DBvolution at Patreon
public int hashCode()
Support DBvolution at Patreon
public boolean equals(Object obj)
Two instances are identical if they wrap the same java property (field or
bean-property) in the same object instance (by object reference, rather
than .equals() equality).
public String javaName()
"uid"
Use columnName() to determine column name.
Support DBvolution at Patreon
public String shortQualifiedJavaName()
"Customer.uid"
Use columnName() to determine column name.
Support DBvolution at Patreon
public String qualifiedJavaName()
"nz.co.mycompany.myproject.Customer.uid"
Use columnName() to determine column name.
Support DBvolution at Patreon
public Class<? extends QueryableDatatype<?>> type()
Use getRawJavaType() in the rare case that you need to know the
underlying java property type.
Support DBvolution at Patreon
public boolean isInstanceOf(Class<? extends QueryableDatatype<?>> refType)
refType.isAssignableFrom(this.type()).refType - refType
Support DBvolution at Patreon
public boolean isInstanceOfLargeObject()
refType.isAssignableFrom(this.type()).
Support DBvolution at Patreon
public String tableName()
getRowDefinitionInstanceWrapper().tableName().
Support DBvolution at Patreon
public String columnName()
DBColumn
annotation is present but does not explicitly specify the column name.
If the DBColumn annotation is missing, this method returns
null.
Support DBvolution at Patreon
public boolean isColumn()
Support DBvolution at Patreon
true if this property is a columnpublic boolean isPrimaryKey()
Support DBvolution at Patreon
true if this property is a primary keypublic boolean isForeignKey()
Support DBvolution at Patreon
true if this property is a foreign keypublic Class<? extends DBRow> referencedClass()
Support DBvolution at Patreon
public String referencedTableName()
Support DBvolution at Patreon
public String referencedColumnName()
DBForeignKey.column() attribute, or it is implicitly the single
primary key of the referenced table if the DBForeignKey.column()
attribute is unset.
Support DBvolution at Patreon
public PropertyWrapperDefinition referencedPropertyDefinitionIdentity()
DBForeignKey.column() attribute, or it is implicitly the single
primary key of the referenced table.
Note that the property definition returned provides identity of the property only. It provides access to the property's: java name, column name, type, and identity information about the table it belongs to (ie: table name). Attempts to get or set its value or get the type adaptor instance will result in an internal exception.
Support DBvolution at Patreon
public Class<? extends Enum<?>> getEnumType()
Support DBvolution at Patreon
DBEnumValuepublic Class<?> getEnumCodeType()
DBEnumValue implementation in the enum.
Support DBvolution at Patreon
public boolean isReadable()
Support DBvolution at Patreon
public boolean isWritable()
Support DBvolution at Patreon
public boolean isTypeAdapted()
Support DBvolution at Patreon
true if a type adaptor is being usedpublic <A extends QueryableDatatype<?>> A getQueryableDatatype()
Use isReadable() beforehand to check whether the property can be
read.
A - the QDT type
Support DBvolution at Patreon
IllegalStateException - if not readable (you should have called
isReadable() first)DBThrownByEndUserCodeException - if any user code throws an exceptionpublic void setQueryableDatatype(QueryableDatatype<?> value)
Use isWritable() beforehand to check whether the property can be
modified.
value - valueIllegalStateException - if not writable (you should have called
isWritable() first)DBThrownByEndUserCodeException - if any user code throws an exceptionpublic Object rawJavaValue()
In most cases you will not need to call this method, as type conversion is
done transparently via the getQueryableDatatype() and
setQueryableDatatype(QueryableDatatype) methods.
Use isReadable() beforehand to check whether the property can be
read.
Support DBvolution at Patreon
IllegalStateException - if not readable (you should have called
isReadable() first)DBThrownByEndUserCodeException - if any user code throws an exceptionpublic void setRawJavaValue(Object value)
In most cases you will not need to call this method, as type conversion is
done transparently via the getQueryableDatatype() and
setQueryableDatatype(QueryableDatatype) methods.
Use isWritable() beforehand to check whether the property can be
modified.
value - new valueIllegalStateException - if not writable (you should have called
isWritable() first)DBThrownByEndUserCodeException - if any user code throws an exceptionpublic Class<?> getRawJavaType()
In most cases you will not need to call this method, as type conversion is
done transparently via the getQueryableDatatype() and
setQueryableDatatype(QueryableDatatype) methods. Use the
type() method to get the DBv-centric property type, after type
conversion.
Support DBvolution at Patreon
public PropertyWrapperDefinition getPropertyWrapperDefinition()
Support DBvolution at Patreon
public RowDefinitionInstanceWrapper getRowDefinitionInstanceWrapper()
Support DBvolution at Patreon
public boolean hasColumnExpression()
Column expressions are derived values created with
DBexpressions like
StringExpression, NumberExpression, and
BooleanExpression. The often involve database columns using
the DBRow column methods or literal
values using the, for instance, the StringExpression
value method.
Support DBvolution at Patreon
public DBExpression[] getColumnExpression() throws ClassCastException
Support DBvolution at Patreon
ClassCastExceptionpublic List<PropertyWrapperDefinition.ColumnAspects> getColumnAspects(DBDefinition db)
Multiple names and aliases are supported for
QueryableDatatypes like
DBNumberStatistics which retrieve several expressions at once.
db - db
Support DBvolution at Patreon
public String[] getColumnAlias(DBDefinition defn)
defn - db
Support DBvolution at Patreon
public boolean isForeignKeyTo(DBRow table)
table - table
Support DBvolution at Patreon
public boolean isAutoIncrement()
This generally means that the column is a primary key. and definitely means you do not need to set the value of the column.
Support DBvolution at Patreon
public boolean isSpatial2DType()
This generally means that the column is a polygon, line, point, or other 2D geometry.
Spatial columns are special in that some databases need indexes to support them properly.
Support DBvolution at Patreon
public boolean isAutoFilling()
Support DBvolution at Patreon
public Class<?> getAutoFillingClass()
AutoFillDuringQueryIfPossible
annotation.
Support DBvolution at Patreon
Copyright © 2018. All Rights Reserved.