xdoclet entity and dao help

Discussion in 'Java' started by William Zumwalt, Sep 25, 2004.

  1. I'm learning to work w/ DAO's and have this question. I'm trying to pull
    my database code out of my entity and and make use of DAO's. My DAO
    class is being generated from my entity by xdoclet, even though there's
    not much in it.

    I have the following in my entity bean ...

    /**
    * @ejb.create-method
    */
    public String ejbCreate(String id, String desc) throws
    ejbCreateException {
    HashMap memento = new HashMap();

    memento.put(SERIAL, serial = id);
    memento.put(DESC, description = desc);

    MyDAO.create(memento);

    return serial;
    }

    My question is how do I define (in this case) a create() method of my
    DAO which will look something like this (but hasn't been generated yet)
    ....

    public abstract class MyDAO {
    static public void create(HashMap data) throws PersistanceException {
    CreateThing.getInstance().execute(data);
    }
    }

    I saw the @dao.call, but not sure how to use it.

    Any help much appreciated.

    Will
     
    William Zumwalt, Sep 25, 2004
    #1
    1. Advertising

  2. William Zumwalt

    Sudsy Guest

    William Zumwalt wrote:
    <snip>
    > My question is how do I define (in this case) a create() method of my
    > DAO which will look something like this (but hasn't been generated yet)
    > ...
    >
    > public abstract class MyDAO {
    > static public void create(HashMap data) throws PersistanceException {
    > CreateThing.getInstance().execute(data);
    > }
    > }
    >
    > I saw the @dao.call, but not sure how to use it.
    >
    > Any help much appreciated.


    I added the following to one of my entity beans:

    * @ejb.dao class="classname"

    and added the dao task to my ejbdoclet. It generated the DAO interface
    with a create method which accepts a single argument of type of the bean
    class. I would imagine that it's up to you (the programmer) to invoke
    the create method in your ejbCreate. Don't know if this helps...
     
    Sudsy, Sep 26, 2004
    #2
    1. Advertising

  3. In article <>,
    Sudsy <> wrote:

    > William Zumwalt wrote:
    > <snip>
    > > My question is how do I define (in this case) a create() method of my
    > > DAO which will look something like this (but hasn't been generated yet)
    > > ...
    > >
    > > public abstract class MyDAO {
    > > static public void create(HashMap data) throws PersistanceException {
    > > CreateThing.getInstance().execute(data);
    > > }
    > > }
    > >
    > > I saw the @dao.call, but not sure how to use it.
    > >
    > > Any help much appreciated.

    >
    > I added the following to one of my entity beans:
    >
    > * @ejb.dao class="classname"
    >
    > and added the dao task to my ejbdoclet. It generated the DAO interface
    > with a create method which accepts a single argument of type of the bean
    > class. I would imagine that it's up to you (the programmer) to invoke
    > the create method in your ejbCreate. Don't know if this helps...
    >


    But as you can see, I am invoking the create method in my ejbCreate. And
    I left out @ejb.dao at the class level declaration of my entity bean
    because that just seems to name the interface w/ a given name from me.
    My DAO's are being generated, but ... and I think what you said may help
    a bit, something to do with defining the method of my DAO inside a DAO
    task. It's that code that goes inside the methods of my DAO's that I'm
    trying to figure out how and where to put. The code within my entities
    seems ok for now.
     
    William Zumwalt, Sep 26, 2004
    #3
  4. William Zumwalt

    Sudsy Guest

    William Zumwalt wrote:
    <snip>
    > But as you can see, I am invoking the create method in my ejbCreate. And
    > I left out @ejb.dao at the class level declaration of my entity bean
    > because that just seems to name the interface w/ a given name from me.
    > My DAO's are being generated, but ... and I think what you said may help
    > a bit, something to do with defining the method of my DAO inside a DAO
    > task. It's that code that goes inside the methods of my DAO's that I'm
    > trying to figure out how and where to put. The code within my entities
    > seems ok for now.


    Sorry, I should have mentioned that a lot of the magic happens in the
    <classname>CMP.java file. A static synchronized getDAO method is
    defined. It gets even spiffier if you specify impl-jndi attribute as
    it performs a context lookup for the named identifier.
    I don't want to include all the code here, but assuming a class of
    org.mine.ejb.entity.MyClass and the inclusion of the following:
    * @ejb-dao class="org.mine.ejb.entity.MyClassDAO"
    * impl-jndi="dao/MyClass"
    look at the generate file MyClassDAO.java and MyClassCMP.java. It's
    a lot of time-saving code. You can simple plug in a class at deployment
    time which implements the interface. Sweet!
     
    Sudsy, Sep 26, 2004
    #4
  5. Thanks, this gives me much to go on and try to work out.


    > William Zumwalt wrote:
    > <snip>
    > > But as you can see, I am invoking the create method in my ejbCreate. And
    > > I left out @ejb.dao at the class level declaration of my entity bean
    > > because that just seems to name the interface w/ a given name from me.
    > > My DAO's are being generated, but ... and I think what you said may help
    > > a bit, something to do with defining the method of my DAO inside a DAO
    > > task. It's that code that goes inside the methods of my DAO's that I'm
    > > trying to figure out how and where to put. The code within my entities
    > > seems ok for now.

    >
    > Sorry, I should have mentioned that a lot of the magic happens in the
    > <classname>CMP.java file. A static synchronized getDAO method is
    > defined. It gets even spiffier if you specify impl-jndi attribute as
    > it performs a context lookup for the named identifier.
    > I don't want to include all the code here, but assuming a class of
    > org.mine.ejb.entity.MyClass and the inclusion of the following:
    > * @ejb-dao class="org.mine.ejb.entity.MyClassDAO"
    > * impl-jndi="dao/MyClass"
    > look at the generate file MyClassDAO.java and MyClassCMP.java. It's
    > a lot of time-saving code. You can simple plug in a class at deployment
    > time which implements the interface. Sweet!
    >
     
    William Zumwalt, Sep 26, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Willian Irving Zumwalt

    help w/ xdoclet entity definition

    Willian Irving Zumwalt, Sep 24, 2004, in forum: Java
    Replies:
    1
    Views:
    529
    Sudsy
    Sep 24, 2004
  2. wizumwalt
    Replies:
    0
    Views:
    404
    wizumwalt
    Apr 13, 2005
  3. wizumwalt

    help with DAO's in xDoclet

    wizumwalt, Apr 19, 2005, in forum: Java
    Replies:
    0
    Views:
    372
    wizumwalt
    Apr 19, 2005
  4. Greg
    Replies:
    0
    Views:
    647
  5. markla
    Replies:
    1
    Views:
    584
    Steven Cheng
    Oct 6, 2008
Loading...

Share This Page