db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Jefferson <a...@jpox.org>
Subject Re: jpox cannot find sequence
Date Fri, 16 Sep 2005 07:13:58 GMT
> Can you help us define a table-based incrementing sequence that can
> be used with the TCK? We (TCK team) will write a factory sequence
> class but as you know, the specification is short on how to define it.

Hi Craig, Karan,

JPOX provides some sequences internally, and also we have a sample "factory" 
sequence in our unit tests. Here's an example

<sequence name="ProductSequence" datastore-sequence="PRODUCT_SEQ" 
strategy="contiguous"/>
Where the RDBMS supports sequences then JPOX will use the RDBMS sequence of 
name "PRODUCT_SEQ". Where the RDBMS doesn't support sequences then JPOX will 
utilise a table in the datastore (by default called SEQUENCE_TABLE) and the 
table will have one row per sequence name, storing the sequence name, and the 
current value.


As for "factory" sequences, I interpret this as something a user can provide 
to utilise their own (maybe corporate) way of generating sequences. Clearly a 
JDO implementation could provide builtin "factory" sequences, but JPOX 
doesn't right now. An incredibly simple example of a "factory" that we use in 
our unit tests is a sequence that just does counting - not intended for use 
in real world apps, just a test of the factory class process

public class SimpleSequenceFactory
{
    public static Sequence newInstance()
    {
        return new SimpleSequence("My Sequence");
    }
}

public class SimpleSequence implements Sequence
{
    String name;
    long current = 0;

    public SimpleSequence(String name)
    {
        this.name = name;
    }

    /**
     * 
     * @see javax.jdo.datastore.Sequence#getName()
     */
    public String getName()
    {
        return name;
    }

    /**
     * 
     * @see javax.jdo.datastore.Sequence#next()
     */
    public Object next()
    {
        current++;
        return new Long(current);
    }

    /**
     * 
     * @see javax.jdo.datastore.Sequence#nextValue()
     */
    public long nextValue()
    {
        current++;
        return current;
    }

    /**
     * 
     * @see javax.jdo.datastore.Sequence#allocate(int)
     */
    public void allocate(int arg0)
    {
    }

    /**
     * 
     * @see javax.jdo.datastore.Sequence#current()
     */
    public Object current()
    {
        return new Long(current);
    }

    /**
     * 
     * @see javax.jdo.datastore.Sequence#currentValue()
     */
    public long currentValue()
    {
        return current;
    }
}


If the TCK wants to define its own factory method that does what our 
"SEQUENCE_TABLE" builtin does then we can point you to the relevant bits of 
code in our CVS.


-- 
Andy

Mime
View raw message