|
|||||||||
| Home >> All >> javatools >> [ db overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
javatools.db
Class DbConstraint

java.lang.Objectjavatools.db.DbConstraint
- Direct Known Subclasses:
- DbDynamicConstraint
- public abstract class DbConstraint
- extends java.lang.Object
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.
- Version:
- 0.2.0
| 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. |
private void |
buildConstraints()
|
private void |
buildDefaultValues()
|
private void |
buildDeleteCascadeChildren()
|
private void |
buildFatherRecords()
|
private void |
buildReferences()
|
private void |
buildSearchSets()
|
private java.util.TreeSet |
buildSet(java.lang.Integer[] refs,
DbIterator it)
|
private void |
buildSonColsList()
|
private DbTable |
buildSonRecords(int numSon)
|
private void |
buildSonsWhereList()
|
private DbExpr |
buildSonWhere(int numSon)
|
private void |
buildUpdateCascadeChildren()
|
private void |
buildUpdateLists()
|
private void |
cascade()
|
abstract void |
check(int operation)
After setting all dynamic (i.e. |
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. |
private java.lang.Integer[] |
findRefPosition(int index)
|
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. |
private int |
iteratorSize(java.util.Iterator refIt)
|
private boolean |
onlyNullValues(int numFather)
|
private void |
optimizeConstraint(DbConstraint constraint,
int operation)
|
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 |
INSERT_OPERATION
public static final int INSERT_OPERATION
- It represents an INSERT operation.
- See Also:
- Constant Field Values
DELETE_OPERATION
public static final int DELETE_OPERATION
- It represents a DELETE operation.
- See Also:
- Constant Field Values
UPDATE_OPERATION
public static final int UPDATE_OPERATION
- It represents a normal UPDATE operation.
- See Also:
- Constant Field Values
UPDATE_CASCADE
protected static final int UPDATE_CASCADE
- It means that an UPDATE-CASCADE operation is outgoing. It is protected because
it is useful only for internal checks-updates.
- See Also:
- Constant Field Values
DO_NOTHING
public static final int DO_NOTHING
- It means that, in case of an UPDATE/DELETE operation, the table MUST NOT do
anything to repair itself.
- See Also:
- Constant Field Values
SET_NULL
public static final 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.
- See Also:
- Constant Field Values
SET_DEFAULT
public static final 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.
- See Also:
- Constant Field Values
CASCADE
public static final 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.
- See Also:
- Constant Field Values
table
protected DbAbstractTable table
- The referenced table to check.
where
protected DbExpr where
- A DbExpr clause used int DELETE/UPDATE operations.
selector
protected DbSelector selector
- A selector used in INSERT operations.
intoList
protected java.util.List intoList
- A list of columns to put data into (used in INSERT/UPDATE operations).
fromList
protected java.util.List fromList
- A list of values/expression to put data into (used in INSERT/UPDATE operations).
automaticChecking
protected boolean automaticChecking
true: check is done at all times;false: check is performed only with an explicit call tocheck.
constraintEmulation
protected boolean constraintEmulation
true: emulation made as needed;false: emulation is not made.
currentOperation
protected int currentOperation
- Represents the current operation. (INSERT, DELETE, UPDATE, UPDATE-CASCADE).
canDoUpdate
protected boolean canDoUpdate
true: update can be done.false: update CANNOT be done. It is put tofalsewhenever the DBMS can perform referencial integrity check by itself; e.g. MySQL cannot, so it must be done in a "software" way.
fatherTables
protected DbAbstractTable[] fatherTables
- It contains all father tables of the one referenced by this constraint.
sonTables
protected DbAbstractTable[] sonTables
- It contains all son tables of the one referenced by this constraint.
updateOperations
protected java.lang.Integer[] updateOperations
- It contains the update operations for each father table.
deleteOperations
protected java.lang.Integer[] deleteOperations
- It contains the delete operations for each father table.
fatherTablesColumns
protected DbColumn[][] fatherTablesColumns
- It contains the father keys for each father table.
refColumns
protected DbColumn[][] refColumns
- It contains for each father table, the referenced column in contained table.
That is each element in
fatherTablesColumns, columns of father tables, must be equal to each element inrefColumns, columns of THIS table.
fatherColsChildren
protected DbColumn[][] fatherColsChildren
- For each son, it contains the referenced column of THIS table. It is built
automatically, to ease checking.
refColsChildren
protected DbColumn[][] refColsChildren
- For each son it contains the referenced columns of son tables. It is built
automatically, to ease checking.
sonIndexes
protected java.lang.Integer[] sonIndexes
- For each son, it contains the position in the
fatherTablesof the son table itself.
refs
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
intoListfor INSERT or UPDATE operations.
searchSets
protected java.util.TreeSet[] searchSets
- Contains the search sets used to perform checks for each son table.
sonsWhere
protected DbExpr[] sonsWhere
- Contains the "where" clauses for each son.
fatherRecords
protected DbTable fatherRecords
- Contains the father records used to find eventually involved rows.
deleteCascadeChildren
protected java.lang.Integer[] deleteCascadeChildren
- Currently unused.
updateCascadeChildren
protected java.lang.Integer[] updateCascadeChildren
- Currently unused.
constraints
protected DbConstraint[] constraints
- Contains an array of constraint to perform cascade-check and cascade-updates.
defaultValues
protected java.lang.Object[][] defaultValues
- Contains default values for each referenced field of each father table.
updateIntoLists
protected java.util.List[] updateIntoLists
- Contains an array of
intoList-like lists, to perform update operations in son tables.
updateFromLists
protected java.util.List[] updateFromLists
- Contains an array of
fromList-like lists, to perform update operations in son tables.
cloned
protected boolean cloned
true: the object is cloned.false: the object is NOT cloned.
| Constructor Detail |
DbConstraint
public DbConstraint()
- Creates new DbConstraint
DbConstraint
public DbConstraint(DbAbstractTable tbl)
- Creates a new DbConstraint for a specified table.
| Method Detail |
getTable
public DbAbstractTable getTable()
- Returns the referenced table.
setWhere
public void setWhere(DbExpr pWhere)
- Sets the "where" clause for an DELETE/UPDATE operation.
setSelector
public void setSelector(DbSelector pSelector)
- Sets the selector for an INSERT operation.
setValueLists
public void setValueLists(java.util.List pIntoList, java.util.List pFromList)
- Sets the lists to perform INSERT/UPDATE operations.
setAutomaticChecking
public void setAutomaticChecking(boolean value)
- Sets a flag to represent automatic checking at all times.
getAutomaticChecking
public boolean getAutomaticChecking()
- Returns the current automatic checking setting.
setConstraintEmulation
public void setConstraintEmulation(boolean value)
- Sets the constraint emulation.
getConstraintEmulation
public boolean getConstraintEmulation()
- Returns if constraint emulation is enabled.
getFatherTablesCount
public int getFatherTablesCount()
- Returns the number of referenced father tables.
getSonTablesCount
public int getSonTablesCount()
- Returns the number of son tables.
getFatherTable
public DbAbstractTable getFatherTable(int index) throws DbException
- Returns a father table whose index is specified.
getSonTable
public DbAbstractTable getSonTable(int index) throws DbException
- Returns a son table whose index is specified.
getSonFatherIndex
public int getSonFatherIndex(int index)
throws DbException
- Returns in which position a son table references THIS table in its constraint.
getUpdateOperation
public int getUpdateOperation(int index)
throws DbException
- Returns what kind of operation will be done in case of an update of the father
table specified by
index.
getDeleteOperation
public int getDeleteOperation(int index)
throws DbException
- Returns what kind of operation will be done in case of a deletion of the father
table specified by
index.
getFatherColumns
public DbColumn[] getFatherColumns(int index) throws DbException
- Returns the referenced father columns of a father table whose index is
specified.
getRefColumns
public DbColumn[] getRefColumns(int index) throws DbException
- Returns the referencing columns of THIS table for a father table whose index
is specified.
getDefaultValues
public java.lang.Object[] getDefaultValues(int index) throws DbException
- Returns an array containing the default values for fields of a father table
whose index is specified.
clear
public void clear()
- Clears everything.
build
public void build()
throws DbException
- After all settings, it finally builds all static references.
check
public abstract void check(int operation)
throws DbException
- After setting all dynamic (i.e. operations, lists etc.) information, it checks
explicitly if all operations can be done. I suggest to call
checkThismethod to perform base checking.
update
public abstract int update(int operation)
throws DbException
- Actually updates the table and all of its son tables. I suggest to call
updateThismethod to perform base update.
updateThis
protected int updateThis(int operation)
throws DbException
- Performs base update. It also checks if automatic checking is set.
checkThis
protected void checkThis(int operation)
throws DbException
- Performs base checks.
checkFathers
protected void checkFathers()
throws DbException
- Performs checking for father tables. Used in INSERT and UPDATE operations.
N.B. Not used in UPDATE-CASCADE operation.
checkChildren
protected void checkChildren()
throws DbException
- Checks recursively each son.
clone
protected java.lang.Object clone() throws java.lang.CloneNotSupportedException
- Clones this object. It is used to build a temporary DbConstraint in
self-referencing tables.
buildReferences
private void buildReferences()
throws DbException
findRefPosition
private java.lang.Integer[] findRefPosition(int index) throws DbException
iteratorSize
private int iteratorSize(java.util.Iterator refIt)
buildSet
private java.util.TreeSet buildSet(java.lang.Integer[] refs, DbIterator it) throws DbException
cascade
private void cascade()
throws DbException
buildSonColsList
private void buildSonColsList()
throws DbException
buildFatherRecords
private void buildFatherRecords()
throws DbException
buildSearchSets
private void buildSearchSets()
throws DbException
buildSonRecords
private DbTable buildSonRecords(int numSon) throws DbException
buildSonWhere
private DbExpr buildSonWhere(int numSon)
buildSonsWhereList
private void buildSonsWhereList()
buildDeleteCascadeChildren
private void buildDeleteCascadeChildren()
buildUpdateCascadeChildren
private void buildUpdateCascadeChildren()
buildConstraints
private void buildConstraints()
throws DbException
buildDefaultValues
private void buildDefaultValues()
throws DbException
buildUpdateLists
private void buildUpdateLists()
throws DbException
optimizeConstraint
private void optimizeConstraint(DbConstraint constraint, int operation)
onlyNullValues
private boolean onlyNullValues(int numFather)
initStaticLists
protected void initStaticLists()
throws DbException
- Inits static lists, like indexes of son tables, default values of father tables
etc.
initLists
protected void initLists()
throws DbException
- Builds all dynamic lists (where clauses, constraints etc.).
|
|||||||||
| Home >> All >> javatools >> [ db overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
javatools.db.DbConstraint