FileDocCategorySizeDatePackage
OracleSequenceDefinition.javaAPI DocGlassfish v2 API7412Tue May 22 16:54:54 BST 2007oracle.toplink.essentials.tools.schemaframework

OracleSequenceDefinition

public class OracleSequenceDefinition extends SequenceDefinition

Purpose: Support Oracle native sequence creation. Oracle has custom support for sequences.

Fields Summary
protected int
increment
The increment can be used to support pre-allocation.
protected int
start
The start is the first sequence value that will be available for TopLink to use.
Constructors Summary
public OracleSequenceDefinition(String name, int preallocationSize)


         
        super(name);
        setIncrement(preallocationSize);
    
public OracleSequenceDefinition(String name, int preallocationSize, int start)

        super(name);
        // sequence value should be positive
        if(start <= 0) {
            start = 1;
        }
        setIncrement(preallocationSize);
        setStart(start);
	
public OracleSequenceDefinition(String name)

        this(name, 1);
	
public OracleSequenceDefinition(NativeSequence sequence)

        this(sequence.getName(), sequence.getPreallocationSize(), sequence.getInitialValue());
	
Methods Summary
public voidalterIncrement(oracle.toplink.essentials.internal.sessions.AbstractSession session, java.io.Writer schemaWriter)
INTERNAL: Execute the SQL required to alter sequence increment. Assume that the sequence exists.

        if (schemaWriter == null) {
            this.alterOnDatabase(session);
        } else {
            this.buildAlterIncrementWriter(session, schemaWriter);
        }
    
public voidalterOnDatabase(oracle.toplink.essentials.internal.sessions.AbstractSession session)
INTERNAL: Execute the SQL required to alter sequence increment. Assume that the sequence exists.

        try {
            session.executeNonSelectingCall(new oracle.toplink.essentials.queryframework.SQLCall(buildAlterIncrementWriter(session, new StringWriter()).toString()));
        } catch (DatabaseException exception) {
            createOnDatabase(session);
        }
    
public java.io.WriterbuildAlterIncrementWriter(oracle.toplink.essentials.internal.sessions.AbstractSession session, java.io.Writer writer)
INTERNAL: Return the SQL required to alter INCREMENT BY

        try {
            writer.write("ALTER SEQUENCE ");
            writer.write(getFullName());
            writer.write(" INCREMENT BY " + getIncrement());
        } catch (IOException ioException) {
            throw ValidationException.fileError(ioException);
        }
        return writer;
    
public java.io.WriterbuildCreationWriter(oracle.toplink.essentials.internal.sessions.AbstractSession session, java.io.Writer writer)
INTERNAL: Return the SQL required to create the Oracle sequence object.

        try {
            writer.write("CREATE SEQUENCE ");
            writer.write(getFullName());
            if (getIncrement() != 1) {
                writer.write(" INCREMENT BY " + getIncrement());
            }
            // startWith value calculated using the initial value and increment.
            // The first time TopLink calls select nextval, the value equal to startWith is returned.
            // The first sequence value TopLink may assign is startWith - getIncrement() + 1.
            int startWith = getStart() + getIncrement() - 1;
            writer.write(" START WITH " + startWith);
        } catch (IOException ioException) {
            throw ValidationException.fileError(ioException);
        }
        return writer;
    
public java.io.WriterbuildDeletionWriter(oracle.toplink.essentials.internal.sessions.AbstractSession session, java.io.Writer writer)
INTERNAL: Return the SQL required to drop the Oracle sequence object.

        try {
            writer.write("DROP SEQUENCE ");
            writer.write(getFullName());
        } catch (IOException ioException) {
            throw ValidationException.fileError(ioException);
        }
        return writer;
    
public booleancheckIfExist(oracle.toplink.essentials.internal.sessions.AbstractSession session)
INTERNAL: Check if the sequence object already exists, in which case dont create it.

        try {
            session.executeSelectingCall(new oracle.toplink.essentials.queryframework.SQLCall("SELECT " + getName() + ".NEXTVAL FROM DUAL"));
        } catch (DatabaseException exception) {
            return false;
        }
        return true;
    
public intgetIncrement()
The increment can be used to support pre-allocation.

        return increment;
    
public intgetStart()
The start used as a starting value for sequence

        return start;
    
public booleanisAlterSupported()
INTERNAL: Indicates whether alterIncrement is supported

        return true;
    
public voidsetIncrement(int increment)
The increment can be used to support pre-allocation.

        this.increment = increment;
    
public voidsetStart(int start)
The start used as a starting value for sequence

        this.start = start;
    
public voidsetStartAndIncrement(int value)
The start used as a starting value for sequence

        setStart(1);
        setIncrement(value);