-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: making a custom Renderer
PostPosted: Tue Aug 03, 2004 12:45 pm 
Beginner
Beginner

Joined: Thu Jul 22, 2004 2:15 pm
Posts: 35
So was trying to make a custom rendered, and I was able to do it. I was trying to make a Struts FormBean renderer.

So I copied the code for BasicRendered from Hibernate Extensions 2.1.2

I saw that my renderer didn't obey extends param, even though I left the extends code intact. I was lazy so I didn't try the extends on BasicRenderer, that report comes tommorrow.

at any rate, I had to get rid of some fields and modify the type for others. So I got the List of fields from the ClassMapping and try to do some removes and sets on the List, the changes didn't reflect on the generated class.

So I did a little bit of code hacking. I went to ClassMapping code and wrote the setFields I believe, so it would let me set my newly modified List back in ClassMapping..

how else could I have asked ClassMapping for the fields list, so it can modified and changes can reflect all over.

I must admit, I have not done much looking into code. I did the bare minimum, mainly in Renderer, AbstractRenderer, Generator and little bit in CodeGenerator..

At any rate.. I am going to try to write a few more renderers that do some Hibernate loads and stuff, so any hints would be good. If you think code will make things clear, I can post it here.

TIA,
Pritpal Dhaliwal


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 4:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
don't understand why you want to reduce the actual fields generated - but if that is what you want you have to run through all the classmappings the first time your render is called to make the necessary changes.

...but why don't you just make the render ignore the irrelevant fields ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 3:20 am 
Beginner
Beginner

Joined: Thu Jul 22, 2004 2:15 pm
Posts: 35
I want to reduce the fields like creation date,last update timestamp etc.. Those are updated by the application and don't need to be in the form bean.

I found it very easy to just shave off the unwanted fields right in the beginning of render function. Otherwise I will be writing TOO MUCH code..
Imagine having to check each fields for all the constructors, member declarations, and gettters and setters. I believe in more code = more bugs.

Changing the list of fields right before renedering everythings works like a charm, except the fact that I had to write the set function on ClassMapping to set the fields list. It wasn't working because I was doing getAllFields, which returns a new List, so changes to the list are not recognized back at the class mapping.

However, I used ClassMapping's getFields and I am happy with it. I guess I won't get inherited class's fields, but I don't care for them anyways.

thanks a lot for the help anyways. I did try to follow your path, but got scared of the amount of work I will need to do.

_________________
--------------------------------------------------
To code or not to code... Is that a question?
--------------------------------------------------
Pritpal Dhaliwal


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 3:46 am 
Beginner
Beginner

Joined: Thu Jul 22, 2004 2:15 pm
Posts: 35
also...
<codegen>
...
<meta attribute="extends">com.foo.CrudFormBean</meta>
...
</codegen>
did not make me happy either :(

I just wanted to extend the form bean and it extended the POJO also, since I run both basic and my form bean generator at the same time.

any way to work around it?

TIA

_________________
--------------------------------------------------
To code or not to code... Is that a question?
--------------------------------------------------
Pritpal Dhaliwal


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 3:54 am 
Beginner
Beginner

Joined: Thu Jul 22, 2004 2:15 pm
Posts: 35
btw.. my workaround for right now is:

MultiMap metaAttribs = cm.getMetaAttribs();
metaAttribs.put("extends",getProperty("extends",null));

.........
<generate renderer="net.sf.hibernate.tool.hbm2java.FormBeanRenderer">
<param name="saved-to-package">com.foo.formbean</param>
<param name="extends">com.foo.formbean.CrudFormBean</param>
</generate>

oh yeah.. and saved-to-package is my other workaround..

please comment about if I am on the right path or not..

_________________
--------------------------------------------------
To code or not to code... Is that a question?
--------------------------------------------------
Pritpal Dhaliwal


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 11:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
subpaul wrote:
However, I used ClassMapping's getFields and I am happy with it. I guess I won't get inherited class's fields, but I don't care for them anyways.


To get inherited fields you need to goto the superclass - ...getSuperClass()

Quote:
thanks a lot for the help anyways. I did try to follow your path, but got scared of the amount of work I will need to do.


eh - where did I lay out a path that demanded alot of work compared to what you are already doing ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 11:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
subpaul wrote:
also...
<codegen>
...
<meta attribute="extends">com.foo.CrudFormBean</meta>
...
</codegen>
did not make me happy either :(

I just wanted to extend the form bean and it extended the POJO also, since I run both basic and my form bean generator at the same time.

any way to work around it?

TIA


Don't generate the basic and form bean generator at the same time...problem solved!

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 1:11 pm 
Beginner
Beginner

Joined: Thu Jul 22, 2004 2:15 pm
Posts: 35
Quote:
eh - where did I lay out a path that demanded alot of work compared to what you are already doing ?


when you said just make the renderer so it ignore the fields.

Quote:
...but why don't you just make the render ignore the irrelevant fields ?


I took it as that you are suggesting me to do it all in the render and other functions, like doFields and doConstructors..

You didn't really lay down the path..

Other than getting rid of the fields from its list, I could not think of another way of "making render ignore" the irrelevant fields.

At any rate.. I am getting happier as I try out more things. Thanks for the super class hint, that will surely come in handy when I want to mess with the super class..

btw, do you work on the hibernate tools?

_________________
--------------------------------------------------
To code or not to code... Is that a question?
--------------------------------------------------
Pritpal Dhaliwal


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 4:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
subpaul wrote:
Quote:
eh - where did I lay out a path that demanded alot of work compared to what you are already doing ?


when you said just make the renderer so it ignore the fields.

Quote:
...but why don't you just make the render ignore the irrelevant fields ?


yes - something like (in dofields())...

Code:
while(fields.hasNext()) {
  field = fields.next();
  if(theMethodYouAlreadyHaveTodecideWetherAFieldIsMentToBeincluded(field)) {
  ..default field stuff...
}
}


That can't be hard ;)

Quote:
Other than getting rid of the fields from its list, I could not think of another way of "making render ignore" the irrelevant fields.


oh - well, if you really like to mutate the fields/classmapping structure we should probably think up a way to add such possibility to the core of hbm2java....or at least add a method in basicRenderer saying: "isFieldRelevant()" or something ;)

Quote:
btw, do you work on the hibernate tools?


Yes - why ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 6:50 pm 
Beginner
Beginner

Joined: Thu Jul 22, 2004 2:15 pm
Posts: 35
Hi Max,

yeah, its not hard to do that but then I have to do it for constructors too :(..

and the fields themselves...

three places..

plus I was also mucking around the the ClassName of the fields.

I think is public boolean isFieldRelevant(FieldProperty field) would be pretty good , but I am writing couple more Renderers, and if you want me to I can give you my input on what more would be helpful..

Something I would like is that a renderer be able to take in a different output path. So there is a default one, and then there is an optional one for each renderer, which ofcourse can be different. Same thing with extends meta attribute. I had to use the param so my form bean could extend a different class.

I am not sure if I am required by LGPL to give out my code if I basically picked up BasicRenderer and modified it to get where I wanted to. I have no problem giving it to you guys if you guys want it for a reason or another.


I asked if you work on tools because you are the only one responding to this..

btw, thanks again for you help.

_________________
--------------------------------------------------
To code or not to code... Is that a question?
--------------------------------------------------
Pritpal Dhaliwal


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.