public final class FieldReference extends java.lang.Object implements Resolvable, Accessor
CompoundQuery
, when
an inner loop where clause of a multi-table query refers to a field within
a buffer retrieved in an outer loop.
This class provides both read and write capability to the backing field, insofar as the DMO has both an accessor (getter) and a mutator (setter) method defined for the specified property. Both indexed and non-indexed versions of these methods are supported. It is assumed that the methods have bean-like signatures. Specifically, the following, public signature patterns are assumed:
<BaseDataType subclass> get<Property>()
<BaseDataType subclass> get<Property>(int)
void set<Property>(<BaseDataType subclass>)
void set<Property>(<BaseDataType subclass>, int)
Modifier and Type | Field and Description |
---|---|
private Database |
database
The associated database
|
private java.lang.Object |
dmo
DMO or DMO proxy instance; the referent of the referencing method
|
private java.lang.Integer |
extent
This field's extent (if an array field), else
null |
private java.lang.reflect.Method |
getter
Method used to resolve this field reference at query execution time
|
private NumberType |
index
Optional index, used with a DMO indexed getter method
|
private static java.util.logging.Logger |
LOG
Logger
|
private java.lang.String |
property
Property name
|
private java.lang.reflect.Method |
setter
Method used to resolve this field reference at query execution time
|
private boolean |
uppercase
Flag to force resolved character result to uppercase/right-trim
|
Constructor and Description |
---|
FieldReference(Database database,
java.lang.Class<?> dmoIface,
java.lang.String property)
Create a new field reference given a DMO interface and property name.
|
FieldReference(DataModelObject dmo,
java.lang.String property)
Create a new field reference given a DMO proxy and property name.
|
FieldReference(DataModelObject dmo,
java.lang.String property,
boolean uppercase)
Create a new field reference given a DMO proxy and property name.
|
FieldReference(DataModelObject dmo,
java.lang.String property,
boolean uppercase,
int index)
Create a new field reference given a DMO proxy, a property name, and
an index for the property.
|
FieldReference(DataModelObject dmo,
java.lang.String property,
boolean uppercase,
NumberType index)
Create a new field reference given a DMO proxy, a property name, and
an index for the property.
|
FieldReference(DataModelObject dmo,
java.lang.String property,
int index)
Create a new field reference given a DMO proxy, a property name, and
an index for the property.
|
FieldReference(DataModelObject dmo,
java.lang.String property,
NumberType index)
Create a new field reference given a DMO proxy, a property name, and
an index for the property.
|
FieldReference(FieldReference fieldRef,
int index)
Specialized copy constructor which copies a non-indexed field reference and applies an
index to the copy.
|
Modifier and Type | Method and Description |
---|---|
BaseDataType |
get()
Resolve the current value of the referent field by invoking the getter
method for the target property.
|
(package private) java.lang.Object |
get(DataModelObject dmo)
Resolve the current value of the referent field by invoking the getter
method for the target property, using the given DMO as the target.
|
(package private) java.lang.Object |
get(Persistable dmo)
Resolve the current value of the referent field by invoking the getter
method for the target property, using the given DMO as the target.
|
java.lang.Object |
getDMO()
Get the DMO or proxy instance associated with this field reference.
|
java.lang.Class<?> |
getDMOInterface()
Get the interface of the DMO associated with this field reference.
|
java.lang.Integer |
getExtent()
Return field's extent, if field reference is to an extent field, else
null . |
private static java.lang.Integer |
getExtent(java.lang.Class<?> dmoIface,
java.lang.String property)
Look up the extent for the specified property and interface.
|
BaseDataType[] |
getExtentValues()
Resolve the current value of the referent field by invoking the getter method for the
target property.
|
private static java.lang.reflect.Method |
getGetter(java.lang.Class<?> dmoIface,
java.lang.String property)
Look up the getter method for the specified property and interface.
|
int |
getIndex()
Returns index used with the DMO indexed getter method.
|
private java.lang.Object |
getObject()
Resolve the current value of the referent field by invoking the getter
method for the target property.
|
RecordBuffer |
getParentBuffer()
Returns the record buffer which contains the referent DMO.
|
java.lang.String |
getProperty()
Get property name (converted field name).
|
private static java.lang.reflect.Method |
getSetter(java.lang.Class<?> dmoIface,
java.lang.String property)
Look up the setter method for the specified property and interface.
|
(package private) java.lang.Object |
getTemp(DataModelObject dmo)
Resolve the current value of the referent field by invoking the getter
method for the target property, using the given DMO as the target.
|
(package private) java.lang.Object |
getTemp(Persistable dmo)
Resolve the current value of the referent field by invoking the getter
method for the target property, using the given DMO as the target.
|
java.lang.Class<?> |
getType()
Determine the data type that will be returned when this field reference
is resolved.
|
BaseDataType |
getValue()
Resolve the field reference's value, bracketed by calls to the error
manager to first enable, then disable, warning mode.
|
private void |
handleException(java.lang.Exception exc)
Handle a thread interruption or database connection error specially,
otherwise return normally.
|
boolean |
isUpperCase()
Indicate whether resolved character value will be uppercased/right-trimmed.
|
BaseDataType |
resolve()
Resolve the current value of the referent field by invoking the getter
method for the target property.
|
void |
set(BaseDataType value)
Set the current value of the referent field by invoking the setter
method for the target property.
|
void |
set(BaseDataType[] value)
Set the current value of the referent field by invoking the setter method for the target
property.
|
java.lang.String |
toString()
Return a string representation of this field reference, in the form:
|
(package private) BaseDataType |
unknownValue()
Create an instance of unknown value of the correct type for this field reference.
|
(package private) static BaseDataType |
unknownValue(java.lang.reflect.Method getter)
Convenience method to produce a
BaseDataType instance
initialized to the unknown value. |
private static final java.util.logging.Logger LOG
private final java.lang.String property
private final java.lang.reflect.Method getter
private final java.lang.reflect.Method setter
private final java.lang.Integer extent
null
private final NumberType index
private Database database
private java.lang.Object dmo
private boolean uppercase
public FieldReference(DataModelObject dmo, java.lang.String property)
dmo
- DMO proxy.property
- Target property name.public FieldReference(DataModelObject dmo, java.lang.String property, boolean uppercase)
dmo
- DMO proxy.property
- Target property name.uppercase
- true
to force a character
value
returned by getObject()
to be uppercased/right-trimmed;
false
to leave the result unchanged.public FieldReference(DataModelObject dmo, java.lang.String property, int index)
dmo
- DMO proxy.property
- Target property name.index
- Index to pass to property's getter method at resolve time.public FieldReference(DataModelObject dmo, java.lang.String property, boolean uppercase, int index)
dmo
- DMO proxy.property
- Target property name.uppercase
- true
to force a character
value
returned by getObject()
to be uppercased/right-trimmed;
false
to leave the result unchanged.index
- Index to pass to property's getter method at resolve time.public FieldReference(DataModelObject dmo, java.lang.String property, NumberType index)
dmo
- DMO proxy.property
- Target property name.index
- Index to pass to property's getter method at resolve time.java.lang.IllegalArgumentException
- if field reference is not recognized.public FieldReference(DataModelObject dmo, java.lang.String property, boolean uppercase, NumberType index)
dmo
- DMO proxy.property
- Target property name.uppercase
- true
to force a character
value
returned by getObject()
to be uppercased/right-trimmed;
false
to leave the result unchanged.index
- Index to pass to property's getter method at resolve time.java.lang.IllegalArgumentException
- if field reference is not recognized.FieldReference(Database database, java.lang.Class<?> dmoIface, java.lang.String property)
get(Persistable)
variant of the get
method.
Note that the created instance can be used to read the related field only.
database
- The associated database.dmoIface
- Interface of the target DMO.property
- Target property namepublic FieldReference(FieldReference fieldRef, int index)
fieldRef
- Original, non-indexed field reference. Although the field is non-indexed, this
should be a reference to an extent field.index
- Zero-based index to be used as the subscript into the extent field represented by
the copy.static BaseDataType unknownValue(java.lang.reflect.Method getter)
BaseDataType
instance
initialized to the unknown value. An attempt is made to return an
object of the correct type (i.e., the getter method's return type).
If this fails for some reason, a new instance of unknown
is returned.getter
- Getter method whose return type is used to determine the type
of object to return.unknown
.private static java.lang.Integer getExtent(java.lang.Class<?> dmoIface, java.lang.String property)
dmoIface
- Referent DMO interface.property
- Name of target property (i.e., field).null
if property
does not match any
property name in the DMO API or is not an extent property.private static java.lang.reflect.Method getGetter(java.lang.Class<?> dmoIface, java.lang.String property)
For the reserved id
property, Persistable
interface
is substituted for dmoIface
.
For extent properties the method is capable to return the indexed or the non-indexed getter.
dmoIface
- Referent DMO interface.property
- Name of target property (i.e., field).null
if property
does not match any property name in the DMO API.private static java.lang.reflect.Method getSetter(java.lang.Class<?> dmoIface, java.lang.String property)
For extent properties the method is capable to return the indexed or the non-indexed setter.
dmoIface
- Referent DMO interface.property
- Name of target property (i.e., field).null
if property
does not match any property name in the DMO API.public java.lang.Class<?> getType()
getType
in interface Resolvable
public BaseDataType getValue()
public BaseDataType resolve()
resolve
in interface Resolvable
public BaseDataType get()
get
in interface Accessor
ErrorConditionException
- if any persistence level error occurs getting the value from
the DMO.java.lang.IllegalStateException
- if the backing property is not read accessible (i.e., no getter
method was found).java.lang.RuntimeException
- if the backing, getter method cannot be accessed or if there
is some other error at the invocation target.public BaseDataType[] getExtentValues()
ErrorConditionException
- if any persistence level error occurs getting the value from the DMO.java.lang.IllegalStateException
- if the backing property is not read accessible (i.e., no getter method was found).java.lang.RuntimeException
- if the backing, getter method cannot be accessed or if there is some other error at
the invocation target.public int getIndex()
-1
if the getter is
not indexed.public java.lang.Object getDMO()
public java.lang.String getProperty()
public void set(BaseDataType value)
set
in interface Accessor
value
- New value to set into the field represented by this object.ErrorConditionException
- if this field reference represents an element in an array, but
the index provided at construction is the unknown value;
if any persistence-level error occurs setting the value into
the DMO, including validation errors.java.lang.IllegalStateException
- if the backing property is not write accessible (i.e., no
setter method was found).java.lang.RuntimeException
- if the backing, getter method cannot be accessed or if there
is some other error at the invocation target.public void set(BaseDataType[] value)
For non-extent fields, the value is placed on the first position in the array. For extent fields, the value is the actual value which needs to be set for the array.
value
- New value to set into the field represented by this object.ErrorConditionException
- if this field reference represents an element in an array, but the index provided
at construction is the unknown value; if any persistence-level error occurs setting
the value into the DMO, including validation errors.java.lang.IllegalStateException
- if the backing property is not write accessible (i.e., no setter method was found).java.lang.RuntimeException
- if the backing, getter method cannot be accessed or if there is some other error at
the invocation target.public java.lang.String toString()
alias.propertyor, if indexed:
alias.property[index]If the field reference is to a case-insensitive character field, the result will be enclosed in the
upper()
function.toString
in class java.lang.Object
public java.lang.Class<?> getDMOInterface()
public boolean isUpperCase()
public RecordBuffer getParentBuffer()
Note: this method only should be invoked on instances of this class which were constructed with a DMO proxy (as opposed to a DMO implementation class instance).
java.lang.Object get(DataModelObject dmo)
null
(or the unknown value for
BaseDataTypes
return types).dmo
- Target object which is used as the method's referent.null
if no value exists.ErrorConditionException
- if any persistence level error occurs getting the value from
the DMO.java.lang.IllegalStateException
- if the backing property is not read accessible (i.e., no getter
method was found).java.lang.RuntimeException
- if the backing, getter method cannot be accessed or if there
is some other error at the invocation target.java.lang.Object get(Persistable dmo)
null
(or the unknown value for
BaseDataTypes
return types).dmo
- Target object which is used as the method's referent.null
if no value exists.ErrorConditionException
- if any persistence level error occurs getting the value from
the DMO.java.lang.IllegalStateException
- if the backing property is not read accessible (i.e., no getter
method was found).java.lang.RuntimeException
- if the backing, getter method cannot be accessed or if there
is some other error at the invocation target.java.lang.Object getTemp(Persistable dmo)
null
(or the unknown value for
BaseDataTypes
return types).
Unlike the get(com.goldencode.p2j.persist.Persistable)
method, it
doesn't make this field reference use the passed DMO for future calls.
dmo
- Target object which is used as the method's referent.null
if no value exists.ErrorConditionException
- if any persistence level error occurs getting the value from
the DMO.java.lang.IllegalStateException
- if the backing property is not read accessible (i.e., no getter
method was found).java.lang.RuntimeException
- if the backing, getter method cannot be accessed or if there
is some other error at the invocation target.java.lang.Object getTemp(DataModelObject dmo)
null
(or the unknown value for
BaseDataTypes
return types).
Unlike the get(com.goldencode.p2j.persist.DataModelObject)
method, it
doesn't make this field reference use the passed DMO for future calls.
dmo
- Target object which is used as the method's referent.null
if no value exists.ErrorConditionException
- if any persistence level error occurs getting the value from
the DMO.java.lang.IllegalStateException
- if the backing property is not read accessible (i.e., no getter
method was found).java.lang.RuntimeException
- if the backing, getter method cannot be accessed or if there
is some other error at the invocation target.public java.lang.Integer getExtent()
null
.null
.BaseDataType unknownValue()
private java.lang.Object getObject()
null
(or the unknown value for BaseDataTypes
return types).null
if no value exists.ErrorConditionException
- if any persistence level error occurs getting the value from
the DMO.java.lang.IllegalStateException
- if the backing property is not read accessible (i.e., no getter
method was found).java.lang.RuntimeException
- if the backing, getter method cannot be accessed or if there
is some other error at the invocation target.private void handleException(java.lang.Exception exc)
exc
- Exception to be inspected.DBUtils.handleException(Database, Exception)