com.triactive.jdo.store.sql
Class SqlIdentifier

java.lang.Object
  extended bycom.triactive.jdo.store.sql.SqlIdentifier
All Implemented Interfaces:
java.lang.Comparable
Direct Known Subclasses:
CatalogName, ColumnName, CorrelationName

public class SqlIdentifier
extends java.lang.Object
implements java.lang.Comparable

An SQL identifier.

Author:
Mike Martin

Field Summary
protected  DatabaseAdapter dba
          The database adapter for the relevant database.
protected  java.lang.String fullName
          The full identifier value before any truncation.
protected  java.lang.String name
          The identifier value, possibly truncated.
 
Method Summary
 int compareTo(java.lang.Object obj)
          Compares this object with the specified object for order.
 boolean equals(java.lang.Object obj)
          Tests this object for equality with another object.
 int hashCode()
          Returns a hash code value for this object.
 SqlIdentifier intern()
          Returns a canonical representation for the identifier object.
 boolean isKeyword()
          Tests whether this identifier is also a SQL keyword in the relevant database.
static java.lang.String javaToSql(java.lang.String javaName)
          Converts the given Java name to its equivalent, full-length SQL identifier value.
 java.lang.String toString()
          Returns the string representation of this SQL identifier.
 java.lang.String undelimited()
          Returns the undelimited string representation of this identifier.
 java.lang.String untruncated()
          Returns the untruncated, undelimited string representation of this identifier.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

dba

protected final DatabaseAdapter dba
The database adapter for the relevant database.


fullName

protected final java.lang.String fullName
The full identifier value before any truncation.


name

protected final java.lang.String name
The identifier value, possibly truncated.

Method Detail

isKeyword

public final boolean isKeyword()
Tests whether this identifier is also a SQL keyword in the relevant database. Identifiers that are keywords will be quoted when converted to string with toString().

Returns:
true if this identifier is a SQL keyword in its database, false otherwise.

intern

public SqlIdentifier intern()
Returns a canonical representation for the identifier object.

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

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

It follows that for any two identifiers i1 and i2, i1.intern() == i2.intern() is true if and only if i1.equals(i2) is true.

Returns:
an identifier that is equivalent to this identifier, but is guaranteed to be from a pool of unique identifiers.

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 SqlIdentifier objects are equal if they are of the same type and their name parts are equal.

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

compareTo

public final int compareTo(java.lang.Object obj)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object. SqlIdentifiers are ordered by their undelimited string representation.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
obj - the Object to be compared.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

toString

public final java.lang.String toString()
Returns the string representation of this SQL identifier. 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.

undelimited

public java.lang.String undelimited()
Returns the undelimited string representation of this identifier. This is the same as the toString() representation except that SQL keywords will not be quoted (delimited).

Returns:
the undelimited string representation of this identifier.

untruncated

public java.lang.String untruncated()
Returns the untruncated, undelimited string representation of this identifier. This is the same as the undelimited() representation except that it returns the original name passed to this object's constructor before any truncation occurred.

Returns:
the untruncated, undelimited string representation of this identifier.

javaToSql

public static java.lang.String javaToSql(java.lang.String javaName)
Converts the given Java name to its equivalent, full-length SQL identifier value.

Conversion consists of breaking the string into words, converting each word to upper-case, and separating each one with an underscore "_". Words are identified by a leading upper-case character. Invalid SQL identifier characters are replaced with a 2 or 4 character string representing their Unicode value in hex. Finally, any leading or trailing underscores are removed.

Java NameSQL Identifier
abcABC
DiskDriveDISK_DRIVE
DiskDrive.numHeadsDISK_DRIVE_NUM_HEADS
JSPPageJSPPAGE
KönigKF6NIG
_fooFOO

Parameters:
javaName - the Java identifier
Returns:
the equivalent SQL identifier as a string.


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