xdoclet entity and dao help

W

William Zumwalt

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
 
S

Sudsy

William Zumwalt wrote:
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...
 
W

William Zumwalt

Sudsy said:
William Zumwalt wrote:


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.
 
S

Sudsy

William Zumwalt wrote:
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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top