org.opengts.dbtools
Class DBRecordKey<gDBR extends DBRecord>

java.lang.Object
  extended by org.opengts.dbtools.DBRecordKey<gDBR>
Direct Known Subclasses:
AccountRecord.AccountKey, SystemProps.Key, UnassignedDevices.Key, UniqueXID.Key

public abstract class DBRecordKey<gDBR extends DBRecord>
extends java.lang.Object

DBRecordKey represents the SQL table key for a DBRecord.


Field Summary
static java.lang.String FLD_autoIndex
           
 
Constructor Summary
protected DBRecordKey()
          Default Constructor
 
Method Summary
protected  void _delete(java.lang.String altIndexName, int whereKeyType)
          Deletes the record corresponding to the Primary Key of thie DBRecordKey.
protected  void _deleteDependencies()
           
protected  boolean _exists(java.lang.String altIndexName, int whereKeyType)
          Returns true if the specified key attribute exists in the table
 gDBR _getDBRecord(boolean reload, java.lang.String... fldNames)
          Gets the DBRecord associated with this key
protected  java.lang.String _getWhereClause(java.lang.String altIndexName, int whereKeyType)
          Return the 'WHERE' clause for this key [CHECK]
 void altIndexDelete(java.lang.String indexName)
          Deletes the record corresponding to the Alternate Key of thie DBRecordKey.
WARNING: If the alternate key is not unique, calling this method when the alternate key fields are blank may cause more records to be deleted than is intended.
 boolean altIndexExists(java.lang.String indexName)
          Returns true if the full Alternate Key exists in the table
 void delete()
          Deletes the record corresponding to the Primary Key of thie DBRecordKey.
 void delete(boolean delDeps)
          Deletes the record corresponding to the Primary Key of thie DBRecordKey.
 boolean equals(java.lang.Object other)
          Returns true if this object is equivilent to the specified object
 boolean exists()
          Returns true if the full Primary Key exists in the table
 boolean exists(boolean fullKeyOnly)
          Returns true if the full (or partial) Primary Key exists in the table
 boolean exists(int whereKeyType)
          Returns true if the partial Primary Key exists in the table
static java.lang.String FilterID(java.lang.String text)
          Filters an ID String, convertering all letters to lowercase and removing invalid characters
protected  DBField[] getAltKeyFields(java.lang.String indexName)
           
 gDBR getDBRecord()
          Gets the DBRecord associated with this key
 gDBR getDBRecord(boolean reload)
          Gets the DBRecord associated with this key
 gDBR getDBRecord(boolean reload, java.lang.String... fldNames)
          Gets the DBRecord associated with this key
abstract  DBFactory<gDBR> getFactory()
          Gets the DBFactory for this DBRecoedKey
 DBField getField(java.lang.String fldName)
           
 DBField[] getFields()
           
 java.lang.Object getFieldValue(java.lang.String fldName)
           
 java.lang.String getFieldValueAsString(java.lang.String fldName)
          See DBFieldValues#getFieldValueAsString(String)
 DBFieldValues getFieldValues()
          Return a DBFieldValues instance for this DBRecordKey
 DBField[] getKeyFields()
           
 java.lang.Object getKeyValue(java.lang.String fldName)
           
 java.lang.String getKeyValueAsString(java.lang.String fldName)
          See DBFieldValues#getFieldValueAsString(String)
 DBFieldValues getKeyValues()
          Return a DBFieldValues instance for this DBRecordKey, which contains only key field values
 java.util.Set<java.lang.String> getTaggedFieldNames()
          Returns a set of tagged field names, or null if no tagged fields have been set.
 java.lang.String getTranslatedTableName()
          Gets the table name for this DBSelect
 java.lang.String getUntranslatedTableName()
           
 gDBR getVirtualDBRecord(ServiceRequest servReq)
          Gets a virtual DBRecord from the specified remote service
 java.lang.String getWhereClause(int whereKeyType)
          Gets the 'WHERE' clause for this key
 boolean hasFieldValue(java.lang.String fldName)
           
 boolean hasKeyValue(java.lang.String fldName)
           
 boolean hasTaggedFields()
          Returns true if any tagged field names have been defined
 boolean isFullKey()
          Returns true if this key fully defines all key fields
 boolean isPartialKey()
          Returns !isFullKey()
 boolean isTaggedFieldName(java.lang.String fldName)
          Returns true if the specified field name is in the 'tagged' list, false otherwise.
