EvidentSolutions / dalesbred

Dalesbred - a database access library for Java
https://dalesbred.org
MIT License
54 stars 15 forks source link

Add H2 dialect to be able to use it for tests #20

Closed alecharp closed 9 years ago

alecharp commented 9 years ago

Hi,

I saw the Dialect class and all implementations but I would need h2 dialect for my tests (HSQLDB doesn't offer all the features I need)

my question: do you have any guidelines to do the implementation? The current implementations seem very basic. Is it that simple to add a new dialect?

Thanks!

komu commented 9 years ago

Hi,

You should be able to use h2 even without support from Dalesbred, you'll just get a log message at the startup saying something like "Could not detect dialect for product name 'h2', falling back to default." Dalesbred will then use its DefaultDialect, which doesn't provide access to any advanced database specific functionality, but should work well enough for most cases.

Since Dalesbred doesn't generate any SQL, but simply executes SQL given by the programmer, the dialects are indeed very simple: they mostly just work around some differences in JDBC-driver implementations or custom datatype-definitions. PostgreSQLDialect allows you to access PostgreSQL's native enums, for example. Most of the dialects are actually just empty implementations which are there just as placeholders to prevent the warning at startup.

So, if you need to access some functionality not specified by JDBC or if you have some specific problems with h2-driver which would need workarounds in Dalesbred, you'll need a custom dialect. But most probably you will not need it. However, it would be nice to include a "dummy default dialect" in Dalesbred. So I can add the support if you'll give me the product-name string that is written to log on startup. Alternatively you can add the dialect yourself, modify Dialect.detect() to detect it and submit a pull request.

Hope this helps!