net.java.ao.schema
Class AbstractFieldNameConverter

java.lang.Object
  extended by net.java.ao.schema.AbstractFieldNameConverter
All Implemented Interfaces:
FieldNameConverter
Direct Known Subclasses:
CamelCaseFieldNameConverter, UnderscoreFieldNameConverter

public abstract class AbstractFieldNameConverter
extends java.lang.Object
implements FieldNameConverter

An abstract implementation of FieldNameConverter which handles common tasks for the name converter (i.e. relations annotations, accessor/mutator annotations, etc). For most tasks, custom field name converters should extend this class, rather than directly implementing FieldNameConverter.

Author:
Daniel Spiewak

Constructor Summary
protected AbstractFieldNameConverter()
          Dummy constructor with protected visibility.
 
Method Summary
protected abstract  java.lang.String convertName(java.lang.String name, boolean entity, boolean polyType)
          Performs the actual conversion logic between a method name (or, more normally a trimmed method name) and the corresponding database field identifier.
 java.lang.String getName(java.lang.reflect.Method method)
          Handles operations which should be common to all field name converters such as overriding of the generated field name through annotations, etc.
 java.lang.String getPolyTypeName(java.lang.reflect.Method method)
          Docuentation on the getName(Method) method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractFieldNameConverter

protected AbstractFieldNameConverter()
Dummy constructor with protected visibility. Does nothing.

Method Detail

getName

public java.lang.String getName(java.lang.reflect.Method method)

Handles operations which should be common to all field name converters such as overriding of the generated field name through annotations, etc. This method also handles the converting through the Java Bean method prefix convention (get/set/is), allowing the implementing class to only concern itself with converting one String (from the method name) into another.

This method delegates the actual conversion logic to the convertName(String, boolean, boolean) method. There is rarely a need for subclasses to override this method.

Specified by:
getName in interface FieldNameConverter
Parameters:
method - The method for which a field name must be generated.
Returns:
A valid database identifier to be used as the field name representative of the method in question.
See Also:
FieldNameConverter.getName(Method)

getPolyTypeName

public java.lang.String getPolyTypeName(java.lang.reflect.Method method)
Docuentation on the getName(Method) method.

Specified by:
getPolyTypeName in interface FieldNameConverter
Parameters:
method - The method for which a corresponding field name must be generated.
Returns:
A valid database identifier to be used as the field name representative of the method in question.
See Also:
FieldNameConverter.getPolyTypeName(Method)

convertName

protected abstract java.lang.String convertName(java.lang.String name,
                                                boolean entity,
                                                boolean polyType)

Performs the actual conversion logic between a method name (or, more normally a trimmed method name) and the corresponding database field identifier. This method may impose conventions such as camelCase, all-lowercase with underscores and so on. There is no need for this method to concern itself with method prefixes such as get, set or is. All of these should be handled within the getName(Method) method.

Some examples of input and their corresponding return values for this method (assuming the CamelCaseFieldNameConverter is in use):

Actual Method Name Param: name Param: entity Param: polyType Return Value
getFirstName FirstName false false firstName
getCompany Company true false companyID
getCompany Company true true companyType
isCool Cool false false cool
setLastName LastName false false lastName

The implementation of this method must execute extremely quickly and be totally thread-safe (stateless if possible). This is because this method will be called many times for some operations. A slow algorithm here will dramaticly affect the execution time of basic tasks.

Parameters:
name - The (often trimmed) method name for which a field name is reqiured.
entity - Indicates whether or not the method in question returns an entity value.
polyType - Indicates whether or not the field in question is a polymorphic type flagging field.
Returns:
A valid database field name which uniquely corresponds to the method name in question. Should never return null.


Copyright © 2007-2010. All Rights Reserved.