static boolean isValidIDChar(char ch)
          Returns true if the specified character is a valid character to use in an ID
 boolean parentsExist()
          Returns true if the parent records in their respective parent tables exist.
static void printXML(java.io.PrintStream out, DBRecordKey... dbrk)
          Encodes the specified DBRecordKyes into XML and writes it to a specified PrintStream
static void printXML(java.io.PrintWriter out, DBRecordKey... dbrk)
          Encodes the specified DBRecordKyes into XML and writes it to a specified PrintWriter
 void printXML(java.io.PrintWriter out, int indent)
          Encodes this DBRecordKey into XML and writes it to a specified PrintWriter
 void printXML(java.io.PrintWriter out, int indent, int sequence)
          Encodes this DBRecordKey into XML and writes it to a specified PrintWriter
 void printXML(java.io.PrintWriter out, int indent, int sequence, boolean soapXML)
          Encodes this DBRecordKey into XML and writes it to a specified PrintWriter
 boolean setFieldValue(java.lang.String fldName, boolean val)
           
 boolean setFieldValue(java.lang.String fldName, double val)
           
 boolean setFieldValue(java.lang.String fldName, int val)
           
 boolean setFieldValue(java.lang.String fldName, long val)
           
 boolean setFieldValue(java.lang.String fldName, java.lang.Object val)
           
 boolean setKeyValue(java.lang.String fldName, boolean val)
           
 boolean setKeyValue(java.lang.String fldName, double val)
           
 boolean setKeyValue(java.lang.String fldName, int val)
           
 boolean setKeyValue(java.lang.String fldName, long val)
           
 boolean setKeyValue(java.lang.String fldName, java.lang.Object val)
           
 void setTaggedFieldNames(java.util.Set<java.lang.String> taggedFields)
          Sets a list of 'tagged' data fields.
 java.lang.String toString()
          Returns a string representation of this object
 java.lang.StringBuffer toXML(java.lang.StringBuffer sb, int indent)
          Encodes this DBRecordKey into XML
 java.lang.StringBuffer toXML(java.lang.StringBuffer sb, int indent, int sequence)
          Encodes this DBRecordKey into XML
 java.lang.StringBuffer toXML(java.lang.StringBuffer sb, int indent, int sequence, boolean soapXML)
          Encodes this DBRecordKey into XML
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FLD_autoIndex

public static final java.lang.String FLD_autoIndex
See Also:
Constant Field Values
Constructor Detail

DBRecordKey

protected DBRecordKey()
Default Constructor

Method Detail

getFactory

public abstract DBFactory<gDBR> getFactory()
Gets the DBFactory for this DBRecoedKey


getUntranslatedTableName

public java.lang.String getUntranslatedTableName()
See Also:
DBFactory.getUntranslatedTableName()

getTranslatedTableName

public java.lang.String getTranslatedTableName()
Gets the table name for this DBSelect

Returns:
The defined table name

getFields

public DBField[] getFields()
See Also:
DBFactory.getFields()

getField

public DBField getField(java.lang.String fldName)
See Also:
DBFactory.getField(String)

getKeyFields

public DBField[] getKeyFields()
See Also:
DBFactory.getKeyFields()

getAltKeyFields

protected DBField[] getAltKeyFields(java.lang.String indexName)
See Also:
DBFactory.getAlternateIndex(String)

getTaggedFieldNames

public java.util.Set<java.lang.String> getTaggedFieldNames()
Returns a set of tagged field names, or null if no tagged fields have been set. 'Tagged' fields may be used by the record handler to indicate that certain data field/columns may be of interest.

