com.jenkov.mrpersister.impl.mapping.method
Class GetterMapping
java.lang.Object
com.jenkov.mrpersister.impl.mapping.method.MethodMapping
com.jenkov.mrpersister.impl.mapping.method.GetterMapping
- All Implemented Interfaces:
- IGetterMapping, IMethodMapping, java.lang.Comparable
- Direct Known Subclasses:
- ArrayGetterMapping, AsciiStreamGetterMapping, BigDecimalGetterMapping, BinaryStreamGetterMapping, BlobGetterMapping, BooleanGetterMapping, ByteArrayGetterMapping, ByteGetterMapping, CalendarGetterMapping, CharacterStreamGetterMapping, ClobGetterMapping, DateGetterMapping, DoubleGetterMapping, FloatGetterMapping, IntGetterMapping, LongGetterMapping, ObjectGetterMapping, RefGetterMapping, ShortGetterMapping, SqlDateGetterMapping, StringGetterMapping, TimeGetterMapping, TimestampGetterMapping, UrlGetterMapping
public class GetterMapping
- extends MethodMapping
- implements IGetterMapping
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. |
protected void |
insertObjectDo(java.lang.Object value,
java.sql.PreparedStatement statement,
int index)
|
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 autoGenerated)
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 class com.jenkov.mrpersister.impl.mapping.method.MethodMapping |
compareTo, equals, getColumnName, getColumnType, getObjectMethod, hashCode, isNumberType, isPrimaryKey, isStringType, isTableMapped, setColumnName, setColumnType, setObjectMethod, setPrimaryKey, setTableMapped, toString |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
isAutoGenerated
protected boolean isAutoGenerated
GetterMapping
public GetterMapping()
isAutoGenerated
public boolean isAutoGenerated()
- Description copied from interface:
IGetterMapping
- 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.
- Specified by:
isAutoGenerated
in interface IGetterMapping
- Returns:
- True if the value of the column matching this getter method method is auto generated.
False if not.
setAutoGenerated
public void setAutoGenerated(boolean autoGenerated)
- Description copied from interface:
IGetterMapping
- 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.
- Specified by:
setAutoGenerated
in interface IGetterMapping
- Parameters:
autoGenerated
- Set to true if the column value is auto generated by the database.
False if not.
insertValueFromObject
public void insertValueFromObject(java.lang.Object target,
java.sql.PreparedStatement statement,
int index)
throws PersistenceException
- Description copied from interface:
IGetterMapping
- 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.
- Specified by:
insertValueFromObject
in interface IGetterMapping
- 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
public void insertObject(java.lang.Object value,
java.sql.PreparedStatement statement,
int index)
throws PersistenceException
- Description copied from interface:
IGetterMapping
- 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.
- Specified by:
insertObject
in interface IGetterMapping
- 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.
insertObjectDo
protected void insertObjectDo(java.lang.Object value,
java.sql.PreparedStatement statement,
int index)
throws java.sql.SQLException
- Throws:
java.sql.SQLException