1 23 package org.objectweb.medor.query; 24 25 import org.objectweb.jorm.api.PException; 26 import org.objectweb.medor.filter.api.FieldOperand; 27 import org.objectweb.medor.expression.api.ParameterOperand; 28 import org.objectweb.medor.expression.api.Expression; 29 import org.objectweb.medor.expression.lib.And; 30 import org.objectweb.medor.filter.lib.BasicFieldOperand; 31 import org.objectweb.medor.expression.lib.BasicParameterOperand; 32 import org.objectweb.medor.expression.lib.Greater; 33 import org.objectweb.medor.expression.lib.Lower; 34 import org.objectweb.medor.expression.lib.BasicOperand; 35 import org.objectweb.medor.query.rdb.api.QualifiedTable; 36 import org.objectweb.medor.query.rdb.api.RdbExpField; 37 import org.objectweb.medor.query.rdb.api.RdbExpQueryLeaf; 38 import org.objectweb.medor.query.rdb.lib.BasicQualifiedTable; 39 import org.objectweb.medor.query.rdb.lib.BasicRdbExpQueryLeaf; 40 import org.objectweb.medor.type.lib.PTypeSpaceMedor; 41 42 50 public class RdbExpLeaf { 51 52 public static void main(String [] arg) { 53 try { 54 QualifiedTable t1 = new BasicQualifiedTable("t1", null); 56 QualifiedTable t2 = new BasicQualifiedTable("t2", "al2"); 57 QualifiedTable t3 = new BasicQualifiedTable("t3", "al3"); 58 QualifiedTable[] tables = {t1, t2}; 59 RdbExpQueryLeaf ql = new BasicRdbExpQueryLeaf(null, tables, ""); 61 RdbExpField f1 = ql.addRdbField("f1", null, "col1", t1); 63 RdbExpField f2 = ql.addRdbField("f2", null, "col2", t2); 64 FieldOperand fieldOp1 = new BasicFieldOperand(f1); 66 FieldOperand fieldOp2 = new BasicFieldOperand(f2); 67 BasicOperand valueL = new BasicOperand(1013); 68 BasicOperand valueR = new BasicOperand("coucou"); 69 Expression left = new Lower(fieldOp1, valueL); 70 Expression right = new Greater(fieldOp2, valueR); 71 Expression filter = new And(left, right); 72 ql.setQueryFilter(filter); 74 System.out.println("First request"); 75 System.out.println(ql.getSqlRequest(null, false, false)); 77 78 ParameterOperand fieldOp3 = 79 new BasicParameterOperand(PTypeSpaceMedor.STRING, "x"); 80 Expression left2 = new Lower(fieldOp3, valueL); 81 filter = new And(left2, right); 82 ql.setQueryFilter(filter); 83 ql.addGroupBy(f2); 84 System.out.println(ql.getSqlRequest(null, false, false)); 85 } 86 catch (Exception e) { 87 System.err.println("Exit with exception: " + e.getMessage()); 88 do { 89 e.printStackTrace(); 90 if (e instanceof PException) 91 e = ((PException) e).getNestedException(); 92 else 93 e = null; 94 } 95 while (e != null); 96 } 97 } 98 } 99 | Popular Tags |