Returns:
A set of 'tagged' fields, or null if not set

setTaggedFieldNames

public void setTaggedFieldNames(java.util.Set<java.lang.String> taggedFields)
Sets a list of 'tagged' data fields. This set should contain only non-primary-key field names defined by the DBFactory of this key.

Parameters:
taggedFields - A set of 'tagged' data fields.

hasTaggedFields

public boolean hasTaggedFields()
Returns true if any tagged field names have been defined

Returns:
True if any tagged field names have been defined

isTaggedFieldName

public boolean isTaggedFieldName(java.lang.String fldName)
Returns true if the specified field name is in the 'tagged' list, false otherwise.

Parameters:
fldName - The field name
Returns:
True if the specified field name is in the 'tagged' list.

isFullKey

public boolean isFullKey()
Returns true if this key fully defines all key fields

Returns:
True if this key fully defines all key fields

isPartialKey

public boolean isPartialKey()
Returns !isFullKey()

Returns:
!isFullKey()
See Also:
isFullKey()

getKeyValues

public DBFieldValues getKeyValues()
Return a DBFieldValues instance for this DBRecordKey, which contains only key field values

Returns:
The DBFieldValues instance

hasKeyValue

public boolean hasKeyValue(java.lang.String fldName)
See Also:
DBFieldValues.hasFieldValue(String)

getKeyValue

public java.lang.Object getKeyValue(java.lang.String fldName)
See Also:
DBFieldValues.getFieldValue(java.lang.String)

getKeyValueAsString

public java.lang.String getKeyValueAsString(java.lang.String fldName)
See DBFieldValues#getFieldValueAsString(String)


setKeyValue

public boolean setKeyValue(java.lang.String fldName,
                           java.lang.Object val)
See Also:
DBFieldValues.setFieldValue(String,Object)

setKeyValue

public boolean setKeyValue(java.lang.String fldName,
                           boolean val)
See Also:
DBFieldValues.setFieldValue(String,boolean)

setKeyValue

public boolean setKeyValue(java.lang.String fldName,
                           int val)
See Also:
DBFieldValues.setFieldValue(String,int)

setKeyValue

public boolean setKeyValue(java.lang.String fldName,
                           long val)
See Also:
DBFieldValues.setFieldValue(String,long)

setKeyValue

public boolean setKeyValue(java.lang.String fldName,
                           double val)
See Also:
DBFieldValues.setFieldValue(String,double)

getFieldValues

public DBFieldValues getFieldValues()
Return a DBFieldValues instance for this DBRecordKey

Returns:
The DBFieldValues instance

hasFieldValue

public boolean hasFieldValue(java.lang.String fldName)
See Also:
DBFieldValues.hasFieldValue(String)

getFieldValue

public java.lang.Object getFieldValue(java.lang.String fldName)
See Also:
DBFieldValues.getFieldValue(java.lang.String)

getFieldValueAsString

public java.lang.String getFieldValueAsString(java.lang.String fldName)
See DBFieldValues#getFieldValueAsString(String)


setFieldValue

public boolean setFieldValue(java.lang.String fldName,
                             java.lang.Object val)
See Also:
DBFieldValues.setFieldValue(String,Object)

setFieldValue

public boolean setFieldValue(java.lang.String fldName,
                             boolean val)
See Also:
DBFieldValues.setFieldValue(String,boolean)

setFieldValue

public boolean setFieldValue(java.lang.String fldName,
                             int val)
See Also:
DBFieldValues.setFieldValue(String,int)

setFieldValue

public boolean setFieldValue(java.lang.String fldName,
                             long val)
See Also:
DBFieldValues.setFieldValue(String,long)

setFieldValue

public boolean setFieldValue(java.lang.String fldName,
                             double val)
See Also:
DBFieldValues.setFieldValue(String,double)

exists

public boolean exists()
               throws DBException
Returns true if the full Primary Key exists in the table

