KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > optim > jorm > rdb > TestRdbJormLeafRewriter


1 /**
2  * MEDOR: Middleware Enabling Distributed Object Requests
3  *
4  * Copyright (C) 2001-2003 France Telecom R&D
5  * Contact: alexandre.lefebvre@rd.francetelecom.com
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * Initial developers: M. Alia, S. Chassande-Barrioz, A. Lefebvre
22  */

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 JavaDoc;
51
52 /**
53  * @author S.Chassande-Barrioz
54  */

55 public class TestRdbJormLeafRewriter extends TestJormLeafRewriter {
56
57     RdbAdapter adapter;
58
59     /**
60      * main method to launch the tests manually
61      */

62     public static void main(String JavaDoc[] args) {
63         TestRunner.run(suite());
64     }
65
66     /**
67      * This method creates a TestSuite object with the current tests
68      */

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 JavaDoc testName) {
78         super(testName, Log.MEDOR_PREFIX + ".optim.jorm.rdb.leafrewriter");
79         try {
80             adapter = RdbAdapterFactory.getTypeConverter((String JavaDoc) 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 JavaDoc rules = new ArrayList JavaDoc(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 JavaDoc name = "org.objectweb.medor.optim.jorm.rdb.A";
110         String JavaDoc 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 JavaDoc name = "org.objectweb.medor.optim.jorm.rdb.One";
126         String JavaDoc 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