Top Description Fields Constructors Methods
org.h2.schema

public final Class TriggerObject

extends SchemaObject
Class Inheritance
Imports
java.lang.reflect.Method, java.sql.Connection, .ResultSet, .SQLException, java.util.Arrays, org.h2.api.ErrorCode, .Trigger, org.h2.engine.Constants, .DbObject, .SessionLocal, org.h2.jdbc.JdbcConnection, .JdbcResultSet, org.h2.message.DbException, .Trace, org.h2.result.Row, .SimpleResult, org.h2.table.Column, .Table, org.h2.tools.TriggerAdapter, org.h2.util.JdbcUtils, .SourceCompiler, .StringUtils, org.h2.value.Value, .ValueToObjectConverter

A trigger is created using the statement CREATE TRIGGER

Field Summary

Modifier and TypeField and Description
private boolean
public static final int
DEFAULT_QUEUE_SIZE

The default queue size.

private boolean
private boolean
private boolean
private int
private boolean
private Table
private Trigger
private String
private String
private int

Constructor Summary

AccessConstructor and Description
public
TriggerObject(Schema schema, int id, String name, Table table)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Close the trigger.

private static Object[]
private static JdbcResultSet
createResultSet(JdbcConnection conn, Table table, Row row, boolean updatable)

public void
fire(SessionLocal
the session
session
,
int
the trigger type
type
,
boolean
if this method is called before applying the changes
beforeAction
)

Call the trigger class if required.

public boolean

Returns:

true if no further action is required (for 'instead of' triggers)
fireRow
(SessionLocal
the session
session
,
Table
the table
table
,
Row
the old row
oldRow
,
Row
the new row
newRow
,
boolean
true if this method is called before the operation is applied
beforeAction
,
boolean
when the operation occurred within a rollback
rollback
)

Call the fire method of the user-defined trigger class if required.

public String
getCreateSQL()

Implements abstract org.h2.engine.DbObject.getCreateSQL.

Construct the CREATE ...

public String
getCreateSQLForCopy(Table
the new table
targetTable
,
String
the quoted name
quotedName
)

Overrides org.h2.engine.DbObject.getCreateSQLForCopy.

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 table

private DbException
public int
public Table

Returns:

the table
getTable
()

Get the table of this trigger.

public String

Returns:

the class name
getTriggerClassName
()

Get the trigger class name.

public String
public int
getType()

Implements abstract org.h2.engine.DbObject.getType.

Get the object type.

public int

Returns:

the trigger type
getTypeMask
()

Returns the trigger type.

public StringBuilder

Returns:

the passed string builder
getTypeNameList
(StringBuilder
the builder
builder
)

Append the trigger types to the given string builder.

public boolean

Returns:

true if it is
isBefore
()

Check if this is a before trigger.

public boolean
public boolean
public boolean
public boolean
public boolean

Returns:

true if it is
isSelectTrigger
()

Check whether this is a select trigger.

private synchronized void
load()

private Trigger
public void
removeChildrenAndResources(SessionLocal
the session
session
)

Implements abstract org.h2.engine.DbObject.removeChildrenAndResources.

Delete all dependent children objects and resources of this object.

public void
setBefore(boolean before)

public void
setInsteadOf(boolean insteadOf)

public void
setNoWait(boolean noWait)

public void
setOnRollback(boolean onRollback)

public void
setQueueSize(int size)

public void
setRowBased(boolean rowBased)

private void
setTriggerAction(String triggerClassName, String source, boolean force)

public void
setTriggerClassName(String
the name of the trigger class
triggerClassName
,
boolean
whether exceptions (due to missing class or access rights) should be ignored
force
)

Set the trigger class name and load the class if possible.

public void
setTriggerSource(String
the source code of a method returning a Trigger
source
,
boolean
whether exceptions (due to syntax error) should be ignored
force
)

Set the trigger source code and compile it if possible.

public void
setTypeMask(int
the type
typeMask
)

Set the trigger type.

Inherited from org.h2.schema.SchemaObject:
getSchemagetSQLgetSQL

Field Detail

beforeback to summary
private boolean before
DEFAULT_QUEUE_SIZEback to summary
public static final int DEFAULT_QUEUE_SIZE

The default queue size.

insteadOfback to summary
private boolean insteadOf
noWaitback to summary
private boolean noWait
onRollbackback to summary
private boolean onRollback
queueSizeback to summary
private int queueSize
rowBasedback to summary
private boolean rowBased
tableback to summary
private Table table
triggerCallbackback to summary
private Trigger triggerCallback
triggerClassNameback to summary
private String triggerClassName
triggerSourceback to summary
private String triggerSource
typeMaskback to summary
private int typeMask

Constructor Detail

