I would LOVE this to be implemented - it would stop me having to put
the trigger classes on the classpath when using the H2 console (which
is a PITA)

On Thu, Jun 24, 2010 at 2:50 PM, Kerry Sainsbury <ke...@fidelma.com> wrote:
> Hi Folks,
> I've been looking at triggers recently and was surprised to see that we
> can't define Java code to execute as part of a trigger.
> Note that we *can* use Java code, but we can't embed it in the trigger
> definition like we can with an "ALIAS".
> Would it be a good thing if we could store any Java code that could be used
> within H2, within H2 itself?
> The most flexible option seemed to be a new command. Something like this:
>
> CREATE CODE MyTriggerExample AS
> $$
> public void fire(Connection conn, Object[] oldRow, Object[] newRow) throws
> SQLException {
>       PreparedStatement prep = conn.prepareStatement("INSERT INTO
> TEST_AUDIT(BLAH) VALUES (?)");
>       prep.setInt(1, (Integer)newRow[0] );
>       prep.execute();
>       prep.close();
> }
> $$
>
> followed by
>           CREATE TRIGGER TRIG_INS BEFORE INSERT ON TEST FOR EACH ROW CALL
> "MyTriggerExample";
> Any "code" objects would also be able to be used in CREATE AGGREGATE, SET
> DATABASE_EVENT_LISTENER, and
> CREATE ALIAS commands.
> Note that MyTriggerExample above does not require all org.h2.api.Trigger
> interface methods to be implemented -- only
> include the methods that are required by the end user.
> The advantage of this is that triggers etc could be shipped as SQL, rather
> than having to be put into a jar file and
> included on the CLASSPATH of the H2 server.
> I anticipate a single instance of each class being instantiated throughout
> the life of the database, so implementation
> classes would need to be threadsafe.
> What do you think? (Especially Thomas :-)
> I've actually got this mostly implemented, but before I spend any more time
> on it I thought I'd better see if anybody
> thought this added any value -- and if other databases did anything similar
> in a nicer way.
> Cheers
> Kerry
>
> --
> You received this message because you are subscribed to the Google Groups
> "H2 Database" group.
> To post to this group, send email to h2-datab...@googlegroups.com.
> To unsubscribe from this group, send email to
> h2-database+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/h2-database?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to h2-datab...@googlegroups.com.
To unsubscribe from this group, send email to 
h2-database+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to