org.paneris.jal.model
Class DDRecord

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable
          extended by org.paneris.util.ExtendedHash
              extended by org.paneris.jal.model.DDRecord
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map
Direct Known Subclasses:
Attachment, Board, Message, User

public class DDRecord
extends ExtendedHash

A DDRecord holds data and metadata for a single record from the database it is passed into the webcontext and introspected by the template.

Note that a DDRecord represents one record in a particular table. It will always hold the metadata (as defined in the datadictionary tables in the DB).

It may also contain values for each field in the record. We say that it is "empty" if it does not contain such values.

Version:
0.9, 11/6/1999
Author:
Paneris
See Also:
Serialized Form

Field Summary
protected  DBConnectionManager connMgr
           
protected  java.lang.String database
           
 DataCache dataCache
           
protected static boolean debug
           
 TableMetaData metaData
           
 
Constructor Summary
DDRecord(java.lang.String db, java.lang.Integer tn)
          Constructor to build an empty DDRecord given an Integer denoting the table number in the DataDictionary.
DDRecord(java.lang.String db, java.lang.Integer tn, java.lang.Integer record)
          Constructor to build a DDRecord given an integer denoting the table and an Integer indicating the record to read into this DDRecord
DDRecord(java.lang.String db, java.lang.Integer tn, java.sql.ResultSet rs)
          Constructor to build a DDRecord given an integer denoting the table and a java.sql.resultSet to find the values from.
DDRecord(java.lang.String db, java.lang.String tn)
          Constructor to build an empty DDRecord given a String describing the table name.
DDRecord(java.lang.String db, java.lang.String tn, java.lang.Integer record)
          Constructor to build a DDRecord given an integer denoting the table and an Integer indicating the record to read into this DDRecord
DDRecord(java.lang.String db, java.lang.String tn, java.sql.ResultSet rs)
          Constructor to build a DDRecord given a string describing the table and a java.sql.resultSet to find the values from
 
Method Summary
 void appendFieldValue(java.lang.String field, java.lang.String v)
          append a value to the value of this field
 void delete()
          Deletes this record from the database
 java.lang.Object get(java.lang.Object key)
          Returns the value to which the specified key is mapped in this ExtendedHash.
 RecordSet getChildren(java.lang.String table, java.lang.String field)
           
 DDField getField(java.lang.String field)
          Returns the DDField for a named field
 java.lang.String getFieldValue(java.lang.String field)
          Get the value of the given field as a String
 java.util.Vector getLinksToThis(boolean full)
          Get a list of records which link to this record.
 java.util.Vector getLinksToThis(boolean full, boolean force)
           
 TableMetaData getMetaData()
          Get the metadata for the table that this DDRecord is in
 RecordSet getOrderedChildren(java.lang.String table, java.lang.String field, java.lang.String orderField)
          gets an ordered record set of child data for this record for a given table
 java.util.Vector getProblems()
          Get any validation problems with this record
protected  java.sql.ResultSet getResultSet(java.lang.Integer record, java.sql.Statement s)
          Gets a ResultSet representing the record indicated by record
protected  void init(java.sql.ResultSet rs)
          Sets the values of this DDRecord from a ResultsSet (a record in the DB)
 boolean isDuplicated(DDField field, java.lang.String value)
          Find out if any other record in the database has the relevant field set to this value.
 void setFieldValue(java.lang.String field, java.lang.Object value)
          Set the value of the given field from a Object
 void setFieldValue(java.lang.String field, java.lang.String value)
          Set the value of the given field from a String
 void setFromDefaults()
          fill in the values for this DDRecord From the defaults set in the DataDictionary
 void setFromForm(org.webmacro.servlet.WebContext context)
          fill in the values for this DDRecord by reading them in from a CGI Form - The idea is that this DDRecord will not have any values set, just the metaData and DDField structure.
 void setFromForm(org.webmacro.servlet.WebContext context, java.lang.String postfix)
           
 void setFromForm(org.webmacro.servlet.WebContext context, java.lang.String postfix, boolean force)
           
 void write()
          Write this record to the database.
 void write(boolean forceid)
          Write this record to the database.
 
Methods inherited from class org.paneris.util.ExtendedHash
clear, elements, joinKeys, keys, put, remove
 
Methods inherited from class java.util.Hashtable
clone, contains, containsKey, containsValue, entrySet, equals, hashCode, isEmpty, keySet, putAll, rehash, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

metaData

public TableMetaData metaData

debug

protected static final boolean debug
See Also:
Constant Field Values

dataCache

public DataCache dataCache

connMgr

protected DBConnectionManager connMgr

database

protected java.lang.String database
Constructor Detail

DDRecord

public DDRecord(java.lang.String db,
                java.lang.String tn)
         throws java.lang.Exception
