com.workingdogs.village
Class Record

java.lang.Object
  |
  +--com.workingdogs.village.Record

public class Record
extends java.lang.Object

A Record represents a row in the database. It contains a collection of Values which are the individual contents of each column in the row.

Version:
$Revision: 1.13 $
Author:
Jon S. Stevens jon@latchkey.com

Field Summary
private  boolean[] isClean
          a 1 To 1 relationship between Values and whether they are clean or not
private  int numberOfColumns
          number of columns in this Record
private  DataSet parentDataSet
          the parent DataSet for this Record
private  int saveType
          this is the state of this record
private  Schema schema
          a saved copy of the schema for this Record
private  boolean status
          the status of a record
private  Value[] values
          an array of Value objects, this is 1 based
 
Constructor Summary
  Record()
          This isn't used and doesn't do anything.
  Record(DataSet ds)
          Creates a new Record and sets the parent dataset to the passed in value.
(package private) Record(DataSet ds, boolean addRecord)
          This is a special case method for Record.
 
Method Summary
 java.lang.String asFormattedString(java.lang.String valueseparator, int[] maxwidths)
          return the value of each column as a string.
private  void createValues(java.sql.ResultSet rs)
          Creates the value objects for this Record.
 DataSet dataset()
          Gets the DataSet for this Record
private  java.lang.String getDeleteSaveString()
          Builds the SQL DELETE statement for this Record
private  java.lang.String getInsertSaveString()
          Builds the SQL INSERT statement for this Record
 java.lang.String getRefreshQueryString()
          This builds the SELECT statement in order to refresh the contents of this Record.
 java.lang.String getSaveString()
          Gets the appropriate SQL string for this record.
(package private)  int getSaveType()
          gets the internal save type as one of the defined privates (ie: ZOMBIE)
private  java.lang.String getUpdateSaveString()
          Builds the SQL UPDATE statement for this Record
 Value getValue(int i)
          gets the value at index i
 Value getValue(java.lang.String columnName)
           
private  void initializeRecord()
          Performs initialization for this Record.
 boolean isAZombie()
          Determines if this record is a Zombie.
 void markForInsert()
          Marks this record to be inserted when a save is executed.
 void markForUpdate()
          Marks this record to be updated when a save is executed.
 void markRecordClean()
          Marks all the values in this record as clean.
 Record markToBeDeleted()
          Marks this record to be deleted when a save is executed.
 void markValueClean(int pos)
          marks a value at a given position as clean.
 void markValueClean(java.lang.String columnName)
          marks a value with a given column name as clean.
 void markValueDirty(int pos)
          marks a value at a given position as dirty.
 void markValueDirty(java.lang.String columnName)
          marks a value with a given column name as dirty.
 boolean needsToBeSaved()
          If the record is not clean, needs to be saved with an Update, Delete or Insert, it returns true.
 boolean recordIsClean()
          Goes through all the values in the record to determine if it is clean or not.
 void refresh(java.sql.Connection connection)
          This method refreshes this Record's Value's.
 int save()
          Saves the data in this Record to the database.
 int save(java.sql.Connection connection)
          Saves the data in this Record to the database.
private  int saveWithDelete(java.sql.Connection connection)
          Saves the data in this Record to the database with an DELETE statement
private  int saveWithInsert(java.sql.Connection connection)
          Saves the data in this Record to the database with an INSERT statement
 void saveWithoutStatusUpdate()
           
private  int saveWithUpdate(java.sql.Connection connection)
          Saves the data in this Record to the database with an UPDATE statement
 Schema schema()
          Gets the schema for the parent DataSet
(package private)  void setParentDataSet(DataSet ds)
          Sets the parent DataSet for this record.
