Re: Support for H2Database

"hkara1" <[email protected]>
Newsgroups gmane.comp.java.orm.simpleorm
Message-ID <[email protected]>
Hello Anthony,

I can only check out from subversion at home, because at work
our firewall does not allow subversion connections. And I come
home late, with little time for computers ...
However I will give it a later try.
Sorry that I did not specifiy, but of course I had
overridden supportsLocking() to return true.
And when I set LOCK_TIMEOUT to any value lower than 2000,
the LongTransactionTest fails again with the error
  "timeout trying to lock table XX_DEPARTMENT"
which was I guess the intention of the LongTransactionTest.

So I will get the latest version from Subversion and try it
at home, to confirm that the tests work "out of the box", using
the LOCK_TIMEOUT parameter.

By the way for H2 I could also connect to it yesterday via
ODBC / MS-Access, via the PostgreSQL ODBC driver, which might
be of interest.

Best regards,

Harry

--- In [email protected], Anthony Berglas <anthony@...> wrote:
>
> Hello Harry,
> 
> Please do check out from subversion, not the zipped versions.  I only 
> create the latter occasionally, and you are supporting a new database 
> which may require tweaks.    I have already changed the mode to QUERY 
> for H2 in subversion.  Subversion is easy to use.  Download the svn 
> client and then run the check out command in the README.
> 
> I can see that the LOCK_TIMEOUT might get the tests to pass by 
> essentially turning off locking, although I am surprised H2 did not 
> throw an exception -- have a look at the output.  But I think that H2 
> may have some locking (unlike HSQL) so maybe try instead to change 
> supportsLocking() as suggested below.  That would be a better solution.
> 
> Anthony
> 
> 
> At 10:43 PM 3/10/2008, hkara1 wrote:
> 
> >Hi,
> >
> >I found the timeout parameter for locks, so all the tests run
> >correctly now.
> >The timeout can be set by adding the parameter to the jdbc url,
> >or by issuing a "SET LOCK_TIMEOUT nnn" statement on the current
> >connection.
> >For the tests, I have put the following properties in
> >%userprofile%\simpleorm.properties :
> >
> >database.url=jdbc:h2:C:/t/TestSimpleorm;LOCK_TIMEOUT=60000
> >database.username=sa
> >database.password=
> >database.driver=org.h2.Driver
> >
> >And tests ran like a charm.
> >
> >Harry
> >
> >--- In 
> ><mailto:SimpleORM%40yahoogroups.com>[email protected], 
> >Anthony Berglas <anthony@> wrote:
> > >
> > > Hello Harry,
> > >
> > > Thanks for your work on H2, which looks quite good. I'm thinking we
> > > should probably make it the default db in the next release of
> > > SimpleORM. The compatibility with the PostgreSQL might be handy for
> > > people like Franck.
> > >
> > > Unlike HSQLDB H2 seems to support locking. Maybe try override
> > > public boolean supportsLocking() {
> > > return true; // was false.
> > > }
> > > It would be interesting to know if that fixes the lock test.
> > >
> > > I do not understand your point about Enum. The current code is
> > > return ((Enum<T>)value).name();
> > > where .name() returns a string.
> > >
> > > Your Offset/Limit code also works for HSLQDB, so has been added to
> > > the SDriverHSQLH2.
> > >
> > > As to registering drivers, I have added the H2 driver to the current
> > > version in subversion. I strongly suggest that you check out from
> > > there. I have added your updates, please check out and confirm that
> > > they work for you. (The crude code in SDriver that registers them
> > > could be improved.)
> > >
> > > Anthony
> > >
> > >
> > > At 03:27 AM 1/10/2008, hkara1 wrote:
> > >
> > > >Hi, the unit tests are OK, except for the long transaction test
> > > >that fails with a lock timeout (this should not be too serious).
> > > >
> > > >BUT READ ON !
> > > >
> > > >However, the unit tests only work for H2 version 1.0, version 0.9
> > > >raises some errors, especially for correlated queries. So ONLY USE
> > > >V. 1.0 (and above, when available) of H2.
> > > >
> > > >There is also a problem I encountered in the SFieldEnum class,
> > > >because H2 tries to write it as Object, and this raises an error :
> > > >
> > > >Value too long for column ETYPE:
> > >
> > >'aced00057e72002173696d706c656f726d2e6578616d706c65732e456d706c6f79 
> > 656524455479706500000000000000001200007872000e6a6176612e6c616...
> > > >[90005-79]
> > > >
> > > >Now the column is declared as VARCHAR when SFieldEnum is used, so
> > > >I guess it should return an object of type String (not of type
> > > >EnumClass). So the unit test works OK when I add the following
> > > >method to SFieldEnum :
> > > >
> > > >@Override
> > > >public Object writeFieldValue(Object value) {
> > > >if (value == null) return null;
> > > >return value.toString();
> > > >}
> > > >
> > > >And anyway Enums should be transformed to Strings using toString()
> > > >according to the JDK docs.
> > > >
> > > >Here is the driver I have used :
> > > >
> > > >/**
> > > >* The H2 is mostly HSQL (H2 is a fork, by the original author of
> >HSQLDB)
> > > >*/
> > > >public class H2Driver
> > > >extends SDriverHSQL
> > > >{
> > > >@Override
> > > >protected String driverName() {
> > > >return "H2 JDBC Driver";
> > > >}
> > > >
> > > >@Override
> > > >protected OffsetStrategy getOffsetStrategy() {
> > > >return OffsetStrategy.QUERY;
> > > >}
> > > >
> > > >@Override
> > > >protected String limitSQL(long offset, long limit) {
> > > >StringBuffer sb = new StringBuffer();
> > > >if (limit != Integer.MAX_VALUE) sb.append(" LIMIT "+limit);
> > > >if (offset > 0) sb.append(" OFFSET "+offset);
> > > >return sb.toString();
> > > >}
> > > >}
> > > >
> > > >And in the TestUte class, I have added the driver registration
> > > >when the properties file gets loaded; this should not be
> > > >necessary if the H2 driver is built-in
> > > >
> > > >...
> > > >in.close();
> > > >new H2Driver().registerDriver();
> > > >...
> > > >
> > > >I guess maybe in the future we could "standardize" a bit more
> > > >the way someone can add a driver for a particular database,
> > > >without having to include it in the H2 distribution (I am thinking
> > > >of sqlite, for example, which has peculiar SQL but has some very
> > > >interesting cross-platform usages, where not all of Simpleorm would
> > > >work, but sufficiently to be interestin). We could look for a
> > > >system property like "simpleorm.extra.drivers" and use
> > > >the class names declared there, for example. This would
> > > >remove the need to support those external drivers, that would come
> > > >in separate jars from elsewhere.
> > > >
> > > >Hope this helps,
> > > >
> > > >Harry
> > > >
> > > >--- In
> > > ><mailto:SimpleORM%40yahoogroups.com><mailto:SimpleORM%40yahoogrou 
> > ps.com>[email protected],
> > > >Anthony Berglas <anthony@> wrote:
> > > > >
> > > > > Oops, I see what you have done, just extended HSQL Driver. I'll
> > > > > refactor a bit and add it.
> > > > >
> > > > > Please confirm the unit tests pass.
> > > > >
> > > > > Anthony
> > > > >
> > > > > At 07:39 PM 25/09/2008, Anthony Berglas wrote:
> > > > > >Hello Harry,
> > > > > >
> > > > > >Thanks for that.
> > > > > >
> > > > > >But before I include your code, what about the other things in
> > > > > >SDriverHSQL? In particular, is the support for SEQUENCES
the same
> > > > > >in H2 as it is in HSQL? Did you remove the code deliberately?
> > > > > >
> > > > > >Your loading code is OK, but if you look at the beginning of
> > > > > >SDriver.java you will see where drivers are loaded
> > > > > >automatically. I'll do that when your done.
> > > > > >
> > > > > >Anthony
> > > > > >
> > > > > >At 07:25 PM 23/09/2008, you wrote:
> > > > > >
> > > > > >>Hi,
> > > > > >>
> > > > > >>I've been using this just as you described, and it works fine.
> > > > > >>Here is the class I use :
> > > > > >>
> > > > > >>package org.hmn.jrsd.demo;
> > > > > >>
> > > > > >>import simpleorm.drivers.SDriverHSQL;
> > > > > >>import simpleorm.sessionjdbc.SDriver;
> > > > > >>
> > > > > >>/*
> > > > > >>*
> > > > > >>* Cree par Harry Karadimas a 9 sept. 08
> > > > > >>*/
> > > > > >>/**
> > > > > >>* The H2 is mostly HSQL (H2 is a fork, by the original
author of
> > > >HSQLDB)
> > > > > >>*/
> > > > > >>public class H2Driver
> > > > > >>extends SDriverHSQL
> > > > > >>{
> > > > > >>@Override
> > > > > >>protected String driverName() {
> > > > > >>return "H2 JDBC Driver";
> > > > > >>}
> > > > > >>
> > > > > >>}
> > > > > >>
> > > > > >>To use the driver, it must first be registered when the
> > > > > >>application starts :
> > > > > >>
> > > > > >>//we register the H2 driver
> > > > > >>new H2Driver().registerDriver();
> > > > > >>
> > > > > >>You can then connect to the H2 database as usual :
> > > > > >>
> > > > > >>try {
> > > > > >>Class.forName("org.h2.Driver");
> > > > > >>driverLoaded = true;
> > > > > >>}
> > > > > >>catch (Exception ex) {
> > > > > >>throw new SQLException("Could not load H2 driver ("+ex+")");
> > > > > >>}
> > > > > >>Connection cxn = DriverManager.getConnection(url, user,
password);
> > > > > >>
> > > > > >>I don't really know if that is the best way to do it, however.
> > > > > >>
> > > > > >>Harry
> > > > > >>
> > > > > >>--- In
> > > > > >><mailto:SimpleORM%40yahoogroups.com><mailto:SimpleORM%40yaho 
> > ogroups.com>[email protected],
> > > > > >>Anthony Berglas <anthony@> wrote:
> > > > > >> >
> > > > > >> > Have not done this yet. But if you copy the HSQL driver it
> >should
> > > > > >> > only require trivial changes. SimpleORM minimizes database
> > > > > >>dependent code.
> > > > > >> >
> > > > > >> > If you do this and it runs through the test cases then
please
> > > >post it
> > > > > >> > back to the list and I'll add it to the source.
> > > > > >> >
> > > > > >> > Anthony
> > > > > >> >
> > > > > >> > At 06:15 AM 23/09/2008, alspaughb wrote:
> > > > > >> > >Does SimpleORM support H2Database? I can't find an SDriver
> > > >subclass
> > > > > >> > >for it.
> > > > > >> > >
> > > > > >> > ><<<http://www.h2database.com>http://www.h2database.com>h 
> > ttp://www.h2database.com>http:/
> > > > /www.h2database.com
> > > > > >> > >
> > > > > >> > >I like the fact that H2 is lightweight, pure Java, and
> > > >supports multi
> > > > > >> > >version concurrency.
> > > > > >> > >
> > > > > >> > >Bruce
> > > > > >> >
> > > > > >> > Dr Anthony Berglas, anthony@ Mobile: +61 4 4838 8874
> > > > > >> > Just because it is possible to push twigs along the
ground with
> > > >ones
> > > > > >>nose
> > > > > >> > does not necessarily mean that is the best way to collect
> >firewood.
> > > > > >> >
> > > > > >>
> > > > > >>
> > > > > >
> > > > > >Dr Anthony Berglas, anthony@ Mobile: +61 4 4838 8874
> > > > > >Just because it is possible to push twigs along the ground with
> > > >ones nose
> > > > > >does not necessarily mean that is the best way to collect
firewood.
> > > > >
> > > > > Dr Anthony Berglas, anthony@ Mobile: +61 4 4838 8874
> > > > > Just because it is possible to push twigs along the ground
with ones
> > > >nose
> > > > > does not necessarily mean that is the best way to collect
firewood.
> > > > >
> > > >
> > > >
> > >
> > > Dr Anthony Berglas, anthony@ Mobile: +61 4 4838 8874
> > > Just because it is possible to push twigs along the ground with ones
> >nose
> > > does not necessarily mean that is the best way to collect firewood.
> > >
> >
> >
> 
> Dr Anthony Berglas, anthony@...       Mobile: +61 4 4838 8874
> Just because it is possible to push twigs along the ground with ones
nose
> does not necessarily mean that is the best way to collect firewood.
>



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/SimpleORM/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/SimpleORM/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[email protected] 
    mailto:[email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.