net.sf.hibernate.tool.hbm2java
Class FinderRenderer

java.lang.Object
  extended by net.sf.hibernate.tool.hbm2java.AbstractRenderer
      extended by net.sf.hibernate.tool.hbm2java.FinderRenderer
All Implemented Interfaces:
Renderer

public class FinderRenderer
extends AbstractRenderer

Title: Basic Finder Generator for Hibernate 2

Description: Generate basic finders for hibernate properties. This requires two things in the hbm.xml files. The first is an indication of which fields you want to generate finders for. You indicate that with a meta block inside a property tag such as findByName The finder method name will be the text enclosed in the meta tags. If you want to generate a finder based on a join you can do something like this: findSavedGames save players Where foreign-finder-name will be the name of the finder when generated, foreign-finder-field is the field in the foreign class that you will want as a paramter to the finder (the criteria in the query) and foreign-join-field is the field in teh foreign class that joins to this object (in case there are more than one collection of these objects in the foreign class). After you've defined your finders, the second thing to do is to create a config file for hbm2java of the format: And then use the param to hbm2java --config=xxx.xml where xxx.xml is the config file you just created. An optional parameter is meta tag at the class level of the format: com.whatever.SessionTable.getSessionTable().getSession(); Which would be the way in which you get sessions if you use the Thread Local Session pattern like I do.

Copyright: Copyright (c) 2003

Version:
1.0
Author:
Matt Hall (matt2k(at)users.sf.net), Max Rydahl Andersen (small adjustments and bugfixes)

Constructor Summary
FinderRenderer()
           
 
Method Summary
 void doFinders(ClassMapping classMapping, Map class2classmap, PrintWriter writer)
          Create finders for properties that have the finderName block defined.
 void doImports(ClassMapping classMapping, PrintWriter writer)
          Generate the imports for the finder class.
static String getFieldAsHibernateType(boolean prependThis, FieldProperty field)
          Return the hibernate type string for the given field
static String getFieldAsObject(boolean prependThis, FieldProperty field)
          Gets the fieldAsObject attribute of the FinderRenderer object
 void render(String savedToPackage, String savedToClass, ClassMapping classMapping, Map class2classmap, PrintWriter mainwriter)
          Render finder classes.
 
Methods inherited from class net.sf.hibernate.tool.hbm2java.AbstractRenderer
configure, genPackageDelaration, getFieldScope, getPackageDeclaration, getSaveToClassName, getSaveToPackage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FinderRenderer

public FinderRenderer()
Method Detail

render

public void render(String savedToPackage,
                   String savedToClass,
                   ClassMapping classMapping,
                   Map class2classmap,
                   PrintWriter mainwriter)
            throws Exception
Render finder classes.

Parameters:
classMapping -
class2classmap -
mainwriter -
savedToPackage - what package is this class placed in
savedToClass - what classname does it really get
Throws:
Exception

doFinders

public void doFinders(ClassMapping classMapping,
                      Map class2classmap,
                      PrintWriter writer)
Create finders for properties that have the finderName block defined. Also, create a findAll(Session) method.

Parameters:
classMapping -
class2classmap -
writer -

doImports

public void doImports(ClassMapping classMapping,
                      PrintWriter writer)
Generate the imports for the finder class.

Parameters:
classMapping -
writer -

getFieldAsObject

public static String getFieldAsObject(boolean prependThis,
                                      FieldProperty field)
Gets the fieldAsObject attribute of the FinderRenderer object

Parameters:
prependThis -
field -
Returns:

getFieldAsHibernateType

public static String getFieldAsHibernateType(boolean prependThis,
                                             FieldProperty field)
Return the hibernate type string for the given field

Parameters:
prependThis -
field -
Returns: