FileDocCategorySizeDatePackage
StandardSequence.javaAPI DocGlassfish v2 API6794Tue May 22 16:54:52 BST 2007oracle.toplink.essentials.sequencing

StandardSequence

public abstract class StandardSequence extends Sequence

Purpose: An abstract class providing default sequence behavior.

Fields Summary
Constructors Summary
public StandardSequence()

        super();
    
public StandardSequence(String name)

        super(name);
    
public StandardSequence(String name, int size)

        super(name, size);
    
public StandardSequence(String name, int size, int initialValue)

        super(name, size, initialValue);
    
Methods Summary
protected java.util.VectorcreateVector(java.lang.Number sequence, java.lang.String seqName, int size)
INTERNAL: given sequence = 10, size = 5 will create Vector (6,7,8,9,10)

param
seqName String is sequencing number field name
param
existingValue Object is a non-null value of PK-mapped attribute.
param
size int size of Vector to create.

        BigDecimal nextSequence;
        BigDecimal increment = new BigDecimal(1);

        if (sequence instanceof BigDecimal) {
            nextSequence = (BigDecimal)sequence;
        } else {
            nextSequence = new BigDecimal(sequence.doubleValue());
        }

        Vector sequencesForName = new Vector(size);

        nextSequence = nextSequence.subtract(new BigDecimal(size));

        // Check for incorrect values return to validate that the sequence is setup correctly.
        // PRS 36451 intvalue would wrap
        if (nextSequence.doubleValue() < -1) {
            throw ValidationException.sequenceSetupIncorrectly(seqName);
        }

        for (int index = size; index > 0; index--) {
            nextSequence = nextSequence.add(increment);
            sequencesForName.addElement(nextSequence);
        }
        return sequencesForName;
    
public java.lang.ObjectgetGeneratedValue(oracle.toplink.essentials.internal.databaseaccess.Accessor accessor, oracle.toplink.essentials.internal.sessions.AbstractSession writeSession, java.lang.String seqName)

        if (shouldUsePreallocation()) {
            return null;
        } else {
            Number value = updateAndSelectSequence(accessor, writeSession, seqName, 1);
            if (value == null) {
                throw DatabaseException.errorPreallocatingSequenceNumbers();
            }
            return value;
        }
    
public java.util.VectorgetGeneratedVector(oracle.toplink.essentials.internal.databaseaccess.Accessor accessor, oracle.toplink.essentials.internal.sessions.AbstractSession writeSession, java.lang.String seqName, int size)

        if (shouldUsePreallocation()) {
            Number value = updateAndSelectSequence(accessor, writeSession, seqName, size);
            if (value == null) {
                throw DatabaseException.errorPreallocatingSequenceNumbers();
            }
            return createVector(value, seqName, size);
        } else {
            return null;
        }
    
public voidonConnect()

        // does nothing
    
public voidonDisconnect()

        // does nothing
    
public abstract booleanshouldAcquireValueAfterInsert()

public booleanshouldOverrideExistingValue(java.lang.String seqName, java.lang.Object existingValue)
INTERNAL: Indicates whether existing attribute value should be overridden. This method is called in case an attribute mapped to PK of sequencing-using descriptor contains non-null value. Default implementation is: Always override for "after insert" sequencing, override non-positive Numbers for "before insert" sequencing.

param
seqName String is sequencing number field name
param
existingValue Object is a non-null value of PK-mapped attribute.

        if (shouldAcquireValueAfterInsert()) {
            return true;
        } else {
            // Check if the stored number is greater than zero (a valid sequence number)
            if (existingValue instanceof BigDecimal) {
                if (((BigDecimal)existingValue).signum() <= 0) {
                    return true;
                }
            } else if (existingValue instanceof BigInteger) {
                if (((BigInteger)existingValue).signum() <= 0) {
                    return true;
                }
            }
            //CR#2645: Fix for String ClassCastException.  Now we don't assume
            //anything which is not a BigDecimal to be a Number.
            else if (existingValue instanceof Number && (((Number)existingValue).longValue() <= 0)) {
                return true;
            }

            return false;
        }
    
public abstract booleanshouldUseTransaction()

protected abstract java.lang.NumberupdateAndSelectSequence(oracle.toplink.essentials.internal.databaseaccess.Accessor accessor, oracle.toplink.essentials.internal.sessions.AbstractSession writeSession, java.lang.String seqName, int size)