Oracle Fusion Middleware Java API Reference for Oracle ADF Model
11g Release 1 (11.1.1.1.0)

E10653-02

oracle.jbo.server
Class SequenceImpl

java.lang.Object
  extended by oracle.jbo.server.SequenceImpl
All Implemented Interfaces:
java.io.Serializable, DomainInterface

public class SequenceImpl
extends java.lang.Object
implements DomainInterface, java.io.Serializable

An encapsulation of a database sequence. This class provides a Java wrapper for a database sequence and may be used whenever it is necessary to query sequence values from a database sequence. See the discussion below for more information on using this class to query database sequences instead of instantiating a dynamic View Object.

Creating View Objects and Generating Sequence Numbers

If you use createViewObjectFromQueryStmt to create View Objects that query database sequences, do not depend on the view object to correctly generate sequence numbers. The process of querying the View Object for sequence numbers causes sequence numbers to be generated twice. For example, if you create a View Object from a query statement which gets the next value from a sequence:

  String sqlStr = "SELECT CRM_INT_PROCESSES_SEQ.NEXTVAL FROM DUAL ";
  ViewObject View0 =appMod.createViewObjectFromQueryStmt("SeqView", sqlStr);
  Row idRow = View0.first();
 

When View0.first() (or last(), for that matter) is executed, the query is executed twice and sequence numbers are lost. Setting the View Object to setForwardOnly also has no effect.

This problem is caused by a JDBC bug that forces "prefetch" to be greater than or equal to 1. That is, when you execute the query for the View Object, it fetches at least one row before you call next(). This is why the sequence number increases by two.

Instead of instantiating a View Object, explicitly create a new sequence:

 import oracle.jbo.server.SequenceImpl;
  .
  .
  SequenceImpl s = new SequenceImpl(sequenceName, thisTransaction);
    Number sVal = s.getSequenceNumber();
  .
  .
    setYourSequenceAttribute(sVal);
  .
  

Since:
Jdeveloper 3.0
See Also:
ViewObject, DBTransaction, ApplicationModule, Serialized Form

Constructor Summary
SequenceImpl()
           
SequenceImpl(java.lang.String seqName, ApplicationModule am)
          Constructor.
SequenceImpl(java.lang.String seqName, DBTransaction trans)
          Constructor.
 
Method Summary
static java.lang.Object createInstanceWithAM(java.lang.String seqName, ApplicationModule am)
          A class method that may be invoked to retrieve the next value from a database sequence.
 boolean equals(java.lang.Object other)
          Test if the specified value is equal to this SequenceImpl object.
 java.lang.Object getData()
          Internal: Applications should not use this method. Returns a sequence value.
 Number getSequenceNumber()
          Returns a sequence value.
 int hashCode()
          Computes a hash code for this SequenceImpl object.
 void setContext(DomainOwnerInterface owner, Transaction trans, java.lang.Object ctx)
          Internal: Applications should not use this method.
 java.lang.String toString()
          For testing purposes only: Returns a string representation of the generated sequence value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SequenceImpl

public SequenceImpl()

SequenceImpl

public SequenceImpl(java.lang.String seqName,
                    ApplicationModule am)
Constructor.

Parameters:
seqName - The name of the database sequence that will be used to generate sequence values.
am - The application module instance that will provide the JDBC connection for the sequence requests.

SequenceImpl

public SequenceImpl(java.lang.String seqName,
                    DBTransaction trans)
Constructor.

Parameters:
seqName - The name of the database sequence that will be used to generate sequence values.
trans - The Transaction instance that will provide the JDBC connection for the sequence requests.
Method Detail

createInstanceWithAM

public static java.lang.Object createInstanceWithAM(java.lang.String seqName,
                                                    ApplicationModule am)
A class method that may be invoked to retrieve the next value from a database sequence.

Parameters:
seqName - The name of the database sequence that will be used to generate the sequence value.
am - The application module instance that will provide the JDBC connection for the sequence request

getData

public java.lang.Object getData()
Internal: Applications should not use this method. Returns a sequence value. The sequence value is generated by the database sequence that was specified when constructing the SequenceImpl object.

This method will increment the encapsulated database sequence the first time that it is invoked. Subsequent calls will return the same value.

Specified by:
getData in interface DomainInterface
Returns:
An object representing the next sequence value.

getSequenceNumber

public Number getSequenceNumber()
Returns a sequence value. The sequence value is generated by the database sequence that was specified when constructing the SequenceImpl object.

This method will increment the encapsulated database sequence the first time that it is invoked. Subsequent calls will return the same value.

Returns:
An instance of oracle.jbo.domain.Number representing the next sequence value.

setContext

public void setContext(DomainOwnerInterface owner,
                       Transaction trans,
                       java.lang.Object ctx)
Internal: Applications should not use this method.

Specified by:
setContext in interface DomainInterface

toString

public java.lang.String toString()
For testing purposes only: Returns a string representation of the generated sequence value.

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object other)
Test if the specified value is equal to this SequenceImpl object.

Overrides:
equals in class java.lang.Object
Parameters:
other - The object to which the SequenceImpl should be compared.
Returns:
true The specified object is equal to the this SequenceImpl.

hashCode

public int hashCode()
Computes a hash code for this SequenceImpl object.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code of this SequenceImpl object.

Oracle Fusion Middleware Java API Reference for Oracle ADF Model
11g Release 1 (11.1.1.1.0)

E10653-02

Copyright © 1997, 2009, Oracle. All rights reserved.