javatools.db
Class DbDynamicConstraint

java.lang.Object
  |
  +--javatools.db.DbConstraint
        |
        +--javatools.db.DbDynamicConstraint

public class DbDynamicConstraint
extends DbConstraint

It is a class representing a "dynamic" constraint, i.e. a constraint that changes references dynamically.


Field Summary
 
Fields inherited from class javatools.db.DbConstraint
automaticChecking, canDoUpdate, CASCADE, cloned, constraintEmulation, constraints, currentOperation, defaultValues, DELETE_OPERATION, deleteCascadeChildren, deleteOperations, DO_NOTHING, fatherColsChildren, fatherRecords, fatherTables, fatherTablesColumns, fromList, INSERT_OPERATION, intoList, refColsChildren, refColumns, refs, searchSets, selector, SET_DEFAULT, SET_NULL, sonIndexes, sonsWhere, sonTables, table, UPDATE_CASCADE, UPDATE_OPERATION, updateCascadeChildren, updateFromLists, updateIntoLists, updateOperations, where
 
Constructor Summary
DbDynamicConstraint(DbAbstractTable tbl)
          Creates new DbDynamicConstraint
 
Method Summary
 void addFatherTable(DbAbstractTable fatherTable, DbColumn[] fatherColumns, DbColumn[] pRefColumns, int updateOperation, int deleteOperation)
          Adds a new father table.
 void addSonTable(DbAbstractTable sonTable, int fatherIndex)
          Adds a son table.
 void build()
          Builds all static lists.
 void check(int operation)
          Performs checking in the table, after setting all dynamic and "static" data.
protected  void checkFathers()
          Checks the fathers.
protected  void checkThis(int operation)
          Performs base checking.
 java.lang.Object[] getDefaultValues(int index)
          Returns the default values of referenced father table whose index is specified.
 int getDeleteOperation(int index)
          Returns the delete operation that should be done for the father table whose index is specified.
 DbColumn[] getFatherColumns(int index)
          The referenced columns of father table whose index is specified.
 DbAbstractTable getFatherTable(int index)
          Returns a father table whose index is specified.
 int getFatherTablesCount()
          Returns the number of referenced father tables.
 DbColumn[] getRefColumns(int index)
          Returns the referencing columns of THIS table to the father table whose index is specified.
 int getSonFatherIndex(int index)
          Returns the index that a son table uses to reference this table.
 DbAbstractTable getSonTable(int index)
          Returns a son table whose index is specified.
 int getSonTablesCount()
          Returns the number of son tables.
 int getUpdateOperation(int index)
          Returns the update operation that should be done for the father table whose index is specified.
 void setAutomaticBuild(boolean value)
          Tells this object to build (or not) automatically all lists at all times.
 int update(int operation)
          Performs actual update in the table and, eventually, cascades.
 
Methods inherited from class javatools.db.DbConstraint
checkChildren, clear, clone, getAutomaticChecking, getConstraintEmulation, getTable, initLists, initStaticLists, setAutomaticChecking, setConstraintEmulation, setSelector, setValueLists, setWhere, updateThis
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbDynamicConstraint

public DbDynamicConstraint(DbAbstractTable tbl)
Creates new DbDynamicConstraint

Parameters:
tbl - The table to be referenced.
Method Detail

check

public void check(int operation)
           throws DbException
Performs checking in the table, after setting all dynamic and "static" data.

Specified by:
check in class DbConstraint
Parameters:
operation - The kind of operation (INSERT, UPDATE etc.) that should be done.
Throws:
DbException - If something goes wrong.

update

public int update(int operation)
           throws DbException
Performs actual update in the table and, eventually, cascades. If automatic checking is set, it also checks before updating.

Specified by:
update in class DbConstraint
Parameters:
operation - The kind of operation (INSERT, UPDATE etc.) that should be done.
Returns:
The result from inserters, updaters or deleters.
Throws:
DbException - If something goes wrong.

addFatherTable

public void addFatherTable(DbAbstractTable fatherTable,
                           DbColumn[] fatherColumns,
                           DbColumn[] pRefColumns,
                           int updateOperation,
                           int deleteOperation)
Adds a new father table.

