KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > tables > Tebasic


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: Tebasic.java,v 1.11 2004/03/19 11:57:15 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.tables;
27
28 import java.rmi.RemoteException JavaDoc;
29 import java.sql.Connection JavaDoc;
30 import java.sql.Statement JavaDoc;
31
32 import javax.naming.NamingException JavaDoc;
33
34 import org.objectweb.util.monolog.api.BasicLevel;
35
36 public class Tebasic extends Tmanager {
37
38     /**
39      * Entry point
40      */

41     public static void init() throws NamingException JavaDoc, RemoteException JavaDoc {
42         mgrInit();
43         createTableSimple("ebasicSimpleEB");
44         createTableSimple("ebasicSimpleEC");
45         createTableAccount("ebasicAccountEC");
46         createTablePerson("ebasicPersonEC");
47         createTablePkAuto("jt2_pkautoobjectec");
48     }
49
50     /**
51      * create a table for the Simple bean of ebasic
52      */

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

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

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

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