Re: Smartest way to realize sequence PID

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Mon Oct 18 2004 - 21:53:23 EDT

  • Next message: Stefaan Huysentruyt: "Re: filtering to-many relationship list"

    When writing an answer to Ken, I was thinking about something like that
    too (though Ken hasn't commented further on his needs). Thanks for the
    good example. Actually implementing this properly to support concurrent
    access would require some work (and probably a lookup table)... or an
    entity bean ;-)

    On Oct 16, 2004, at 6:01 AM, Jürgen Saar wrote:
    > I don't know if I understand ist the right way, but is sounds
    > like my problem with invoiceNo.
    >
    > In Germany this has to be a strict set of Numbers
    > where not one may miss.
    >
    > It has to be for example 1, 2 , 3, 4, ...
    > and not 1, 2, 4, 5, 8, ...
    >
    > This is for controlling the correct tax ...
    >
    > This Number must not be used as PK.
    >
    > --- Juergen ---
    >
    > andru..bjectstyle.org schrieb am 14.10.04 16:43:03:
    >>
    >> Hi Ken,
    >>
    >> You didn't mention if "id" is a database primary key of TUser. Is it?
    >> If
    >> so you can simply rely on Cayenne default PK generation mechanism
    >> (http://objectstyle.org/cayenne/userguide/design/autopk.html). You
    >> don't
    >> really need to do anything special for it, it will just work.
    >>
    >> If not, then the best idea IMO would still be to take advantage of
    >> Cayenne
    >> PkGenerator, though I need to understand your requirements before I
    >> can
    >> comment on that further.
    >>
    >> Andrus
    >>
    >>
    >>> Hi every one.
    >>> I want your advice to realize sequenced primary id.
    >>> (like SERIAL data type in Postgres)
    >>>
    >>> Follow is my idea.But I think it is not samrt way.
    >>> It use many memory space and CPU power.
    >>> -------------------------------------------------------
    >>> public class TUser extends _TUser {
    >>>
    >>> public Integer nextId() {
    >>> int maxId = 0;
    >>>
    >>> DataContext ctx = DataContext.createDataContext();
    >>> SelectQuery query = new SelectQuery(TUser.class);
    >>> List list = ctx.performQuery(query);
    >>>
    >>> Iterator i = list.iterator();
    >>> while(i.hasNext()) {
    >>> TUser user = (TUser)i.next();
    >>>
    >>> int tempId = user.getId().intValue();
    >>>
    >>> if(tempId > maxId){
    >>> maxId = tempId;
    >>> }
    >>> }
    >>>
    >>> return new Integer(maxId + 1);
    >>> }
    >>> }
    >>> --------------------------------------------------------------
    >>> //insert the data
    >>> tUser.setId(tUser.nextId());
    >>> tUser.setAccount(userForm.getAccount());
    >>> tUser.setPass(userForm.getPass());
    >>> ctx.commitChanges(org.apache.log4j.Level.WARN);
    >>> --------------------------------------------------------------
    >>>
    >>> If some one has realized that. Please tell me the way to realize.
    >>>
    >>> Ken Yasue.
    >>
    >>
    >>
    >
    >
    > __________________________________________________________
    > Mit WEB.DE FreePhone mit hoechster Qualitaet ab 0 Ct./Min.
    > weltweit telefonieren! http://freephone.web.de/?mc=021201
    >
    >



    This archive was generated by hypermail 2.0.0 : Mon Oct 18 2004 - 21:53:27 EDT