butler.sql.record
Class Record

java.lang.Object
  extended by butler.util.BaseGroovyObjectSupport
      extended by butler.sql.record.Record
All Implemented Interfaces:
groovy.lang.GroovyObject
Direct Known Subclasses:
AttributedRecord, AttributesRecord, GeneratorRecord, OperationRecord, OpFieldRecord, TransRecord

public class Record
extends butler.util.BaseGroovyObjectSupport

Record in the database.

Author:
Fredrik Bertilsson

Nested Class Summary
static class Record.State
          The state for a record.
static class Record.ValidationException
           
 
Field Summary
 java.util.Map _relatedRecord
           
 java.util.Map _relatedRecords
           
 
Constructor Summary
Record(Table table)
           
Record(Table table, java.lang.String content)
           
 
Method Summary
 void addRelatedRecord(ForeignKey fk, Record rec)
           
 void addRelatedRecord(Join join, Record rec)
           
 Record addRelatedRecord(ManyToManyRelation relation, Record rec)
          Connects a record using a many-to-many relation.
 void addRelatedRecord(java.lang.String fkName, Record rec)
           
 void checkMandatory()
           
 void copy(java.util.Map map)
          Copies the content of the given map to this record.
 void copy(Record rec)
          Copies the content of the given record to this record.
 void delete()
          Deletes the record in the database.
 void delete(boolean cascade)
           
 boolean equals(java.lang.Object anOther)
           
 java.lang.Object get(Column column)
          Returns the value for the given column.
 java.lang.Object get(java.lang.String colname)
          Returns the value for the given column.
 java.util.Set getChangedColumns()
           
 java.util.Map getContent()
          Returns the column values as a Map.
 double getDouble(Column col)
           
 double getDouble(java.lang.String colname)
           
 butler.util.Tuple getFKValues(ForeignKey fk)
           
 java.lang.String getFormattedValue(Column col)
           
 long getID()
           
 int getInt(Column col)
           
 int getInt(java.lang.String colname)
           
 PrimaryKeyTuple getPrimaryKey()
          Returns the values for the primary key.
 java.lang.Object getProperty(java.lang.String property)
           
 Record getRelatedRecord(ForeignKey fk)
          Returns the related record in a one-to-many relation.
 Record getRelatedRecord(java.lang.String fkName)
           
 Record getRelatedRecord(Table table)
           
 RecordList getRelatedRecords(ForeignKey fk)
          Returns the related records in a many-to-one relation.
 RecordList getRelatedRecords(ManyToManyRelation relation)
           
 RecordList getRelatedRecords(java.lang.String name)
           
 RecordList getRelatedRecords(Table table)
           
 Record.State getState()
          Returns the state of this record.
 Table getTable()
          Returns the table to which the record belongs.
 int hashCode()
           
 void initDefaultValues()
           
 boolean isAggregate()
           
 boolean isChanged()
          Checks if this record has changed in the database.
 void makeClean()
          Make this record and all related records to clean.
static Record parseRecord(org.dom4j.Element element)
           
static Record parseRecord(org.dom4j.Element element, Join join)
           
static Record parseRecord(org.dom4j.Element element, Query q)
           
static Record parseRecord(org.dom4j.Element element, Table tab)
           
static Record parseXML(java.lang.String xml)
           
 void reset()
           
 void save()
          Saves the record in the database by using update, insert or delete.
 void saveOptimistic()
           
 void set(Column column, java.lang.Object value)
          Sets a column in the record.
 void set(java.lang.String colname, java.lang.Object value)
          Sets a column in the record.
 void setAggregate(boolean aggregate)
           
 void setFormattedValue(Column col, java.lang.String value)
           
 void setPrimaryKey(butler.util.Tuple key)
           
 void setProperty(java.lang.String property, java.lang.Object newValue)
           
 void setRelatedRecord(ForeignKey fk, Record rec)
           
 void setRelatedRecord(java.lang.String fkName, Record rec)
           
 void setRelatedRecords(ForeignKey fk, RecordList recList)
           
 void setRelatedRecords(ManyToManyRelation relation, RecordList recList)
           
 void setRelatedRecords(java.lang.String name, RecordList recList)
           
 void setState(Record.State state)
          Sets the state of this record.
 java.lang.String toString()
           
 java.lang.String toString(java.util.List cols)
           
 java.lang.String toXML()
           
 void toXML(org.xml.sax.ContentHandler handler)
           
 void toXMLCompact(org.xml.sax.ContentHandler handler)
           
 void toXMLCompact(org.xml.sax.ContentHandler handler, java.util.List cols, java.util.List nextJoins, java.lang.String alias, ForeignKey fk)
           
 void toXMLSimple(org.xml.sax.ContentHandler handler, java.util.List cols, java.util.List nextJoins)
           
