You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-dev@db.apache.org by Craig Russell <Cr...@Sun.COM> on 2005/09/17 21:24:25 UTC
Sequence factory
Hi,
I was thinking it would be a good idea to provide a sample sequence
factory in the JDO API package, along the lines of your example below.
That is a good nontransactional factory implementation that we can
use for testing, but not for production use, as you have pointed out.
I'm thinking it would be nice to provide a transactional
implementation also but I don't think we have the infrastructure in
the specification to have a standard transactional sequence factory.
Craig
On Sep 16, 2005, at 12:13 AM, Andy Jefferson wrote:
>> 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
>
Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!