KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > serversystem > dmlvalidation > constraintsystem > ConstraintTable


1 package com.daffodilwoods.daffodildb.server.serversystem.dmlvalidation.constraintsystem;
2
3 import com.daffodilwoods.daffodildb.server.serversystem.*;
4 import com.daffodilwoods.database.general.*;
5 import com.daffodilwoods.database.resource.*;
6
7 /**
8  *
9  * <p>Title: Constraint Table</p>
10  * <p>Description: </p>
11  * Objective of the constraint table is to verify the values of the constraints , set for update , delete and insert operations.
12  */

13 public class ConstraintTable implements _ConstraintTable {
14
15    boolean deferrable;
16    public PrimaryAndUniqueConstraintVerifier primaryAndUniqueConstraintVerifier;
17    CheckConstraintsVerifier checkConstraintVerifier;
18    ReferencingConstraintsVerifier referencingConstraintsVerifier;
19    ReferencedConstraintsVerifier referencedConstraintsVerifier;
20    _ConstraintDatabase constraintDatabase;
21    private boolean hasDefferred = false;
22    private QualifiedIdentifier tableName;
23
24    /**
25     * Used to construct the constraint table with the following arguments.
26     * @param deferrabl used to detemine whether the constraints are of deferred type.
27     * @param primaryAndUniqueVerifier instance of primaryAndUniqueConstraintVerifier used to verify the
28     * primary and the unique constraints on the table
29     * @param cConstraintVerifier instance of checkconstraintverifier used to verify the
30     * check constraints on the table.
31     * @param referencingVerifier instance of referncingconstraintverifier used to verify the
32     * referencing constraints on the table
33     * @param referencedVerifier instance of referencedconstraintverifier used to verify the
34     * referenced constraints on the table.
35     * @param constrantDatabase instance of constraint table to which the constraint table belongs.
36     * @param hasDeff
37     * @throws DException
38     */

39    public ConstraintTable(boolean deferrabl, PrimaryAndUniqueConstraintVerifier primaryAndUniqueVerifier, CheckConstraintsVerifier cConstraintVerifier, ReferencingConstraintsVerifier referencingVerifier, ReferencedConstraintsVerifier referencedVerifier, _ConstraintDatabase constrantDatabase, boolean hasDeff, QualifiedIdentifier tabName) throws DException {
40       deferrable = deferrabl;
41       primaryAndUniqueConstraintVerifier = primaryAndUniqueVerifier;
42       checkConstraintVerifier = cConstraintVerifier;
43       referencedConstraintsVerifier = referencedVerifier;
44       referencingConstraintsVerifier = referencingVerifier;
45       constraintDatabase = constrantDatabase;
46       hasDefferred = hasDeff;
47       tableName = tabName;
48    }
49
50    /**
51     * used to retreive the constraint table from constraint Database.
52     * @param tableName name of the table
53     * @return _ConstraintTable instance of _constraint table that has been retreived by the method.
54     * @throws DException
55     */

56
57    public _ConstraintTable getConstraintTable(QualifiedIdentifier tableName) throws DException {
58       return constraintDatabase.getConstraintTable(tableName);
59    }
60
61    /**
62     * retreives a boolean determining whether the constraints on the table has been set to Defferred (Defferred means all the changes will be made at the time of Commit Otherwise the changes will be made side by side)
63     * @return boolean true if the constraints are defferred
64     * @throws DException
65     */

66
67    public boolean hasDefferred() throws DException {
68       return hasDefferred;
69    }
70
71    /**
72     * used to verify all the constraints for the delete operation.
73     * @param globalSession instance of server session in which the operation is performed.
74     * @param statementExecutionContext instance of statementexecutioncontext
75     * @throws ConstraintException
76     */

77
78    public void checkDeleteConstraints(_ServerSession globalSession, _StatementExecutionContext statementExecutionContext) throws DException {
79       referencedConstraintsVerifier.verifyReferencedConstraintsForDelete(globalSession, statementExecutionContext);
80    }
81
82    /**
83     *used to verify all the constraints for the update operation.
84     * @param globalSession instance of server session in which the operation is performed.
85     * @param statementExecutionContext instance of statementexecutioncontext
86     * @param columns array of columns whose value are to be updated
87     * @throws ConstraintException
88     * @throws DException
89     */

90
91    public void checkUpdateConstraints(_ServerSession globalSession, _StatementExecutionContext statementExecutionContext, int[] columns) throws ConstraintException, DException {
92       checkConstraintVerifier.verifyCheckConstraintsForUpdate(columns, statementExecutionContext, globalSession);
93       primaryAndUniqueConstraintVerifier.verifyPrimaryConstraintsForUpdate(columns, statementExecutionContext, globalSession);
94       primaryAndUniqueConstraintVerifier.verifyUniqueConstraintsForUpdate(columns, statementExecutionContext, globalSession);
95       referencingConstraintsVerifier.verifyReferencingConstraintsForUpdate(columns, globalSession, statementExecutionContext);
96       referencedConstraintsVerifier.verifyReferencedConstraintsForUpdate(columns, globalSession, statementExecutionContext);
97    }
98
99    /**
100        used to verify all the constraints for the insert operation.
101     * @param globalSession instance of server session in which the operation is performed.
102     * @param statementExecutionContext instance of statementexecutioncontext
103     * @param columns array of columns which are to be inserted in the table.
104     * @throws ConstraintException
105     * @throws DException
106     */

107
108    public void checkInsertConstraints(_ServerSession globalSession, _StatementExecutionContext statementExecutionContext, int[] columns) throws ConstraintException, DException {
109       try {
110          checkConstraintVerifier.verifyCheckConstraints(statementExecutionContext, globalSession);
111       } catch (DException ex) {
112          if (ex.getDseCode().equalsIgnoreCase("DSE1251")) {
113             Object JavaDoc[] parameters = ex.getParameters();
114             parameters[0] = "INSERT";
115             ex.setParameters(parameters);
116             throw new DException("DSE1251", parameters);
117          }
118          throw ex;
119       }
120       primaryAndUniqueConstraintVerifier.verifyUniqueConstraints(columns, statementExecutionContext, globalSession);
121       primaryAndUniqueConstraintVerifier.verifyPrimaryConstraints(columns, statementExecutionContext, globalSession);
122       referencingConstraintsVerifier.verifyReferencingConstraints(columns, globalSession, statementExecutionContext);
123    }
124
125    /**
126     * retreives a boolean that determines whether the constraints are deferred or not.
127     * @return boolean returns true if the table type has been set to Defferrable (Defferred means all the
128     * changes will be made at the time of Commit Otherwise the changes will be made side by side)
129     * @throws DException
130     */

131
132    public boolean isDeferredType() throws DException {
133       return deferrable;
134    }
135
136    public String JavaDoc toString() {
137       return " XXXXXXXXXXXXXYYYYYYYYYYYYYYZZZZZZZZZZZZ " + referencingConstraintsVerifier.toString();
138    }
139 }
140
Popular Tags