protected  java.lang.String trim(java.lang.String str)
           
 void unload(java.io.PrintStream stream)
           
 void validate()
           
 
Methods inherited from class butler.util.BaseGroovyObjectSupport
getMetaClass, invokeMethod, setMetaClass
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_relatedRecord

public java.util.Map _relatedRecord

_relatedRecords

public java.util.Map _relatedRecords
Constructor Detail

Record

public Record(Table table)

Record

public Record(Table table,
              java.lang.String content)
       throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

getTable

public Table getTable()
               throws java.lang.Exception
Returns the table to which the record belongs.

Throws:
java.lang.Exception

set

public void set(Column column,
                java.lang.Object value)
         throws java.lang.Exception
Sets a column in the record.

Throws:
java.lang.Exception

set

public void set(java.lang.String colname,
                java.lang.Object value)
         throws java.lang.Exception
Sets a column in the record.

Throws:
java.lang.Exception

get

public java.lang.Object get(Column column)
                     throws java.lang.Exception
Returns the value for the given column.

Throws:
java.lang.Exception

get

public java.lang.Object get(java.lang.String colname)
                     throws java.lang.Exception
Returns the value for the given column.

Throws:
java.lang.Exception

getInt

public int getInt(Column col)
           throws java.lang.Exception
Throws:
java.lang.Exception

getInt

public int getInt(java.lang.String colname)
           throws java.lang.Exception
Throws:
java.lang.Exception

getDouble

public double getDouble(Column col)
                 throws java.lang.Exception
Throws:
java.lang.Exception

getDouble

public double getDouble(java.lang.String colname)
                 throws java.lang.Exception
Throws:
java.lang.Exception

getProperty

public java.lang.Object getProperty(java.lang.String property)
Specified by:
getProperty in interface groovy.lang.GroovyObject
Overrides:
getProperty in class butler.util.BaseGroovyObjectSupport

setProperty

public void setProperty(java.lang.String property,
                        java.lang.Object newValue)
Specified by:
setProperty in interface groovy.lang.GroovyObject
Overrides:
setProperty in class butler.util.BaseGroovyObjectSupport

getFormattedValue

public java.lang.String getFormattedValue(Column col)
                                   throws java.lang.Exception
Throws:
java.lang.Exception

setFormattedValue

public void setFormattedValue(Column col,
                              java.lang.String value)
                       throws java.lang.Exception
Throws:
java.lang.Exception

getPrimaryKey

public PrimaryKeyTuple getPrimaryKey()
                              throws java.lang.Exception
Returns the values for the primary key.

Throws:
java.lang.Exception

setPrimaryKey

public void setPrimaryKey(butler.util.Tuple key)
                   throws java.lang.Exception
Throws:
java.lang.Exception

getContent

public java.util.Map getContent()
Returns the column values as a Map.


save

public void save()
          throws java.lang.Exception
Saves the record in the database by using update, insert or delete.

Throws:
java.lang.Exception

delete

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

Throws:
java.lang.Exception

delete

public void delete(boolean cascade)
            throws java.lang.Exception
Throws:
java.lang.Exception

copy

public void copy(Record rec)
          throws java.lang.Exception
Copies the content of the given record to this record.

Throws:
java.lang.Exception

copy

public void copy(java.util.Map map)
          throws java.lang.Exception
Copies the content of the given map to this record.

Throws:
java.lang.Exception

getState

public Record.State getState()
Returns the state of this record.


setState

public void setState(Record.State state)
              throws java.lang.Exception
Sets the state of this record.

Throws:
java.lang.Exception

getRelatedRecord

public Record getRelatedRecord(ForeignKey fk)
                        throws java.lang.Exception
Returns the related record in a one-to-many relation.

Throws:
java.lang.Exception

getRelatedRecord

public Record getRelatedRecord(Table table)
                        throws java.lang.Exception
Throws:
java.lang.Exception

getRelatedRecord

public Record getRelatedRecord(java.lang.String fkName)
                        throws java.lang.Exception
Throws:
java.lang.Exception

getRelatedRecords

public RecordList getRelatedRecords(ForeignKey fk)
                             throws java.lang.Exception
Returns the related records in a many-to-one relation.

Throws:
java.lang.Exception

getRelatedRecords

public RecordList getRelatedRecords(java.lang.String name)
                             throws java.lang.Exception
Throws:
java.lang.Exception

getRelatedRecords

public RecordList getRelatedRecords(Table table)
                             throws java.lang.Exception
Throws:
java.lang.Exception

setRelatedRecord

