1 24 package org.objectweb.jalisto.se.query.constraint; 25 26 import org.objectweb.jalisto.se.api.Session; 27 import org.objectweb.jalisto.se.api.internal.SessionInternal; 28 import org.objectweb.jalisto.se.api.query.FielComparator; 29 import org.objectweb.jalisto.se.api.query.Query; 30 import org.objectweb.jalisto.se.api.query.Constraint; 31 import org.objectweb.jalisto.se.query.exception.QueryEngineException; 32 import org.objectweb.jalisto.se.query.execution.ExecutionTree; 33 import org.objectweb.jalisto.se.query.parameter.SubQuery; 34 import org.objectweb.jalisto.se.query.result.QueryResultWrapper; 35 36 import java.util.ArrayList ; 37 38 public class SubQueryConstraintImpl extends ConstraintImpl { 39 public SubQueryConstraintImpl(SubQuery subQuery, String className, ArrayList subFieldNames) { 40 this.className = className; 41 this.subQuery = subQuery; 42 this.fieldNames = new String [subFieldNames.size()]; 43 for (int i = 0; i < fieldNames.length; i++) { 44 fieldNames[i] = (String ) subFieldNames.get(i); 45 } 46 } 47 48 public Object getObject() { 49 return subQuery; 50 } 51 52 public Query getQuery() { 53 return subQuery.getQuery(); 54 } 55 56 public ExecutionTree getTree() { 57 return subQuery.getTree(null); 58 } 59 60 public String getFieldName() { 61 return fieldNames[0]; 62 } 63 64 public String [] getFieldNames() { 65 return fieldNames; 66 } 67 68 public Constraint contains() { 69 throw new QueryEngineException("cannot do this operation on a subQuery"); 70 } 71 72 public Constraint equal() { 73 throw new QueryEngineException("cannot do this operation on a subQuery"); 74 } 75 76 public Constraint greater() { 77 throw new QueryEngineException("cannot do this operation on a subQuery"); 78 } 79 80 public Constraint identity() { 81 throw new QueryEngineException("cannot do this operation on a subQuery"); 82 } 83 84 public Constraint like() { 85 throw new QueryEngineException("cannot do this operation on a subQuery"); 86 } 87 88 public Constraint not() { 89 not = !not; 90 return this; 91 } 92 93 public Constraint smaller() { 94 throw new QueryEngineException("cannot do this operation on a subQuery"); 95 } 96 97 public boolean execute(Session session, FielComparator comparator, Object candidate) { 98 return subQuery.getTree(null).resolveOnOneElement( 99 (SessionInternal) session, 100 (QueryResultWrapper) candidate); 101 } 102 103 public String getClassName() { 104 return className; 105 } 106 107 public String toString() { 108 StringBuffer sb = new StringBuffer (); 109 sb.append("SubQueryConstraint"); 110 return sb.toString(); 111 } 112 113 private SubQuery subQuery; 114 private String className; 115 private String [] fieldNames; 116 private boolean not = false; 117 } 118 | Popular Tags |