1 23 24 import org.objectweb.medor.api.Field; 25 import org.objectweb.medor.api.MedorException; 26 import org.objectweb.medor.api.TupleStructure; 27 import org.objectweb.medor.eval.api.ConnectionResources; 28 import org.objectweb.medor.eval.api.QueryEvaluator; 29 import org.objectweb.medor.eval.lib.MedorEvaluator; 30 import org.objectweb.medor.expression.api.Expression; 31 import org.objectweb.medor.expression.api.VariableOperand; 32 import org.objectweb.medor.expression.lib.BasicOperand; 33 import org.objectweb.medor.expression.lib.BasicVariableOperand; 34 import org.objectweb.medor.expression.lib.Lower; 35 import org.objectweb.medor.filter.api.FieldOperand; 36 import org.objectweb.medor.filter.lib.BasicFieldOperand; 37 import org.objectweb.medor.lib.BasicField; 38 import org.objectweb.medor.lib.BasicTupleStructure; 39 import org.objectweb.medor.optim.api.ExecPlanGenerator; 40 import org.objectweb.medor.optim.lib.IndexesGenerator; 41 import org.objectweb.medor.query.api.QueryTree; 42 import org.objectweb.medor.query.api.QueryTreeField; 43 import org.objectweb.medor.query.api.TCQueryLeaf; 44 import org.objectweb.medor.query.lib.MedorTCQueryLeaf; 45 import org.objectweb.medor.tuple.api.Tuple; 46 import org.objectweb.medor.tuple.api.TupleCollection; 47 import org.objectweb.medor.tuple.lib.ExplicitTupleCollection; 48 import org.objectweb.medor.tuple.lib.MemoryTuple; 49 import org.objectweb.medor.type.lib.PTypeSpaceMedor; 50 51 54 public class MedorTCQuery { 55 public static void main(String [] args) throws MedorException{ 56 Field[] fields = new Field[4]; 59 fields[0] = new BasicField("NSS", PTypeSpaceMedor.INT); 60 fields[1] = new BasicField("NAME", PTypeSpaceMedor.STRING); 61 fields[2] = new BasicField("ADRESS", PTypeSpaceMedor.STRING); 62 fields[3] = new BasicField("SEX", PTypeSpaceMedor.CHAR); 63 64 TupleStructure ts = new BasicTupleStructure(fields); 66 67 VariableOperand[] vops1 = new VariableOperand[4]; 69 vops1[0] = new BasicVariableOperand(201); 71 vops1[1] = new BasicVariableOperand("MEDOR"); 72 vops1[2] = new BasicVariableOperand("MARS"); 73 vops1[3] = new BasicVariableOperand('M'); 74 75 VariableOperand[] vops2 = new VariableOperand[4]; 76 vops2[0] = new BasicVariableOperand(101); 77 vops2[1] = new BasicVariableOperand("JORM"); 78 vops2[2] = new BasicVariableOperand("MARS"); 79 vops2[3] = new BasicVariableOperand('M'); 80 81 Tuple t1 = new MemoryTuple(vops1); 83 Tuple t2 = new MemoryTuple(vops2); 84 85 ExplicitTupleCollection tc = new ExplicitTupleCollection(ts); 87 88 tc.insertTuple(t1); 90 tc.insertTuple(t2); 91 92 TCQueryLeaf medorQTLeaf = new MedorTCQueryLeaf("", "jorm_medor", tc); 93 QueryTreeField mfield1 = medorQTLeaf.addField("NSS", PTypeSpaceMedor.INT, fields[0]); 94 QueryTreeField mfield2 = medorQTLeaf.addField("NAME", PTypeSpaceMedor.STRING, fields[1]); 95 QueryTreeField mfield3 = medorQTLeaf.addField("ADRESS", PTypeSpaceMedor.STRING, fields[2]); 96 97 FieldOperand mfieldOp = new BasicFieldOperand(new BasicField("NSS", PTypeSpaceMedor.INT)); 99 BasicOperand mvalue = new BasicOperand(1000); 100 Expression mFilter = new Lower(mfieldOp, mvalue); 101 102 medorQTLeaf.setQueryFilter(mFilter); 104 105 ExecPlanGenerator indexesGen = new IndexesGenerator(); 107 108 System.out.print(" Generating indexes..."); 109 QueryTree query = null; 110 try { 111 query = indexesGen.transform(medorQTLeaf); 112 } 113 catch (Exception e) { 114 System.out.println("Fail:"); 115 e.printStackTrace(); 116 } 117 System.out.println("success"); 118 119 QueryEvaluator evaluator = new MedorEvaluator(query, 0); 121 122 ConnectionResources connRess = evaluator.getRequiredConnectionResources(); 124 125 TupleCollection queryResult = evaluator.evaluate(null, null, null); 128 129 System.out.println("RESULTS :"); 131 int cpt = 0; 132 if (!queryResult.isEmpty()) { 133 do { 134 cpt++; 135 System.out.println("Tuple " + cpt + " :"); 136 System.out.println(queryResult.getMetaData().getField(1).getName() + 137 " = " + queryResult.getTuple().getObject(1)); 138 System.out.println(queryResult.getMetaData().getField(2).getName() + 139 " = " + queryResult.getTuple().getObject(2)); 140 System.out.println(); 141 } while (queryResult.next()); 142 } else { 143 System.out.println("No result for this query "); 144 } 145 } 146 } 147 | Popular Tags |