Hello Navaneeth,
Suppose you have your EJBs in a JAR file and suppose you have designed it to
use databases like, for example Oracle. Suppose now you're using a class to
query to database for the next primary key.
Now we have a JAR file with the EJBs and this class.
At this moment, suppose I want to deploy your components in my system. And
suppose I have MySQL. There is no problem, ok.
But suppose I have not a database like Oracle, for example a database which
generates the primary with another method... and the class we use to do this
is not valid.
A solution could be change this class with another implementation but with
the same name (un-jar the file, obtain the new class, re-jar, and everything
to have two different classes with the same name! ... argh!). Think that all
those things must be done by me: a deployer, not the developer. Think that I
don't know anything about your source code.
But if you had used a session bean to query for the next primary key, you
only have to give me the new component (another session bean with other
classes -other names, other implementations-) specially developed to access
to my database. At deployer time, I only have to put (and to bind) the
suitable component to obtain the next key from database.
It's only an idea. I want you to comment it; it will be appreciated.
Thank you. Regards
Luis Canals.
-----Original Message-----
From: Navaneeth [mailto:[EMAIL PROTECTED]]
Sent: martes, 12 de septiembre de 2000 14:26
To: [EMAIL PROTECTED]
Subject: Re: Generating ID???
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".
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".