Class TriggerObject
java.lang.Object
org.h2.engine.DbObject
org.h2.schema.SchemaObject
org.h2.schema.TriggerObject
- All Implemented Interfaces:
HasSQL
A trigger is created using the statement
CREATE TRIGGER
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanstatic final intThe default queue size.private booleanprivate booleanprivate booleanprivate intprivate booleanprivate Tableprivate Triggerprivate Stringprivate Stringprivate intFields inherited from class DbObject
AGGREGATE, comment, COMMENT, CONSTANT, CONSTRAINT, database, DOMAIN, FUNCTION_ALIAS, INDEX, RIGHT, ROLE, SCHEMA, SEQUENCE, SETTING, SYNONYM, TABLE_OR_VIEW, trace, TRIGGER, USERFields inherited from interface HasSQL
ADD_PLAN_INFORMATION, DEFAULT_SQL_FLAGS, NO_CASTS, QUOTE_ONLY_WHEN_REQUIRED, REPLACE_LOBS_FOR_TRACE, TRACE_SQL_FLAGS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the trigger.private static Object[]convertToObjectList(Row row, JdbcConnection conn) private static JdbcResultSetcreateResultSet(JdbcConnection conn, Table table, Row row, boolean updatable) voidfire(SessionLocal session, int type, boolean beforeAction) Call the trigger class if required.booleanfireRow(SessionLocal session, Table table, Row oldRow, Row newRow, boolean beforeAction, boolean rollback) Call the fire method of the user-defined trigger class if required.Construct the CREATE ...getCreateSQLForCopy(Table targetTable, String quotedName) Build a SQL statement to re-create the object, or to create a copy of the object with a different name or referencing a different tableprivate DbExceptionintgetTable()Get the table of this trigger.Get the trigger class name.intgetType()Get the object type.intReturns the trigger type.getTypeNameList(StringBuilder builder) Append the trigger types to the given string builder.booleanisBefore()Check if this is a before trigger.booleanbooleanisNoWait()booleanbooleanbooleanCheck whether this is a select trigger.private voidload()private TriggervoidremoveChildrenAndResources(SessionLocal session) Delete all dependent children objects and resources of this object.voidsetBefore(boolean before) voidsetInsteadOf(boolean insteadOf) voidsetNoWait(boolean noWait) voidsetOnRollback(boolean onRollback) voidsetQueueSize(int size) voidsetRowBased(boolean rowBased) private voidsetTriggerAction(String triggerClassName, String source, boolean force) voidsetTriggerClassName(String triggerClassName, boolean force) Set the trigger class name and load the class if possible.voidsetTriggerSource(String source, boolean force) Set the trigger source code and compile it if possible.voidsetTypeMask(int typeMask) Set the trigger type.Methods inherited from class SchemaObject
getSchema, getSQL, getSQL, isHiddenMethods inherited from class DbObject
checkRename, getChildren, getComment, getCreateSQLForMeta, getDatabase, getDropSQL, getId, getModificationId, getName, invalidate, isTemporary, isValid, rename, setComment, setModified, setObjectName, setTemporary, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface HasSQL
getTraceSQL
-
Field Details
-
DEFAULT_QUEUE_SIZE
public static final int DEFAULT_QUEUE_SIZEThe default queue size.- See Also:
-
insteadOf
private boolean insteadOf -
before
private boolean before -
typeMask
private int typeMask -
rowBased
private boolean rowBased -
onRollback
private boolean onRollback -
queueSize
private int queueSize -
noWait
private boolean noWait -
table
-
triggerClassName
-
triggerSource
-
triggerCallback
-
-
Constructor Details
-
TriggerObject
-
-
Method Details
-
setBefore
public void setBefore(boolean before) -
isInsteadOf
public boolean isInsteadOf() -
setInsteadOf
public void setInsteadOf(boolean insteadOf) -
load
private void load() -
loadFromSource
-
setTriggerClassName
Set the trigger class name and load the class if possible.- Parameters:
triggerClassName- the name of the trigger classforce- whether exceptions (due to missing class or access rights) should be ignored
-
setTriggerSource
-
setTriggerAction
-
fire
Call the trigger class if required. This method does nothing if the trigger is not defined for the given action. This method is called before or after any rows have been processed, once for each statement.- Parameters:
session- the sessiontype- the trigger typebeforeAction- if this method is called before applying the changes
-
convertToObjectList
-
fireRow
public boolean fireRow(SessionLocal session, Table table, Row oldRow, Row newRow, boolean beforeAction, boolean rollback) Call the fire method of the user-defined trigger class if required. This method does nothing if the trigger is not defined for the given action. This method is called before or after a row is processed, possibly many times for each statement.- Parameters:
session- the sessiontable- the tableoldRow- the old rownewRow- the new rowbeforeAction- true if this method is called before the operation is appliedrollback- when the operation occurred within a rollback- Returns:
- true if no further action is required (for 'instead of' triggers)
-
createResultSet
private static JdbcResultSet createResultSet(JdbcConnection conn, Table table, Row row, boolean updatable) throws SQLException - Throws:
SQLException
-
getErrorExecutingTrigger
-
getTypeMask
public int getTypeMask()Returns the trigger type.- Returns:
- the trigger type
-
setTypeMask
public void setTypeMask(int typeMask) Set the trigger type.- Parameters:
typeMask- the type
-
setRowBased
public void setRowBased(boolean rowBased) -
isRowBased
public boolean isRowBased() -
setQueueSize
public void setQueueSize(int size) -
getQueueSize
public int getQueueSize() -
setNoWait
public void setNoWait(boolean noWait) -
isNoWait
public boolean isNoWait() -
setOnRollback
public void setOnRollback(boolean onRollback) -
isOnRollback
public boolean isOnRollback() -
getCreateSQLForCopy
Description copied from class:DbObjectBuild a SQL statement to re-create the object, or to create a copy of the object with a different name or referencing a different table- Specified by:
getCreateSQLForCopyin classDbObject- Parameters:
targetTable- the new tablequotedName- the quoted name- Returns:
- the SQL statement
-
getTypeNameList
Append the trigger types to the given string builder.- Parameters:
builder- the builder- Returns:
- the passed string builder
-
getCreateSQL
Description copied from class:DbObjectConstruct the CREATE ... SQL statement for this object.- Specified by:
getCreateSQLin classDbObject- Returns:
- the SQL statement
-
getType
-
removeChildrenAndResources
Description copied from class:DbObjectDelete all dependent children objects and resources of this object.- Specified by:
removeChildrenAndResourcesin classDbObject- Parameters:
session- the session
-
getTable
-
isBefore
public boolean isBefore()Check if this is a before trigger.- Returns:
- true if it is
-
getTriggerClassName
-
getTriggerSource
-
close
-
isSelectTrigger
public boolean isSelectTrigger()Check whether this is a select trigger.- Returns:
- true if it is
-