com.triactive.jdo.store.sql
Class ColumnName

java.lang.Object
  extended bycom.triactive.jdo.store.sql.SqlIdentifier
      extended bycom.triactive.jdo.store.sql.ColumnName
All Implemented Interfaces:
java.lang.Comparable

public final class ColumnName
extends SqlIdentifier

An SQL column name.

A ColumnName is mostly just an SqlIdentifier subclassed for type safety.

Column names in TJDO are generated using a suffix convention based on their "role". The inRole(com.triactive.jdo.store.sql.Role, java.lang.Class) method is used to add role suffixes. The role disambiguates columns in some situations where two columns would otherwise have the same name. For example, a Map table names its columns according to data type. A Map whose key and value are both of type String would produce columns named STRING_KEY and STRING_VAL.

Author:
Mike Martin

Field Summary
static int MAX_SUFFIX_LENGTH
          The maximum length in characters reserved at the end of column names for suffixes used to indicate a column's role (such as _ID for an ID column).
 
Fields inherited from class com.triactive.jdo.store.sql.SqlIdentifier
dba, fullName, name
 
Constructor Summary
ColumnName(DatabaseAdapter dba, java.lang.String identifier)
          Constructs a column name.
 
Method Summary
static ColumnName fromJavaName(DatabaseAdapter dba, java.lang.String javaName)
          Converts a Java name string to an SQL column name.
 ColumnName inRole(Role role, java.lang.Class javaType)
          Returns a new column name equal to this column name plus a role suffix.
 
Methods inherited from class com.triactive.jdo.store.sql.SqlIdentifier
compareTo, equals, hashCode, intern, isKeyword, javaToSql, toString, undelimited, untruncated
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_SUFFIX_LENGTH

public static int MAX_SUFFIX_LENGTH
The maximum length in characters reserved at the end of column names for suffixes used to indicate a column's role (such as _ID for an ID column).

Constructor Detail

ColumnName

public ColumnName(DatabaseAdapter dba,
                  java.lang.String identifier)
Constructs a column name. The identifier will be truncated if necessary to the maximum allowed catalog name length.

Parameters:
dba - a database adapter for the relevant database
identifier - the SQL identifier value as a string
Method Detail

inRole

public ColumnName inRole(Role role,
                         java.lang.Class javaType)
Returns a new column name equal to this column name plus a role suffix. Always used when generating names for new columns.

The column name identifier is first truncated if necessary to reserve MAX_SUFFIX_LENGTH characters for a suffix. Then a suitable suffix is appended based on the column's role and javaType.

Parameters:
role - The column's role.
javaType - The Java type of the data stored in the column.
Returns:
a new ColumnName object.
See Also:
Role.getSqlIdentifierSuffix(com.triactive.jdo.store.adapter.DatabaseAdapter, java.lang.Class)

fromJavaName

public static ColumnName fromJavaName(DatabaseAdapter dba,
                                      java.lang.String javaName)
Converts a Java name string to an SQL column name. This method returns a new ColumnName object where the SQL identifier is generated from the given Java identifier. The column name SQL identifier will be truncated if necessary to the maximum allowed column name length, minus characters reserved for any role suffix.

Parameters:
dba - a database adapter for the relevant database
javaName - the Java identifier name. Must not be null.
Returns:
a new ColumnName object.
See Also:
SqlIdentifier.javaToSql(java.lang.String)


Copyright © 2001-2007 The TJDO Project All Rights Reserved.