You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by Michael Hart <mi...@baselinesols.com> on 2004/08/10 11:59:19 UTC
Mod to support HSQLDB sequences
Hey Guys,
I've searched around for this a bit, but haven't been able to find
anything on it so far - the sequence support introduced in HSQLDB 1.7.2
(http://hsqldb.sourceforge.net/doc/guide/ch02.html#N104BA) seems to work
fine with SequenceManagerNextValImpl when the following code is added to
org/apache/ojb/broker/platforms/PlatformHsqldbImpl.java (brief
explanation below):
public class PlatformHsqldbImpl extends PlatformDefaultImpl
{
...
public String createSequenceQuery(String sequenceName)
{
return "CREATE SEQUENCE " + sequenceName;
}
public String nextSequenceQuery(String sequenceName)
{
return "CALL NEXT VALUE FOR " + sequenceName;
}
public String dropSequenceQuery(String sequenceName)
{
return "DROP SEQUENCE " + sequenceName;
}
...
}
Sequences are created starting at 0 (as with Postgres and probably other
DBs) - to change this, add a "START WITH n" at the end of the create
query. Also, they are implemented as Java Integers in the backend when
specified like this, so you may want to add an "AS BIGINT" after the
create statement (but before the "START WITH") to support larger values.
The SYSTEM_SEQUENCES table (which seems to be a virtual table) stores
all of the sequences in HSQLDB - NB, the documentation is incorrect when
it states that the NEXT_VALUE field stores the next sequence value -
there is no such field, it's actually called START_WITH. It seems to me
that the "NEXT VALUE FOR" expression will return the START_WITH value
and then increment the field - this post-increment (as opposed to pre)
constrasts to the Postgres (for eg) functionality, but probably makes no
difference as far as OJB is concerned.
Note that I haven't tested this extensively at all - only very briefly.
Let me know if there are any problems.
Cheers,
Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org
Re: Mod to support HSQLDB sequences
Posted by Thomas Dudziak <to...@first.fhg.de>.
Michael Hart wrote:
> Hey Guys,
>
> I've searched around for this a bit, but haven't been able to find
> anything on it so far - the sequence support introduced in HSQLDB
> 1.7.2 (http://hsqldb.sourceforge.net/doc/guide/ch02.html#N104BA) seems
> to work fine with SequenceManagerNextValImpl when the following code
> is added to org/apache/ojb/broker/platforms/PlatformHsqldbImpl.java
> (brief explanation below):
>
> public class PlatformHsqldbImpl extends PlatformDefaultImpl
> {
>
> ...
>
> public String createSequenceQuery(String sequenceName)
> {
> return "CREATE SEQUENCE " + sequenceName;
> }
>
> public String nextSequenceQuery(String sequenceName)
> {
> return "CALL NEXT VALUE FOR " + sequenceName;
> }
>
> public String dropSequenceQuery(String sequenceName)
> {
> return "DROP SEQUENCE " + sequenceName;
> }
>
> ...
>
> }
>
> Sequences are created starting at 0 (as with Postgres and probably
> other DBs) - to change this, add a "START WITH n" at the end of the
> create query. Also, they are implemented as Java Integers in the
> backend when specified like this, so you may want to add an "AS
> BIGINT" after the create statement (but before the "START WITH") to
> support larger values.
>
> The SYSTEM_SEQUENCES table (which seems to be a virtual table) stores
> all of the sequences in HSQLDB - NB, the documentation is incorrect
> when it states that the NEXT_VALUE field stores the next sequence
> value - there is no such field, it's actually called START_WITH. It
> seems to me that the "NEXT VALUE FOR" expression will return the
> START_WITH value and then increment the field - this post-increment
> (as opposed to pre) constrasts to the Postgres (for eg) functionality,
> but probably makes no difference as far as OJB is concerned.
>
> Note that I haven't tested this extensively at all - only very
> briefly. Let me know if there are any problems.
A while back we thought about updating the Hsqldb that comes with OJB
but there were some problems with Torque. Could you try OJB's unit tests
to see whether they run as before (or better) ?
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org