public void setRelatedRecord(ForeignKey fk,
                             Record rec)
                      throws java.lang.Exception
Throws:
java.lang.Exception

setRelatedRecord

public void setRelatedRecord(java.lang.String fkName,
                             Record rec)
                      throws java.lang.Exception
Throws:
java.lang.Exception

setRelatedRecords

public void setRelatedRecords(ForeignKey fk,
                              RecordList recList)

setRelatedRecords

public void setRelatedRecords(java.lang.String name,
                              RecordList recList)

addRelatedRecord

public void addRelatedRecord(Join join,
                             Record rec)
                      throws java.lang.Exception
Throws:
java.lang.Exception

addRelatedRecord

public void addRelatedRecord(java.lang.String fkName,
                             Record rec)
                      throws java.lang.Exception
Throws:
java.lang.Exception

addRelatedRecord

public void addRelatedRecord(ForeignKey fk,
                             Record rec)
                      throws java.lang.Exception
Throws:
java.lang.Exception

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(java.util.List cols)

toXMLCompact

public void toXMLCompact(org.xml.sax.ContentHandler handler)
                  throws java.lang.Exception
Throws:
java.lang.Exception

toXMLCompact

public void toXMLCompact(org.xml.sax.ContentHandler handler,
                         java.util.List cols,
                         java.util.List nextJoins,
                         java.lang.String alias,
                         ForeignKey fk)
                  throws java.lang.Exception
Throws:
java.lang.Exception

toXMLSimple

public void toXMLSimple(org.xml.sax.ContentHandler handler,
                        java.util.List cols,
                        java.util.List nextJoins)
                 throws java.lang.Exception
Throws:
java.lang.Exception

toXML

public java.lang.String toXML()
                       throws java.lang.Exception
Throws:
java.lang.Exception

toXML

public void toXML(org.xml.sax.ContentHandler handler)
           throws java.lang.Exception
Throws:
java.lang.Exception

equals

public boolean equals(java.lang.Object anOther)
Overrides:
equals in class java.lang.Object

trim

protected java.lang.String trim(java.lang.String str)

unload

public void unload(java.io.PrintStream stream)
            throws java.lang.Exception
Throws:
java.lang.Exception

getChangedColumns

public java.util.Set getChangedColumns()

parseXML

public static Record parseXML(java.lang.String xml)
                       throws java.lang.Exception
Throws:
java.lang.Exception

parseRecord

public static Record parseRecord(org.dom4j.Element element)
                          throws java.lang.Exception
Throws:
java.lang.Exception

parseRecord

public static Record parseRecord(org.dom4j.Element element,
                                 Table tab)
                          throws java.lang.Exception
Throws:
java.lang.Exception

parseRecord

public static Record parseRecord(org.dom4j.Element element,
                                 Query q)
                          throws java.lang.Exception
Throws:
java.lang.Exception

parseRecord

public static Record parseRecord(org.dom4j.Element element,
                                 Join join)
                          throws java.lang.Exception
Throws:
java.lang.Exception

isChanged

public boolean isChanged()
                  throws java.lang.Exception
Checks if this record has changed in the database.

Throws:
java.lang.Exception

saveOptimistic

public void saveOptimistic()
                    throws java.lang.Exception
Throws:
java.lang.Exception

addRelatedRecord

public Record addRelatedRecord(ManyToManyRelation relation,
                               Record rec)
                        throws java.lang.Exception
Connects a record using a many-to-many relation.

Returns:
The generated link record.
Throws:
java.lang.Exception

setRelatedRecords

public void setRelatedRecords(ManyToManyRelation relation,
                              RecordList recList)
                       throws java.lang.Exception
Throws:
java.lang.Exception

getRelatedRecords

public RecordList getRelatedRecords(ManyToManyRelation relation)
                             throws java.lang.Exception
Throws:
java.lang.Exception

validate

public void validate()
              throws java.lang.Exception
Throws:
java.lang.Exception

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getID

public long getID()

reset

public void reset()
           throws java.lang.Exception
Throws:
java.lang.Exception

getFKValues

public butler.util.Tuple getFKValues(ForeignKey fk)
                              throws java.lang.Exception
Throws:
java.lang.Exception

initDefaultValues

public void initDefaultValues()
                       throws java.lang.Exception
Throws:
java.lang.Exception

checkMandatory

public void checkMandatory()
                    throws MandatoryColumnException,
                           java.lang.Exception
Throws:
MandatoryColumnException
java.lang.Exception

makeClean

public void makeClean()
               throws java.lang.Exception
Make this record and all related records to clean.

Throws:
java.lang.Exception

isAggregate

public boolean isAggregate()

setAggregate

public void setAggregate(boolean aggregate)