com.triactive.jdo.store.sql
Class ConstraintName

java.lang.Object
  extended bycom.triactive.jdo.store.sql.QualifiedName
      extended bycom.triactive.jdo.store.sql.ConstraintName

public final class ConstraintName
extends QualifiedName

An SQL constraint name.

A ConstraintName is a type of QualifiedName naming an SQL database constraint. Constraints include the primary key, other candidate keys, and foreign keys.

Constraint names in TJDO are generated using a suffix convention based on their type. For example, all primary key constraints are named based on their table with a _PK suffix appended.

Author:
Mike Martin

Field Summary
static int MAX_FOREIGN_KEYS
          The maximum number of foreign keys allowed.
static int MAX_SUFFIX_LENGTH
          The maximum length in characters reserved at the end of constraint names for suffixes used to indicate the type of constraint.
 
Fields inherited from class com.triactive.jdo.store.sql.QualifiedName
identifier, schemaName
 
Constructor Summary
ConstraintName(DatabaseAdapter dba, SchemaName schemaName, java.lang.String identifier)
          Constructs a constraint name.
ConstraintName(DatabaseAdapter dba, java.lang.String identifier)
          Constructs a constraint name.
 
Method Summary
static ConstraintName forCandidateKey(BaseTable table, int seq)
          Generates a new candidate key constraint name.
static ConstraintName forForeignKey(BaseTable table, int seq)
          Generates a new foreign key constraint name.
static ConstraintName forPrimaryKey(BaseTable table)
          Generates a new primary key constraint name.
 
Methods inherited from class com.triactive.jdo.store.sql.QualifiedName
effectiveCatalogName, effectiveSchemaName, equals, fullyQualified, getIdentifier, getSchemaName, hashCode, intern, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_SUFFIX_LENGTH

public static final int MAX_SUFFIX_LENGTH
The maximum length in characters reserved at the end of constraint names for suffixes used to indicate the type of constraint.

See Also:
Constant Field Values

MAX_FOREIGN_KEYS

public static final int MAX_FOREIGN_KEYS
The maximum number of foreign keys allowed. This is limited only due to the suffix convention.

See Also:
Constant Field Values
Constructor Detail

ConstraintName

public ConstraintName(DatabaseAdapter dba,
                      java.lang.String identifier)
Constructs a constraint name. The identifier will be truncated if necessary to the maximum allowed constraint name length. The name will not be schema-qualified.

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

ConstraintName

public ConstraintName(DatabaseAdapter dba,
                      SchemaName schemaName,
                      java.lang.String identifier)
Constructs a constraint name. The identifier will be truncated if necessary to the maximum allowed constraint name length.

Parameters:
dba - a database adapter for the relevant database
schemaName - the schema name part of the constraint name, or null if the name is not schema-qualified
identifier - the SQL identifier value as a string
Method Detail

forPrimaryKey

public static ConstraintName forPrimaryKey(BaseTable table)
Generates a new primary key constraint name. Always used when generating names for new primary key constraints.

The table name is used as the base of the new constraint name. The table name identifier is first truncated if necessary to reserve MAX_SUFFIX_LENGTH characters for a suffix. Then _PK is appended.

If the specified table's name is schema-qualified then the constraint name will be schema-qualified.

Parameters:
table - The base table for the named primary key constraint.
Returns:
a new ConstraintName object.

forCandidateKey

public static ConstraintName forCandidateKey(BaseTable table,
                                             int seq)
Generates a new candidate key constraint name. Always used when generating names for new candidate key constraints.

The table name is used as the base of the new constraint name. The table name identifier is first truncated if necessary to reserve MAX_SUFFIX_LENGTH characters for a suffix. Then _Un is appended, where n is a character from [0-9A-Z] representing the given seq parameter.

If the specified table's name is schema-qualified then the constraint name will be schema-qualified.

Parameters:
table - The base table for the named candidate key constraint.
seq - The number of the candidate key for this table. By convention, should start at 1.
Returns:
a new ConstraintName object.

forForeignKey

public static ConstraintName forForeignKey(BaseTable table,
                                           int seq)
Generates a new foreign key constraint name. Always used when generating names for new foreign key constraints.

The table name is used as the base of the new constraint name. The table name identifier is first truncated if necessary to reserve MAX_SUFFIX_LENGTH characters for a suffix. Then _FKn is appended, where n is a character from [0-9A-Z] representing the given seq parameter.

If the specified table's name is schema-qualified then the constraint name will be schema-qualified.

Parameters:
table - The base table for the named foreign key constraint.
seq - The number of the foreign key for this table. By convention, should start at 1.
Returns:
a new ConstraintName object.


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