I like the change. It matches postgresql nicely. (I didn't test it, I'm only commentting on the behavior) What do you think, Thomas?
Hm... actually, the more I think about this, the default behavior
_should_ be to use the 'tablename_columnname_seq'. It'd likely break
current behavior for people who are mapping this way (like my stuff) but
it cleans up code for those using the SERIAL column. I'd like to see
this be the default behavior when used within PostgreSQL. Comments
anyone?
Speaking of sequences, I'm still trying to see how we can implement the
RETURNING clause within postgresql. The database doesn't support it
currently. And as of PostgreSQL 7.2, the OID is optional for tables.
So, calling getInsertedOID() may not return a valid value.
(Also, the OID has turned into a long value, rather than an int, but
it's backwards compatiable. In addition to getInsertedOID() which return
an int (old way), they now have getLastOID() which returns a long (new
way))
I want to find a better way to do the sequences with Postgresql.
(Current technique can't use getInsertedOID() if we're using a pooling
driver that doesn't support it anyways) Ideas anyone? Anyone wanting
to help with this, let me know.
On Tue, 2001-12-11 at 13:49, Daniel Serodio wrote:
> Here I am, replying to myself... Well, did a little research on the
> subject, and `[tablename]_[columnname]_sec' really is the default
> sequence name for SERIAL columns on PostgreSQL. Quoting from the
> PostgreSQL Users Guide:
>
> ---8<---------------------------------------------------------------------
>
> The Serial Type
>
> The serial type is a special-case type constructed by Postgres from
> other existing components. It is typically used to create unique
> identifiers for table entries. In the current implementation, specifying
>
> CREATE TABLE tablename (colname SERIAL);
>
> is equivalent to specifying:
>
> CREATE SEQUENCE tablename_colname_seq;
> CREATE TABLE tablename
> (colname INT4 DEFAULT nextval('tablename_colname_seq');
> CREATE UNIQUE INDEX tablename_colname_key on tablename (colname);
>
> ---8<---------------------------------------------------------------------
>
> I modified SequenceKeyGenerator.java (in
> org.exolab.castor.jdo.drivers), and now `{1}' expands to the columns'
> name. If you don't use `{1}' in your sequence, you won't notice any
> changes, so I'm pretty positive I didn't break anything.
>
> Attached is the patch against Castor 0.9.3, please comment on it. I'm
> using the patched Castor right now, I'll report anything strange.
>
>
> On Tue, 2001-12-11 at 14:38, Daniel Serodio wrote:
> > I'm learning to use Castor JDO, and I have run into the following
> > problem:
> >
> > I use `<tablename>_<columnname>_seq' for naming my PostgreSQL
> > sequences. I the docs, I can see that `{0}' expands to the table name.
> > Is there some way to make `{1}' expand to the column name? I tried:
> >
> > <key-generator name="SEQUENCE">
> > <param name="sequence" value="{0}_{1}_seq"/>
> > </key-generator>
> >
> > But got ``java.sql.SQLException: ERROR: pg_aclcheck: class
> > "product_{1}_seq" not found''.
>
>
> --
> []'s
> Daniel Serodio <[EMAIL PROTECTED]>
>
> ----
>
> --- SequenceKeyGenerator.java Tue Dec 11 18:35:48 2001
> +++ SequenceKeyGenerator.java.dist Tue Dec 11 18:35:46 2001
> @@ -170,7 +170,7 @@
> } else {
> if ( _style == BEFORE_INSERT ) {
> stmt = conn.prepareStatement("SELECT nextval('" +
> - MessageFormat.format( _seqName, new String[]
>{tableName, primKeyName}) + "')" );
> + MessageFormat.format( _seqName, new String[]
>{tableName}) + "')" );
> rs = stmt.executeQuery();
> } else if (_triggerPresent && _factoryName.equals( "postgresql" )) {
> Object insStmt = props.get("insertStatement");
> @@ -185,7 +185,7 @@
>
> } else {
> stmt = conn.prepareStatement("SELECT " + _factory.quoteName(
> - MessageFormat.format( _seqName, new String[]
>{tableName, primKeyName} ) +
> + MessageFormat.format( _seqName, new String[]
>{tableName} ) +
> ".currval") + " FROM " + _factory.quoteName( tableName
>) );
> rs = stmt.executeQuery();
> }
--
Virtually,
Ned Wolpert <[EMAIL PROTECTED]>
D08C2F45: 28E7 56CB 58AC C622 5A51 3C42 8B2B 2739 D08C 2F45
msg03533/pgp00000.pgp
Description: PGP signature
