public class JdbcStatementUpdateVisitor extends VisitorBase
ComponentInterface.acceptVisitor(Visitor)
of a
component or visitComponent(ComponentInterface)
of this visitor.
This visitor cannot be reused! It must be instantiated each time before it is sent to a component.
The visitor is initialized with a prepared JDBC statement, an attribute
mediator list and an optional index of the first field to be updated in the
prepared statement (default is 1). The parameters of the prepared statement
are set by the method JdbcAttributeMediatorInterface.fillStatement(List,PreparedStatement,ComponentInterface,AttributeInterface)
of the attribute mediators. The method JdbcAttributeMediatorInterface.getAttributeKeyword()
of these attribute
mediators is called to determine the attributes of the component this visitor
is sent to. The order of the attribute mediators in the list determines the
visiting order of the attributes. The order of the parameters in the prepared
statement must match the order of the attribute mediators in the list. The
method JdbcAttributeMediatorInterface.getColumnNames()
of the
attribute mediator is called to determine how many parameters are processed
by the mediator. This array is used to create the index list for the method
fillStatement() of the mediators. The order of the column names in
this array must match the order of the parameters in the prepared statement.
For each visited attribute the method fillStatement() of the related attribute mediator is called, passing the prepared statement, the index list of the parameters in the statement to be updated, the parent component of the attribute and the attribute itself.
Constructor and Description |
---|
JdbcStatementUpdateVisitor(java.sql.PreparedStatement statement,
java.util.Collection<? extends JdbcAttributeMediatorInterface> attributeMediators,
int firstParameterIndex)
The constructor initializes the private members with the passed
parameters.
|
Modifier and Type | Method and Description |
---|---|
void |
visitAttribute(AttributeInterface<?> attribute)
This method overrides the method of the base class and sets the value of
the passed attribute into the prepared statement using the current
attribute mediator.
|
void |
visitComponent(ComponentInterface<?> component)
This method overrides the method of the base class and forwards the
visitor to all attributes of the component specified by the attribute
mediator collection passed to the constructor.
|
<C extends ComponentInterface<?>> |
visitComponentReference(ComponentReferenceInterface<?,C> componentReference)
This method overrides the method of the base class and calls the method
visitAttribute(AttributeInterface) . |
visitComponentContainer, visitContainerReference, visitSequenceContainer
public JdbcStatementUpdateVisitor(java.sql.PreparedStatement statement, java.util.Collection<? extends JdbcAttributeMediatorInterface> attributeMediators, int firstParameterIndex)
statement
- The prepared statement, of which the the parameters
should be set by the visitor.attributeMediators
- The attribute mediators used to set the
statement parameters.firstParameterIndex
- The index of the first parameter in the
statement to be updated.public void visitAttribute(AttributeInterface<?> attribute) throws AcafException
visitComponent(ComponentInterface)
.
This method cannot be used as entry point for this visitor.
visitAttribute
in interface Visitor
visitAttribute
in class VisitorBase
attribute
- The attribute, used to retrieve the value for the
parameter of the prepared statement.AcafException
- Thrown, when retrieving the attribute values or
setting the statement parameter fails.public void visitComponent(ComponentInterface<?> component) throws AcafException
visitAttribute(AttributeInterface)
.visitComponent
in interface Visitor
visitComponent
in class VisitorBase
component
- The component, of which the attribute values are
inserted into the statement parameters.AcafException
- Thrown, when retrieving the attribute values or
setting the statement parameter fails.public <C extends ComponentInterface<?>> void visitComponentReference(ComponentReferenceInterface<?,C> componentReference) throws AcafException
visitAttribute(AttributeInterface)
.visitComponentReference
in interface Visitor
visitComponentReference
in class VisitorBase
C
- The type of the component referenced by the attribute.componentReference
- The reference attribute, which accepted the
visitor.AcafException
- Thrown, when retrieving the attribute values or
setting the statement parameter fails.