Class Sequence

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable
    Direct Known Subclasses:
    DefaultSequence, StandardSequence, UUIDSequence

    public abstract class Sequence
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Cloneable

    Purpose: Abstract class to define sequencing.

    Description A sequence defines how generated ids are obtained. The main sequence types are TableSequence and NativeSequence. Descriptors using sequencing will use the sequence object defined in their session's DatabaseLogin with the name matching their sequence name. If a specific sequence is not defined for the name the DatabaseLogin's default sequence will be used.

    See Also:
    TableSequence, NativeSequence, Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      Sequence()  
      Sequence​(java.lang.String name)
      Create a new sequence with the name.
      Sequence​(java.lang.String name, int size)
      Create a new sequence with the name and sequence pre-allocation size.
      Sequence​(java.lang.String name, int size, int initialValue)  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object clone()  
      static boolean equalNameAndSize​(Sequence seq1, Sequence seq2)
      INTERNAL: Used in equals.
      boolean equals​(java.lang.Object obj)  
      org.eclipse.persistence.internal.databaseaccess.Platform getDatasourcePlatform()  
      java.lang.Object getGeneratedValue​(org.eclipse.persistence.internal.databaseaccess.Accessor accessor, org.eclipse.persistence.internal.sessions.AbstractSession writeSession)
      INTERNAL: Return the newly-generated sequencing value.
      abstract java.lang.Object getGeneratedValue​(org.eclipse.persistence.internal.databaseaccess.Accessor accessor, org.eclipse.persistence.internal.sessions.AbstractSession writeSession, java.lang.String seqName)
      INTERNAL: Return the newly-generated sequencing value.
      java.util.Vector getGeneratedVector​(org.eclipse.persistence.internal.databaseaccess.Accessor accessor, org.eclipse.persistence.internal.sessions.AbstractSession writeSession)
      INTERNAL: Return a Vector of newly-generated sequencing values.
      abstract java.util.Vector getGeneratedVector​(org.eclipse.persistence.internal.databaseaccess.Accessor accessor, org.eclipse.persistence.internal.sessions.AbstractSession writeSession, java.lang.String seqName, int size)
      INTERNAL: Return a Vector of newly-generated sequencing values.
      int getInitialValue()  
      java.lang.String getName()  
      int getPreallocationSize()  
      java.lang.String getQualified​(java.lang.String str)
      INTERNAL:
      java.lang.String getQualifier()
      INTERNAL:
      int hashCode()  
      boolean isConnected()
      PUBLIC: Indicates that Sequence is connected.
      boolean isCustomQualifier()
      INTERNAL:
      boolean isNative()  
      boolean isTable()  
      boolean isUnaryTable()  
      abstract void onConnect()
      INTERNAL: This method is called when Sequencing object is created.
      void onConnect​(org.eclipse.persistence.internal.databaseaccess.Platform platform)
      INTERNAL: This method is called when Sequencing object is created.
      abstract void onDisconnect()
      INTERNAL: This method is called when Sequencing object is destroyed.
      void onDisconnect​(org.eclipse.persistence.internal.databaseaccess.Platform platform)
      INTERNAL: This method is called when Sequencing object is destroyed.
      protected void setDatasourcePlatform​(org.eclipse.persistence.internal.databaseaccess.Platform platform)  
      void setInitialValue​(int initialValue)  
      void setName​(java.lang.String name)  
      void setPreallocationSize​(int size)  
      void setQualifier​(java.lang.String qualifier)
      INTERNAL:
      void setShouldAlwaysOverrideExistingValue​(boolean shouldAlwaysOverrideExistingValue)
      ADVANCED: Set that to true if the sequence should always override the existing pk value.
      abstract boolean shouldAcquireValueAfterInsert()
      INTERNAL: Indicates whether sequencing value should be acquired after INSERT.
      boolean shouldAlwaysOverrideExistingValue()
      INTERNAL: Indicates whether the existing pk value should always be overridden by the sequence.
      boolean shouldAlwaysOverrideExistingValue​(java.lang.String seqName)
      INTERNAL: Indicates whether the existing pk value should always be overridden by the sequence.
      boolean shouldUsePreallocation()
      INTERNAL: Indicates whether several sequencing values should be acquired at a time and be kept by TopLink.
      abstract boolean shouldUseTransaction()
      INTERNAL: Indicates whether TopLink should internally call beginTransaction() before getGeneratedValue/Vector, and commitTransaction after.
      java.lang.String toString()  
      protected void verifyPlatform​(org.eclipse.persistence.internal.databaseaccess.Platform otherPlatform)
      INTERNAL: Make sure that the sequence is not used by more than one platform.
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • name

        protected java.lang.String name
      • size

        protected int size
      • platform

        protected org.eclipse.persistence.internal.databaseaccess.Platform platform
      • initialValue

        protected int initialValue
      • depth

        protected int depth
      • qualifier

        protected java.lang.String qualifier
      • isCustomQualifier

        protected boolean isCustomQualifier
      • shouldAlwaysOverrideExistingValue

        protected boolean shouldAlwaysOverrideExistingValue
    • Constructor Detail

      • Sequence

        public Sequence()
      • Sequence

        public Sequence​(java.lang.String name)
        Create a new sequence with the name.
      • Sequence

        public Sequence​(java.lang.String name,
                        int size)
        Create a new sequence with the name and sequence pre-allocation size.
      • Sequence

        public Sequence​(java.lang.String name,
                        int size,
                        int initialValue)
    • Method Detail

      • isNative

        public boolean isNative()
      • isTable

        public boolean isTable()
      • isUnaryTable

        public boolean isUnaryTable()
      • getName

        public java.lang.String getName()
      • setName

        public void setName​(java.lang.String name)
      • getPreallocationSize

        public int getPreallocationSize()
      • setPreallocationSize

        public void setPreallocationSize​(int size)
      • getInitialValue

        public int getInitialValue()
      • setInitialValue

        public void setInitialValue​(int initialValue)
      • clone

        public java.lang.Object clone()
        Overrides:
        clone in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • equalNameAndSize

        public static boolean equalNameAndSize​(Sequence seq1,
                                               Sequence seq2)
        INTERNAL: Used in equals.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • setDatasourcePlatform

        protected void setDatasourcePlatform​(org.eclipse.persistence.internal.databaseaccess.Platform platform)
      • getDatasourcePlatform

        public org.eclipse.persistence.internal.databaseaccess.Platform getDatasourcePlatform()
      • shouldAcquireValueAfterInsert

        public abstract boolean shouldAcquireValueAfterInsert()
        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.
      • shouldUsePreallocation

        public boolean shouldUsePreallocation()
        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.
      • shouldUseTransaction

        public abstract boolean shouldUseTransaction()
        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.
      • getGeneratedValue

        public abstract java.lang.Object getGeneratedValue​(org.eclipse.persistence.internal.databaseaccess.Accessor accessor,
                                                           org.eclipse.persistence.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).
        Parameters:
        accessor - Accessor is a separate sequencing accessor (may be null);
        writeSession - Session is a Session used for writing (either ClientSession or DatabaseSession);
        seqName - String is sequencing number field name
      • getGeneratedValue

        public java.lang.Object getGeneratedValue​(org.eclipse.persistence.internal.databaseaccess.Accessor accessor,
                                                  org.eclipse.persistence.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).
        Parameters:
        accessor - Accessor is a separate sequencing accessor (may be null);
        writeSession - Session is a Session used for writing (either ClientSession or DatabaseSession);
      • getGeneratedVector

        public abstract java.util.Vector getGeneratedVector​(org.eclipse.persistence.internal.databaseaccess.Accessor accessor,
                                                            org.eclipse.persistence.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).
        Parameters:
        accessor - Accessor is a separate sequencing accessor (may be null);
        writeSession - Session is a Session used for writing (either ClientSession or DatabaseSession);
        seqName - String is sequencing number field name
        size - int number of values to preallocate (output Vector size).
      • getGeneratedVector

        public java.util.Vector getGeneratedVector​(org.eclipse.persistence.internal.databaseaccess.Accessor accessor,
                                                   org.eclipse.persistence.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).
        Parameters:
        accessor - Accessor is a separate sequencing accessor (may be null);
        writeSession - Session is a Session used for writing (either ClientSession or DatabaseSession);
      • onConnect

        public void onConnect​(org.eclipse.persistence.internal.databaseaccess.Platform platform)
        INTERNAL: This method is called when Sequencing object is created. Don't override this method.
      • onConnect

        public abstract void onConnect()
        INTERNAL: This method is called when Sequencing object is created. If it requires initialization, subclass should override this method.
      • onDisconnect

        public void onDisconnect​(org.eclipse.persistence.internal.databaseaccess.Platform platform)
        INTERNAL: This method is called when Sequencing object is destroyed. Don't override this method.
      • onDisconnect

        public abstract void onDisconnect()
        INTERNAL: This method is called when Sequencing object is destroyed. If it requires deinitialization, subclass should override this method.
      • isConnected

        public boolean isConnected()
        PUBLIC: Indicates that Sequence is connected.
      • verifyPlatform

        protected void verifyPlatform​(org.eclipse.persistence.internal.databaseaccess.Platform otherPlatform)
        INTERNAL: Make sure that the sequence is not used by more than one platform.
      • setQualifier

        public void setQualifier​(java.lang.String qualifier)
        INTERNAL:
      • isCustomQualifier

        public boolean isCustomQualifier()
        INTERNAL:
      • getQualifier

        public java.lang.String getQualifier()
        INTERNAL:
      • getQualified

        public java.lang.String getQualified​(java.lang.String str)
        INTERNAL:
      • setShouldAlwaysOverrideExistingValue

        public void setShouldAlwaysOverrideExistingValue​(boolean shouldAlwaysOverrideExistingValue)
        ADVANCED: Set that to true if the sequence should always override the existing pk value.
      • shouldAlwaysOverrideExistingValue

        public boolean shouldAlwaysOverrideExistingValue()
        INTERNAL: Indicates whether the existing pk value should always be overridden by the sequence. As always the version of the method taking seqName is provided for the benefit of DefaultSequence.
      • shouldAlwaysOverrideExistingValue

        public boolean shouldAlwaysOverrideExistingValue​(java.lang.String seqName)
        INTERNAL: Indicates whether the existing pk value should always be overridden by the sequence.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object