Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Sequence support in DB2

>Does EclipseLink support DB2 SEQUENCE objects?
Currently it doesn't - but please consider contributing this functionality to Eclipselink yourself.
 
1. Implement the following methods in DB2Platform class (the code below is copied from PostgreSQLPlatfrom, also see OraclePlatform and InformixPlatform):
    /**
     *  INTERNAL:
     *  Indicates whether the platform supports sequence objects.
     *  This method is to be used *ONLY* by sequencing classes
     */
    public boolean supportsSequenceObjects() {
        return true;
    }
 
    /**
     * INTERNAL:
     * Returns query used to read value generated by sequence object (like Oracle sequence).
     * This method is called when sequence object NativeSequence is connected,
     * the returned query used until the sequence is disconnected.
     * If the platform supportsSequenceObjects then (at least) one of buildSelectQueryForSequenceObject
     * methods should return non-null query.
     */
    public ValueReadQuery buildSelectQueryForSequenceObject(String seqName, Integer size) {
        return new ValueReadQuery("select nextval(\'"  + getQualifiedName(seqName) + "\')");
    }
 
    /**
     * INTERNAL:
     * Override this method if the platform supports sequence objects.
     * Returns sql used to create sequence object in the database.
     */
    public Writer buildSequenceObjectCreationWriter(Writer writer, String fullSeqName, int increment, int start) throws IOException {
        writer.write("CREATE SEQUENCE ");
        writer.write(fullSeqName);
        if (increment != 1) {
            writer.write(" INCREMENT BY " + increment);
        }
        writer.write(" START WITH " + start);
        return writer;
    }
 
    /**
     * INTERNAL:
     * Override this method if the platform supports sequence objects.
     * Returns sql used to delete sequence object from the database.
     */
    public Writer buildSequenceObjectDeletionWriter(Writer writer, String fullSeqName) throws IOException {
        writer.write("DROP SEQUENCE ");
        writer.write(fullSeqName);
        return writer;
    }
 
    /**
     * INTERNAL:
     * Override this method if the platform supports sequence objects
     * and isAlterSequenceObjectSupported returns true.
     * Returns sql used to alter sequence object's increment in the database.
     */
    public Writer buildSequenceObjectAlterIncrementWriter(Writer writer, String fullSeqName, int increment) throws IOException {
        writer.write("ALTER SEQUENCE ");
        writer.write(fullSeqName);
        writer.write(" INCREMENT BY " + increment);
        return writer;
    }
 
    /**
     * INTERNAL:
     * Override this method if the platform supports sequence objects
     * and it's possible to alter sequence object's increment in the database.
     */
    public boolean isAlterSequenceObjectSupported() {
        return true;
    }
 
2.    Because of Eclipse Foundation rules, in order for us to accept the changed code, it must be submitted through Bugzilla.
(https://bugs.eclipse.org/bugs/query.cgi    Classification: RT      Product Eclipselink).
 
After that the code will be reviewed and (if all is well) checked in by one of the committers.
 
 
The behaviour you are seeing right now is due to Eclipselink attempting to use Identity instead of sequence object on the platforms that don't support sequence objects.
Thanks,
 
Andrei
----- Original Message -----
Sent: Friday, February 06, 2009 6:42 AM
Subject: [eclipselink-users] Sequence support in DB2

Hi All,

Does EclipseLink support DB2 SEQUENCE objects? I have an application that should run on Oracle and DB2 databases. I’m using @SequenceGenerator in my entities for generating unique IDs. This works fine under Oracle but in DB2 I get NPE while accessing the ID after the entity was persisted. It looks like my entity reference was set to null after calling persist.

 

My scenario:

 

PackageJPAEntity packageEntity = new PackageJPAEntity();

……

packageEntity = em.merge(packageEntity);

……

em.persist(packageEntity);

……

return packageEntity.getPackageId();

 

 

 

The NPE is thrown from the line with the return statement.

 

I would appreciate any help.

 

Peter Szaniszlo 
Software Developer

Fortent
Pu
škinova 3
040 01
Košice, Slovakia

www.fortent.com

 


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Back to the top