1 21 package com.db4o; 22 23 import com.db4o.foundation.*; 24 import com.db4o.reflect.*; 25 26 35 public class QConPath extends QConClass { 36 37 public QConPath(){ 38 39 } 40 41 QConPath(Transaction a_trans, QCon a_parent, QField a_field) { 42 super(a_trans, a_parent, a_field, null); 43 if(a_field != null){ 44 i_yapClass = a_field.getYapClass(); 45 } 46 } 47 48 public boolean canLoadByIndex() { 49 return false; 50 } 51 52 boolean evaluate(QCandidate a_candidate) { 53 if (a_candidate.classReflector() == null) { 54 visitOnNull(a_candidate.getRoot()); 55 } 56 return true; 57 } 58 59 void evaluateSelf() { 60 } 62 63 boolean isNullConstraint() { 64 return ! hasChildren(); 65 } 66 67 QConClass shareParentForClass(ReflectClass a_class, boolean[] removeExisting) { 68 if (i_parent == null) { 69 return null; 70 } 71 if (! i_field.canHold(a_class)) { 72 return null; 73 } 74 QConClass newConstraint = new QConClass(i_trans, i_parent, i_field, a_class); 75 morph(removeExisting,newConstraint, a_class); 76 return newConstraint; 77 } 78 79 80 QCon shareParent(Object a_object, boolean[] removeExisting) { 81 if (i_parent == null) { 82 return null; 83 } 84 Object obj = i_field.coerce(a_object); 85 if(obj == No4.INSTANCE){ 86 QConObject falseConstraint = new QConFalse(i_trans, i_parent, i_field); 87 morph(removeExisting, falseConstraint, reflectClassForObject(obj)); 88 return falseConstraint; 89 } 90 QConObject newConstraint = new QConObject(i_trans, i_parent, i_field, obj); 91 morph(removeExisting, newConstraint, reflectClassForObject(obj)); 92 return newConstraint; 93 } 94 95 private ReflectClass reflectClassForObject(Object obj) { 96 return i_trans.reflector().forObject(obj); 97 } 98 99 private void morph(boolean[] removeExisting, QConObject newConstraint, ReflectClass claxx) { 104 boolean mayMorph = true; 105 if (claxx != null) { 106 YapClass yc = i_trans.stream().produceYapClass(claxx); 107 if (yc != null) { 108 Iterator4 i = iterateChildren(); 109 while (i.moveNext()) { 110 QField qf = ((QCon) i.current()).getField(); 111 if (!yc.hasField(i_trans.stream(), qf.i_name)) { 112 mayMorph = false; 113 break; 114 } 115 } 116 } 117 } 118 119 121 if (mayMorph) { 122 Iterator4 j = iterateChildren(); 123 while (j.moveNext()) { 124 newConstraint.addConstraint((QCon) j.current()); 125 } 126 if(hasJoins()){ 127 Iterator4 k = iterateJoins(); 128 while (k.moveNext()) { 129 QConJoin qcj = (QConJoin)k.current(); 130 qcj.exchangeConstraint(this, newConstraint); 131 newConstraint.addJoin(qcj); 132 } 133 } 134 i_parent.exchangeConstraint(this, newConstraint); 135 removeExisting[0] = true; 136 137 } else { 138 i_parent.addConstraint(newConstraint); 139 } 140 } 141 142 final boolean visitSelfOnNull() { 143 return false; 144 } 145 146 public String toString(){ 147 if(! Debug4.prettyToStrings){ 148 return super.toString(); 149 } 150 return "QConPath " + super.toString(); 151 } 152 153 154 } 155 | Popular Tags |