com.triactive.jdo.store.sql
Class QualifiedName

java.lang.Object
  extended bycom.triactive.jdo.store.sql.QualifiedName
Direct Known Subclasses:
ConstraintName, IndexName, TableName

public abstract class QualifiedName
extends java.lang.Object

An SQL qualified name.

A QualifiedName is a name of an SQL object which can be schema-qualified. Table names, constraint names, etc. are kinds of qualified names. Qualified names have the general form:

 [ [ catalog ] . schema ] . name
 

The [catalog].schema part is represented by a SchemaName object, and the name part is a plain SqlIdentifier.

The term qualified name comes from the SQL standard.

Author:
Mike Martin

Field Summary
protected  SqlIdentifier identifier
          The identifier part of the qualified name.
protected  SchemaName schemaName
          The schema name part of the qualified name.
 
Constructor Summary
protected QualifiedName(DatabaseAdapter dba, SchemaName schemaName, java.lang.String identifier, int maxLength)
          Constructs a qualified name.
 
Method Summary
 java.lang.String effectiveCatalogName(StoreManager storeMgr)
          Returns the effective catalog name for this object.
 java.lang.String effectiveSchemaName(StoreManager storeMgr)
          Returns the effective schema name for this object.
 boolean equals(java.lang.Object obj)
          Tests this object for equality with another object.
 QualifiedName fullyQualified(StoreManager storeMgr)
          Returns a new qualified name object representing this name fully-qualified (if possible) with catalog and schema.
 SqlIdentifier getIdentifier()
          Returns the identifier part of this qualified name.
 SchemaName getSchemaName()
          Returns the (catalog and) schema name part of this qualified name.
 int hashCode()
          Returns a hash code value for this object.
 QualifiedName intern()
          Returns a canonical representation for the name object.
 java.lang.String toString()
          Returns the SQL string representation of this qualified name.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

schemaName

protected final SchemaName schemaName
The schema name part of the qualified name. May be null.


identifier

protected final SqlIdentifier identifier
The identifier part of the qualified name.

Constructor Detail

QualifiedName

protected QualifiedName(DatabaseAdapter dba,
                        SchemaName schemaName,
                        java.lang.String identifier,
                        int maxLength)
Constructs a qualified name. The identifier will be truncated if necessary to maxLength.

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

getSchemaName

public SchemaName getSchemaName()
Returns the (catalog and) schema name part of this qualified name.

Returns:
the (catalog and) schema name part of this qualified name, or null if this name is not schema-qualified.

getIdentifier

public SqlIdentifier getIdentifier()
Returns the identifier part of this qualified name.

Returns:
the identifier part of this qualified name

fullyQualified

public QualifiedName fullyQualified(StoreManager storeMgr)
Returns a new qualified name object representing this name fully-qualified (if possible) with catalog and schema. If this name object has a schema name part, it is returned. Otherwise, a new QualifiedName object is constructed whose schema name part represents the default schema for the given store manager.

The returned object is of the same type as this object, even in subclasses of QualifiedName.

Parameters:
storeMgr - the store manager to use to determine the default catalog and schema.
Returns:
The fully-qualified version of this name.

effectiveCatalogName

public java.lang.String effectiveCatalogName(StoreManager storeMgr)
Returns the effective catalog name for this object. If this object specifically names a catalog, its name is returned as a string. Otherwise the default catalog name from the specified store manager is returned.

Parameters:
storeMgr - the store manager to use to determine the default catalog
Returns:
the effective catalog name, undelimited, or null if the database doesn't support catalogs.

effectiveSchemaName

public java.lang.String effectiveSchemaName(StoreManager storeMgr)
Returns the effective schema name for this object. If this object specifically names a schema, its name is returned as a string (excluding any catalog name part). Otherwise the default schema name from the specified store manager is returned.

Parameters:
storeMgr - the store manager to use to determine the default schema
Returns:
the effective schema name, undelimited, or null if the database doesn't support schemas.

intern

public QualifiedName intern()
Returns a canonical representation for the name object.

This method behaves much like String.intern(). A pool of names, initially empty, is maintained privately.

When the intern method is invoked, if the pool already contains an object equal to this QualifiedName object as determined by the equals(Object) method, then the name from the pool is returned. Otherwise, this QualifiedName object is added to the pool and a reference to this QualifiedName object is returned.

It follows that for any two names n1 and n2, n1.intern() == n2.intern() is true if and only if n1.equals(n2) is true.

Returns:
a name that is equivalent to this name, but is guaranteed to be from a pool of unique names.

hashCode

public final int hashCode()
Returns a hash code value for this object.


equals

public final boolean equals(java.lang.Object obj)
Tests this object for equality with another object. Two QualifiedName objects are equal if they are of the same type and their schema name and identifier parts are equal.

Parameters:
obj - the object to compare with
Returns:
true if the objects are equal, false otherwise.

toString

public final java.lang.String toString()
Returns the SQL string representation of this qualified name. The string representation is suitable for use directly in SQL statement text. In particular, any SQL keywords will be quoted.

Returns:
the SQL string representation of this qualified name.


Copyright 2001-2007 The TJDO Project All Rights Reserved.