org.araneaframework.backend.list.helper.naming
Class StandardNamingStrategy

java.lang.Object
  extended byorg.araneaframework.backend.list.helper.naming.StandardNamingStrategy
All Implemented Interfaces:
NamingStrategy
Direct Known Subclasses:
PrefixMapNamingStrategy

public class StandardNamingStrategy
extends Object
implements NamingStrategy

Standard naming conventions between list fields and database columns.

Field names are transformed into database column names as following:

E.g:
   firstName -> first_name
   location.address -> location.address
   client.group.id -> client_group.id
 
Field names are transformed into database column aliases as following:

E.g:
   lastName -> last_name
   location.address -> location_address
   client.group.id -> client_group_id
 

Since:
1.1
Author:
Rein Raudjärv

Constructor Summary
StandardNamingStrategy()
           
 
Method Summary
static String addUnderscores(String name)
          Replace all dots with underscores and add an underscore before upper-case letters followed by a non-upper-case letter.
protected  String concatFullname(String prefix, String suffix)
           
protected  String extractPrefix(String varName)
           
protected  String extractSuffix(String varName)
           
 String fieldToColumnAlias(String fieldName)
          Converts field name into database column alias.
 String fieldToColumnName(String fieldName)
          Converts field name into database column name.
protected  String resolvePrefix(String fieldNamePrefix)
           
protected  String resolveSuffix(String fieldNameSuffix)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StandardNamingStrategy

public StandardNamingStrategy()
Method Detail

fieldToColumnName

public String fieldToColumnName(String fieldName)
Description copied from interface: NamingStrategy
Converts field name into database column name.

E.g.
firstName -> FIRST_NAME
group.name -> G.NAME
name -> FIRSTNAME || " " || LASTNAME total -> sum(POINTS)

Specified by:
fieldToColumnName in interface NamingStrategy
Parameters:
fieldName - field name of the list.
Returns:
corresponding database column name used in SQL query.

extractPrefix

protected String extractPrefix(String varName)

extractSuffix

protected String extractSuffix(String varName)

resolvePrefix

protected String resolvePrefix(String fieldNamePrefix)

resolveSuffix

protected String resolveSuffix(String fieldNameSuffix)

concatFullname

protected String concatFullname(String prefix,
                                String suffix)

fieldToColumnAlias

public String fieldToColumnAlias(String fieldName)
Description copied from interface: NamingStrategy
Converts field name into database column alias.

When two or more tables are used in SELECT with the same column name they must be distinguishable. Thus each column name must be followed by a unique alias which is referred later in WHERE and ORDER BY clause and also in the result set.

In ORDER BY expressions cannot be used like COUNT(points) instead these expressions must be defined together with aliases in the column list right after SELECT.

An alias must not contain dots neither it can be a SQL expression.

E.g.
description -> DESCRIPTION
mother.firstName -> MOTHER_FIRST_NAME
father.firstName -> FATHER_FIRST_NAME
total -> TOTAL

Specified by:
fieldToColumnAlias in interface NamingStrategy
Parameters:
fieldName - field name of the list.
Returns:
corresponding database column alias used in SQL query.

addUnderscores

public static String addUnderscores(String name)
Replace all dots with underscores and add an underscore before upper-case letters followed by a non-upper-case letter.

E.g.

 "a" -> "a"
 "a.b" -> "a_b"
 "aBc" -> "a_bc"
 "aB" -> "aB"