See http://www.sdmagazine.com/uml/thinking/s9912to.shtml - this article
adresses keys generation problem.
Dimitri
http://dima.dhs.org
On Tue, 12 Sep 2000, Navaneeth wrote:
> Hi Luis ,
>
> Just a simple question ...
>
> Why not use a simple java class to do this for you ??
> Why did u go for a session ejb ??
>
> Regards,
> Navaneeth
>
>
>
>
> ----- Original Message -----
> From: Luis Canals <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, September 08, 2000 9:12 PM
> Subject: Re: Generating ID???
>
>
> > Hi,
> >
> > well, I implment this method in a Session Bean in order to be able
> > to change this Session Bean to access to another "exotic" database without
> > recompiling or redeploying your Entity Beans. Again, an example: you can
> > have two types of this Session Bean called DataBaseSpecificOracle and
> > DataBaseSpecificSQLServer, with methods specifics for each database; at
> > deploying time, you only have to link the reference in your JNDI to the
> > desired Session Bean, depending on the database.
> >
> > In the other hand, you say "supposedly written by experts"
> .."experts"....
> > I think there are more experts in discussion lists like that. If your
> > question has not been made by "these experts" (and answered), I think you
> > know more about EJBs than them... it's logical, isn't it? If you don't
> know
> > anything, you can't ask anything; if you know a lot, you have a lot of
> > questions too.
> >
> > Bye.
> > Luis Canals.
> >
> > -----Original Message-----
> > From: Jerson Chua [mailto:[EMAIL PROTECTED]]
> > Sent: viernes, 08 de septiembre de 2000 17:09
> > To: [EMAIL PROTECTED]
> > Subject: Re: Generating ID???
> >
> >
> > Hello Luis...
> > That's what we're currently using but instead of implementing it in a
> > session bean, we
> > implemented the query in a private method of the particular entity bean
> > using it.
> > I'm asking this question cause I thought that there's something wrong with
> > the
> > implementation. I thought I'm missing something cause articles like the
> one
> > I read are
> > supposedly written by experts.
> >
> > Jerson
> >
> > --- Luis Canals <[EMAIL PROTECTED]> wrote:
> > > Hello,
> > >
> > > I think your right: it doesn't works because two (or more) beans
> > can
> > > take the same id. My solution is a query (to the database) to obtain the
> > > next value for the primary key. For example, in Oracle, something like
> > > SEQ_XXX.NEXTVAL. To do this, I propose the use of Stateless Session Bean
> > > (specific to each Database) which will take the next value with a query
> to
> > > database. If you change your database, your only must change this
> > Stateless
> > > Session Bean.
> > >
> > > For example, you have something like that:
> > > public class DataBaseSpecificLikeOracleBean implements SessionBean {
> > > public int nextPrimaryKey(String table) {
> > > String query1 =
> > > ctx.lookup("java:comp/env/SQLNextValFirstPart"); // For example
> > > SELECT SEQ_
> > > String query2 =
> > > ctx.lookup("java:comp/env/SQLNextValSecondPart"); // For example FROM
> DUAL
> > >
> > > query = query1 + table + query2;
> > > // Execute the query and return the result
> > > }
> > > }
> > >
> > > In your Entity Bean:
> > >
> > > public class CustomerEntityBean implements EntityBean {
> > > // Instead of getEJBHome().findNewest() use..
> > > DataBaseSpecific dbs =
> ctx.lookup("EJBDataBaseSpecific");
> > > nextKey = dbs.nextPrimaryKey(0
> > > protected long getNextKey() {
> > > long nextKey = 0;
> > >
> > > Customer newestCustomer = ((CustomerHome)
> > > entityContext.getEJBHome()).findNewest();
> > > // the implementation of findNewest is not shown,
> > > // i guess the findNewest returns the bean with the
> > highest
> > > id/primary key
> > > // in my point of view this is like select max(id) from
> > > customer + 1
> > > nextKey =
> > ((CustomerKey)newestCustomer.getPrimaryKey()).key
> > > + 1;
> > > return nextKey;
> > > }
> > > }
> > >
> > >
> > > And you need, in your JNDI the two parts of a query to obtain next
> value.
> > > You can use another DataBaseSpecificBean (for other databses) with the
> > same
> > > interface and put it instead of this implementation.
> > > This is not a final solution, only an idea... please, think about it and
> > > rebuild it!
> > >
> > > Regards.
> > >
> > > Luis Canals.
> > >
> > >
> > > -----Original Message-----
> > > From: Jerson Chua [mailto:[EMAIL PROTECTED]]
> > > Sent: viernes, 08 de septiembre de 2000 9:39
> > > To: [EMAIL PROTECTED]
> > > Subject: Generating ID???
> > >
> > >
> > > Hello Guys...
> > >
> > > I've read an IBM article and it has an example in generating id/primary
> > key.
> > > I have a
> > > doubt that 1 or more bean can get the same id. I want to verify this
> > doubt.
> > > Is this
> > > scenario possible?
> > >
> > > 1. Customerbean1 retrieves max id
> > > 2. Customerbean2 retrieves max id
> > > 3. Customerbean1 increments maxid and store to db
> > > 4. Customerbean2 increments maxid and store to db
> > >
> > > public class CustomerEntityBean {
> > > public void ejbCreate(String name, int type) {
> > > key = getNextKey();
> > > ...
> > > }
> > >
> > > protected long getNextKey() {
> > > long nextKey = 0;
> > >
> > > Customer newestCustomer = ((CustomerHome)
> > > entityContext.getEJBHome()).findNewest();
> > > // the implementation of findNewest is not shown,
> > > // i guess the findNewest returns the bean with the
> > highest
> > > id/primary key
> > > // in my point of view this is like select max(id) from
> > > customer + 1
> > > nextKey =
> > ((CustomerKey)newestCustomer.getPrimaryKey()).key
> > > + 1;
> > > return nextKey;
> > > }
> > > }
> > >
> > > What's your opinion? Will this design work?
> > >
> > > Jerson
> > >
> > >
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Yahoo! Mail - Free email you can access from anywhere!
> > > http://mail.yahoo.com/
> > >
> > >
> >
> ===========================================================================
> > > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> > body
> > > of the message "signoff EJB-INTEREST". For general help, send email to
> > > [EMAIL PROTECTED] and include in the body of the message "help".
> > >
> > > This message and any files transmitted with it are confidential and
> > intended
> > > solely for the use of the individual or entity to whom they are
> addressed.
> > > No confidentiality or privilege is waived or lost by any wrong
> > transmission.
> > > If you have received this message in error, please immediately destroy
> it
> > > and kindly notify the sender by reply email.
> > > You must not, directly or indirectly, use, disclose, distribute, print,
> or
> > > copy any part of this message if you are not the intended recipient.
> > > Opinions, conclusions and other information in this message that do not
> > > relate to the official business of Newknow shall be understood as
> neither
> > > given nor endorsed by it.
> > >
> > >
> >
> ===========================================================================
> > > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> > body
> > > of the message "signoff EJB-INTEREST". For general help, send email to
> > > [EMAIL PROTECTED] and include in the body of the message "help".
> > >
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Yahoo! Mail - Free email you can access from anywhere!
> > http://mail.yahoo.com/
> >
> >
> ===========================================================================
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> > of the message "signoff EJB-INTEREST". For general help, send email to
> > [EMAIL PROTECTED] and include in the body of the message "help".
> >
> > This message and any files transmitted with it are confidential and
> intended
> > solely for the use of the individual or entity to whom they are addressed.
> > No confidentiality or privilege is waived or lost by any wrong
> transmission.
> > If you have received this message in error, please immediately destroy it
> > and kindly notify the sender by reply email.
> > You must not, directly or indirectly, use, disclose, distribute, print, or
> > copy any part of this message if you are not the intended recipient.
> > Opinions, conclusions and other information in this message that do not
> > relate to the official business of Newknow shall be understood as neither
> > given nor endorsed by it.
> >
> >
> ===========================================================================
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> > of the message "signoff EJB-INTEREST". For general help, send email to
> > [EMAIL PROTECTED] and include in the body of the message "help".
> >
> >
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff EJB-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".