public class JdbcStringAttributeMediator extends JdbcAttributeMediatorBase
JdbcAttributeMediatorInterface
and extends the class JdbcAttributeMediatorBase
. It is used to
mediate between a string attribute implementing the interface StringAttributeInterface
and a string database field.
The mediator may be initialized with the flag isEmptyStringNull, which determines if the empty string is represented by the SQL NULL value (true) in the database (i.e. for Oracle) or as empty string (false). The default value of this flag is true. The database column must accept SQL NULL values in this case.
The mediator exchanges the attribute value between the attribute and a ResultSet
field or a PreparedStatement
parameter. When a result set
is passed to a method, the current row is used to update or retrieve the
attribute value. The method ResultSet.getString(int)
is called to
retrieve the attribute value and the static utility method JdbcUtilityFunctions.updateResultSetWithString(String,ResultSet,int)
is
called to update the result set field. This method checks if the field value
has been changed and if the field is updatable before the field value is
updated. The method PreparedStatement.setString(int,String)
is called
to set the parameter of the prepared statement.
Note, that the column name passed to the constructor is not used to access
the result set column or prepared statement parameter. Instead the first
index in the index list passed to the methods is used, which improves
performance. The column name is used by the framework to determine the column
of a result set, the mediator is related to (see description of interface
JdbcAttributeMediatorInterface
). The mediator uses the column name
furthermore to insert the field name in error messages of exceptions like
JdbcAttributeWriteError
or JdbcFieldReadError
.
attributeKeyword, columnNames
Constructor and Description |
---|
JdbcStringAttributeMediator(java.lang.String attributeKeyword)
The constructor initializes the mediator with the passed parameter.
|
JdbcStringAttributeMediator(java.lang.String attributeKeyword,
boolean isEmptyStringNull)
The constructor initializes the mediator with the passed parameters.
|
JdbcStringAttributeMediator(java.lang.String attributeKeyword,
java.lang.String columnName)
The constructor initializes the mediator with the passed parameters.
|
JdbcStringAttributeMediator(java.lang.String attributeKeyword,
java.lang.String columnName,
boolean isEmptyStringNull)
The constructor initializes the mediator with the passed parameters.
|
Modifier and Type | Method and Description |
---|---|
void |
fillStatement(java.util.List<java.lang.Integer> parameterIndices,
java.sql.PreparedStatement statement,
ComponentInterface<?> component,
AttributeInterface<?> attribute)
This method implements the interface
JdbcAttributeMediatorInterface and sets the parameter with the first
index in the passed index list of the passed statement with the value of
the passed attribute. |
void |
updateAttribute(java.sql.ResultSet resultSet,
java.util.List<java.lang.Integer> fieldIndices,
ComponentInterface<?> component,
AttributeInterface<?> attribute)
This method implements the interface
JdbcAttributeMediatorInterface and sets the attribute value with the
value of the field in the result set at the current cursor position and
in the column with the first index of the passed index list. |
void |
updateResultSet(java.util.List<java.lang.Integer> fieldIndices,
java.sql.ResultSet resultSet,
ComponentInterface<?> component,
AttributeInterface<?> attribute)
This method implements the interface
JdbcAttributeMediatorInterface and updates the field of the passed
result set at the current cursor position and the first index of the
passed index list with the attribute value. |
getAttributeKeyword, getColumnIndices, getColumnNames
public JdbcStringAttributeMediator(java.lang.String attributeKeyword)
attributeKeyword
- The attribute keyword and database column name.public JdbcStringAttributeMediator(java.lang.String attributeKeyword, boolean isEmptyStringNull)
attributeKeyword
- The attribute keyword and database column name.isEmptyStringNull
- Determines if the empty string is represented by
the SQL NULL value (true) in the database or as empty
string (false).public JdbcStringAttributeMediator(java.lang.String attributeKeyword, java.lang.String columnName)
attributeKeyword
- The attribute keyword.columnName
- The database column name.public JdbcStringAttributeMediator(java.lang.String attributeKeyword, java.lang.String columnName, boolean isEmptyStringNull)
attributeKeyword
- The attribute keyword.columnName
- The database column name.isEmptyStringNull
- Determines if the empty string is represented by
the SQL NULL value (true) in the database or as empty
string (false).public void fillStatement(java.util.List<java.lang.Integer> parameterIndices, java.sql.PreparedStatement statement, ComponentInterface<?> component, AttributeInterface<?> attribute) throws JdbcAttributeWriteError, java.lang.ClassCastException
JdbcAttributeMediatorInterface
and sets the parameter with the first
index in the passed index list of the passed statement with the value of
the passed attribute. When the attribute value is the empty string and
the mediator has been initialized with isEmptyStringNull=true, the
parameter value is set to null.parameterIndices
- The index list specifying the parameters to be
set with the attribute value. When the list is empty, no parameter is
set. This method uses only the first index in the list.statement
- The prepared statement containing the parameter to be
set.component
- The (parent) component containing the attribute. The
component is only used to retrieve information for the exception JdbcAttributeWriteError
.attribute
- The attribute used to retrieve the value for the
statement parameter. This attribute must implement the interface StringAttributeInterface
.JdbcAttributeWriteError
- Thrown, when setting the parameter of the
prepared statement fails.java.lang.ClassCastException
- Thrown, when the attribute doesn't implement
the interface StringAttributeInterface
.public void updateAttribute(java.sql.ResultSet resultSet, java.util.List<java.lang.Integer> fieldIndices, ComponentInterface<?> component, AttributeInterface<?> attribute) throws AttributeException, JdbcAttributeReadError, java.lang.ClassCastException
JdbcAttributeMediatorInterface
and sets the attribute value with the
value of the field in the result set at the current cursor position and
in the column with the first index of the passed index list. When the
database value is NULL the attribute value is set with the empty
string.resultSet
- The result set containing the field for the attribute
value.fieldIndices
- The index list specifying the columns in the result
set with the attribute value. When the list is empty, the attribute value
is not set. This method uses only the first index in the list.component
- The (parent) component containing the attribute. The
component is only used to retrieve information for the exception JdbcAttributeReadError
.attribute
- The attribute, of which the value is set with the value
retrieved from the result set. This attribute must implement the
interface StringAttributeInterface
.AttributeException
- Thrown, when setting the attribute value
fails.JdbcAttributeReadError
- Thrown, when accessing the result set
field fails.java.lang.ClassCastException
- Thrown, when the attribute doesn't implement
the interface StringAttributeInterface
.public void updateResultSet(java.util.List<java.lang.Integer> fieldIndices, java.sql.ResultSet resultSet, ComponentInterface<?> component, AttributeInterface<?> attribute) throws JdbcAttributeWriteError, java.lang.ClassCastException
JdbcAttributeMediatorInterface
and updates the field of the passed
result set at the current cursor position and the first index of the
passed index list with the attribute value. The method JdbcUtilityFunctions.updateResultSetWithString(String,ResultSet,int)
is called to update the result set field. This method updates the field
only if it is writable and if the value is different. When the attribute
value is the empty string and the mediator has been initialized with
isEmptyStringNull=true, the result set field value is set to
null.resultSet
- The result set containing the field for the attribute
value.fieldIndices
- The index list specifying the columns in the result
set for the attribute value. When the list is empty, the result set is
not updated. This method uses only the first index in the list.component
- The (parent) component containing the attribute. The
component is only used to retrieve information for the exception JdbcAttributeWriteError
.attribute
- The attribute delivering the value for the result set.
This attribute must implement the interface StringAttributeInterface
.JdbcAttributeWriteError
- Thrown, when updating the result set
field fails.java.lang.ClassCastException
- Thrown, when the attribute doesn't implement
the interface StringAttributeInterface
.