Hi, I think it's somewhat unlogical (at least inconsistent) that a module doesn't have a name when you create it, but has a name when you drop it. I would prefer it having a name in both cases. The name doesn't need to match the class name.
You have used an unnamed package. Does this mean the package name can be specified in the source code. First I thought that's a bit dangerous, but it's probably not a problem (it's not a bigger security risk) and more logical that way. By the way, did you see http://h2database.com/javadoc/org/h2/tools/TriggerAdapter.html ? It's very similar to SimpleTrigger - only it uses result sets instead of arrays. Maybe we should add a second TriggerAdapter with arrays? Regards, Thomas On Thu, Aug 5, 2010 at 6:25 AM, Kerry Sainsbury <[email protected]> wrote: > Hi Thomas, > > How do you like this example. It's very simple. Basically you copy and paste > Java code and call it a "MODULE". The class can then be called from whatever > wants it (and I can easily implement my simpler trigger idea just by putting > in a "SimpleTrigger" class that I can extend in another module. Note there > is no need to name a module, as we can just use the class name: > > > CREATE MODULE AS > $$ > import java.sql.*; > import org.h2.api.Trigger; > > public abstract class SimpleTrigger implements Trigger { > public void init(Connection conn, String schemaName, String > triggerName, String tableName, boolean before, int type) throws SQLException > { > } > public abstract void fire(Connection conn, Object[] oldRow, > Object[] newRow) throws SQLException; > public void close() throws SQLException { > } > public void remove() throws SQLException { > } > } > $$ > > > CREATE MODULE AS > $$ > import java.sql.*; > > public class MyTrigger extends SimpleTrigger { > public void fire(Connection conn, Object[] oldRow, Object[] newRow) > throws SQLException { > newRow[0] = ((String)newRow[0]).toUpperCase(); > } > } > $$ > > > CREATE TRIGGER TRIG_INS BEFORE INSERT ON TEST FOR EACH ROW CALL "MyTrigger" > > > DROP TRIGGER TRIG_INS > DROP MODULE MyTrigger > DROP MODULE SimpleTrigger > > > What do you think? > > Cheers > Kerry > > > > On Thu, Jul 22, 2010 at 8:02 AM, Thomas Mueller > <[email protected]> wrote: >> >> Hi, >> >> I think the >> CREATE CODE MyTriggerCode LANGUAGE JAVA FOR TRIGGER AS >> is very verbose. What about: >> CREATE TRIGGER ... AS? >> That's similar syntax as CREATE ALIAS ... AS. >> >> H2 only supports Java currently, so there is no reason to require >> "JAVA". Once other languages are supported it can still be added as an >> option. >> >> However I'm not sure if it makes sense to provide shortcut to directly >> register a trigger as source code *snippet* (that is, only the fire >> method). I think it's no problem to require the source code of the >> *complete* class in this case. If you write short static function, >> then the current CREATE ALIAS ... AS source is handy (I used it many >> times). But if you write a trigger, you anyway do that in the IDE, >> meaning you anyway have the source code of the complete class >> somewhere. Because you want to use auto-complete of the IDE, and so >> forth. Triggers are almost never as simple as a Java function. >> >> I think if we want to support CREATE CODE then this should be only >> used to add classes to the "internal classpath" of H2. Independent of >> for what those classes are used (trigger, aggregate, function >> alias,...), and therefore without any magic to adopt to the right type >> / add missing glue code. Even without automatically adding import >> statements. Those classes can then be used for many things. For >> example a class that contains multiple public static methods plus a >> trigger (or even multiple triggers using inner classes). Or it could >> even contain multiple classes, or a jar file (which would be stored in >> the database). Instead of CREATE CODE what about CREATE MODULE or >> CREATE LIBRARY? There could be a module / library for MySQL helper >> functions, for PostgreSQL helper functions, and so on. Like a Apache >> HTTP module. There should be an way to "auto-start", maybe using a >> method in the loaded library. >> >> Existing features could then be retro-fitted as modules / libraries. >> For example fulltext search. >> >> Regards, >> Thomas >> >> -- >> 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. >> > > -- > 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. > -- 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.