(package private)  void setSaveType(int type)
          sets the internal save type as one of the defined privates (ie: ZOMBIE)
 Record setValue(int pos, java.math.BigDecimal value)
          sets the value at pos with a BigDecimal
 Record setValue(int pos, boolean value)
          sets the value at pos with a boolean
 Record setValue(int pos, byte[] value)
          sets the value at pos with a byte[]
 Record setValue(int pos, java.util.Date value)
          sets the value at pos with a java.util.Date
 Record setValue(int pos, java.sql.Date value)
          sets the value at pos with a java.sql.Date
 Record setValue(int pos, double value)
          sets the value at pos with a double
 Record setValue(int pos, float value)
          sets the value at pos with a float
 Record setValue(int pos, int value)
          sets the value at pos with a int
 Record setValue(int pos, long value)
          sets the value at pos with a long
 Record setValue(int pos, java.lang.String value)
          sets the value at pos with a String
 Record setValue(int pos, java.sql.Time value)
          sets the value at pos with a java.sql.Time
 Record setValue(int pos, java.sql.Timestamp value)
          sets the value at pos with a java.sql.Timestamp
 Record setValue(int pos, Value value)
          sets the value at pos with a Value
 Record setValue(java.lang.String columnName, java.math.BigDecimal value)
          sets the value at column name with a BigDecimal
 Record setValue(java.lang.String columnName, boolean value)
          sets the value at column name with a boolean
 Record setValue(java.lang.String columnName, byte[] value)
          sets the value at column name with a byte[]
 Record setValue(java.lang.String columnName, java.util.Date value)
          sets the value at column name with a java.util.Date
 Record setValue(java.lang.String columnName, java.sql.Date value)
          sets the value at column name with a java.sql.Date
 Record setValue(java.lang.String columnName, double value)
          sets the value at column name with a double
 Record setValue(java.lang.String columnName, float value)
          sets the value at column name with a float
 Record setValue(java.lang.String columnName, int value)
          sets the value at column name with a int
 Record setValue(java.lang.String columnName, long value)
          sets the value at column name with a long
 Record setValue(java.lang.String columnName, java.lang.String value)
          sets the value at column name with a String
 Record setValue(java.lang.String columnName, java.sql.Time value)
          sets the value at column name with a java.sql.Time
 Record setValue(java.lang.String columnName, java.sql.Timestamp value)
          sets the value at column name with a java.sql.Timestamp
 Record setValue(java.lang.String columnName, Value value)
          sets the value at column name with a Value
 Record setValueNull(int pos)
          sets the value at pos with a NULL
 Record setValueNull(java.lang.String columnName)
          sets the value at column name with a NULL
 int size()
          the number of columns in this object
 boolean toBeSavedWithDelete()
          whether or not this Record is to be saved with an SQL delete statement
 boolean toBeSavedWithInsert()
          whether or not this Record is to be saved with an SQL insert statement
 boolean toBeSavedWithUpdate()
          whether or not this Record is to be saved with an SQL update statement
 java.lang.String toString()
          This returns a representation of this Record
 Record unmarkToBeDeleted()
          Unmarks a record that has been marked for deletion.
 void updateStatus()
          Updates the status of a Record after a saveWithoutStatusUpdate()
 boolean valueIsClean(int i)
          Determines whether or not a value stored in the record is clean.
(package private)  boolean valueIsClean(java.lang.String column)
          Determines whether or not a value stored in the record is clean.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

values

private Value[] values
an array of Value objects, this is 1 based

isClean

private boolean[] isClean
a 1 To 1 relationship between Values and whether they are clean or not

parentDataSet

private DataSet parentDataSet
the parent DataSet for this Record

numberOfColumns

private int numberOfColumns
number of columns in this Record

saveType

private int saveType
this is the state of this record

schema

private Schema schema
a saved copy of the schema for this Record

status

private boolean status
the status of a record
Constructor Detail

Record

public Record()
This isn't used and doesn't do anything.

Record

public Record(DataSet ds)
       throws DataSetException,
              java.sql.SQLException
Creates a new Record and sets the parent dataset to the passed in value. This method also creates the Value objects which are associated with this Record.

Record

Record(DataSet ds,
       boolean addRecord)
 throws DataSetException,
        java.sql.SQLException
This is a special case method for Record. This case is really only used when DataSet.addRecord() is called because we may not have an existing ResultSet so there will not be any values in the Value objects that are created. Passing null to createValues forces the Value object to be created, but no processing to be done within the Value object constructor.

This method is a package method only because it is really not useful outside of the package.

Parameters:
ds - the dataset
addRecord - whether or not this method is being called from DataSet.addRecord()
Method Detail

initializeRecord

private void initializeRecord()
                       throws DataSetException
Performs initialization for this Record.

createValues

private void createValues(java.sql.ResultSet rs)
                   throws DataSetException,
                          java.sql.SQLException
Creates the value objects for this Record. It is 1 based
Throws:
DataSetException -  
java.sql.SQLException -  

save

public int save()
         throws DataSetException,
                java.sql.SQLException
Saves the data in this Record to the database. Uses the parent dataset's connection.
Returns:
1 if the save completed. 0 otherwise.

save

public int save(java.sql.Connection connection)
         throws DataSetException,
                java.sql.SQLException
Saves the data in this Record to the database. Uses the connection passed into it.
Returns:
1 if the save completed. 0 otherwise.

saveWithDelete

private int saveWithDelete(java.sql.Connection connection)
                    throws DataSetException,
                           java.sql.SQLException
Saves the data in this Record to the database with an DELETE statement
Returns:
SQL DELETE statement

saveWithUpdate

private int saveWithUpdate(java.sql.Connection connection)
                    throws DataSetException,
                           java.sql.SQLException
