00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 package org.openmobileis.database.fastobjectdb.db.query.soda;
00030
00031 import org.odbms.Constraint;
00032 import org.openmobileis.common.util.collection.LongArray;
00033 import org.openmobileis.database.fastobjectdb.db.exception.FODBException;
00034
00041 public class FODBSodaConstraint extends BaseConstraint {
00042
00043
00044 private FODBSodaIndexPath indexpath;
00045 private boolean error;
00046 private int constraintId;
00047 boolean hasOperande = false;
00048
00049 public FODBSodaConstraint(FODBSodaQuery query, int constraintId) {
00050 super();
00051 this.constraintId = constraintId;
00052 }
00053
00054 void setIndex(FODBSodaIndexPath index) {
00055 indexpath = index;
00056 }
00057
00058 String getIndexMember() {
00059 return indexpath.getIndexMember();
00060 }
00061
00062 private void setError(boolean err) {
00063 if (!err) this.error = false;
00064 }
00065
00066 boolean setOperand(Object ope) {
00067 if (indexpath != null) {
00068 this.setHasOperande(true);
00069 return indexpath.setOperand(ope);
00070 }
00071 return false;
00072 }
00073
00074 boolean addComparator(int ope) {
00075 if (indexpath != null) {
00076 return indexpath.addComparator(ope);
00077 }
00078 return false;
00079 }
00080
00081 protected void execute(LongArray longArray) throws FODBException {
00082 if (error) throw new FODBException("Bad Query construction.");
00083 BaseConstraint nextConst = this.getNextConstraint();
00084 if (nextConst != null) {
00085 nextConst.execute(longArray);
00086 }
00087
00088 long[] newPtrList = indexpath.execute();
00089 if (this.getNextConstraint() == null) {
00090 longArray.add(newPtrList);
00091 } else if (this.nextContraintLink == BaseConstraint.CONSTRAINT_OR) {
00092 longArray.addUnion(newPtrList);
00093 } else {
00094 longArray.addIntersect(newPtrList);
00095 }
00096 }
00097
00098
00099
00100
00101
00102 public Constraint and(Constraint with) {
00103 FODBSodaConstraint newConst = (FODBSodaConstraint)with;
00104 if (newConst.getIndexMember().equals(this.getIndexMember())) {
00105 indexpath.mergeIndexComporator(newConst.indexpath.getIndexComparator());
00106 if (newConst.getNextConstraint() != null) {
00107 this.setNextConstraint(newConst.getNextConstraint(), newConst.nextContraintLink);
00108 }
00109 } else {
00110 this.setNextConstraint((BaseConstraint)with, BaseConstraint.CONSTRAINT_AND);
00111 }
00112 return this;
00113 }
00114
00115
00116
00117
00118 public Constraint or(Constraint with) {
00119 this.setNextConstraint((BaseConstraint)with, BaseConstraint.CONSTRAINT_OR);
00120 return this;
00121 }
00122
00123
00124
00125 public Constraint equal() {
00126 this.setError(this.addComparator(BaseConstraint.EQUALS));
00127 return this;
00128 }
00129
00130
00131
00132
00133 public Constraint greater() {
00134 this.setError(this.addComparator(BaseConstraint.GREATER));
00135 return this;
00136 }
00137
00138
00139
00140
00141 public Constraint smaller() {
00142 this.setError(this.addComparator(BaseConstraint.SMALLER));
00143 return this;
00144 }
00145
00146
00147
00148
00149 public Constraint identity() {
00150 this.setError(this.addComparator(BaseConstraint.IDENTITY));
00151 return this;
00152 }
00153
00154
00155
00156
00157 public Constraint like() {
00158 this.setError(this.addComparator(BaseConstraint.LIKE));
00159 return this;
00160 }
00161
00167 public Constraint distinct () {
00168 this.setError(this.addComparator(BaseConstraint.DISTINCT));
00169 return this;
00170 }
00171
00172
00173
00174
00175 public Constraint contains() {
00176 this.setError(this.addComparator(BaseConstraint.CONTAINS));
00177 return this;
00178 }
00179
00180
00181
00182
00183 public Constraint not() {
00184 this.setError(this.addComparator(BaseConstraint.NOT));
00185 return this;
00186 }
00187
00188
00189
00190
00191 public Object getObject() {
00192
00193 return null;
00194 }
00195
00196 boolean hasIndex() {
00197 return (indexpath!=null);
00198 }
00202 public int getConstraintId() {
00203 return constraintId;
00204 }
00205
00206 public boolean equals(Object con) {
00207 if (con instanceof FODBSodaConstraint) {
00208 if (((FODBSodaConstraint)con).constraintId == this.constraintId) {
00209 return true;
00210 }
00211 }
00212 return false;
00213 }
00214
00218 boolean isHasOperande() {
00219 return hasOperande;
00220 }
00221
00225 void setHasOperande(boolean b) {
00226 hasOperande = b;
00227 }
00228
00229 }