com.workingdogs.village
Class KeyDef

java.lang.Object
  extended by com.workingdogs.village.KeyDef

public class KeyDef
extends java.lang.Object

A KeyDef is a way to define the key columns in a table. The KeyDef is generally used in conjunction with a TableDataSet. Essentially a KeyDef is what forms the WHERE clause for an UPDATE or DELETE.

In order to use the KeyDef, you simply use it like this:

  KeyDef kd = new KeyDef().addAttrib("key_column_a");
  TableDataSet tds = new TableDataSet ( connection, "table", kd );
  tds.fetchRecords();
  Record rec = tds.getRecord(0);
  rec.setValue("column_name", "new value" );
  rec.save();
  tds.close();
  
In the above example, Record 0 is retrieved from the database table and the following update statement is generated:

UPDATE table SET column_name=? WHERE key_column_a=?

Version:
$Revision: 568 $
Author:
Jon S. Stevens

Constructor Summary
KeyDef()
          Constructor for KeyDef.
 
Method Summary
 KeyDef addAttrib(java.lang.String name)
          Adds the named attribute to the KeyDef.
 boolean containsAttrib(java.lang.String name)
          Determines if the KeyDef contains the requested Attribute.
 java.lang.String getAttrib(int pos)
          getAttrib is 1 based.
 int size()
          KeyDef's are 1 based, returns size - 1
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyDef

public KeyDef()
Constructor for KeyDef. Make sure to always initialize KeyDef with an initial element because it is 1 based.

Method Detail

addAttrib

public KeyDef addAttrib(java.lang.String name)
Adds the named attribute to the KeyDef.

Parameters:
name - TODO: DOCUMENT ME!
Returns:
a copy of itself

containsAttrib

public boolean containsAttrib(java.lang.String name)
Determines if the KeyDef contains the requested Attribute.

Parameters:
name - TODO: DOCUMENT ME!
Returns:
true if the attribute has been defined. false otherwise.

getAttrib

public java.lang.String getAttrib(int pos)
getAttrib is 1 based. Setting pos to 0 will attempt to return pos 1.

Parameters:
pos - TODO: DOCUMENT ME!
Returns:
value of Attribute at pos as String. null if value is not found.

size

public int size()
KeyDef's are 1 based, returns size - 1

Returns:
the number of elements in the KeyDef that were set by addAttrib()
See Also:
addAttrib(java.lang.String)


Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.