Saves the data in this Record to the database with an UPDATE statement
Returns:
SQL UPDATE statement

saveWithInsert

private int saveWithInsert(java.sql.Connection connection)
                    throws DataSetException,
                           java.sql.SQLException
Saves the data in this Record to the database with an INSERT statement
Returns:
SQL INSERT statement

getUpdateSaveString

private java.lang.String getUpdateSaveString()
                                      throws DataSetException
Builds the SQL UPDATE statement for this Record
Returns:
SQL UPDATE statement

getDeleteSaveString

private java.lang.String getDeleteSaveString()
                                      throws DataSetException
Builds the SQL DELETE statement for this Record
Returns:
SQL DELETE statement

getInsertSaveString

private java.lang.String getInsertSaveString()
                                      throws DataSetException
Builds the SQL INSERT statement for this Record
Returns:
SQL INSERT statement

getSaveString

public java.lang.String getSaveString()
                               throws DataSetException
Gets the appropriate SQL string for this record.
Returns:
SQL string

getValue

public Value getValue(int i)
               throws DataSetException
gets the value at index i
Returns:
the Value object at index i

getValue

public Value getValue(java.lang.String columnName)
               throws DataSetException

size

public int size()
the number of columns in this object
Returns:
the number of columns in this object

toBeSavedWithInsert

public boolean toBeSavedWithInsert()
whether or not this Record is to be saved with an SQL insert statement
Returns:
true if saved with insert

toBeSavedWithUpdate

public boolean toBeSavedWithUpdate()
whether or not this Record is to be saved with an SQL update statement
Returns:
true if saved with update

toBeSavedWithDelete

public boolean toBeSavedWithDelete()
whether or not this Record is to be saved with an SQL delete statement
Returns:
true if saved with delete

markRecordClean

public void markRecordClean()
                     throws DataSetException
Marks all the values in this record as clean.

markForInsert

public void markForInsert()
                   throws DataSetException
Marks this record to be inserted when a save is executed.

markForUpdate

public void markForUpdate()
                   throws DataSetException
Marks this record to be updated when a save is executed.

markToBeDeleted

public Record markToBeDeleted()
                       throws DataSetException
Marks this record to be deleted when a save is executed.

unmarkToBeDeleted

public Record unmarkToBeDeleted()
                         throws DataSetException
Unmarks a record that has been marked for deletion.

WARNING: You must reset the save type before trying to save this record again.

See Also:
markForUpdate(), markForInsert(), markToBeDeleted()

markValueClean

public void markValueClean(int pos)
                    throws DataSetException
marks a value at a given position as clean.

markValueClean

public void markValueClean(java.lang.String columnName)
                    throws DataSetException
marks a value with a given column name as clean.

markValueDirty

public void markValueDirty(int pos)
                    throws DataSetException
marks a value at a given position as dirty.

markValueDirty

public void markValueDirty(java.lang.String columnName)
                    throws DataSetException
marks a value with a given column name as dirty.

setSaveType

void setSaveType(int type)
sets the internal save type as one of the defined privates (ie: ZOMBIE)

getSaveType

int getSaveType()
gets the internal save type as one of the defined privates (ie: ZOMBIE)

setValue

public Record setValue(int pos,
                       java.math.BigDecimal value)
                throws DataSetException
sets the value at pos with a BigDecimal

setValue

public Record setValue(int pos,
                       boolean value)
                throws DataSetException
sets the value at pos with a boolean

setValue

public Record setValue(int pos,
                       byte[] value)
                throws DataSetException
sets the value at pos with a byte[]

setValue

public Record setValue(int pos,
                       java.util.Date value)
                throws DataSetException
sets the value at pos with a java.util.Date

setValue

public Record setValue(int pos,
                       java.sql.Date value)
                throws DataSetException
sets the value at pos with a java.sql.Date

setValue

public Record setValue(int pos,
                       double value)
                throws DataSetException
sets the value at pos with a double

setValue

public Record setValue(int pos,
                       float value)
                throws DataSetException
sets the value at pos with a float

setValue

public Record setValue(int pos,
                       int value)
                throws DataSetException
sets the value at pos with a int

setValue

public Record setValue(int pos,
                       long value)
                throws DataSetException
sets the value at pos with a long

setValue

public Record setValue(int pos,
                       java.lang.String value)
                throws DataSetException
sets the value at pos with a String

setValue

public Record setValue(int pos,
                       java.sql.Time value)
                throws DataSetException
sets the value at pos with a java.sql.Time

setValue

public Record setValue(int pos,
                       java.sql.Timestamp value)
                throws DataSetException
sets the value at pos with a java.sql.Timestamp

setValue

