I believe if you look, there's a class called CounterUtils that wraps all
this nicely.

Can't remember the usage, but offhand it's something like

CounterUtils.getNextID(jndiLocation, beanname);

Cheers,
Mike

australia.internet.com - http://australia.internet.com
Email: [EMAIL PROTECTED]
Phone: (612) 9251 3397
Fax: (612) 9251 2819
Mobile: 0416 106090

INTERNET.COM - THE INTERNET INDUSTRY PORTAL

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Joseph B.
Ottinger
Sent: Friday, May 12, 2000 6:17 AM
To: Orion-Interest
Subject: obtaining sequences portably for entity EJB


Since this is a common problem that ends up getting asked a lot, and there
are few published good ways to go about it... it turns out orion has a
file in the news app called "counter.jar" that does just this. Here's the
quick-and-dirty on its use:

1) Add the counter.jar to the application.xml file as an ejb module.

2) Make sure that the ejb-jar.xml contains a reference to the Counter
bean, which should look something like this:

                <ejb-ref>
                        <description>The id counter for the
entity</description>
                        <ejb-ref-name>ejb/Counter</ejb-ref-name>
                        <ejb-ref-type>Entity</ejb-ref-type>
                        <home>com.evermind.ejb.CounterHome</home>
                        <remote>com.evermind.ejb.Counter</remote>
                </ejb-ref>

3) In your EJB code, have this kind of sequence:

public void ejbCreate() throws RemoteException, CreateException
        {
        try
                {
                        CounterHome chome=(CounterHome)new
InitialContext().lookup("java:comp/env/ejb/Counter");
                        Counter ctr;
                        try
                                {
                                ctr=chome.findByPrimaryKey("mybeannameid");
                                }
                        catch(FinderException fe)
                                {
                                ctr=chome.create("mybeannameid");
                                }
                        id=ctr.getNextID());
                }
        catch(NamingException ne)
                {
                throw new CreateException("NamingException:\nCould not"+
" create EJB: "+ne.getMessage());
                }
        }

This will set id - a long - to the next available sequence.

-----------------------------------------------------------
Joseph B. Ottinger               [EMAIL PROTECTED]
http://cupid.suninternet.com/~joeo      HOMES.COM Developer




Reply via email to