Constructor to build an empty DDRecord given a String describing the table name.

Parameters:
db - a String indicating which database to use. This is used to look up the full (JDBC) database details
tn - the name of the table that this DDRecord is from
Throws:
can - throw exceptions if we can't connect to the db
java.lang.Exception

DDRecord

public DDRecord(java.lang.String db,
                java.lang.Integer tn)
         throws java.lang.Exception
Constructor to build an empty DDRecord given an Integer denoting the table number in the DataDictionary.

Parameters:
db - a String indicating which database to use. This is used to look up the full (JDBC) database details
tn - the number of the table that this DDRecord is from as defined by the DataDictionaryTables table
Throws:
can - throw exceptions if we can't connect to the db
java.lang.Exception

DDRecord

public DDRecord(java.lang.String db,
                java.lang.String tn,
                java.sql.ResultSet rs)
         throws java.lang.Exception
Constructor to build a DDRecord given a string describing the table and a java.sql.resultSet to find the values from

Parameters:
db - a String indicating which database to use. This is used to look up the full (JDBC) database details
tn - the name of the table that this DDRecord is from
rs - a record used to fill in the values of this DDRecord
Throws:
can - throw exceptions if we can't connect to the db
java.lang.Exception

DDRecord

public DDRecord(java.lang.String db,
                java.lang.Integer tn,
                java.sql.ResultSet rs)
         throws java.lang.Exception
Constructor to build a DDRecord given an integer denoting the table and a java.sql.resultSet to find the values from.

Parameters:
db - a String indicating which database to use. This is used to look up the full (JDBC) database details
tn - the number of the table that this DDRecord is from as defined by the DataDictionaryTables table
rs - a record used to fill in the values of this DDRecord
Throws:
can - throw exceptions if we can't connect to the db
java.lang.Exception

DDRecord

public DDRecord(java.lang.String db,
                java.lang.String tn,
                java.lang.Integer record)
         throws java.lang.Exception
Constructor to build a DDRecord given an integer denoting the table and an Integer indicating the record to read into this DDRecord

Parameters:
db - a String indicating which database to use. This is used to look up the full (JDBC) database details
tn - the name of the table that this DDRecord is from
record - the id of a record used to fill in the values of this DDRecord
Throws:
can - throw exceptions if we can't connect to the db
java.lang.Exception

DDRecord

public DDRecord(java.lang.String db,
                java.lang.Integer tn,
                java.lang.Integer record)
         throws java.lang.Exception
Constructor to build a DDRecord given an integer denoting the table and an Integer indicating the record to read into this DDRecord

Parameters:
db - a String indicating which database to use. This is used to look up the full (JDBC) database details
tn - the number of the table that this DDRecord is from as defined by the DataDictionaryTables table
record - the id of a record used to fill in the values of this DDRecord
Throws:
java.lang.Exception - if we can't connect to the db
Method Detail

init

protected void init(java.sql.ResultSet rs)
             throws java.lang.Exception
Sets the values of this DDRecord from a ResultsSet (a record in the DB)

Parameters:
rs - the ResultSet to use in setting the values of the DDRecord
Throws:
java.lang.Exception - if cannot connect to the DB or column not found

getResultSet

protected java.sql.ResultSet getResultSet(java.lang.Integer record,
                                          java.sql.Statement s)
                                   throws java.lang.Exception
Gets a ResultSet representing the record indicated by record

Parameters:
record - the id of a record
s - a Statement used to execute a query
Returns:
a ResultSet representing the record
Throws:
can - throw exceptions if we can't connect to the db
java.lang.Exception

getMetaData

public TableMetaData getMetaData()
Get the metadata for the table that this DDRecord is in

Returns:
A TableMetaData object representing the metadata

getFieldValue

public java.lang.String getFieldValue(java.lang.String field)
Get the value of the given field as a String

Parameters:
field - the name of the field
Returns:
the value of the field as a String

setFieldValue

public void setFieldValue(java.lang.String field,
                          java.lang.String value)
Set the value of the given field from a String

Parameters:
field - the name of the field
value - the value we wish to set the field to

appendFieldValue

public void appendFieldValue(java.lang.String field,
                             java.lang.String v)
append a value to the value of this field


getField

public DDField getField(java.lang.String field)
Returns the DDField for a named field

Parameters:
field - the name of the field
Returns:
the named DDField

setFieldValue

public void setFieldValue(java.lang.String field,
                          java.lang.Object value)
Set the value of the given field from a Object

Parameters:
field - the name of the field
value - the value we wish to set the field to

getProblems

public java.util.Vector getProblems()
                             throws java.lang.Exception
Get any validation problems with this record