Returns:
True if the full Primary key exists in the table, false otherwise
Throws:
DBException

exists

public boolean exists(int whereKeyType)
               throws DBException
Returns true if the partial Primary Key exists in the table

Returns:
True if the partial Primary key exists in the table, false otherwise
Throws:
DBException

exists

public boolean exists(boolean fullKeyOnly)
               throws DBException
Returns true if the full (or partial) Primary Key exists in the table

Parameters:
fullKeyOnly - True to test for existence of the full Primary Key, false to allow testing for existance of a partial primary key.
Returns:
True if the full/partial primary key exists in the table, false otherwise
Throws:
DBException

altIndexExists

public boolean altIndexExists(java.lang.String indexName)
                       throws DBException
Returns true if the full Alternate Key exists in the table

Returns:
True if the full Alternate key exists in the table, false otherwise
Throws:
DBException

_exists

protected boolean _exists(java.lang.String altIndexName,
                          int whereKeyType)
                   throws java.sql.SQLException,
                          DBException
Returns true if the specified key attribute exists in the table

Parameters:
altIndexName - The alternate index name, or null to use the primary index
whereKeyType - The partial key match type
Returns:
True if the specified key attribute exists in the table, false otherwise
Throws:
java.sql.SQLException
DBException

parentsExist

public boolean parentsExist()
                     throws DBException
Returns true if the parent records in their respective parent tables exist.

Returns:
True if the parent records exist.
Throws:
DBException

delete

public void delete()
            throws DBException
Deletes the record corresponding to the Primary Key of thie DBRecordKey. (Warning: Dependent children records are not deleted!)

Throws:
DBException

delete

public void delete(boolean delDeps)
            throws DBException
Deletes the record corresponding to the Primary Key of thie DBRecordKey.

Parameters:
delDeps - True to also delete dependent children records
Throws:
DBException

altIndexDelete

public void altIndexDelete(java.lang.String indexName)
                    throws DBException
Deletes the record corresponding to the Alternate Key of thie DBRecordKey.
WARNING: If the alternate key is not unique, calling this method when the alternate key fields are blank may cause more records to be deleted than is intended.

Parameters:
indexName - The alternate index name (defaults to DBProvider.DEFAULT_ALT_INDEX_NAME)
Throws:
DBException

_delete

protected void _delete(java.lang.String altIndexName,
                       int whereKeyType)
                throws java.sql.SQLException,
                       DBException
Deletes the record corresponding to the Primary Key of thie DBRecordKey.

Parameters:
altIndexName - The alternate index name, or null to delete the primary index
whereKeyType - WHERE key type: Full, PartialFirst, PartialAll
Throws:
java.sql.SQLException
DBException

_deleteDependencies

protected void _deleteDependencies()
                            throws DBException
Throws:
DBException

getWhereClause

public java.lang.String getWhereClause(int whereKeyType)
                                throws DBException
Gets the 'WHERE' clause for this key

Parameters:
whereKeyType - The where key type. One of the constants from DBWhere
Returns:
The 'WHERE' clause for this key
Throws:
DBException - If a database exception occurs

_getWhereClause

protected java.lang.String _getWhereClause(java.lang.String altIndexName,
                                           int whereKeyType)
                                    throws DBException
Return the 'WHERE' clause for this key [CHECK]

Parameters:
altIndexName - The alternate index name. If null or blank, uses primary keys instead
whereKeyType - The where key type. One of the constants from DBWhere
Returns:
The 'WHERE' clause for this key
Throws:
DBException

getDBRecord

public gDBR getDBRecord()
Gets the DBRecord associated with this key

Returns:
The DBRecord associated with this key

getDBRecord

public gDBR getDBRecord(boolean reload)
Gets the DBRecord associated with this key

Parameters:
reload - If the record should be reloaded before it is returned
Returns:
The DBRecord associated with this key

getDBRecord

public gDBR getDBRecord(boolean reload,
                        java.lang.String... fldNames)
Gets the DBRecord associated with this key

