Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > xdoclet entity and dao help

Reply
Thread Tools

xdoclet entity and dao help

 
 
William Zumwalt
Guest
Posts: n/a
 
      09-25-2004
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
 
Reply With Quote
 
 
 
 
Sudsy
Guest
Posts: n/a
 
      09-26-2004
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...

 
Reply With Quote
 
 
 
 
William Zumwalt
Guest
Posts: n/a
 
      09-26-2004
In article <(E-Mail Removed)>,
Sudsy <(E-Mail Removed)> 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.
 
Reply With Quote
 
Sudsy
Guest
Posts: n/a
 
      09-26-2004
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!

 
Reply With Quote
 
William Zumwalt
Guest
Posts: n/a
 
      09-26-2004
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!
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
simpler over view on dao: a functional logic solver with builtinparsing power, and dinpy, the sugar syntax for dao in python Simeon Chaos Python 0 11-08-2011 05:34 AM
How to relate a SQL based entity with an Object based entity in Entity Framework markla ASP .Net 1 10-06-2008 09:42 AM
Maven2 and XDoclet : org.xdoclet.plugin.web.TaglibPlugin don't generate TLD inherited attributes Greg Java 0 05-17-2006 07:37 AM
help with DAO's in xDoclet wizumwalt Java 0 04-19-2005 08:43 PM
using xDoclet, can EJB pass ref to itself to DAO? wizumwalt Java 0 04-13-2005 08:56 PM



Advertisments