Le vendredi 23 janvier 2015 04:40:04 UTC+1, Noel Grandin a écrit :
>
> On Thu, Jan 22, 2015 at 5:16 PM, ILM <[email protected] <javascript:>> 
> wrote: 
> > 
> > 1/ Not having to have the Trigger class on the server classpath 
>
> That doesn't make any sense - the function you call and the object it 
> returns still needs to be on the server classpath. 
>

Yes but it's still very useful since there's the whole JRE and H2 API, i.e. 
you're not limited to the simple example I've provided where the custom 
trigger class is on the server. You can declare a new anonymous trigger 
class using only H2 and Java APIs, that way it works on any H2 server, 
regardless of its class path.

> 2/ Allowing to pass parameters, e.g. you create once a trigger class to 
> > update a last modified field and each table can have a different name 
> for 
> > this field 
> > AS $$ org.h2.api.Trigger create(){ return new 
> > LastModifiedTrigger("MODIFICATION_DATE"); } $$ 
> > for one table and 
> > AS $$ org.h2.api.Trigger create(){ return new 
> > LastModifiedTrigger("LAST_MOD_TIME"); } $$ 
> > for another 
> > 
>
> OK, I can see the benefit of this. 
>
> Perhaps we make it even more convenient and make the construction look 
> like: 
>
>   AS $$ myclass.CreateLastModifiedTrigger("MODIFICATION_DATE"); $$ 
>
> where H2 will assume that the code is a call to a method that returns 
> an org.h2.api.Trigger object. 
>

Why not, though I would prefix with the 'return' keyword, I think this 
would be more legible and be easier for H2 to tell when we're passing a 
full method and when we're only passing a statement.

Static method :
 AS $$ return myclass.CreateLastModifiedTrigger("MODIFICATION_DATE"); $$ 
Constructor :
 AS $$ return new LastModifiedTrigger("MODIFICATION_DATE"); $$ 
Complex code (e.g. as I've said above calling only H2 and JRE : works on 
any H2 server) : 
 AS $$ org.h2.api.Trigger create(){

// as much statements as needed

String fieldName = "MODIFICATION_DATE";

Object someVar = ...

return new org.h2.api.Trigger {

init(){}

fire(){}
close(){}
remove(){}

}; 

} $$ 


Cheers,
Sylvain CUAZ 

 
 

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to