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.  [ 5 posts ] 
Author Message
 Post subject: toString and equals for jdbcconfiguration
PostPosted: Thu Oct 19, 2006 12:36 pm 
Hi,

I'm thinking of adding the ability to create toString and equals methods to hbm2java when reverse engineering from a database.


The approach I'm considering so far is:

1) add methods to the ReverseEngineeringStrategy along the lines of:

List<Property> getPropertiesForToString(Table table)

List<Property> getPropertiesForEquals(Table table)


2) add an implemetation for the above methods which takes the equivalent of meta include-in-tostring and include-in-equals from additional elements inside <table> elements in reveng.xml


Before I start I'd like to know if:

Anyone has got something written already which lets me generate equals and tostring off a database schema...

If not, is the aproach I describe above sensible?

Cheers,

Andy


Top
  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 12:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Hi Andy :),

did you notice that the latest version has a tableToMetaAttributes and columnToMetaAttributes in revengstrategy and accordingly there is a <meta> element available in reveng.xml ?

it doesn't make it explicit, but then you can atleast inject those meta attributes.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 12:52 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
The version in SVN has a couple new methods in ReverseEngineeringStrategy:
Code:
public Map columnToMetaAttributes(TableIdentifier identifier, String column)
public Map tableToMetaAttributes(TableIdentifier tableIdentifier)


You should be able to leverage columnToMetaAttributes to generate the include-in-to-string meta attribute for the apporpriate columns. e.g.

Code:
   @Override
   public Map columnToMetaAttributes(TableIdentifier identifier, String column) {
      Map<String, MetaAttribute> metaAttributes = new HashMap<String, MetaAttribute>();
      if ("DONT_WANT_THIS_IN_TOSTRING".equalsIgnoreCase(column)    ||
            "DONT_WANT_THIS_IN_TOSTRING_EITHER".equalsIgnoreCase(column)  ||
            "DEFINITELY_DONT_WANT_THIS_IN_TOSTRING".equalsIgnoreCase(column)   ||
            "NO_TO_STRING_FOR_YOU".equalsIgnoreCase(column)) {
         MetaAttribute genProperty = new MetaAttribute("use-in-tostring");
         genProperty.addValue("false");
         metaAttributes.put("use-in-tostring", genProperty);
      }
      return metaAttributes;
   }


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 12:56 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
exactly.

I just have one correction:

Remember to call super.whatever(x,y,z) when you overwrite whatever(x,y,z) to collect what users might have defined in a reveng.xml.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 4:03 am 
Thanks, I hadn't noticed the changes to revengstrategy - very grateful that you (both) pointed them out :)

I'll have a go with this later today.

Cheers,

Andy


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.