Parameters:
reload - If the record should be reloaded before it is returned
fldNames - The specific field-names to reload (null to reload all)
Returns:
The DBRecord associated with this key

_getDBRecord

public gDBR _getDBRecord(boolean reload,
                         java.lang.String... fldNames)
                                   throws DBException
Gets the DBRecord associated with this key

Parameters:
reload - If the record should be reloaded before it is returned
fldNames - The specific field-names to reload (null to reload all)
Returns:
The DBRecord associated with this key
Throws:
DBException

getVirtualDBRecord

public gDBR getVirtualDBRecord(ServiceRequest servReq)
                                         throws DBException
Gets a virtual DBRecord from the specified remote service

Parameters:
servReq - The remote web service
Returns:
The virtual DBRecord (cannot be saved or reloaded)
Throws:
DBException

equals

public boolean equals(java.lang.Object other)
Returns true if this object is equivilent to the specified object

Overrides:
equals in class java.lang.Object
Parameters:
other - The other object
Returns:
True if other is the same class and all fields and field values are the same

toString

public java.lang.String toString()
Returns a string representation of this object

Overrides:
toString in class java.lang.Object
Returns:
The string representation of this object

printXML

public static void printXML(java.io.PrintStream out,
                            DBRecordKey... dbrk)
Encodes the specified DBRecordKyes into XML and writes it to a specified PrintStream

Parameters:
out - The PrintStream
dbrk - The list of DBRecordKeys

printXML

public static void printXML(java.io.PrintWriter out,
                            DBRecordKey... dbrk)
Encodes the specified DBRecordKyes into XML and writes it to a specified PrintWriter

Parameters:
out - The PrintWriter
dbrk - The list of DBRecordKeys

printXML

public void printXML(java.io.PrintWriter out,
                     int indent)
Encodes this DBRecordKey into XML and writes it to a specified PrintWriter

Parameters:
out - The PrintWriter
indent - The number of spaces to indent

printXML

public void printXML(java.io.PrintWriter out,
                     int indent,
                     int sequence)
Encodes this DBRecordKey into XML and writes it to a specified PrintWriter

Parameters:
out - The PrintWriter
indent - The number of spaces to indent
sequence - Optional sequence value

printXML

public void printXML(java.io.PrintWriter out,
                     int indent,
                     int sequence,
                     boolean soapXML)
Encodes this DBRecordKey into XML and writes it to a specified PrintWriter

Parameters:
out - The PrintWriter
indent - The number of spaces to indent
sequence - Optional sequence value
soapXML - True for SOAP XML

toXML

public java.lang.StringBuffer toXML(java.lang.StringBuffer sb,
                                    int indent)
Encodes this DBRecordKey into XML

Parameters:
sb - The StringBuffer to which the DBRecord XML is writen
indent - The number of spaces to indent
Returns:
The StringBuffer

toXML

public java.lang.StringBuffer toXML(java.lang.StringBuffer sb,
                                    int indent,
                                    int sequence)
Encodes this DBRecordKey into XML

Parameters:
sb - The StringBuffer to which the DBRecord XML is writen
indent - The number of spaces to indent
sequence - An optional record sequence number
Returns:
The StringBuffer

toXML

public java.lang.StringBuffer toXML(java.lang.StringBuffer sb,
                                    int indent,
                                    int sequence,
                                    boolean soapXML)
Encodes this DBRecordKey into XML

Parameters:
sb - The StringBuffer to which the DBRecord XML is writen
indent - The number of spaces to indent
sequence - An optional record sequence number
soapXML - True for SOAP XML
Returns:
The StringBuffer

isValidIDChar

public static boolean isValidIDChar(char ch)
Returns true if the specified character is a valid character to use in an ID

Parameters:
ch - The character
Returns:
True if the specified character is a valid character to use in an ID

FilterID

public static java.lang.String FilterID(java.lang.String text)
Filters an ID String, convertering all letters to lowercase and removing invalid characters

Parameters:
text - The ID String to filter
Returns:
The filtered ID String