com.strangelight.db
Class KeyedRow

java.lang.Object
  |
  +--com.strangelight.db.TableRow
        |
        +--com.strangelight.db.KeyedRow
Direct Known Subclasses:
User

public abstract class KeyedRow
extends TableRow

A TableRow row which also has a standardized primary key. The column which must be present in a database table with KeyedRows is:

id
the PRIMARY KEY of this table. Must be of type INT and be declared AUTO_INCREMENT.
In other words: the SQL CREATE TABLE definition of a database table encapsulated by a subclass of KeyedRow must look something like this:
                 CREATE TABLE MyTableName (
                         id                      int PRIMARY KEY auto_increment,
                         ...
         
Applications typically subclass KeyedRow by defining a TableRow.getTableName() method and accessor methods which wrap TableRow.getString( String ), TableRow.setString( String, String ), TableRow.getObject( String ), and/or TableRow.setObject( String, Object ).

See Also:
JoinRow

Constructor Summary
KeyedRow()
          Creates a new, empty KeyedRow object.
KeyedRow(int id)
          Fetches the KeyedRow object with the given PRIMARY KEY (specified as an int) from the database.
KeyedRow(java.lang.Integer id)
          Fetches the KeyedRow object with the given PRIMARY KEY (specified as an Integer object) from the database.
 
Method Summary
 void commit()
          Writes any changes made to this KeyedRow object back to the database.
 void finalize()
           
 java.lang.String get_id()
          gets the primary key of this DB row as an int.
 java.lang.Integer getId()
          gets the primary key of this DB row as an Integer object.
 
Methods inherited from class com.strangelight.db.TableRow
drop, getFields, getObject, getString, getTableName, getWhereClause, setObject, setString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyedRow

public KeyedRow()
Creates a new, empty KeyedRow object. (This object will not be written back to the database unless and until at least one of its fields is explicitly set.)


KeyedRow

public KeyedRow(java.lang.Integer id)
Fetches the KeyedRow object with the given PRIMARY KEY (specified as an Integer object) from the database.

Parameters:
id - the PRIMARY KEY of the desired database row.

KeyedRow

public KeyedRow(int id)
         throws E_NoSuchEntity
Fetches the KeyedRow object with the given PRIMARY KEY (specified as an int) from the database.

Parameters:
id - the PRIMARY KEY of the desired database row.
Method Detail

getId

public java.lang.Integer getId()
gets the primary key of this DB row as an Integer object.

Returns:
the PRIMARY KEY of this row as an Integer object, or null if this is a new object which has not yet been written to the database and therefore does not yet have a PRIMARY KEY.

get_id

public java.lang.String get_id()
gets the primary key of this DB row as an int.

Returns:
the PRIMARY KEY of this row as a String, or null if this is a new object which has not yet been written to the database and therefore does not yet have a PRIMARY KEY.

commit

public void commit()
Writes any changes made to this KeyedRow object back to the database. If this is a newly-created row, then commit() also fetches the newly-generated PRIMARY KEY back from the database.

Note that this method is called automatically during garbage-collection.

Overrides:
commit in class TableRow

finalize

public void finalize()
Overrides:
finalize in class TableRow