KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.serversystem.dmlvalidation.constraintsystem;
2
3 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*;
4 import com.daffodilwoods.daffodildb.utils.comparator.*;
5 import com.daffodilwoods.database.general.*;
6 import com.daffodilwoods.database.resource.*;
7
8 /**
9  *
10  * <p>Title: Constraint Database</p>
11  * <p>Description: </p>
12  * Constraint Database maintains a list of all the constraint tables in the database.
13  * It retreives the table from the list when a call is made to get the table and
14  * removes the table from the list when the method remove table is called.
15  */

16 public class ConstraintDatabase implements _ConstraintDatabase {
17
18    /**
19     * returns true if the constraints are of deferred type.
20     */

21    private boolean deferrable;
22
23    /**
24     * instance of datadictionary system is used to create a new constraint table.
25     */

26    private _DataDictionary dataDictionary;
27
28    /**
29     * used to maintain a list of constraint tables in the database.
30     */

31    private WeakOrderedKeyList constraintTablePool = new WeakOrderedKeyList(new CTusjohDbtfJoTfotjujwfDpnqbsbups());
32
33    /**
34     * used to construct the constraint database with the given object
35     * @param dDictionary instance of datadictionary system
36     * @param deff boolean to determine the type of constraint.
37     * @throws DException
38     */

39    public ConstraintDatabase(_DataDictionary dDictionary, boolean deff) throws DException {
40       dataDictionary = dDictionary;
41       deferrable = deff;
42    }
43
44    /**
45     * Used to retreive a table with the given name from the list.
46     * If the table is not present in the list , it creates a new instance of the table
47     * and adds it up in the list.
48     * @param tableName name of the table
49     * @return _ConstraintTable instance of constraint table that has been retrieved by the method.
50     * @throws DException
51     */

52
53    public synchronized _ConstraintTable getConstraintTable(QualifiedIdentifier tableName) throws DException {
54       _ConstraintTable constraintTable = (_ConstraintTable) constraintTablePool.get(tableName.getIdentifier());
55       if (constraintTable != null) {
56          return constraintTable;
57       }
58       _DDSConstraintOperations DDSConstraintOperations = dataDictionary.getDDSConstraintsOperation();
59       _CheckConstraintCharacteristics checkConstraintCharacteristics = DDSConstraintOperations.getCheckConstraintCharacteristics(tableName, deferrable);
60       _PrimaryAndUniqueConstraintCharacteristics primaryAndUniqueConstraintCharacteristics = DDSConstraintOperations.getPrimaryAndUniqueConstraintCharacteristics(tableName, deferrable);
61       _ReferencingConstraintCharacteristics referencingConstraintCharacteristics = DDSConstraintOperations.getReferencingConstraintCharacteristics(tableName, deferrable);
62       _ReferencedConstraintCharacteristics referencedConstraintCharacteristics = DDSConstraintOperations.getReferencedConstraintCharacteristics(tableName, deferrable);
63       boolean hasDefferred = DDSConstraintOperations.hasDefferedConstraints(tableName);
64       PrimaryAndUniqueConstraintVerifier primaryAndUniqueCV = new PrimaryAndUniqueConstraintVerifier(primaryAndUniqueConstraintCharacteristics, tableName, deferrable);
65       CheckConstraintsVerifier checkCV = new CheckConstraintsVerifier(checkConstraintCharacteristics, tableName, deferrable);
66       ReferencingConstraintsVerifier referencingCV = new ReferencingConstraintsVerifier(referencingConstraintCharacteristics, tableName, deferrable);
67       ReferencedConstraintsVerifier referencedCV = new ReferencedConstraintsVerifier(referencedConstraintCharacteristics, dataDictionary, tableName, deferrable);
68       constraintTable = (_ConstraintTable)new ConstraintTable(deferrable, primaryAndUniqueCV, checkCV, referencingCV, referencedCV, this, hasDefferred, tableName);
69       constraintTablePool.put(tableName.getIdentifier(), constraintTable);
70       return constraintTable;
71    }
72
73    /**
74     * removes the entry from constraintTablePool for the table name specified.
75     * @param tableName name of the table
76     * @throws DException
77     */

78
79    public void removeTable(QualifiedIdentifier tableName) throws DException {
80       constraintTablePool.remove(tableName.getIdentifier());
81    }
82 }
83
Popular Tags