de.mathema.pride
Class ExtendedAttributeDescriptor

java.lang.Object
  extended by de.mathema.pride.ExtendedAttributeDescriptor
All Implemented Interfaces:
RecordDescriptor.ExtractionMode, SQLExpression.Operator

public class ExtendedAttributeDescriptor
extends java.lang.Object

Author:
Jan Lessner

Field Summary
protected  java.lang.reflect.Method conversionMethod
           
protected  int databaseColumnType
           
protected  java.lang.String databaseFieldName
           
protected  java.lang.reflect.Method databaseGetByIndexMethod
          Method to fetch data from a database result set by index
protected  java.lang.reflect.Method databaseGetByNameMethod
          Method to fetch data from a database result set by name
protected  java.lang.reflect.Method databaseSetMethod
          Method to store data in a database prepared statement
protected  java.lang.Class<java.lang.Enum> enumType
          True if the attribute represented by this descriptor is an enumeration type
protected  int extractionMode
          Specifies the ResultSet data extraction mode.
protected  java.lang.reflect.Method getMethod
           
protected  boolean isPrimitive
          True if the attribute represented by this descriptor is of a primitive type
static java.lang.String REVISION_ID
           
protected  java.lang.reflect.Method setMethod
           
 
Fields inherited from interface de.mathema.pride.SQLExpression.Operator
BETWEEN, EQUAL, GREATER, GREATEREQUAL, IN, LESS, LESSEQUAL, LIKE, NOTIN, UNEQUAL
 
Fields inherited from interface de.mathema.pride.RecordDescriptor.ExtractionMode
AUTO, INDEX, NAME
 
Constructor Summary
ExtendedAttributeDescriptor(java.lang.Class objectType, java.lang.String[] attrInfo, int extractionMode)
           
 
Method Summary
 void applyResult(java.lang.Object obj, java.lang.String stringValue)
           
 int getColumnType(java.sql.Connection con, java.lang.String table)
          Retrieve the column's SQL type, required for setting NULL values in prepared statements.
protected static java.lang.reflect.Method getConversionMethod(java.lang.Class destinationType)
           
 java.lang.String getCreationValue(java.lang.Object obj, Database db)
          Returns a string representation of the passed object's value for this descriptor's attribute.
 java.lang.String getFieldName()
          Returns the database field name
 int getParameter(java.lang.Object obj, PreparedOperation pop, java.lang.String table, int position)
          Writes an attribute of the passed value object to a PreparedOperation
 java.lang.String getUpdateValue(java.lang.Object obj, Database db)
          Returns an update expression of the form " = " by extracting the pased object's value for this descriptor's attribute.
 java.lang.Object getValue(java.lang.Object obj)
          Returns the object's value for this attribute
 java.lang.String getWhereValue(java.lang.Object obj, Database db, boolean byLike)
          Returns a constraint expression of the form " = " if the objects's value for this descriptor's attribute defers from null, " IS NULL" otherwise
protected  void record2object(java.lang.Object obj, java.sql.ResultSet results, int position)
          Fetch a value from a database result set and copy it into an object according to this attribute descriptor
protected  java.lang.Object record2object(java.sql.ResultSet results, int position)
          Fetch a value from a database result set according to this descriptor's extraction mode.
protected  int selectDataType(java.sql.Connection con, java.lang.String table, java.lang.String column)
           
protected static void setConversionMethods()
           