TriggerObjectback to summary
public TriggerObject(Schema schema, int id, String name, Table table)

Method Detail

closeback to summary
public void close() throws SQLException

Close the trigger.

Exceptions
SQLException:
on failure
convertToObjectListback to summary
private static Object[] convertToObjectList(Row row, JdbcConnection conn)
createResultSetback to summary
private static JdbcResultSet createResultSet(JdbcConnection conn, Table table, Row row, boolean updatable) throws SQLException
fireback to summary
public void fire(SessionLocal session, int type, boolean beforeAction)

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:SessionLocal

the session

type:int

the trigger type

beforeAction:boolean

if this method is called before applying the changes

fireRowback to summary
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:SessionLocal

the session

table:Table

the table

oldRow:Row

the old row

newRow:Row

the new row

beforeAction:boolean

true if this method is called before the operation is applied

rollback:boolean

when the operation occurred within a rollback

Returns:boolean

true if no further action is required (for 'instead of' triggers)

getCreateSQLback to summary
public String getCreateSQL()

Implements abstract org.h2.engine.DbObject.getCreateSQL.

Doc from org.h2.engine.DbObject.getCreateSQL.

Construct the CREATE ... SQL statement for this object.

Returns:String

the SQL statement

Annotations
@Override
getCreateSQLForCopyback to summary
public String getCreateSQLForCopy(Table targetTable, String quotedName)

Overrides org.h2.engine.DbObject.getCreateSQLForCopy.

Doc from org.h2.engine.DbObject.getCreateSQLForCopy.

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 table

Parameters
targetTable:Table

the new table

quotedName:String

the quoted name

Returns:String

the SQL statement

Annotations
@Override
getErrorExecutingTriggerback to summary
private DbException getErrorExecutingTrigger(Throwable e)
getQueueSizeback to summary
public int getQueueSize()
getTableback to summary
public Table getTable()

Get the table of this trigger.

Returns:Table

the table

getTriggerClassNameback to summary
public String getTriggerClassName()

Get the trigger class name.

Returns:String

the class name

getTriggerSourceback to summary
public String getTriggerSource()
getTypeback to summary
public int getType()

Implements abstract org.h2.engine.DbObject.getType.

Doc from org.h2.engine.DbObject.getType.

Get the object type.

Returns:int

the object type

Annotations
@Override
getTypeMaskback to summary
public int getTypeMask()

Returns the trigger type.

Returns:int

the trigger type

getTypeNameListback to summary
public StringBuilder getTypeNameList(StringBuilder builder)

Append the trigger types to the given string builder.

Parameters
builder:StringBuilder

the builder

Returns:StringBuilder

the passed string builder

isBeforeback to summary
public boolean isBefore()

Check if this is a before trigger.

Returns:boolean

true if it is

isInsteadOfback to summary
public boolean isInsteadOf()
isNoWaitback to summary
public boolean isNoWait()
isOnRollbackback to summary
public boolean isOnRollback()
isRowBasedback to summary
public boolean isRowBased()
isSelectTriggerback to summary
public boolean isSelectTrigger()

Check whether this is a select trigger.

Returns:boolean

true if it is

loadback to summary
private synchronized void load()
loadFromSourceback to summary
private Trigger loadFromSource()
removeChildrenAndResourcesback to summary
public void removeChildrenAndResources(SessionLocal session)

Implements abstract org.h2.engine.DbObject.removeChildrenAndResources.

Doc from org.h2.engine.DbObject.removeChildrenAndResources.

Delete all dependent children objects and resources of this object.

Parameters
session:SessionLocal

the session

Annotations
@Override
setBeforeback to summary
public void setBefore(boolean before)
setInsteadOfback to summary
public void setInsteadOf(boolean insteadOf)
setNoWaitback to summary
public void setNoWait(boolean noWait)
setOnRollbackback to summary
public void setOnRollback(boolean onRollback)
setQueueSizeback to summary
public void setQueueSize(int size)
setRowBasedback to summary
public void setRowBased(boolean rowBased)
setTriggerActionback to summary
private void setTriggerAction(String triggerClassName, String source, boolean force)
setTriggerClassNameback to summary
public void setTriggerClassName(String triggerClassName, boolean force)

Set the trigger class name and load the class if possible.

Parameters
triggerClassName:String

the name of the trigger class

force:boolean

whether exceptions (due to missing class or access rights) should be ignored

setTriggerSourceback to summary
public void setTriggerSource(String source, boolean force)

Set the trigger source code and compile it if possible.

Parameters
source:String

the source code of a method returning a Trigger

force:boolean

whether exceptions (due to syntax error) should be ignored

setTypeMaskback to summary
public void setTypeMask(int typeMask)

Set the trigger type.

Parameters
typeMask:int

the type