KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.serversystem.dmlvalidation.constraintsystem;
2
3 import java.util.*;
4
5 import com.daffodilwoods.daffodildb.server.serversystem.*;
6 import com.daffodilwoods.daffodildb.server.sql99.common.*;
7 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*;
8 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*;
9 import com.daffodilwoods.daffodildb.server.sql99.expression.expressionprimary.*;
10 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
11 import com.daffodilwoods.daffodildb.utils.comparator.*;
12 import com.daffodilwoods.database.resource.*;
13
14 /**
15  * <p>Title: Constraint Store</p>
16  * <p>Description: Used to keep the information about the condition, the
17  * columns on which the condition is applied, and theiterator on the condition
18  */

19 public class ConstraintStore {
20
21    _Iterator iterator;
22    int[] columns;
23    int[] userColumns;
24    booleanvalueexpression bve;
25    BitSet bitSet = null;
26    BitSet universalBitSet = null;
27    int bitSetLength = 0;
28    String JavaDoc constraintName = null;
29    Object JavaDoc lastKey;
30    SuperComparator superComparator;
31
32    _Reference[] checkSementicRef;
33    ArrayList checkConstraintAllRef;
34    boolean isFirst = true;
35
36    /**
37     * used to construct a new instance of constraint store with
38     * the given arguments.
39     * @param itera iterator on the condition
40     * @param col columns on which the condition apply
41     * @param bv condition for the performing particular task
42     */

43
44    public ConstraintStore(_Iterator itera, int[] col, booleanvalueexpression bv) {
45       iterator = itera;
46       columns = col;
47       bve = bv;
48    }
49
50    /**
51     * used to get the iterator for the condition set in this constraint store
52     * @return an instance of _iterator.
53     */

54
55    public _Iterator getIterator() {
56       return iterator;
57    }
58
59    /**
60     * used to retreive the condition for the descriptor for which this
61     * constraint store was instantiated
62     * @return condition that has been returned by the method.
63     */

64
65    public booleanvalueexpression getCondition() {
66       return bve;
67    }
68
69    public String JavaDoc toString() {
70       String JavaDoc ss = " RRRRRRRRRRRRRRRRRRR Iterator ==> " + iterator + " " + bve.toString();
71       return ss;
72    }
73
74    public void setBitSet(BitSet bs) {
75       bitSet = bs;
76       bitSetLength = bs.length();
77       universalBitSet = new BitSet(bitSetLength);
78    }
79
80    public boolean fireDescriptor(int[] col) {
81       BitSet gotBitSet = new BitSet(bitSetLength);
82       for (int i = 0; i < col.length; i++)
83          gotBitSet.set(col[i]);
84       gotBitSet.and(bitSet);
85       return!gotBitSet.equals(universalBitSet);
86    }
87
88    /**
89     * Sets constraint name.
90     * @param nam
91     */

92    public void setConstraintName(String JavaDoc nam) {
93       constraintName = nam;
94    }
95
96    public void checkConstraintReferences(_ServerSession serverSession, TableDetails tableDetails) throws DException {
97       if (isFirst) {
98          _Reference[] ref = bve.checkSemantic(serverSession);
99          _Reference[] upperRef = bve.getReferences(new TableDetails[] {tableDetails});
100          ArrayList allRefs = new ArrayList();
101          if (upperRef != null)
102
103             for (int i = 0; i < upperRef.length; i++) {
104                if (upperRef[i].getReferenceType() == SimpleConstants.SUBQUERY) {
105                   _Iterator selectIterator = ( (subquery) upperRef[i]).
106                       getSelectIterator(serverSession);
107                   allRefs.add(new Object JavaDoc[] {upperRef[i], selectIterator});
108                }
109             }
110          checkSementicRef = ref;
111          checkConstraintAllRef = allRefs;
112          isFirst = false;
113       }
114
115    }
116
117    public void setLastKey(Object JavaDoc key) {
118       lastKey = key;
119    }
120
121    public Object JavaDoc getLastKey() {
122       return lastKey;
123    }
124
125    public void setComparator(SuperComparator com) {
126       superComparator = com;
127    }
128
129    public SuperComparator getComparator() {
130       return superComparator;
131    }
132
133
134 }
135
136
Popular Tags