com.jenkov.mrpersister.itf.mapping
Interface IGetterMapping

All Superinterfaces:
IMethodMapping
All Known Implementing Classes:
ArrayGetterMapping, AsciiStreamGetterMapping, BigDecimalGetterMapping, BinaryStreamGetterMapping, BlobGetterMapping, BooleanGetterMapping, ByteArrayGetterMapping, ByteGetterMapping, CalendarGetterMapping, CharacterStreamGetterMapping, ClobGetterMapping, DateGetterMapping, DoubleGetterMapping, FloatGetterMapping, GetterMapping, IntGetterMapping, LongGetterMapping, ObjectGetterMapping, RefGetterMapping, ShortGetterMapping, SqlDateGetterMapping, StringGetterMapping, TimeGetterMapping, TimestampGetterMapping, UrlGetterMapping

public interface IGetterMapping
extends IMethodMapping

This interface represents the functions special to getter method mappings. Getter method mappings represent a method from a getter method in a class to a column in the database.

Getter method mappings are used when writing/updating objects to/in the database. Getter method mappings can extract the values from objects to be inserted/updated by calling the getter method they are method from (on the target object), and insert these values into a PreparedStatement). Getter method mappings are also used when doing a read-by-primary-key.

Author:
Jakob Jenkov, Jenkov Development

Method Summary
 void insertObject(java.lang.Object value, java.sql.PreparedStatement statement, int index)
          This method inserts the given object into the given PreparedStatement as a statement parameter using the given index as index to what "?" in the PreparedStatement to insert the value for.
 void insertValueFromObject(java.lang.Object target, java.sql.PreparedStatement statement, int index)
          This method extracts a value from an object by calling the getter method associated with this getter method method on the target object.
 boolean isAutoGenerated()
          Returns whether or not the value of the column in the database matching this getter method method is auto generated by the database.
 void setAutoGenerated(boolean isAutoGenerated)
          Sets whether or not the value of the column in the database matching this getter method method is auto generated by the database.
 
Methods inherited from interface com.jenkov.mrpersister.itf.mapping.IMethodMapping
getColumnName, getColumnType, getObjectMethod, isPrimaryKey, isTableMapped, setColumnName, setColumnType, setObjectMethod, setPrimaryKey, setTableMapped
 

Method Detail

insertValueFromObject

void insertValueFromObject(java.lang.Object target,
                           java.sql.PreparedStatement statement,
                           int index)
                           throws PersistenceException
This method extracts a value from an object by calling the getter method associated with this getter method method on the target object. The extracted value is inserted into the given PreparedStatement as a statement parameter using the given index as index to what "?" in the PreparedStatement to insert the value for.

Parameters:
target - The object to extract the value from.
statement - The PreparedStatement to insert the value into.
index - The index to insert the value into the PreparedStatement at.
Throws:
PersistenceException - If anything goes wrong during the insertion.

insertObject

void insertObject(java.lang.Object value,
                  java.sql.PreparedStatement statement,
                  int index)
                  throws PersistenceException
This method inserts the given object into the given PreparedStatement as a statement parameter using the given index as index to what "?" in the PreparedStatement to insert the value for.

Parameters:
value - The object to insert.
statement - The PreparedStatement to insert the value into.
index - The index to insert the value into the PreparedStatement at.
Throws:
PersistenceException - If anything goes wrong during the insertion.

isAutoGenerated

boolean isAutoGenerated()
Returns whether or not the value of the column in the database matching this getter method method is auto generated by the database. Examples of auto generated column values are primary key values that are inserted automatically by the database when a new record is inserted, or r timestamps columns updated by the database each time a record is updated.

It is important to mark getter method mappings as auto generated if they are. Trying to specify a value for an auto generated column when inserting or updating records will result in a database error. The database will refuse this action. Therefore it is essential for the SQL generator and the object writer to know if a certain column is auto generated, so they can exclude it from inserts and updates. The getter method method of an auto generated column cannot be removed altogether though. If the column is a primary key the getter method method is still used when executing read-by-primary-key, delete, or delete-by-primary-key actions.

Returns:
True if the value of the column matching this getter method method is auto generated. False if not.

setAutoGenerated

void setAutoGenerated(boolean isAutoGenerated)
Sets whether or not the value of the column in the database matching this getter method method is auto generated by the database. Examples of auto generated column values are primary key values that are inserted automatically by the database when a new record is inserted, or timestamps columns updated by the database each time a record is updated.

It is important to mark getter method mappings as auto generated if they are. Trying to specify a value for an auto generated column when inserting or updating records will result in a database error. The database will refuse this action. Therefore it is essential for the SQL generator and the object writer to know if a certain column is auto generated, so they can exclude it from inserts and updates. The getter method method of an auto generated column cannot be removed altogether though. If the column is a primary key the getter method method is still used when executing read-by-primary-key, delete, or delete-by-primary-key actions.

Parameters:
isAutoGenerated - Set to true if the column value is auto generated by the database. False if not.