import Zql.*; import java.util.*; /** * Determines whether a particular query can be satisfied from the data present in the local cache * */ public class Solver { private ZQuery user_ ; private ZQuery modified_ ; private ZQuery answerby_ ; private ZQuery remainder_ ; public ZQuery getUQuery() { return user_; } public ZQuery getModified() { return modified_; } public ZQuery getAnswerby() { return answerby_; } public ZQuery getRemainder() { return remainder_; } /** check whether the user query can be satisfied from local data * if satisfied, find the modified, answerby & remainder queries and return TRUE * else return FALSE */ public boolean isQuerySatisfiable(QueryObject ob) { user_ = ob.getZQuery(); // qgidVector contains ID's of all queries in cache whose signatures match with new query "ob" Vector qgidVector = Cache.signatureMatch(ob); if(qgidVector==null) // implies hashSet or hashTable empty { System.out.println("New Query: " + user_.toString()); System.out.println("No previous queries in cache: New query cannot be satisfied locally "); remainder_ = user_; return false; } else if(qgidVector.size()==0) // implies no match found { System.out.println("New Query: " + user_.toString()); System.out.println("No signature match found in cache: New query cannot be satisfied locally "); remainder_ = user_; return false; } else { Vector iterateVector = new Vector(); Vector principalVector = new Vector(); // a vector of vectors (vector T) // each Ti is a vector of negated atoms for(int i=0;it) is true // -(-q v t) == (q ^ -t) // == q ^ -t1 ^ -t2 ^ .... // but for each atoms in t1 ... disjunction has to be handled if(isSat(ob.getPredicates(),principalVector)) { // currently we are only working with queries that are completely answerable from cache //modified_ = userQuery.getZQuery(); //answerby_ = cachedQuery.getZQuery(); remainder_ = null; System.out.println("New Query: " + user_.toString()); System.out.println("Query can be satisfied locally: "); return true; } System.out.println("New Query: " + user_.toString()); System.out.println("Signature match found: But new query cannot be completely satisfied locally "); remainder_ = user_; return false; } } // Q in conjunctive form only. // that will lead to negated T in disjunctive form public boolean isSat(Vector object1, Vector T) { //System.out.println("Object predicates" + object1.toString()); //System.out.println("Cache predicates" + T.toString()); //System.out.println(); Satisfy stf; Vector parcel; int tSize = T.size(); parcel = new Vector(tSize); for(int i=0;i=0;i--) { arr[i][1] = ((Vector)T.get(i)).size(); arr[i][0] = pr; pr *= arr[i][1]; } for(int j=0;j