persistence@glassfish.java.net

Re: Question about code in StandardSequence.createVector() related to a posting in GF Discussion Forum

From: Andrei Ilitchev <andrei.ilitchev_at_oracle.com>
Date: Tue, 28 Mar 2006 14:42:24 -0500

This exception always happens on the first attempt to obtain a sequence
number after sequence was created - in case initialValue < allocationSize:
CREATE SEQUENCE CHANNEL_SEQ INCREMENT BY 25;
SELECT CHANNEL_SEQ FROM DUAL // returns 1, causes the exception.

That could be easily fixed in
oracle.toplink.essentials.tools.schemaframework.OracleSequenceDefinition:
currently initialValue used ad START WITH, what should happen is:
startWithValue = initialValue + allocationSize + 1;

Suppose initialValue =1; allocationSize = 25; then startWithValue = 27 =>
the first sequence value read will be 27 and the first sequence value
allocated to an object will be 27 - 25 = 2 - next value after initialValue
(TableSequence behaves exactly in the same way).

Thanks,

Andrei

To cure it: in
----- Original Message -----
From: "Andrei Ilitchev" <andrei.ilitchev_at_oracle.com>
To: "Pramod Gopinath" <Pramod.Gopinath_at_Sun.COM>; "Tom Ware"
<tom.ware_at_oracle.com>; "Gordon Yorke" <gordon.yorke_at_oracle.com>;
<persistence_at_glassfish.dev.java.net>
Sent: Tuesday, March 28, 2006 2:11 PM
Subject: Re: Question about code in StandardSequence.createVector() related
to a posting in GF Discussion Forum


> The check safeguards from the following situation: in the db Oracle
> sequence is defined with increment = 1; but specifies sequence with
> allocationSize=50.
> Correct setup: sequence increment in the db and allocationSize in Java
> should be the same.
>
> Thanks,
>
> Andrei
>
> ----- Original Message -----
> From: "Pramod Gopinath" <Pramod.Gopinath_at_Sun.COM>
> To: "Tom Ware" <tom.ware_at_oracle.com>; "Gordon Yorke"
> <gordon.yorke_at_oracle.com>; "Andrei Ilitchev" <andrei.ilitchev_at_oracle.com>;
> <persistence_at_glassfish.dev.java.net>
> Sent: Tuesday, March 28, 2006 1:35 PM
> Subject: Question about code in StandardSequence.createVector() related to
> a posting in GF Discussion Forum
>
>
>> Hi Andrei/Tom/Gordon
>> This question has arisen based on a posting in the Glassfish discussion
>> forum :
>> http://forums.java.net/jive/thread.jspa?threadID=14185&tstart=0
>>
>> If the user has defined an allocation size < 50 in their entity class,
>> then we would get an exception from the toplink code. The complete stack
>> trace is present in the discussion forum posting. I am listing just the
>> top few lines :
>> Caused by: Exception [TOPLINK-7027] (Oracle TopLink Essentials - 2006.3
>> (Build 060324)): oracle.toplink.essentials.exceptions.ValidationException
>> Exception Description: The sequence named [CHANNEL_SEQ] is setup
>> incorrectly. Its increment does not match its pre-allocation size.
>> at
>> oracle.toplink.essentials.exceptions.ValidationException.sequenceSetupIncorrectly(ValidationException.java:1278)
>> at
>> oracle.toplink.essentials.sequencing.StandardSequence.createVector(StandardSequence.java:149)
>> at
>> oracle.toplink.essentials.sequencing.StandardSequence.getGeneratedVector(StandardSequence.java:85)
>>
>>
>> I was looking at the code in
>> oracle.toplink.essentials.sequencing.StandardSequence.createVector()
>> lines 144 through 150 and had a question about this code.
>>
>> Why do we have the following check in the code
>> nextSequence = nextSequence.subtract(new BigDecimal(size));
>>
>> This code would always return a value < 0 if the allocation size
>> specified by the user is less than the default allocation size (50)
>> defined in Sequence.java.
>>
>> Why is this check there in the code.
>>
>> Thanks
>> Pramod
>>
>