org.eigenbase.enki.hibernate.codegen
Class HibernateGenerator

java.lang.Object
  org.eigenbase.enki.codegen.GeneratorBase
      org.eigenbase.enki.codegen.MdrGenerator
          org.eigenbase.enki.hibernate.codegen.HibernateGenerator
All Implemented Interfaces:
Generator

public class HibernateGenerator
extends MdrGenerator

HibernateGenerator is the main entry point for Hibernate code generation. It loads an XMI representation of a UML model via Netbeans MDR and produces:

  1. Interfaces for the UML model.
  2. Implementations of the interfaces that represent concrete classes.
  3. A Hibernate mapping file to provide storage for those implementations.

Supported options:

Name Description
"tablePrefix" A prefix to be used for all metamodel-specific tables. Use is optional, but highly recommended. Without this option only a single metamodel can be stored in a particular database schema.
"defaultStringLength" Controls the default length of string columns. If unspecified, the default is defined in CodeGenUtils.DEFAULT_STRING_LENGTH. Optional.
"identifierLimit" Controls the length of generated identifiers such as attribute and reference data members and their corresponding accessor methods. This may be necessary for metamodels containing long object names; for example, MySQL column names can be 64 characters long at most. Setting this limit too high can lead to errors during Hibernate mapping; setting this limit too low can lead to uniqueness clashes in generated identifiers (simple truncation is used, without mangling). Consequently, setting this limit may require experimentation for a given metamodel and DBMS combination (and requires upgrade consideration as well when metamodels change). If unspecified, the default is unlimited. Optional.
"include" List of packages (by fully-qualified Java name) to include. All other packages are excluded. If unspecified, all packages are included. Optional.
"plugin" Boolean flag to control whether the generated code is a plugin (requiring a base model generated separately). Defaults to false. Optional.

Author:
Stephan Zuercher

Field Summary
static String DEFAULT_STRING_LENGTH_OPTION
          The name of the generator option for setting the default string length.
private  int defaultStringLength
          Default string length.
static String IDENTIFIER_LIMIT_OPTION
          The name of the generator option for setting the identifier limit.
private  int identifierLimit
          Identifier limit.
static String INCLUDE_PACKAGE_OPTION
          The name of the generator option for including specific packages.
private  List<String> includedPackageList
          Included package list.
static String PLUGIN_OPTION
          The name of the plug-in mode option.
private  boolean pluginMode
          Plug-in flag.
static String TABLE_PREFIX_OPTION
          The name of the generator option for setting the table prefix.
private  String tablePrefix
          Prefix for all table names in this metamodel.
 
Fields inherited from class org.eigenbase.enki.codegen.MdrGenerator
DEFAULT_ENKI_MODEL_EXTENT_NAME
 
Fields inherited from class org.eigenbase.enki.codegen.GeneratorBase
enableGenerics, outputDir, xmiFile
 
Constructor Summary
HibernateGenerator()
           
 
Method Summary
protected  void configureHandlers()
          Configures a JmiTemplateHandler for UML interfaces, a HibernateJavaHandler for Hibernate entities and a HibernateMappingHandler to generate a Hibernate mapping file.
static void main(String[] args)
          Provides an entry point for testing without Any.
 void setOptions(Map<String,String> options)
          Accepts the options described in HibernateGenerator and ignores all others.
 String transformIdentifier(String identifier)
          Applies any transformations required by this generator to an identifier.
 
Methods inherited from class org.eigenbase.enki.codegen.MdrGenerator
doMain, execute, getExtent, getExtentName, setExtentName
 
Methods inherited from class org.eigenbase.enki.codegen.GeneratorBase
addHandler, generateObject, getAccessorName, getAccessorName, getAccessorName, getAccessorName, getAssociationEnds, getAssociationKind, getClassFieldName, getCollectionType, getEnumFieldName, getMutatorName, getMutatorName, getParam, getRefBaseObject, getSimpleTypeName, getSimpleTypeName, getTypeName, getTypeName, getTypeName, getTypeName, getTypeName, getTypeName, getTypeName, getTypeName, getXmiFile, setOutputDirectory, setUseGenerics, setXmiFile, visitRefAssociation, visitRefBaseObject, visitRefClass, visitRefObject, visitRefPackage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TABLE_PREFIX_OPTION

public static final String TABLE_PREFIX_OPTION
The name of the generator option for setting the table prefix.

See Also:
Constant Field Values

DEFAULT_STRING_LENGTH_OPTION

public static final String DEFAULT_STRING_LENGTH_OPTION
The name of the generator option for setting the default string length.

See Also:
Constant Field Values

IDENTIFIER_LIMIT_OPTION

public static final String IDENTIFIER_LIMIT_OPTION
The name of the generator option for setting the identifier limit.

See Also:
Constant Field Values

INCLUDE_PACKAGE_OPTION

public static final String INCLUDE_PACKAGE_OPTION
The name of the generator option for including specific packages.

See Also:
Constant Field Values

PLUGIN_OPTION

public static final String PLUGIN_OPTION
The name of the plug-in mode option.

See Also:
Constant Field Values

tablePrefix

private String tablePrefix
Prefix for all table names in this metamodel.


defaultStringLength

private int defaultStringLength
Default string length. A value of -1 indicates that no value has been set.


identifierLimit

private int identifierLimit
Identifier limit. A value of -1 indicates that no limit has been set.


includedPackageList

private List<String> includedPackageList
Included package list.


pluginMode

private boolean pluginMode
Plug-in flag.

Constructor Detail

HibernateGenerator

public HibernateGenerator()
Method Detail

setOptions

public void setOptions(Map<String,String> options)
Accepts the options described in HibernateGenerator and ignores all others.

Specified by:
setOptions in interface Generator
Overrides:
setOptions in class GeneratorBase
Parameters:
options - map of option name to option value

configureHandlers

protected void configureHandlers()
Configures a JmiTemplateHandler for UML interfaces, a HibernateJavaHandler for Hibernate entities and a HibernateMappingHandler to generate a Hibernate mapping file.

Specified by:
configureHandlers in class MdrGenerator

transformIdentifier

public String transformIdentifier(String identifier)
Description copied from interface: Generator
Applies any transformations required by this generator to an identifier. Example transformations are truncation and mangling.

Specified by:
transformIdentifier in interface Generator
Overrides:
transformIdentifier in class GeneratorBase
Parameters:
identifier - identifier to be transformed
Returns:
transformed identifier

main

public static void main(String[] args)
Provides an entry point for testing without Any.

Parameters:
args -