public Record setValue(int pos,
                       Value value)
                throws DataSetException
sets the value at pos with a Value

setValue

public Record setValue(java.lang.String columnName,
                       java.math.BigDecimal value)
                throws DataSetException
sets the value at column name with a BigDecimal

setValue

public Record setValue(java.lang.String columnName,
                       boolean value)
                throws DataSetException
sets the value at column name with a boolean

setValue

public Record setValue(java.lang.String columnName,
                       byte[] value)
                throws DataSetException
sets the value at column name with a byte[]

setValue

public Record setValue(java.lang.String columnName,
                       java.util.Date value)
                throws DataSetException
sets the value at column name with a java.util.Date

setValue

public Record setValue(java.lang.String columnName,
                       java.sql.Date value)
                throws DataSetException
sets the value at column name with a java.sql.Date

setValue

public Record setValue(java.lang.String columnName,
                       double value)
                throws DataSetException
sets the value at column name with a double

setValue

public Record setValue(java.lang.String columnName,
                       float value)
                throws DataSetException
sets the value at column name with a float

setValue

public Record setValue(java.lang.String columnName,
                       int value)
                throws DataSetException
sets the value at column name with a int

setValue

public Record setValue(java.lang.String columnName,
                       long value)
                throws DataSetException
sets the value at column name with a long

setValue

public Record setValue(java.lang.String columnName,
                       java.lang.String value)
                throws DataSetException
sets the value at column name with a String

setValue

public Record setValue(java.lang.String columnName,
                       java.sql.Time value)
                throws DataSetException
sets the value at column name with a java.sql.Time

setValue

public Record setValue(java.lang.String columnName,
                       java.sql.Timestamp value)
                throws DataSetException
sets the value at column name with a java.sql.Timestamp

setValue

public Record setValue(java.lang.String columnName,
                       Value value)
                throws DataSetException
sets the value at column name with a Value

setValueNull

public Record setValueNull(int pos)
                    throws DataSetException
sets the value at pos with a NULL

setValueNull

public Record setValueNull(java.lang.String columnName)
                    throws DataSetException
sets the value at column name with a NULL

isAZombie

public boolean isAZombie()
Determines if this record is a Zombie. A Zombie is a record that has been deleted from the database, but not yet removed from the DataSet.
Returns:
a boolean

needsToBeSaved

public boolean needsToBeSaved()
If the record is not clean, needs to be saved with an Update, Delete or Insert, it returns true.
Returns:
boolean

valueIsClean

public boolean valueIsClean(int i)
Determines whether or not a value stored in the record is clean.
Returns:
true if clean

valueIsClean

boolean valueIsClean(java.lang.String column)
               throws DataSetException
Determines whether or not a value stored in the record is clean.
Returns:
true if clean

recordIsClean

public boolean recordIsClean()
Goes through all the values in the record to determine if it is clean or not.
Returns:
true if clean

refresh

public void refresh(java.sql.Connection connection)
             throws DataSetException,
                    java.sql.SQLException
This method refreshes this Record's Value's. It can only be performed on a Record that has not been modified and has been created with a TableDataSet and corresponding KeyDef.
Parameters:
connection -  
Throws:
DataSetException -  
java.sql.SQLException -  

getRefreshQueryString

public java.lang.String getRefreshQueryString()
                                       throws DataSetException
This builds the SELECT statement in order to refresh the contents of this Record. It depends on a valid KeyDef to exist and it must have been created with a TableDataSet.
Returns:
the SELECT string
Throws:
DataSetException -  

saveWithoutStatusUpdate

public void saveWithoutStatusUpdate()
                             throws DataSetException

schema

public Schema schema()
              throws DataSetException
Gets the schema for the parent DataSet
Returns:
the schema for the parent DataSet

dataset

public DataSet dataset()
Gets the DataSet for this Record
Returns:
the DataSet for this Record

setParentDataSet

void setParentDataSet(DataSet ds)
Sets the parent DataSet for this record.

asFormattedString

public java.lang.String asFormattedString(java.lang.String valueseparator,
                                          int[] maxwidths)
                                   throws DataSetException
return the value of each column as a string. Not yet implemented!
Parameters:
valueseparator -  
maxwidths -  
Returns:
the formatted string
Throws:
DataSetException -  

toString

public java.lang.String toString()
This returns a representation of this Record
Overrides:
toString in class java.lang.Object
Returns:
java.lang.String

updateStatus

public void updateStatus()
                  throws java.sql.SQLException,
                         DataSetException
Updates the status of a Record after a saveWithoutStatusUpdate()
Throws:
java.sql.SQLException -  
DataSetException -  


Copyright © 1999-2002 Share.Whichever.com All Rights Reserved.