001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: Tebasic.java 4406 2004-03-19 11:57:20Z benoitf $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.tables;
027:
028: import java.rmi.RemoteException;
029: import java.sql.Connection;
030: import java.sql.Statement;
031:
032: import javax.naming.NamingException;
033:
034: import org.objectweb.util.monolog.api.BasicLevel;
035:
036: public class Tebasic extends Tmanager {
037:
038: /**
039: * Entry point
040: */
041: public static void init() throws NamingException, RemoteException {
042: mgrInit();
043: createTableSimple("ebasicSimpleEB");
044: createTableSimple("ebasicSimpleEC");
045: createTableAccount("ebasicAccountEC");
046: createTablePerson("ebasicPersonEC");
047: createTablePkAuto("jt2_pkautoobjectec");
048: }
049:
050: /**
051: * create a table for the Simple bean of ebasic
052: */
053: private static void createTableSimple(String name)
054: throws RemoteException {
055:
056: // get connection
057: Connection conn = null;
058: try {
059: conn = dataSource.getConnection();
060: } catch (Exception e) {
061: throw new RemoteException("Cannot get Connection");
062: }
063:
064: Statement stmt;
065: try {
066: stmt = conn.createStatement();
067: stmt.execute("DROP TABLE " + name);
068: stmt.close();
069: logger.log(BasicLevel.INFO, "Table " + name + " dropped");
070: } catch (Exception e) {
071: logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"
072: + e);
073: }
074: try {
075: stmt = conn.createStatement();
076: stmt.execute("create table " + name
077: + "(c_testname varchar(30) not null primary key,"
078: + "c_info integer, c_numtest integer )");
079: stmt.execute("insert into " + name
080: + " values('pk1', 10, 4)");
081: stmt.execute("insert into " + name
082: + " values('pk2', 10, 4)");
083: stmt.execute("insert into " + name
084: + " values('pk3', 10, 4)");
085: stmt.execute("insert into " + name
086: + " values('pk4', 40, 8)");
087: stmt.execute("insert into " + name
088: + " values('pk5', 50, 8)");
089: stmt.execute("insert into " + name
090: + " values('pk6', 60, 8)");
091: stmt.execute("insert into " + name
092: + " values('pk7', 70, 8)");
093: stmt.execute("insert into " + name
094: + " values('pk8', 45, 20)");
095: stmt.execute("insert into " + name
096: + " values('pk9', 55, 30)");
097: stmt.execute("insert into " + name
098: + " values('pk10',80, 80)");
099: stmt.execute("insert into " + name
100: + " values('pk11',80, 80)");
101: stmt.execute("insert into " + name
102: + " values('pk12',90, 90)");
103: stmt.execute("insert into " + name
104: + " values('pk13',100, 90)");
105: stmt.execute("insert into " + name
106: + " values('pk14',110, 90)");
107:
108: stmt.close();
109: conn.close(); // release connection
110: } catch (Exception e) {
111: logger.log(BasicLevel.ERROR, "Exception in createTable : "
112: + e);
113: throw new RemoteException("Exception in createTable : " + e);
114: }
115: logger.log(BasicLevel.INFO, "Table " + name + " created");
116: }
117:
118: /**
119: * create a table for the Account bean of ebasic
120: */
121: private static void createTableAccount(String name)
122: throws RemoteException {
123:
124: // get connection
125: Connection conn = null;
126: try {
127: conn = dataSource.getConnection();
128: } catch (Exception e) {
129: throw new RemoteException("Cannot get Connection");
130: }
131:
132: Statement stmt;
133: try {
134: stmt = conn.createStatement();
135: stmt.execute("DROP TABLE " + name);
136: stmt.close();
137: logger.log(BasicLevel.INFO, "Table " + name + " dropped");
138: } catch (Exception e) {
139: logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"
140: + e);
141: }
142: try {
143: stmt = conn.createStatement();
144: stmt.execute("create table " + name
145: + "(c_number integer not null primary key,"
146: + " c_customer varchar(30) )");
147: stmt.execute("insert into " + name
148: + " values(0, 'to be removed')");
149: stmt.execute("insert into " + name + " values(10, 'Eric')");
150: stmt.execute("insert into " + name
151: + " values(20, 'Helene')");
152: stmt.execute("insert into " + name
153: + " values(30, 'Guilhem')");
154: stmt
155: .execute("insert into " + name
156: + " values(40, 'Malva')");
157:
158: stmt.close();
159: conn.close(); // release connection
160: } catch (Exception e) {
161: logger.log(BasicLevel.ERROR, "Exception in createTable : "
162: + e);
163: throw new RemoteException("Exception in createTable : " + e);
164: }
165: logger.log(BasicLevel.INFO, "Table " + name + " created");
166: }
167:
168: /**
169: * create a table for the Person bean of ebasic
170: */
171: private static void createTablePerson(String name)
172: throws RemoteException {
173:
174: // get connection
175: Connection conn = null;
176: try {
177: conn = dataSource.getConnection();
178: } catch (Exception e) {
179: throw new RemoteException("Cannot get Connection");
180: }
181:
182: Statement stmt;
183: try {
184: stmt = conn.createStatement();
185: stmt.execute("DROP TABLE " + name);
186: stmt.close();
187: logger.log(BasicLevel.INFO, "Table " + name + " dropped");
188: } catch (Exception e) {
189: logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"
190: + e);
191: }
192: try {
193: stmt = conn.createStatement();
194: stmt.execute("create table " + name
195: + "(c_number integer not null primary key,"
196: + " c_name varchar(30) )");
197: stmt.execute("insert into " + name
198: + " values(0, 'to be removed')");
199: stmt.execute("insert into " + name + " values(10, 'Eric')");
200: stmt.execute("insert into " + name
201: + " values(20, 'Helene')");
202: stmt.execute("insert into " + name
203: + " values(30, 'Guilhem')");
204: stmt
205: .execute("insert into " + name
206: + " values(40, 'Malva')");
207:
208: stmt.close();
209: conn.close(); // release connection
210: } catch (Exception e) {
211: logger.log(BasicLevel.ERROR, "Exception in createTable : "
212: + e);
213: throw new RemoteException("Exception in createTable : " + e);
214: }
215: logger.log(BasicLevel.INFO, "Table " + name + " created");
216: }
217:
218: /**
219: * create a table for the Simple bean of ebasic
220: */
221: private static void createTablePkAuto(String name)
222: throws RemoteException {
223:
224: // get connection
225: Connection conn = null;
226: try {
227: conn = dataSource.getConnection();
228: } catch (Exception e) {
229: throw new RemoteException("Cannot get Connection");
230: }
231:
232: Statement stmt;
233: try {
234: stmt = conn.createStatement();
235: stmt.execute("DROP TABLE " + name);
236: stmt.close();
237: logger.log(BasicLevel.INFO, "Table " + name + " dropped");
238: } catch (Exception e) {
239: logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"
240: + e);
241: }
242: try {
243: stmt = conn.createStatement();
244: stmt
245: .execute("create table "
246: + name
247: + "(c_field1 integer, c_field2 integer, pkautoincrementee integer not null primary key )");
248:
249: stmt.close();
250: conn.close(); // release connection
251: } catch (Exception e) {
252: logger.log(BasicLevel.ERROR, "Exception in createTable : "
253: + e);
254: throw new RemoteException("Exception in createTable : " + e);
255: }
256: logger.log(BasicLevel.INFO, "Table " + name + " created");
257: }
258:
259: }
|