Returns:
a vector of any ValidationProblems found
Throws:
Database - problems only?
java.lang.Exception

setFromForm

public void setFromForm(org.webmacro.servlet.WebContext context)
                 throws java.lang.Exception
fill in the values for this DDRecord by reading them in from a CGI Form - The idea is that this DDRecord will not have any values set, just the metaData and DDField structure.

It may, however, have the id set. If an id is read in from the form then this will override the current value. If there is no id in the form then the current value is left.

If postfix is set, then it is appended to the name of the to read the value from the form. For example, normally the field "myfield" will be set to the value of the form field "myfield". If postfix is set to "_default" then the field will be set from the form field "myfield_default".

Parameters:
context - a WebContext which contains the Form object from which we read the values
postfix - A string to append to the fieldnames before getting the values from the form
force - Set fields to null if input is null useful to set this to false when not all fields are on the form watch out for checkboxes which return null when unchecked
Throws:
Database - problems only?
java.lang.Exception

setFromForm

public void setFromForm(org.webmacro.servlet.WebContext context,
                        java.lang.String postfix)
                 throws java.lang.Exception
Throws:
java.lang.Exception

setFromForm

public void setFromForm(org.webmacro.servlet.WebContext context,
                        java.lang.String postfix,
                        boolean force)
                 throws java.lang.Exception
Throws:
java.lang.Exception

setFromDefaults

public void setFromDefaults()
                     throws java.lang.Exception
fill in the values for this DDRecord From the defaults set in the DataDictionary

Throws:
Database - problems only?
java.lang.Exception

write

public void write()
           throws java.lang.Exception

Write this record to the database.

If this record has a autorandom field, and we are 'inserting', the autorandom field will be set to (surprise) a random number. This is then used by the reread() method to reload the record from the database. This means the the id field will be set, and can be used in your program.

Throws:
Database - problems only?
java.lang.Exception

write

public void write(boolean forceid)
           throws java.lang.Exception

Write this record to the database.

The id of the record should be 0 (or forceid should be true) if you wish to create a new record. If this is not the case then we update the record that already exists (and we'll get an error if it doesn't!)

If this record has a autorandom field, and we are 'inserting', the autorandom field will be set to (surprise) a random number. This is then used by the reread() method to reload the record from the database. This means the the id field will be set, and can be used in your program.

Parameters:
forceid - Write a new record into the database, even if one already exists (i.e. don't just update the existing record)
Throws:
Database - problems only?
java.lang.Exception

delete

public void delete()
            throws java.lang.Exception
Deletes this record from the database

Throws:
Database - problems only?
java.lang.Exception

isDuplicated

public boolean isDuplicated(DDField field,
                            java.lang.String value)
                     throws java.lang.Exception
Find out if any other record in the database has the relevant field set to this value.

It is assumed that the id of this DDField is already set to a value which we are going to use to insert this record into the DB under (which could be 0)

Parameters:
field - the field we want to be unique
value - the value we don't want to already exist for this field
Returns:
'true' if the value already exists for this field, 'false' otherwise
Throws:
Database - problems only?
java.lang.Exception

getLinksToThis

public java.util.Vector getLinksToThis(boolean full)
                                throws java.lang.Exception
Get a list of records which link to this record. Note that if the id is not set,

Parameters:
full - if true then the return Vector will have one entry for each record linking to this one. Otherwise, the vector will only contain one (representative, i.e. only containing metadata) DDRecord for each table/field combination which links to this recrod
force - if true, then the eturn Vector will have an entry even if no data in the child table links to this record
Returns:
A vector of records linking to this record
Throws:
If - the id field is not set, we cannot find out if any records link to us, so we get an exception
java.lang.Exception

getLinksToThis

public java.util.Vector getLinksToThis(boolean full,
                                       boolean force)
                                throws java.lang.Exception
Throws:
java.lang.Exception

getChildren

public RecordSet getChildren(java.lang.String table,
                             java.lang.String field)
                      throws java.lang.Exception
Throws:
java.lang.Exception

getOrderedChildren

public RecordSet getOrderedChildren(java.lang.String table,
                                    java.lang.String field,
                                    java.lang.String orderField)
                             throws java.lang.Exception
gets an ordered record set of child data for this record for a given table

Throws:
java.lang.Exception

get

public java.lang.Object get(java.lang.Object key)
Returns the value to which the specified key is mapped in this ExtendedHash.

Specified by:
get in interface java.util.Map
Overrides:
get in class java.util.Hashtable
Parameters:
key - a key in the DDRecord.
Returns:
the value to which the key is mapped in this DDRecord;
See Also:
if the key is not mapped to any value in this DDRecord, as that means the field name is wrong.


Copyright © 2000-2008 PanEris. All Rights Reserved.