Re: Smartest way to realize sequence PID

From: Jürgen Saar (jsaa..eb.de)
Date: Sat Oct 16 2004 - 06:01:05 EDT

  • Next message: Oliver Layug: "out of memory error"

    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 : Sat Oct 16 2004 - 06:01:10 EDT