5 public class ImplicitSchema {
7 SetAnalysis setanalysis;
8 public ImplicitSchema(State state) {
10 this.setanalysis=new SetAnalysis(state);
13 public void update() {
16 updaterelationconstraints();
19 void updaterelationconstraints() {
20 Vector reldescriptors=state.stRelations.getAllDescriptors();
21 for(int i=0;i<reldescriptors.size();i++) {
22 RelationDescriptor rd=(RelationDescriptor) reldescriptors.get(i);
23 Constraint c=new Constraint();
25 /* Construct quantifier */
26 RelationQuantifier rq=new RelationQuantifier();
27 String varname1=new String("relationvar1");
28 String varname2=new String("relationvar2");
29 VarDescriptor var1=new VarDescriptor(varname1);
30 VarDescriptor var2=new VarDescriptor(varname2);
31 c.getSymbolTable().add(var1);
32 c.getSymbolTable().add(var2);
33 var1.setType(rd.getDomain().getType());
34 var2.setType(rd.getRange().getType());
35 rq.setTuple(var1,var2);
38 VarExpr ve1=new VarExpr(varname1);
39 SetExpr se1=new SetExpr(rd.getDomain());
40 LogicStatement incpred1=new InclusionPredicate(ve1,se1);
41 VarExpr ve2=new VarExpr(varname2);
42 SetExpr se2=new SetExpr(rd.getRange());
43 LogicStatement incpred2=new InclusionPredicate(ve2,se2);
44 c.setLogicStatement(new LogicStatement(LogicStatement.AND,incpred1,incpred2));
45 state.vConstraints.add(c);
49 void updateconstraints() {
50 Vector setdescriptors=state.stSets.getAllDescriptors();
51 for(int i=0;i<setdescriptors.size();i++) {
52 SetDescriptor sd=(SetDescriptor) setdescriptors.get(i);
53 if(sd.isPartition()) {
54 Constraint c=new Constraint();
55 /* Construct quantifier */
56 SetQuantifier sq=new SetQuantifier();
57 String varname=new String("partitionvar");
58 VarDescriptor var=new VarDescriptor(varname);
59 c.getSymbolTable().add(var);
60 var.setType(sd.getType());
65 /*Construct logic statement*/
66 LogicStatement ls=null;
67 for(int j=0;j<sd.getSubsets().size();j++) {
68 LogicStatement conj=null;
69 for(int k=0;k<sd.getSubsets().size();k++) {
70 VarExpr ve=new VarExpr(varname);
71 SetExpr se=new SetExpr((SetDescriptor) sd.getSubsets().get(k));
72 LogicStatement incpred=new InclusionPredicate(ve,se);
74 incpred=new LogicStatement(LogicStatement.NOT ,incpred);
79 conj=new LogicStatement(LogicStatement.AND, conj, incpred);
84 ls=new LogicStatement(LogicStatement.OR, ls, conj);
86 c.setLogicStatement(ls);
87 state.vConstraints.add(c);
93 Vector oldrules=state.vRules;
94 Vector newrules=new Vector();
95 for(int i=0;i<oldrules.size();i++) {
96 Rule r=(Rule)oldrules.get(i);
97 if (r.inclusion instanceof SetInclusion) {
98 SetDescriptor sd=((SetInclusion)r.inclusion).getSet();
99 Set supersets=setanalysis.getSuperset(sd);
101 for(Iterator superit=supersets.iterator();superit.hasNext();) {
102 SetDescriptor sd1=(SetDescriptor)superit.next();
105 nr.quantifiers=r.quantifiers;
106 nr.isstatic=r.isstatic;
107 nr.isdelay=r.isdelay;
108 nr.inclusion=new SetInclusion(((SetInclusion)r.inclusion).elementexpr,sd1);
114 oldrules.addAll(newrules);