KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > ftables > Tfbasic


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: Tfbasic.java,v 1.2 2004/01/21 14:51:28 legrasi Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.ftables;
27
28 import java.rmi.RemoteException JavaDoc;
29 import java.sql.Connection JavaDoc;
30 import java.sql.Statement JavaDoc;
31 import javax.naming.NamingException JavaDoc;
32 import javax.sql.DataSource JavaDoc;
33 //import org.objectweb.jonas.common.Log;
34
//import org.objectweb.util.monolog.api.Logger;
35
//import org.objectweb.util.monolog.api.BasicLevel;
36

37 public class Tfbasic extends Tmanager {
38
39     /**
40      * Entry point
41      */

42     public static void init() throws NamingException JavaDoc, RemoteException JavaDoc {
43         mgrInit();
44         createTableSimple("fbasicSimpleEB");
45         //createTableSimple("fbasicSimpleEC");
46
//createTableAccount("fbasicAccountEC");
47
//createTablePerson("fbasicPersonEC");
48
//createTablePkAuto("fjt2_pkautoec");
49
}
50
51     /**
52      * create a table for the Simple bean of fbasic
53      */

54     private static void createTableSimple(String JavaDoc name) throws RemoteException JavaDoc {
55
56         // get connection
57
Connection JavaDoc conn = null;
58         try {
59             conn = dataSource.getConnection();
60         } catch(Exception JavaDoc e) {
61             throw new RemoteException JavaDoc("Cannot get Connection");
62         }
63     
64         Statement JavaDoc stmt;
65         try {
66             stmt = conn.createStatement();
67             stmt.execute("DROP TABLE "+name);
68             stmt.close();
69             //logger.log(BasicLevel.INFO, "Table "+name+" dropped");
70
} catch(Exception JavaDoc e) {
71             // logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e);
72
}
73         try {
74             stmt = conn.createStatement();
75             stmt.execute("create table " + name +
76                          "(c_testname varchar(30) not null primary key,"+
77                          "c_info integer, c_numtest integer )");
78             stmt.execute("insert into "+name+" values('pk1', 10, 4)");
79             stmt.execute("insert into "+name+" values('pk2', 10, 4)");
80             stmt.execute("insert into "+name+" values('pk3', 10, 4)");
81             stmt.execute("insert into "+name+" values('pk4', 40, 8)");
82             stmt.execute("insert into "+name+" values('pk5', 50, 8)");
83             stmt.execute("insert into "+name+" values('pk6', 60, 8)");
84             stmt.execute("insert into "+name+" values('pk7', 70, 8)");
85             stmt.execute("insert into "+name+" values('pk8', 45, 20)");
86             stmt.execute("insert into "+name+" values('pk9', 55, 30)");
87             stmt.execute("insert into "+name+" values('pk10',80, 80)");
88             stmt.execute("insert into "+name+" values('pk11',80, 80)");
89             stmt.execute("insert into "+name+" values('pk12',90, 90)");
90             stmt.execute("insert into "+name+" values('pk13',100, 90)");
91             stmt.execute("insert into "+name+" values('pk14',110, 90)");
92             
93
94             stmt.close();
95             conn.close(); // release connection
96
} catch(Exception JavaDoc e) {
97             //logger.log(BasicLevel.ERROR, "Exception in createTable : "+e);
98
throw new RemoteException JavaDoc("Exception in createTable : "+e);
99         }
100         // logger.log(BasicLevel.INFO, "Table "+name+" created");
101
}
102
103     /**
104      * create a table for the Account bean of fbasic
105      */

106     private static void createTableAccount(String JavaDoc name) throws RemoteException JavaDoc {
107
108         // get connection
109
Connection JavaDoc conn = null;
110         try {
111             conn = dataSource.getConnection();
112         } catch(Exception JavaDoc e) {
113             throw new RemoteException JavaDoc("Cannot get Connection");
114         }
115     
116         Statement JavaDoc stmt;
117         try {
118             stmt = conn.createStatement();
119             stmt.execute("DROP TABLE "+name);
120             stmt.close();
121             //logger.log(BasicLevel.INFO, "Table "+name+" dropped");
122
} catch(Exception JavaDoc e) {
123             //logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e);
124
}
125         try {
126             stmt = conn.createStatement();
127             stmt.execute("create table " + name +
128                          "(c_number integer not null primary key,"+
129                          " c_customer varchar(30) )");
130             stmt.execute("insert into "+name+" values(0, 'to be removed')");
131             stmt.execute("insert into "+name+" values(10, 'Eric')");
132             stmt.execute("insert into "+name+" values(20, 'Helene')");
133             stmt.execute("insert into "+name+" values(30, 'Guilhem')");
134             stmt.execute("insert into "+name+" values(40, 'Malva')");
135
136             stmt.close();
137             conn.close(); // release connection
138
} catch(Exception JavaDoc e) {
139             //logger.log(BasicLevel.ERROR, "Exception in createTable : "+e);
140
throw new RemoteException JavaDoc("Exception in createTable : "+e);
141         }
142         //logger.log(BasicLevel.INFO, "Table "+name+" created");
143
}
144
145     /**
146      * create a table for the Person bean of fbasic
147      */

148     private static void createTablePerson(String JavaDoc name) throws RemoteException JavaDoc {
149
150         // get connection
151
Connection JavaDoc conn = null;
152         try {
153             conn = dataSource.getConnection();
154         } catch(Exception JavaDoc e) {
155             throw new RemoteException JavaDoc("Cannot get Connection");
156         }
157     
158         Statement JavaDoc stmt;
159         try {
160             stmt = conn.createStatement();
161             stmt.execute("DROP TABLE "+name);
162             stmt.close();
163             //logger.log(BasicLevel.INFO, "Table "+name+" dropped");
164
} catch(Exception JavaDoc e) {
165             //logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e);
166
}
167         try {
168             stmt = conn.createStatement();
169             stmt.execute("create table " + name +
170                          "(c_number integer not null primary key,"+
171                          " c_name varchar(30) )");
172             stmt.execute("insert into "+name+" values(0, 'to be removed')");
173             stmt.execute("insert into "+name+" values(10, 'Eric')");
174             stmt.execute("insert into "+name+" values(20, 'Helene')");
175             stmt.execute("insert into "+name+" values(30, 'Guilhem')");
176             stmt.execute("insert into "+name+" values(40, 'Malva')");
177
178             stmt.close();
179             conn.close(); // release connection
180
} catch(Exception JavaDoc e) {
181             //logger.log(BasicLevel.ERROR, "Exception in createTable : "+e);
182
throw new RemoteException JavaDoc("Exception in createTable : "+e);
183         }
184         //logger.log(BasicLevel.INFO, "Table "+name+" created");
185
}
186
187     /**
188      * create a table for the Simple bean of fbasic
189      */

190     private static void createTablePkAuto(String JavaDoc name) throws RemoteException JavaDoc {
191
192         // get connection
193
Connection JavaDoc conn = null;
194         try {
195             conn = dataSource.getConnection();
196         } catch(Exception JavaDoc e) {
197             throw new RemoteException JavaDoc("Cannot get Connection");
198         }
199     
200         Statement JavaDoc stmt;
201         try {
202             stmt = conn.createStatement();
203             stmt.execute("DROP TABLE "+name);
204             stmt.close();
205             //logger.log(BasicLevel.INFO, "Table "+name+" dropped");
206
} catch(Exception JavaDoc e) {
207             //logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e);
208
}
209         try {
210             stmt = conn.createStatement();
211             stmt.execute("create table " + name +
212                          "(c_field1 integer, c_field2 integer, c_field3 integer not null primary key )");
213
214             stmt.close();
215             conn.close(); // release connection
216
} catch(Exception JavaDoc e) {
217             //logger.log(BasicLevel.ERROR, "Exception in createTable : "+e);
218
throw new RemoteException JavaDoc("Exception in createTable : "+e);
219         }
220         //logger.log(BasicLevel.INFO, "Table "+name+" created");
221
}
222
223
224 }
225
Popular Tags