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

Sequence

public abstract class Sequence extends Object implements Serializable, Cloneable

Purpose: Define an interface for sequencing customization.

Description: Customary sequencing behavior could be achieved by implementing this interface and passing the instance to DatabaseSession.getSequencingControl().setValueGenerationPolicy(..). TopLink internally uses the same method to set its default implementation of this interface, which provides native sequencing and table sequencing. Note that the following methods: shouldAcquireValueAfterInsert(); shouldUsePreallocation(); shouldUseSeparateConnection(); shouldUseTransaction(); are called only once - during creation of the sequencing object. Therefore during the lifetime of sequencing object these methods should return the same values as when called for the first time. If this is not true - resetSequencing (call SequencingControl.resetSequencing()).

Responsibilities:

  • Define the APIs for customary sequencing.
see
SequencingControl

Fields Summary
protected String
name
protected int
size
protected Platform
platform
protected int
initialValue
protected int
depth
Constructors Summary
public Sequence()


      
        super();
    
public Sequence(String name)

        this();
        setName(name);
    
public Sequence(String name, int size)

        this();
        setName(name);
        setPreallocationSize(size);
    
public Sequence(String name, int size, int initialValue)

        this();
        setName(name);
        setPreallocationSize(size);
        setInitialValue(initialValue);
    
Methods Summary
public java.lang.Objectclone()

        try {
            Sequence clone = (Sequence)super.clone();
            if (isConnected()) {
                clone.depth = 1;
                clone.onDisconnect(getDatasourcePlatform());
            }
            return clone;
        } catch (Exception exception) {
            throw new InternalError("Clone failed");
        }
    
public static booleanequalNameAndSize(oracle.toplink.essentials.sequencing.Sequence seq1, oracle.toplink.essentials.sequencing.Sequence seq2)

        if (seq1 == seq2) {
            return true;
        }
        return seq1.getName().equals(seq2.getName()) && (seq1.getPreallocationSize() == seq2.getPreallocationSize());
    
public booleanequals(java.lang.Object obj)

        if (obj instanceof Sequence) {
            return equalNameAndSize(this, (Sequence)obj);
        } else {
            return false;
        }
    
public oracle.toplink.essentials.internal.databaseaccess.PlatformgetDatasourcePlatform()

        return platform;
    
public abstract java.lang.ObjectgetGeneratedValue(oracle.toplink.essentials.internal.databaseaccess.Accessor accessor, oracle.toplink.essentials.internal.sessions.AbstractSession writeSession, java.lang.String seqName)
INTERNAL: Return the newly-generated sequencing value. Used only in case preallocation is not used (shouldUsePreallocation()==false). Accessor may be non-null only in case shouldUseSeparateConnection()==true. Even in this case accessor could be null - if SequencingControl().shouldUseSeparateConnection()==false; Therefore in case shouldUseSeparateConnection()==true, implementation should handle both cases: use a separate connection if provided (accessor != null), or get by without it (accessor == null).

param
accessor Accessor is a separate sequencing accessor (may be null);
param
writeSession Session is a Session used for writing (either ClientSession or DatabaseSession);
param
seqName String is sequencing number field name

public java.lang.ObjectgetGeneratedValue(oracle.toplink.essentials.internal.databaseaccess.Accessor accessor, oracle.toplink.essentials.internal.sessions.AbstractSession writeSession)
INTERNAL: Return the newly-generated sequencing value. Used only in case preallocation is not used (shouldUsePreallocation()==false). Accessor may be non-null only in case shouldUseSeparateConnection()==true. Even in this case accessor could be null - if SequencingControl().shouldUseSeparateConnection()==false; Therefore in case shouldUseSeparateConnection()==true, implementation should handle both cases: use a separate connection if provided (accessor != null), or get by without it (accessor == null).

param
accessor Accessor is a separate sequencing accessor (may be null);
param
writeSession Session is a Session used for writing (either ClientSession or DatabaseSession);

        return getGeneratedValue(accessor, writeSession, getName());
    
public abstract java.util.VectorgetGeneratedVector(oracle.toplink.essentials.internal.databaseaccess.Accessor accessor, oracle.toplink.essentials.internal.sessions.AbstractSession writeSession, java.lang.String seqName, int size)
INTERNAL: Return a Vector of newly-generated sequencing values. Used only in case preallocation is used (shouldUsePreallocation()==true). Accessor may be non-null only in case shouldUseSeparateConnection()==true. Even in this case accessor could be null - if SequencingControl().shouldUseSeparateConnection()==false; Therefore in case shouldUseSeparateConnection()==true, implementation should handle both cases: use a separate connection if provided (accessor != null), or get by without it (accessor == null).

