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

java.lang.Object
  extended byorg.araneaframework.backend.list.helper.naming.MappingNamingStrategyAndFields
All Implemented Interfaces:
Fields, NamingStrategy

public class MappingNamingStrategyAndFields
extends Object
implements NamingStrategy, Fields

Naming conventions and list of fields provider which is based on mappings.

There are 3 types of fields:

The term SELECT refers to the corresponding SQL segment constructed by Aranea Lists. That may be wrapped inside another SQL clause for example.

Each list field must be added together with it's corresponding column name (and alias).

This implementation is based on the ListSqlHelper methods up to Aranea MVC 1.1-M5.

Since:
1.1
Author:
Rein Raudjärv
See Also:
NamingStrategy, ListSqlHelper.getMappingNamingStrategyAndFields()

Constructor Summary
MappingNamingStrategyAndFields()
           
 
Method Summary
 void addDatabaseFieldMapping(String fieldName, String columnName)
          Adds a field name to database column name mapping.
 void addDatabaseFieldMapping(String fieldName, String columnName, String columnAlias)
          Adds a field name to database column name and column alias mapping.
 void addMapping(String fieldName, String columnName)
          Adds a field name to database column name.
 void addMapping(String fieldName, String columnName, String columnAlias)
          Adds a field name to database column name and column alias mapping.
 void addResultSetMapping(String fieldName, String columnAlias)
          Adds a field name to database column alias mapping.
protected  String createAlias(String columnName)
           
 String fieldToColumnAlias(String variableName)
          Converts field name into database column alias.
 String fieldToColumnName(String variableName)
          Converts field name into database column name.
 Collection getNames()
          Return the list of fields used in SELECT.
 Collection getResultSetNames()
          Return the list of fields read from the ResultSet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MappingNamingStrategyAndFields

public MappingNamingStrategyAndFields()
Method Detail

addDatabaseFieldMapping

public void addDatabaseFieldMapping(String fieldName,
                                    String columnName,
                                    String columnAlias)
Adds a field name to database column name and column alias mapping.

A given field is listed in the SELECT but is not read from the ResultSet.

Parameters:
fieldName - field name.
columnName - database column name.
columnAlias - database column alias.
See Also:
addMapping(String, String, String), addMapping(String, String), addDatabaseFieldMapping(String, String), addResultSetMapping(String, String)

addDatabaseFieldMapping

public void addDatabaseFieldMapping(String fieldName,
                                    String columnName)
Adds a field name to database column name mapping.

A given field is listed in the SELECT but is not read from the ResultSet.

The corresponding column alias is generated automatically.

Parameters:
fieldName - field name.
columnName - database column name.
See Also:
addMapping(String, String, String), addMapping(String, String), addDatabaseFieldMapping(String, String, String), addResultSetMapping(String, String)

addResultSetMapping

public void addResultSetMapping(String fieldName,
                                String columnAlias)
Adds a field name to database column alias mapping.

A given field is not listed in the SELECT but is read from the ResultSet.

Parameters:
fieldName - field name.
columnAlias - database column name in the result set.
See Also:
addMapping(String, String, String), addMapping(String, String), addDatabaseFieldMapping(String, String, String), addDatabaseFieldMapping(String, String)

addMapping

public void addMapping(String fieldName,
                       String columnName,
                       String columnAlias)
Adds a field name to database column name and column alias mapping.

A given field is listed in the SELECT and is read from the ResultSet.

Parameters:
fieldName - field name.
columnName - database column name.
columnAlias - database column alias.
See Also:
addMapping(String, String), addDatabaseFieldMapping(String, String, String), addDatabaseFieldMapping(String, String), addResultSetMapping(String, String)

addMapping

public void addMapping(String fieldName,
                       String columnName)
Adds a field name to database column name.

A given field is listed in the SELECT and is read from the ResultSet.

The corresponding column alias is generated automatically.

Parameters:
fieldName - field name.
columnName - database column name.
See Also:
addMapping(String, String, String), addDatabaseFieldMapping(String, String, String), addDatabaseFieldMapping(String, String), addResultSetMapping(String, String)

getNames

public Collection getNames()
Description copied from interface: Fields
Return the list of fields used in SELECT.

Specified by:
getNames in interface Fields
Returns:
List<String> the names of the fields used in SELECT.

getResultSetNames

public Collection getResultSetNames()
Description copied from interface: Fields
Return the list of fields read from the ResultSet.

Specified by:
getResultSetNames in interface Fields
Returns:
List<String> the names of the fields read from the ResultSet.

fieldToColumnName

public String fieldToColumnName(String variableName)
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:
variableName - field name of the list.
Returns:
corresponding database column name used in SQL query.

fieldToColumnAlias

public String fieldToColumnAlias(String variableName)
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:
variableName - field name of the list.
Returns:
corresponding database column alias used in SQL query.

createAlias

protected String createAlias(String columnName)
Returns:
a new column alias.