Parameters:
fatherTable - The father table to be referenced.
fatherColumns - The father columns to use as father keys.
pRefColumns - The columns to be used as son keys.
updateOperation - What kind of operation should I do in case of an update?
deleteOperation - What kind of operation should I do in case of a deletion?

addSonTable

public void addSonTable(DbAbstractTable sonTable,
                        int fatherIndex)
Adds a son table.

Parameters:
sonTable - The table to be added as a son table.
fatherIndex - The index that the new son table uses to reference THIS table.

getFatherTablesCount

public int getFatherTablesCount()
Returns the number of referenced father tables.

Overrides:
getFatherTablesCount in class DbConstraint
Returns:
The father tables count.

getSonTablesCount

public int getSonTablesCount()
Returns the number of son tables.

Overrides:
getSonTablesCount in class DbConstraint
Returns:
The son tables count.

getFatherTable

public DbAbstractTable getFatherTable(int index)
                               throws DbException
Returns a father table whose index is specified.

Overrides:
getFatherTable in class DbConstraint
Parameters:
index - The index of the requested father table.
Returns:
The requested table.
Throws:
DbException - If something goes wrong.

getSonTable

public DbAbstractTable getSonTable(int index)
                            throws DbException
Returns a son table whose index is specified.

Overrides:
getSonTable in class DbConstraint
Parameters:
index - The index of the requested son table.
Returns:
The requested son table.
Throws:
DbException - If something goes wrong.

getSonFatherIndex

public int getSonFatherIndex(int index)
                      throws DbException
Returns the index that a son table uses to reference this table.

Overrides:
getSonFatherIndex in class DbConstraint
Parameters:
index - The index of the requested son table.
Returns:
The requested index.
Throws:
DbException - If something goes wrong.

getUpdateOperation

public int getUpdateOperation(int index)
                       throws DbException
Returns the update operation that should be done for the father table whose index is specified.

Overrides:
getUpdateOperation in class DbConstraint
Parameters:
index - The index of the requested father table.
Returns:
The requested operation.
Throws:
DbException - If something goes wrong.

getDeleteOperation

public int getDeleteOperation(int index)
                       throws DbException
Returns the delete operation that should be done for the father table whose index is specified.

Overrides:
getDeleteOperation in class DbConstraint
Parameters:
index - The index of the requested father table.
Returns:
The requested operation.
Throws:
DbException - If something goes wrong.

getFatherColumns

public DbColumn[] getFatherColumns(int index)
                            throws DbException
The referenced columns of father table whose index is specified.

Overrides:
getFatherColumns in class DbConstraint
Parameters:
index - The index of requested father table.
Returns:
An array containing all the referenced columns.
Throws:
DbException - If something goes wrong.

getRefColumns

public DbColumn[] getRefColumns(int index)
                         throws DbException
Returns the referencing columns of THIS table to the father table whose index is specified.

Overrides:
getRefColumns in class DbConstraint
Parameters:
index - The index of requested father table.
Returns:
An array containing the columns of THIS table referencing the requested father table.
Throws:
DbException - If something goes wrong.

setAutomaticBuild

public void setAutomaticBuild(boolean value)
Tells this object to build (or not) automatically all lists at all times.

Parameters:
value - true: automatic build will be done; false: it won't be done.

build

public void build()
           throws DbException
Builds all static lists.

Overrides:
build in class DbConstraint
Throws:
DbException - If something goes wrong.

checkThis

protected void checkThis(int operation)
                  throws DbException
Performs base checking.

Overrides:
checkThis in class DbConstraint
Parameters:
operation - The operation that should be done.
Throws:
DbException - If something goes wrong.

checkFathers

protected void checkFathers()
                     throws DbException
Checks the fathers.

Overrides:
checkFathers in class DbConstraint
Throws:
DbException - If something goes wrong.

getDefaultValues

public java.lang.Object[] getDefaultValues(int index)
                                    throws DbException
Returns the default values of referenced father table whose index is specified.

Overrides:
getDefaultValues in class DbConstraint
Parameters:
index - The index of requested father table.
Returns:
An array containing all default values for the requested father table.
Throws:
DbException - If something goes wrong.