protected  java.lang.Object wrapArrayTypedValue(java.sql.Connection connection, java.lang.Object attrValue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

conversionMethod

protected java.lang.reflect.Method conversionMethod

REVISION_ID

public static final java.lang.String REVISION_ID
See Also:
Constant Field Values

databaseFieldName

protected java.lang.String databaseFieldName

databaseColumnType

protected int databaseColumnType

databaseGetByNameMethod

protected java.lang.reflect.Method databaseGetByNameMethod
Method to fetch data from a database result set by name


databaseGetByIndexMethod

protected java.lang.reflect.Method databaseGetByIndexMethod
Method to fetch data from a database result set by index


databaseSetMethod

protected java.lang.reflect.Method databaseSetMethod
Method to store data in a database prepared statement


getMethod

protected java.lang.reflect.Method getMethod

setMethod

protected java.lang.reflect.Method setMethod

extractionMode

protected int extractionMode
Specifies the ResultSet data extraction mode. See class RecordDescriptor for details.


isPrimitive

protected boolean isPrimitive
True if the attribute represented by this descriptor is of a primitive type


enumType

protected java.lang.Class<java.lang.Enum> enumType
True if the attribute represented by this descriptor is an enumeration type

Constructor Detail

ExtendedAttributeDescriptor

public ExtendedAttributeDescriptor(java.lang.Class objectType,
                                   java.lang.String[] attrInfo,
                                   int extractionMode)
                            throws IllegalDescriptorException
Throws:
IllegalDescriptorException
Method Detail

setConversionMethods

protected static void setConversionMethods()
                                    throws java.lang.NoSuchMethodException
Throws:
java.lang.NoSuchMethodException

getConversionMethod

protected static java.lang.reflect.Method getConversionMethod(java.lang.Class destinationType)
                                                       throws java.lang.NoSuchMethodException
Throws:
java.lang.NoSuchMethodException

applyResult

public void applyResult(java.lang.Object obj,
                        java.lang.String stringValue)
                 throws java.lang.IllegalAccessException,
                        java.lang.reflect.InvocationTargetException
Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

getFieldName

public java.lang.String getFieldName()
Returns the database field name


getColumnType

public int getColumnType(java.sql.Connection con,
                         java.lang.String table)
                  throws java.sql.SQLException
Retrieve the column's SQL type, required for setting NULL values in prepared statements. The retrieval is performed lazy as it may take some time and is not always required.

Parameters:
con - the database connection to fetch meta data from
table - the database table to fetch the column type from. The function assumes that the type is equal in all tables making use of the same attribute descriptor (e.g. all tables of a descriptor derivation hierarchy).
Throws:
java.sql.SQLException - if meta data retrieval failed

selectDataType

protected int selectDataType(java.sql.Connection con,
                             java.lang.String table,
                             java.lang.String column)
                      throws java.sql.SQLException
Throws:
java.sql.SQLException

getValue

public java.lang.Object getValue(java.lang.Object obj)
                          throws java.lang.IllegalAccessException,
                                 java.lang.reflect.InvocationTargetException
Returns the object's value for this attribute

Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

getUpdateValue

public java.lang.String getUpdateValue(java.lang.Object obj,
                                       Database db)
                                throws java.lang.IllegalAccessException,
                                       java.lang.reflect.InvocationTargetException
Returns an update expression of the form " = " by extracting the pased object's value for this descriptor's attribute.

Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

getWhereValue

public java.lang.String getWhereValue(java.lang.Object obj,
                                      Database db,
                                      boolean byLike)
                               throws java.lang.IllegalAccessException,
                                      java.lang.reflect.InvocationTargetException
Returns a constraint expression of the form " = " if the objects's value for this descriptor's attribute defers from null, " IS NULL" otherwise

Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

record2object

protected java.lang.Object record2object(java.sql.ResultSet results,
                                         int position)
                                  throws java.lang.reflect.InvocationTargetException,
                                         java.lang.IllegalAccessException
Fetch a value from a database result set according to this descriptor's extraction mode. If mode is ExtractionMode.AUTO or NAME extract the field value by name. If the extraction causes an InvocationTargetExtraction and the extraction mode is AUTO, the descriptor is switched to INDEX mode and an extraction by index is immediatly attempted.

Parameters:
results - The ResultSet to extract data from
position - The index of the field to extract. Ignored in NAME mode. Passsing -1 forces extraction by name.
Returns:
The extracted value
Throws:
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException

record2object

protected void record2object(java.lang.Object obj,
                             java.sql.ResultSet results,
                             int position)
                      throws java.sql.SQLException,
                             java.lang.IllegalAccessException,
                             java.lang.reflect.InvocationTargetException
Fetch a value from a database result set and copy it into an object according to this attribute descriptor

Throws:
java.sql.SQLException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

getCreationValue

public java.lang.String getCreationValue(java.lang.Object obj,
                                         Database db)
                                  throws java.lang.IllegalAccessException,
                                         java.lang.reflect.InvocationTargetException
Returns a string representation of the passed object's value for this descriptor's attribute. If obj is null, returns "?", required for prepared statements.

Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

getParameter

public int getParameter(java.lang.Object obj,
                        PreparedOperation pop,
                        java.lang.String table,
                        int position)
                 throws java.lang.IllegalAccessException,
                        java.lang.reflect.InvocationTargetException,
                        java.sql.SQLException
Writes an attribute of the passed value object to a PreparedOperation

Parameters:
obj - the value object to read from
pop - the PreparedOperation to write to
table - the name of the database table, the operation refers to. This is only required in case of NULL attribute values, which require to retrieve the column type first. This is a nasty detail in the JDBC API which we must take care of. Some databases allow just to set type NULL in this case, but especially DB2 and Oracle do not. See method PreparedStatement.setNull(int, int) for further details.
position - index of the parameter in the prepared statement to write
Returns:
next parameter index (i.e. passed value + 1)
Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.sql.SQLException

wrapArrayTypedValue

protected java.lang.Object wrapArrayTypedValue(java.sql.Connection connection,
                                               java.lang.Object attrValue)
                                        throws java.sql.SQLException
Throws:
java.sql.SQLException