1 23 package org.objectweb.medor.optim.jorm.rdb; 24 25 import junit.framework.Test; 26 import junit.framework.TestSuite; 27 import junit.textui.TestRunner; 28 import org.objectweb.jorm.api.PException; 29 import org.objectweb.jorm.api.PMapper; 30 import org.objectweb.jorm.type.api.PTypeSpace; 31 import org.objectweb.jorm.mapper.rdb.lib.MapperJDBC; 32 import org.objectweb.jorm.mapper.rdb.lib.ConnectionSpecJDBC; 33 import org.objectweb.jorm.mapper.rdb.adapter.RdbAdapterFactory; 34 import org.objectweb.jorm.mapper.rdb.adapter.api.RdbAdapter; 35 import org.objectweb.jorm.mapper.rdb.adapter.api.RdbAdapterException; 36 import org.objectweb.medor.api.MedorException; 37 import org.objectweb.medor.lib.Log; 38 import org.objectweb.medor.optim.api.QueryRewriter; 39 import org.objectweb.medor.optim.jorm.JormFlatten2Rdb; 40 import org.objectweb.medor.optim.jorm.TestJormLeafRewriter; 41 import org.objectweb.medor.optim.lib.BasicQueryRewriter; 42 import org.objectweb.medor.optim.lib.FlattenQueryTreeRule; 43 import org.objectweb.medor.query.api.QueryLeaf; 44 import org.objectweb.medor.query.api.QueryTreeField; 45 import org.objectweb.medor.query.rdb.api.QualifiedTable; 46 import org.objectweb.medor.query.rdb.api.RdbExpQueryLeaf; 47 import org.objectweb.medor.query.rdb.lib.BasicQualifiedTable; 48 import org.objectweb.medor.query.rdb.lib.BasicRdbExpQueryLeaf; 49 50 import java.util.ArrayList ; 51 52 55 public class TestRdbJormLeafRewriter extends TestJormLeafRewriter { 56 57 RdbAdapter adapter; 58 59 62 public static void main(String [] args) { 63 TestRunner.run(suite()); 64 } 65 66 69 public static Test suite() { 70 return new TestSuite(TestRdbJormLeafRewriter.class); 71 } 72 73 public TestRdbJormLeafRewriter() { 74 this("TestRdbJormLeafRewriter"); 75 } 76 77 public TestRdbJormLeafRewriter(String testName) { 78 super(testName, Log.MEDOR_PREFIX + ".optim.jorm.rdb.leafrewriter"); 79 try { 80 adapter = RdbAdapterFactory.getTypeConverter((String ) null); 81 } catch (RdbAdapterException ex) { 82 fail(ex.getMessage()); 83 } 84 } 85 86 public PMapper newMappper() { 87 MapperJDBC m = null; 88 try { 89 m = new MapperJDBC(); 90 ConnectionSpecJDBC cs = 91 new ConnectionSpecJDBC("jdbc:product:basename", "java.lang.String"); 92 m.setConnectionFactory(cs); 93 } 94 catch (PException e) { 95 e.printStackTrace(); 96 } 97 return m; 98 } 99 100 public QueryRewriter createQueryRewriter() { 101 ArrayList rules = new ArrayList (2); 102 rules.add(new FlattenQueryTreeRule()); 103 rules.add(new JormFlatten2Rdb()); 104 return new BasicQueryRewriter(rules); 105 } 106 107 protected QueryLeaf getQueryLeaf_A() throws MedorException { 108 QualifiedTable table = new BasicQualifiedTable("T_REF_SING_A", "T_REF_SING_A_0"); 109 String name = "org.objectweb.medor.optim.jorm.rdb.A"; 110 String prefix = name + "."; 111 RdbExpQueryLeaf leaf = new BasicRdbExpQueryLeaf(null, 112 new QualifiedTable[] {table}, name); 113 leaf.setRdbAdapter(adapter); 114 QueryTreeField id = leaf.addRdbField( 115 prefix + "id", PTypeSpace.LONG, "id_col", table); 116 QueryTreeField f1 = leaf.addRdbField( 117 prefix + "field1", PTypeSpace.STRING, "FIELD_1", table); 118 QueryTreeField f2 = leaf.addRdbField( 119 prefix + "field2", PTypeSpace.STRING, "FIELD_2", table); 120 return leaf; 121 } 122 123 protected QueryLeaf getQueryLeaf_One() throws MedorException { 124 QualifiedTable table = new BasicQualifiedTable("T_REF_SING_ONE", "T_REF_SING_ONE_0"); 125 String name = "org.objectweb.medor.optim.jorm.rdb.One"; 126 String prefix = name + "."; 127 RdbExpQueryLeaf leaf = new BasicRdbExpQueryLeaf(null, 128 new QualifiedTable[] {table}, name); 129 leaf.setRdbAdapter(adapter); 130 QueryTreeField id = leaf.addRdbField( 131 prefix + "id", PTypeSpace.STRING, "ID", table); 132 QueryTreeField f1 = leaf.addRdbField( 133 prefix + "field1", PTypeSpace.STRING, "FIELD_1", table); 134 QueryTreeField ida = leaf.addRdbField( 135 prefix + "idA", PTypeSpace.LONG, "ID_A", table); 136 return leaf; 137 } 138 139 } 140 | Popular Tags |