Hi, The DatabaseEventListener is running on the server side (where the database is open).
What you could do is: within the database event listener, buffer the log messages into the database (in an in-memory table for example). Then, on then client side, read from this buffer from time to time. Remove the records that you already read. Regards, Thomas On Tue, May 8, 2012 at 10:52 PM, Lizard Lizard <[email protected]> wrote: > OK, I'm having a bit of a quandary, which is probably obviously simple to > everyone else. > > I start up an H2 server from the command line, thus: java -cp h2-latest.jar > org.h2.tools.Server -tcp -tcpPort 9091 -tcpAllowOthers > > In my application (currently being debugged in Eclipse, but it shouldn't > matter), I connect to the server thus: > URL="jdbc:h2:tcp://192.168.0.102:9091/file://C:\Development\VARisk Related > Files\workspace\TC_VARisk\VARiskDB"; (It's not actually hard-coded in the > app, this is a sample of a generated URL to make it clear.) > Connection conn=conn = DriverManager.getConnection(URL, "sa", ""); > > This has been working fine for a long time now. > > I created a very basic stub class that implemented DatabaseEventListener, > with a few printlns to show that it was working, etc. > > The first thing I tried was changing my code for the URL to include > ";DATABASE_EVENT_LISTENER='"+H2DBListener.class.getName()+"'" > > This threw "class not found" exceptions. I tried a lot of variants on this > theme before the caffeine hit and I figured it out. Once I was done bashing > my head on the desk, I built a .jar containing my H2DBListener class, and > added it to the classpath for the H2Server startup. > > This stopped the "class not found" errors. Unfortunately, the Listener is > outputting information to the server console, not the Eclipse console. I > need it tied to the connection I create internally to my app. > > Further, I really need to be able to create an object of the H2DBListener > class, attach it during particular processes I care about listening to, and > then detach it. Is there a way to do something like: > H2DBListener h=new H2DBListener(); > SetDatabaseEventListener(h); > > I noticed that there is a SQL command to set the DBEvent listener, but it > also sets it to a class, not an instance. > > To be clear as to my long term goals, what I mostly want/need is to be able > to do something like this: > > class someLongProcess implements DatabaseEventListener > { > ProgressBar pb=new ProgressBar(); > ... > public void DoSomething() > { > //here's where I'd like to attach the listener > query="Select * from HugeDatabase"; > executeQuery(); > //here's where I detach the listener > } > > public void setProgress(int state, String name, int x, int max) > { > if(state==valueICareAbout) > { > pb.update(x,max); > } > } > } > > To make matters more interesting, my app runs (when doing real work) in > multiple VMs. It's a very simple work splitting model, using Cajo to > coordinate the small amount of state I need to share -- and of course part > of that state is "how far long are we?". Currently, I probably don't need to > use DatabaseEventListener, because progress on the main function of the > application is already being tracked and shared, but I see a future time > when I might need to implement it, so I wanted to bring it up. What happens > if/when multiple connections to the same server set or unset the Listener > class? If it's tied to the connection, that's likely no issue; each class > that creates a connection and needs a listener ought to be fairly atomic in > what it's doing and what it's listening for. I want to be sure that if class > foo calls SET DATABASE_EVENT_LISTENER, it won't be affected by what class > bar, running in a different thread in the same VM, or in another VM > entirely, does. > > Thank you for your patience with what are probably self-evident questions. > > Also, I normally only edit in plain text in gmail, but to make the code more > readable, I had to switch to rich formatting. I hope it actually is > formatted clearly on other people's systems. > -- > ======================= > Personal Blog: http://www.xanga.com/lizard_sf > Facebook: http://www.facebook.com/lizard_sf > MrLizard: Gaming and Geekery: http://www.mrlizard.com > > -- > 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.
