1 21 package com.db4o; 22 23 import com.db4o.foundation.*; 24 25 31 public class QConJoin extends QCon { 32 33 35 public boolean i_and; 36 public QCon i_constraint1; 37 public QCon i_constraint2; 38 39 40 public QConJoin(){ 41 } 43 44 QConJoin(Transaction a_trans, QCon a_c1, QCon a_c2, boolean a_and) { 45 super(a_trans); 46 i_constraint1 = a_c1; 47 i_constraint2 = a_c2; 48 i_and = a_and; 49 } 50 51 void doNotInclude(QCandidate a_root) { 52 i_constraint1.doNotInclude(a_root); 53 i_constraint2.doNotInclude(a_root); 54 } 55 56 void exchangeConstraint(QCon a_exchange, QCon a_with) { 57 super.exchangeConstraint(a_exchange, a_with); 58 if (a_exchange == i_constraint1) { 59 i_constraint1 = a_with; 60 } 61 if (a_exchange == i_constraint2) { 62 i_constraint2 = a_with; 63 } 64 } 65 66 void evaluatePending( 67 QCandidate a_root, 68 QPending a_pending, 69 int a_secondResult) { 70 71 boolean res = 72 i_evaluator.not( 73 i_and 74 ? ((a_pending._result + a_secondResult) > 0) 75 : (a_pending._result + a_secondResult) > -4); 76 77 if (hasJoins()) { 78 Iterator4 i = iterateJoins(); 79 while (i.moveNext()) { 80 QConJoin qcj = (QConJoin) i.current(); 81 if (Debug.queries) { 82 System.out.println( 83 "QConJoin creates pending this:" 84 + i_id 85 + " Join:" 86 + qcj.i_id 87 + " res:" 88 + res); 89 } 90 a_root.evaluate(new QPending(qcj, this, res)); 91 } 92 } else { 93 if (!res) { 94 if (Debug.queries) { 95 System.out.println( 96 "QConJoin evaluatePending FALSE " 97 + i_id 98 + " Calling: " 99 + i_constraint1.i_id 100 + ", " 101 + i_constraint2.i_id); 102 } 103 i_constraint1.doNotInclude(a_root); 104 i_constraint2.doNotInclude(a_root); 105 }else{ 106 if (Debug.queries) { 107 System.out.println( 108 "QConJoin evaluatePending TRUE " 109 + i_id 110 + " NOT calling: " 111 + i_constraint1.i_id 112 + ", " 113 + i_constraint2.i_id); 114 } 115 } 116 117 } 118 } 119 120 public QCon getOtherConstraint(QCon a_constraint) { 121 if (a_constraint == i_constraint1) { 122 return i_constraint2; 123 } else if (a_constraint == i_constraint2) { 124 return i_constraint1; 125 } 126 throw new IllegalArgumentException (); 127 } 128 129 String logObject(){ 130 if (Debug.queries) { 131 String msg = i_and ? "&" : "|"; 132 return " " + i_constraint1.i_id + msg + i_constraint2.i_id; 133 } 134 return ""; 135 } 136 137 138 boolean removeForParent(QCon a_constraint) { 139 if (i_and) { 140 QCon other = getOtherConstraint(a_constraint); 141 other.removeJoin(this); other.remove(); 143 return true; 144 } 145 return false; 146 } 147 148 public String toString(){ 149 if(! Debug4.prettyToStrings){ 150 return super.toString(); 151 } 152 String str = "QConJoin " + (i_and ? "AND ": "OR"); 153 if(i_constraint1 != null){ 154 str += "\n " + i_constraint1; 155 } 156 if(i_constraint2 != null){ 157 str += "\n " + i_constraint2; 158 } 159 return str; 160 } 161 162 public boolean isOr() { 163 return !i_and; 164 } 165 166 167 } 168 | Popular Tags |