param
accessor Accessor is a separate sequencing accessor (may be null);
param
writeSession Session is a Session used for writing (either ClientSession or DatabaseSession);
param
seqName String is sequencing number field name
param
size int number of values to preallocate (output Vector size).

public java.util.VectorgetGeneratedVector(oracle.toplink.essentials.internal.databaseaccess.Accessor accessor, oracle.toplink.essentials.internal.sessions.AbstractSession writeSession)
INTERNAL: Return a Vector of newly-generated sequencing values. Used only in case preallocation is used (shouldUsePreallocation()==true). Accessor may be non-null only in case shouldUseSeparateConnection()==true. Even in this case accessor could be null - if SequencingControl().shouldUseSeparateConnection()==false; Therefore in case shouldUseSeparateConnection()==true, implementation should handle both cases: use a separate connection if provided (accessor != null), or get by without it (accessor == null).

param
accessor Accessor is a separate sequencing accessor (may be null);
param
writeSession Session is a Session used for writing (either ClientSession or DatabaseSession);

        return getGeneratedVector(accessor, writeSession, getName(), getPreallocationSize());
    
public intgetInitialValue()

        return initialValue;
    
public java.lang.StringgetName()

        return name;
    
public intgetPreallocationSize()

        return size;
    
public booleanisConnected()
PUBLIC: Indicates that Sequence is connected.

        return platform != null;
    
public voidonConnect(oracle.toplink.essentials.internal.databaseaccess.Platform platform)
INTERNAL: This method is called when Sequencing object is created. Don't override this method.

param
ownerSession DatabaseSession

        if (isConnected()) {
            verifyPlatform(platform);
        } else {
            setDatasourcePlatform(platform);
            onConnect();
        }
        depth++;
    
protected abstract voidonConnect()
INTERNAL: This method is called when Sequencing object is created. If it requires initialization, subclass should override this method.

param
ownerSession DatabaseSession

public voidonDisconnect(oracle.toplink.essentials.internal.databaseaccess.Platform platform)
INTERNAL: This method is called when Sequencing object is destroyed. Don't overridethis method.

        if (isConnected()) {
            depth--;
            if (depth == 0) {
                onDisconnect();
                setDatasourcePlatform(null);
            }
        }
    
protected abstract voidonDisconnect()
INTERNAL: This method is called when Sequencing object is destroyed. If it requires deinitialization, subclass should override this method.

protected voidsetDatasourcePlatform(oracle.toplink.essentials.internal.databaseaccess.Platform platform)

        this.platform = platform;
    
public voidsetInitialValue(int initialValue)

        this.initialValue = initialValue;
    
public voidsetName(java.lang.String name)

        this.name = name;
    
public voidsetPreallocationSize(int size)

        this.size = size;
    
public abstract booleanshouldAcquireValueAfterInsert()
INTERNAL: Indicates whether sequencing value should be acquired after INSERT. Note that preallocation could be used only in case sequencing values should be acquired before insert (this method returns false). In default implementation, it is true for table sequencing and native sequencing on Oracle platform, false for native sequencing on other platforms.

public abstract 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.

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

public booleanshouldOverrideExistingValue(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.

param
existingValue Object is a non-null value of PK-mapped attribute.

        return shouldOverrideExistingValue(getName(), existingValue);
    
public booleanshouldUsePreallocation()
INTERNAL: Indicates whether several sequencing values should be acquired at a time and be kept by TopLink. This in only possible in case sequencing numbers should be acquired before insert (shouldAcquireValueAfterInsert()==false). In default implementation, it is true for table sequencing and native sequencing on Oracle platform, false for native sequencing on other platforms.

        return !shouldAcquireValueAfterInsert();
    
public abstract booleanshouldUseTransaction()
INTERNAL: Indicates whether TopLink should internally call beginTransaction() before getGeneratedValue/Vector, and commitTransaction after. In default implementation, it is true for table sequencing and false for native sequencing.

protected voidverifyPlatform(oracle.toplink.essentials.internal.databaseaccess.Platform otherPlatform)
INTERNAL: Make sure that the sequence is not used by more than one platform.

        if (getDatasourcePlatform() != otherPlatform) {
            String hashCode1 = Integer.toString(System.identityHashCode(getDatasourcePlatform()));
            String name1 = ((DatasourcePlatform)getDatasourcePlatform()).toString() + '(" + hashCode1 + ')";

            String hashCode2 = Integer.toString(System.identityHashCode(otherPlatform));
            String name2 = ((DatasourcePlatform)otherPlatform).toString() + '(" + hashCode2 + ')";

            throw ValidationException.sequenceCannotBeConnectedToTwoPlatforms(getName(), name1, name2);
        }