|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javatools.db.DbConstraint
This abstract class represents a generic set of constraints for a table. It
contains a lot of code already written for generic purposes, i.e. it can be
derived with few code. If you want to add additional checks, you can easily add
your own code, rewriting check
and update
methods.
Field Summary | |
protected boolean |
automaticChecking
true : check is done at all times;
false : check is performed only with an explicit call to
check . |
protected boolean |
canDoUpdate
true : update can be done.
|
static int |
CASCADE
It means that, in case of an UPDATE/DELETE operation, the constraint MUST cascade the operation, that is updating/deleting in cascade all involved rows. |
protected boolean |
cloned
true : the object is cloned.
|
protected boolean |
constraintEmulation
true : emulation made as needed;
false : emulation is not made. |
protected DbConstraint[] |
constraints
Contains an array of constraint to perform cascade-check and cascade-updates. |
protected int |
currentOperation
Represents the current operation. |
protected java.lang.Object[][] |
defaultValues
Contains default values for each referenced field of each father table. |
static int |
DELETE_OPERATION
It represents a DELETE operation. |
protected java.lang.Integer[] |
deleteCascadeChildren
Currently unused. |
protected java.lang.Integer[] |
deleteOperations
It contains the delete operations for each father table. |
static int |
DO_NOTHING
It means that, in case of an UPDATE/DELETE operation, the table MUST NOT do anything to repair itself. |
protected DbColumn[][] |
fatherColsChildren
For each son, it contains the referenced column of THIS table. |
protected DbTable |
fatherRecords
Contains the father records used to find eventually involved rows. |
protected DbAbstractTable[] |
fatherTables
It contains all father tables of the one referenced by this constraint. |
protected DbColumn[][] |
fatherTablesColumns
It contains the father keys for each father table. |
protected java.util.List |
fromList
A list of values/expression to put data into (used in INSERT/UPDATE operations). |
static int |
INSERT_OPERATION
It represents an INSERT operation. |
protected java.util.List |
intoList
A list of columns to put data into (used in INSERT/UPDATE operations). |
protected DbColumn[][] |
refColsChildren
For each son it contains the referenced columns of son tables. |
protected DbColumn[][] |
refColumns
It contains for each father table, the referenced column in contained table. |
protected java.lang.Integer[][] |
refs
It's an array built at runtime to represent, for each father, the referenced fields if they are specified in intoList for INSERT or UPDATE
operations. |
protected java.util.TreeSet[] |
searchSets
Contains the search sets used to perform checks for each son table. |
protected DbSelector |
selector
A selector used in INSERT operations. |
static int |
SET_DEFAULT
It means that, in case of an UPDATE/DELETE operation, the constraint MUST set an array of fields in involved rows to DEFAULT values, to repair referenced table. |
static int |
SET_NULL
It means that, in case of an UPDATE/DELETE operation, the constraint MUST set an array of fields in involved rows to NULL values, to repair referenced table. |
protected java.lang.Integer[] |
sonIndexes
For each son, it contains the position in the fatherTables of
the son table itself. |
protected DbExpr[] |
sonsWhere
Contains the "where" clauses for each son. |
protected DbAbstractTable[] |
sonTables
It contains all son tables of the one referenced by this constraint. |
protected DbAbstractTable |
table
The referenced table to check. |
protected static int |
UPDATE_CASCADE
It means that an UPDATE-CASCADE operation is outgoing. |
static int |
UPDATE_OPERATION
It represents a normal UPDATE operation. |
protected java.lang.Integer[] |
updateCascadeChildren
Currently unused. |
protected java.util.List[] |
updateFromLists
Contains an array of fromList -like lists, to perform update
operations in son tables. |
protected java.util.List[] |
updateIntoLists
Contains an array of intoList -like lists, to perform update
operations in son tables. |
protected java.lang.Integer[] |
updateOperations
It contains the update operations for each father table. |
protected DbExpr |
where
A DbExpr clause used int DELETE/UPDATE operations. |
Constructor Summary | |
DbConstraint()
Creates new DbConstraint |
|
DbConstraint(DbAbstractTable tbl)
Creates a new DbConstraint for a specified table. |
Method Summary | |
void |
build()
After all settings, it finally builds all static references. |
abstract void |
check(int operation)
After setting all dynamic (i.e. operations, lists etc.) information, it checks explicitly if all operations can be done. |
protected void |
checkChildren()
Checks recursively each son. |
protected void |
checkFathers()
Performs checking for father tables. |
protected void |
checkThis(int operation)
Performs base checks. |
void |
clear()
Clears everything. |
protected java.lang.Object |
clone()
Clones this object. |
boolean |
getAutomaticChecking()
Returns the current automatic checking setting. |
boolean |
getConstraintEmulation()
Returns if constraint emulation is enabled. |
java.lang.Object[] |
getDefaultValues(int index)
Returns an array containing the default values for fields of a father table whose index is specified. |
int |
getDeleteOperation(int index)
Returns what kind of operation will be done in case of a deletion of the father table specified by index . |
DbColumn[] |
getFatherColumns(int index)
Returns the referenced father columns of a 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 for a father table whose index is specified. |
int |
getSonFatherIndex(int index)
Returns in which position a son table references THIS table in its constraint. |
DbAbstractTable |
getSonTable(int index)
Returns a son table whose index is specified. |
int |
getSonTablesCount()
Returns the number of son tables. |
DbAbstractTable |
getTable()
Returns the referenced table. |
int |
getUpdateOperation(int index)
Returns what kind of operation will be done in case of an update of the father table specified by index . |
protected void |
initLists()
Builds all dynamic lists (where clauses, constraints etc.). |
protected void |
initStaticLists()
Inits static lists, like indexes of son tables, default values of father tables etc. |
void |
setAutomaticChecking(boolean value)
Sets a flag to represent automatic checking at all times. |
void |
setConstraintEmulation(boolean value)
Sets the constraint emulation. |
void |
setSelector(DbSelector pSelector)
Sets the selector for an INSERT operation. |
void |
setValueLists(java.util.List pIntoList,
java.util.List pFromList)
Sets the lists to perform INSERT/UPDATE operations. |
void |
setWhere(DbExpr pWhere)
Sets the "where" clause for an DELETE/UPDATE operation. |
abstract int |
update(int operation)
Actually updates the table and all of its son tables. |
protected int |
updateThis(int operation)
Performs base update. |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int INSERT_OPERATION
public static final int DELETE_OPERATION
public static final int UPDATE_OPERATION
protected static final int UPDATE_CASCADE
public static final int DO_NOTHING
public static final int SET_NULL
public static final int SET_DEFAULT
public static final int CASCADE
protected DbAbstractTable table
protected DbExpr where
protected DbSelector selector
protected java.util.List intoList
protected java.util.List fromList
protected boolean automaticChecking
true
: check is done at all times;
false
: check is performed only with an explicit call to
check
.
protected boolean constraintEmulation
true
: emulation made as needed;
false
: emulation is not made.
protected int currentOperation
protected boolean canDoUpdate
true
: update can be done.
false
: update CANNOT be done.
It is put to false
whenever the DBMS can perform referencial
integrity check by itself; e.g. MySQL cannot, so it must be done in a
"software" way.
protected DbAbstractTable[] fatherTables
protected DbAbstractTable[] sonTables
protected java.lang.Integer[] updateOperations
protected java.lang.Integer[] deleteOperations
protected DbColumn[][] fatherTablesColumns
protected DbColumn[][] refColumns
fatherTablesColumns
, columns of father
tables, must be equal to each element in refColumns
, columns of
THIS table.
protected DbColumn[][] fatherColsChildren
protected DbColumn[][] refColsChildren
protected java.lang.Integer[] sonIndexes
fatherTables
of
the son table itself.
protected java.lang.Integer[][] refs
intoList
for INSERT or UPDATE
operations.
protected java.util.TreeSet[] searchSets
protected DbExpr[] sonsWhere
protected DbTable fatherRecords
protected java.lang.Integer[] deleteCascadeChildren
protected java.lang.Integer[] updateCascadeChildren
protected DbConstraint[] constraints
protected java.lang.Object[][] defaultValues
protected java.util.List[] updateIntoLists
intoList
-like lists, to perform update
operations in son tables.
protected java.util.List[] updateFromLists
fromList
-like lists, to perform update
operations in son tables.
protected boolean cloned
true
: the object is cloned.
false
: the object is NOT cloned.
Constructor Detail |
public DbConstraint()
public DbConstraint(DbAbstractTable tbl)
tbl
- The table to be checked.Method Detail |
public DbAbstractTable getTable()
public void setWhere(DbExpr pWhere)
pWhere
- The requested clause.public void setSelector(DbSelector pSelector)
pSelector
- The requested selector.public void setValueLists(java.util.List pIntoList, java.util.List pFromList)
pIntoList
- It will be put into intoList
.pFromList
- It will be put into fromList
.public void setAutomaticChecking(boolean value)
value
- true
: check is done at all times;
false
: check is performed only with an explicit call to
check
.public boolean getAutomaticChecking()
true
: check is done at all times;
false
: check is performed only with an explicit call to
check
.public void setConstraintEmulation(boolean value)
value
- true
: constraint emulation is done as needed;
false
: constraint emulation is NEVER done.public boolean getConstraintEmulation()
true
: constraint emulation is done as needed;
false
: constraint emulation is NEVER done.public int getFatherTablesCount()
public int getSonTablesCount()
public DbAbstractTable getFatherTable(int index) throws DbException
index
- The index of a father table.
DbException
- If something goes wrong.public DbAbstractTable getSonTable(int index) throws DbException
index
- The index of a son table.
DbException
- If something goes wrong.public int getSonFatherIndex(int index) throws DbException
index
- The son table index.
DbException
- If something goes wrong.public int getUpdateOperation(int index) throws DbException
index
.
index
- The index of the father table.
DbException
- If something goes wrong.public int getDeleteOperation(int index) throws DbException
index
.
index
- The index of the father table.
DbException
- If something goes wrong.public DbColumn[] getFatherColumns(int index) throws DbException
index
- The index of the father table.
DbException
- If something goes wrong.public DbColumn[] getRefColumns(int index) throws DbException
index
- The index of the father column.
DbException
- If something goes wrong.public java.lang.Object[] getDefaultValues(int index) throws DbException
index
- The index of the father table.
DbException
- If something goes wrong.public void clear()
public void build() throws DbException
DbException
- If something goes wrong.public abstract void check(int operation) throws DbException
checkThis
method to perform base checking.
operation
- The kind of operation (INSERT, UPDATE etc.) that should be done.
DbException
- If something goes wrong.public abstract int update(int operation) throws DbException
updateThis
method to perform base update.
operation
- The kind of operation (INSERT, UPDATE etc.) that should be done.
execute
calls to inserters,
deleters of updaters.
DbException
- If something goes wrong.protected int updateThis(int operation) throws DbException
operation
- The operation to be done.
DbException
- If something goes wrong.protected void checkThis(int operation) throws DbException
operation
- The operations that should be done.
DbException
- If something goes wrong.protected void checkFathers() throws DbException
DbException
- If checking fails.protected void checkChildren() throws DbException
DbException
- If checking fails.protected java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- Never thrown... usually...protected void initStaticLists() throws DbException
DbException
- If something goes wrong.protected void initLists() throws DbException
DbException
- If something goes wrong.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |