Thomas,
Replies below...
On 06/07/2011 1:18 AM, Thomas Mueller wrote:
Hi,
I am expecting a Trigger to belong to *one* of those types.
I don't agree. It doesn't make sense to create one trigger object for
DELETE, one trigger object for INSERT, and one trigger object for
UPDATE.
Why? What are you worried about?
In fact,
if you look at the original RFE that led to this feature getting
added, they had the same thing in mind:
How did you come to this conclusion?
MattShaw writes "We have logic in our triggers that uses this
information to determine what to do". My interpretation is that he'd
like to know the operation type in fire() in order to determine what to
do. After all, the bit-field passed into init() doesn't tell you what
specific operation that will trigger fire() so he couldn't have been
talking about that.
2. Add a new "type" parameter to the fire() method so we can act on
the actual type that gets fired (better from a performance point of
view).
That's possible, also for compatibility with HSQLDB. I guess it
doesn't make sense to change the existing interface (backwards
compatibility); instead, an Adapter style extension could be added.
Can you give an example of what you had in mind?
Currently the following logic can be used:
if (oldRow != null) {
if (newRow != null) {
// update
if (hasChanged(oldRow, newRow, indexColumns)) {
delete(oldRow);
insert(newRow);
}
} else {
// delete
delete(oldRow);
}
} else if (newRow != null) {
// insert
insert(newRow);
}
You've outlined a way for detecting whether fire() is handling
UPDATE, DELETE or INSERT. What about SELECT or ROLLBACK?
Either way, the Javadoc should match the actual behavior.
I will document in Trigger.init()
The type of operation is a bit field with the
appropriate flags set. As an example, if the trigger is of type INSERT
and UPDATE, then the parameter type is set to (INSERT | UPDATE).
@param type the operation type: INSERT, UPDATE, DELETE, SELECT, or a
combination (this parameter is a bit field)
Regards,
Thomas
Please also document how to detect the operation type in fire(),
not only in init().
Thanks,
Gili
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.