net.java.ao.schema
Class UnderscoreTableNameConverter

java.lang.Object
  extended by net.java.ao.schema.AbstractTableNameConverter
      extended by net.java.ao.schema.UnderscoreTableNameConverter
All Implemented Interfaces:
TableNameConverter

public class UnderscoreTableNameConverter
extends AbstractTableNameConverter

Imposes an underscore word-separation convention on table names. This will convert entity names in the following way:

Entity Name Table Name
Person person
LicenseRegistration license_registration
Volume4 volume_4
Company company

This converter allows for both all-lowercase and all-uppercase table name conventions. For example, depending on the configuration, LicenseRegistration may convert to "LICENSE_REGISTRATION".

This converter, coupled with PluralizedNameConverter is all that is required to emulate the ActiveRecord table name conversion.

Author:
Francis Chong, Daniel Spiewak

Constructor Summary
UnderscoreTableNameConverter(boolean uppercase)
          Creates a new table name converter in which all table names will be either fully uppercase or fully lowercase.
 
Method Summary
protected  String convertName(Class<? extends RawEntity<?>> entity)
          Performs the actual operation of converting a class type into a proper table name.
 boolean isUppercase()
          Returns whether or not resulting table names will be entirely uppercase.
protected  String postProcessName(String back)
          Performs second-step post-processing on converted names.
 
Methods inherited from class net.java.ao.schema.AbstractTableNameConverter
addClassMapping, addClassMappings, addPatternMapping, addPatternMappings, getName, processName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UnderscoreTableNameConverter

public UnderscoreTableNameConverter(boolean uppercase)
Creates a new table name converter in which all table names will be either fully uppercase or fully lowercase.

Parameters:
uppercase - true if table names should be all uppercase, false if table names should be all lowercase.
Method Detail

isUppercase

public boolean isUppercase()
Returns whether or not resulting table names will be entirely uppercase. If false, table names will be entirely lowercase.


convertName

protected String convertName(Class<? extends RawEntity<?>> entity)
Description copied from class: AbstractTableNameConverter

Performs the actual operation of converting a class type into a proper table name. This method need not concern itself with particulars of @Table annotations or pattern mappings. All of these things are handled in the AbstractTableNameConverter.getName(Class) method in the superclass implementation.

This method must run as fast as possible and should be thread-safe. If necessary, caching may be employed, but it is also within scope for such caching to be utilized within the superclass. As such, the implementation of this method should be kept extremely simple. Also note that this method may not be called for every entity type which must be converted (due to mappings, @Table overrides, etc).

Specified by:
convertName in class AbstractTableNameConverter
Parameters:
entity - The entity type which must be converted.
Returns:
The unique table name which corresponds to the given type.

postProcessName

protected String postProcessName(String back)
Description copied from class: AbstractTableNameConverter

Performs second-step post-processing on converted names. This method is called to perform last-stage conventions enforcement prior to utilization of the table name. This allows implementations to impose sweeping conventions such as "all table names should be uppercase" and so on. Any minor or name-specific conventions should be enforced within the AbstractTableNameConverter.processName(String) method.

The main reason for this method's existence is actually to allow for table name pluralizing on conversions imposing odd conventions, such as all uppercase or all lowercase. This method should be invoked as the last step of any table name conversion (with the exception of class mappings and @Table annotations) to allow for extremely broad-brush changes. The default implementation simply returns the passed name.

Overrides:
postProcessName in class AbstractTableNameConverter
Parameters:
back - The generated table name which should be processed to suit large-scale conventions.
Returns:
An (optionally) modified version of the given table name.


Copyright © 2007-2011. All Rights Reserved.