Re: Sequence generator - as a service

View: New views
3 Messages — Rating Filter:   Alert me  

Re: Sequence generator - as a service

by Jan Vissers :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Let me try and clarify.

Basically I want to have an entity, say

  @Entity
  public class Master implements Serializable {
      @Id
      private long id;

      public void setId(long id) {
          this.id = id;
      }
  }

For which the primary key will be created separately - in the most
efficient way (like EclipseLink which caches a number of unique numbers
from a sequence) - in order to set it later. The creation of the key value
and the actual storage of the Master are not within the same persistency
context.

-J.




> Well, it looks like you want to have eclipselink run some queries,
> nothing strange there. Is there something I'm missing?
>
> ./tch
>
>
>
> On Wed, Aug 6, 2008 at 5:52 PM, Jan Vissers <Jan.Vissers@...>
> wrote:
>> Might be a silly/hard to understand question...
>>
>> How would I use EclipseLink as a means to implement sequence block
>> pattern? What I want to do is this:
>>
>>
>> a. Remote client (Flex) calls Java service do so work, amongst others it
>>   passes in an identifier (initially '0').
>>
>> b. Java service uses 'sequence block' to obtain next unique identifier
>>   (not '0') when the passed in identifier is '0'. --> this would be
>>   the place where I would want to use EclipseLink <--
>>
>> c. Java service performs requested work and returns the identifier,
>> which
>>   might have been not '0' in the first place i.e. passed in at a.
>>   or initialized at b.
>>
>> d. Remote client (Flex) continues to call a. as long as there is work to
>>   be done. If everything is completed continues with e.
>>
>> e. Remote client (Flex) calls into (another) Java service to 'finalize'
>> the
>>   operation. It passes in the not '0' identifier and other stuff.
>>
>> f. Java service uses not '0' identifier as the primary key (@Id) via
>>   setId() of a record to be created.
>>
>> Now, let us first wait and see who understands what I'm trying to do
>> here ;-)
>>
>> Thanks,
>> Jan.
>>
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@...
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@...
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>


_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: Sequence generator - as a service

by tch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

So if you want eclipselink to run a query to get the value of your id
right? If so you could use the snippet I posted earlier. How you get
your nextval depends on your dbms though, not eclipselink.

./tch



On Wed, Aug 6, 2008 at 6:06 PM, Jan Vissers <Jan.Vissers@...> wrote:

> Let me try and clarify.
>
> Basically I want to have an entity, say
>
>  @Entity
>  public class Master implements Serializable {
>      @Id
>      private long id;
>
>      public void setId(long id) {
>          this.id = id;
>      }
>  }
>
> For which the primary key will be created separately - in the most
> efficient way (like EclipseLink which caches a number of unique numbers
> from a sequence) - in order to set it later. The creation of the key value
> and the actual storage of the Master are not within the same persistency
> context.
>
> -J.
>
>
>
>
>> Well, it looks like you want to have eclipselink run some queries,
>> nothing strange there. Is there something I'm missing?
>>
>> ./tch
>>
>>
>>
>> On Wed, Aug 6, 2008 at 5:52 PM, Jan Vissers <Jan.Vissers@...>
>> wrote:
>>> Might be a silly/hard to understand question...
>>>
>>> How would I use EclipseLink as a means to implement sequence block
>>> pattern? What I want to do is this:
>>>
>>>
>>> a. Remote client (Flex) calls Java service do so work, amongst others it
>>>   passes in an identifier (initially '0').
>>>
>>> b. Java service uses 'sequence block' to obtain next unique identifier
>>>   (not '0') when the passed in identifier is '0'. --> this would be
>>>   the place where I would want to use EclipseLink <--
>>>
>>> c. Java service performs requested work and returns the identifier,
>>> which
>>>   might have been not '0' in the first place i.e. passed in at a.
>>>   or initialized at b.
>>>
>>> d. Remote client (Flex) continues to call a. as long as there is work to
>>>   be done. If everything is completed continues with e.
>>>
>>> e. Remote client (Flex) calls into (another) Java service to 'finalize'
>>> the
>>>   operation. It passes in the not '0' identifier and other stuff.
>>>
>>> f. Java service uses not '0' identifier as the primary key (@Id) via
>>>   setId() of a record to be created.
>>>
>>> Now, let us first wait and see who understands what I'm trying to do
>>> here ;-)
>>>
>>> Thanks,
>>> Jan.
>>>
>>> _______________________________________________
>>> eclipselink-users mailing list
>>> eclipselink-users@...
>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>>
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@...
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>
>
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@...
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: Sequence generator - as a service

by James Sutherland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

So my understanding is that you want to assign the sequence numbers to your objects yourself, outside of the transaction where the objects are persisted.

You can do this in EclipseLink using the EclipseLink Session API getNextSequenceNumberValue(Class).  You will need to cast your JPA EntityManager to get the EclipseLink Session from it.

Jan Vissers wrote:
Let me try and clarify.

Basically I want to have an entity, say

  @Entity
  public class Master implements Serializable {
      @Id
      private long id;

      public void setId(long id) {
          this.id = id;
      }
  }

For which the primary key will be created separately - in the most
efficient way (like EclipseLink which caches a number of unique numbers
from a sequence) - in order to set it later. The creation of the key value
and the actual storage of the Master are not within the same persistency
context.

-J.