public interface DeferModification
Updating a column that is used in the WHERE clause might or might not give the VTI implementation trouble; the update might cause the same row to be selected more than once. This problem can be solved by building the complete list of rows to be updated and the new column values before updating any rows. The updates are applied after the list is built. This process is called "deferred update".
By default, updates on a VTI are deferred when the VTI ResultSet is scrollable (ResultSet.TYPE_SCROLL_SENSITIVE or TYPE_SCROLL_INSENSITIVE), and one or more of the following is true.
By default, deletes on a VTI are deferred in a similar situation: when the VTI ResultSet is scrollable (ResultSet.TYPE_SCROLL_SENSITIVE or TYPE_SCROLL_INSENSITIVE), and the where clause contains a subselect on a VTI from the same class as the target VTI. We do not look at the VTI parameters, just the VTI class name.
By default, inserts into a VTI are deferred when the same VTI class is used as both the source and target. It does not depend on the scrollability of the VTI ResultSet because inserts can be deferred without scrolling the ResultSet.
If these defaults are not appropriate then the class implementing the VTI should also implement this interface (org.apache.derby.vti.DeferModification).
(A read/write VTI is implemented by a class that implements the java.sql.PreparedStatement interface, often by extending the UpdatableVTITemplate interface. @see UpdatableVTITemplate).
Update and delete statement deferral is implemented by scrolling the VTI's ResultSet. Therefore, updates and deletes on a VTI are never deferred unless the VTI's ResultSets are scrollable, even if the DeferModification interface methods return true. Therefore for an update or delete to be deferred the VTI getResultSetType() method must return ResultSet.TYPE_SCROLL_SENSITIVE or TYPE_SCROLL_INSENSITIVE and the VTI must produce scrollable java.sql.ResultSets that implement the getRow() and absolute() methods. If your VTI is implemented as an extension to UpdatableVTITemplate then you must override the getResultSetMethod: UpdatableVTITemplate.getResultSetType() throws an exception. If your VTI's ResultSets are implemented as extensions to VTITemplate then you must override the getRow() and absolute() methods: VTITemplate.getRow() and absolute() throw exceptions.
This interface is not used when the VTI is referenced only in a subselect; it is only used when a VTI appears as the target of an INSERT, UPDATE, or DELETE statement.
Modifier and Type | Field and Description |
---|---|
static int |
DELETE_STATEMENT |
static int |
INSERT_STATEMENT |
static int |
UPDATE_STATEMENT |
Modifier and Type | Method and Description |
---|---|
boolean |
alwaysDefer(int statementType)
This method is called during preparation of an insert, update, or delete statement with this VTI
as the target.
|
boolean |
columnRequiresDefer(int statementType,
java.lang.String columnName,
boolean inWhereClause)
This method is called during preparation of an update or delete statement on the virtual
table if getResultSetType() returns ResultSet.TYPE_SCROLL_SENSITIVE or TYPE_SCROLL_SENSITIVE and
alwaysDefer( statementType) returns false.
|
void |
modificationNotify(int statementType,
boolean deferred)
This VTI method is called by Derby when a VTI modification (insert, update, or delete)
is executed.
|
boolean |
subselectRequiresDefer(int statementType,
java.lang.String VTIClassName)
This method is called during preparation of an insert, update, or delete statement that has this virtual
table as its target and that has a sub-select.
|
boolean |
subselectRequiresDefer(int statementType,
java.lang.String schemaName,
java.lang.String tableName)
This method is called during preparation of an insert, update, or delete statement that has this virtual
table as its target and that has a sub-select.
|
static final int INSERT_STATEMENT
static final int UPDATE_STATEMENT
static final int DELETE_STATEMENT
boolean alwaysDefer(int statementType) throws java.sql.SQLException
statementType
- One of INSERT_STATEMENT, UPDATE_STATEMENT, DELETE_STATEMENT.java.sql.SQLException
- on an unexpected condition.boolean columnRequiresDefer(int statementType, java.lang.String columnName, boolean inWhereClause) throws java.sql.SQLException
statementType
- UPDATE_STATEMENT or DELETE_STATEMENT.columnName
- the name of one of the columns being updatedinWhereClause
- indicates whether the column also appears in the where clausejava.sql.SQLException
- a parameter is invalid or there is another unexpected failure.boolean subselectRequiresDefer(int statementType, java.lang.String schemaName, java.lang.String tableName) throws java.sql.SQLException
statementType
- the statement type: INSERT_STATEMENT, UPDATE_STATEMENT, or DELETE_STATEMENT.schemaName
- the schema of the table in the sub-select.tableName
- the name of the table in the sub-select.java.sql.SQLException
- a parameter is invalid or there is another unexpected failure.boolean subselectRequiresDefer(int statementType, java.lang.String VTIClassName) throws java.sql.SQLException
statementType
- the statement type: INSERT_STATEMENT, UPDATE_STATEMENT, or DELETE_STATEMENT.VTIClassName
- the name of the class implementing the VTI in the sub-select.java.sql.SQLException
- a parameter is invalid or there is another unexpected failure.void modificationNotify(int statementType, boolean deferred) throws java.sql.SQLException
statementType
- one of INSERT_STATEMENT, UPDATE_STATEMENT, or DELETE_STATEMENTdeferred
- true if the modification will be deferred, false if not.java.sql.SQLException
- thrown on an unexpected failureApache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.