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: Tfbasic.java 4066 2004-01-21 14:51:28Z legrasi $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.ftables;
027:
028: import java.rmi.RemoteException;
029: import java.sql.Connection;
030: import java.sql.Statement;
031: import javax.naming.NamingException;
032: import javax.sql.DataSource;
033:
034: //import org.objectweb.jonas.common.Log;
035: //import org.objectweb.util.monolog.api.Logger;
036: //import org.objectweb.util.monolog.api.BasicLevel;
037:
038: public class Tfbasic extends Tmanager {
039:
040: /**
041: * Entry point
042: */
043: public static void init() throws NamingException, RemoteException {
044: mgrInit();
045: createTableSimple("fbasicSimpleEB");
046: //createTableSimple("fbasicSimpleEC");
047: //createTableAccount("fbasicAccountEC");
048: //createTablePerson("fbasicPersonEC");
049: //createTablePkAuto("fjt2_pkautoec");
050: }
051:
052: /**
053: * create a table for the Simple bean of fbasic
054: */
055: private static void createTableSimple(String name)
056: throws RemoteException {
057:
058: // get connection
059: Connection conn = null;
060: try {
061: conn = dataSource.getConnection();
062: } catch (Exception e) {
063: throw new RemoteException("Cannot get Connection");
064: }
065:
066: Statement stmt;
067: try {
068: stmt = conn.createStatement();
069: stmt.execute("DROP TABLE " + name);
070: stmt.close();
071: //logger.log(BasicLevel.INFO, "Table "+name+" dropped");
072: } catch (Exception e) {
073: // logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e);
074: }
075: try {
076: stmt = conn.createStatement();
077: stmt.execute("create table " + name
078: + "(c_testname varchar(30) not null primary key,"
079: + "c_info integer, c_numtest integer )");
080: stmt.execute("insert into " + name
081: + " values('pk1', 10, 4)");
082: stmt.execute("insert into " + name
083: + " values('pk2', 10, 4)");
084: stmt.execute("insert into " + name
085: + " values('pk3', 10, 4)");
086: stmt.execute("insert into " + name
087: + " values('pk4', 40, 8)");
088: stmt.execute("insert into " + name
089: + " values('pk5', 50, 8)");
090: stmt.execute("insert into " + name
091: + " values('pk6', 60, 8)");
092: stmt.execute("insert into " + name
093: + " values('pk7', 70, 8)");
094: stmt.execute("insert into " + name
095: + " values('pk8', 45, 20)");
096: stmt.execute("insert into " + name
097: + " values('pk9', 55, 30)");
098: stmt.execute("insert into " + name
099: + " values('pk10',80, 80)");
100: stmt.execute("insert into " + name
101: + " values('pk11',80, 80)");
102: stmt.execute("insert into " + name
103: + " values('pk12',90, 90)");
104: stmt.execute("insert into " + name
105: + " values('pk13',100, 90)");
106: stmt.execute("insert into " + name
107: + " values('pk14',110, 90)");
108:
109: stmt.close();
110: conn.close(); // release connection
111: } catch (Exception e) {
112: //logger.log(BasicLevel.ERROR, "Exception in createTable : "+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 fbasic
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"+e);
140: }
141: try {
142: stmt = conn.createStatement();
143: stmt.execute("create table " + name
144: + "(c_number integer not null primary key,"
145: + " c_customer varchar(30) )");
146: stmt.execute("insert into " + name
147: + " values(0, 'to be removed')");
148: stmt.execute("insert into " + name + " values(10, 'Eric')");
149: stmt.execute("insert into " + name
150: + " values(20, 'Helene')");
151: stmt.execute("insert into " + name
152: + " values(30, 'Guilhem')");
153: stmt
154: .execute("insert into " + name
155: + " values(40, 'Malva')");
156:
157: stmt.close();
158: conn.close(); // release connection
159: } catch (Exception e) {
160: //logger.log(BasicLevel.ERROR, "Exception in createTable : "+e);
161: throw new RemoteException("Exception in createTable : " + e);
162: }
163: //logger.log(BasicLevel.INFO, "Table "+name+" created");
164: }
165:
166: /**
167: * create a table for the Person bean of fbasic
168: */
169: private static void createTablePerson(String name)
170: throws RemoteException {
171:
172: // get connection
173: Connection conn = null;
174: try {
175: conn = dataSource.getConnection();
176: } catch (Exception e) {
177: throw new RemoteException("Cannot get Connection");
178: }
179:
180: Statement stmt;
181: try {
182: stmt = conn.createStatement();
183: stmt.execute("DROP TABLE " + name);
184: stmt.close();
185: //logger.log(BasicLevel.INFO, "Table "+name+" dropped");
186: } catch (Exception e) {
187: //logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e);
188: }
189: try {
190: stmt = conn.createStatement();
191: stmt.execute("create table " + name
192: + "(c_number integer not null primary key,"
193: + " c_name varchar(30) )");
194: stmt.execute("insert into " + name
195: + " values(0, 'to be removed')");
196: stmt.execute("insert into " + name + " values(10, 'Eric')");
197: stmt.execute("insert into " + name
198: + " values(20, 'Helene')");
199: stmt.execute("insert into " + name
200: + " values(30, 'Guilhem')");
201: stmt
202: .execute("insert into " + name
203: + " values(40, 'Malva')");
204:
205: stmt.close();
206: conn.close(); // release connection
207: } catch (Exception e) {
208: //logger.log(BasicLevel.ERROR, "Exception in createTable : "+e);
209: throw new RemoteException("Exception in createTable : " + e);
210: }
211: //logger.log(BasicLevel.INFO, "Table "+name+" created");
212: }
213:
214: /**
215: * create a table for the Simple bean of fbasic
216: */
217: private static void createTablePkAuto(String name)
218: throws RemoteException {
219:
220: // get connection
221: Connection conn = null;
222: try {
223: conn = dataSource.getConnection();
224: } catch (Exception e) {
225: throw new RemoteException("Cannot get Connection");
226: }
227:
228: Statement stmt;
229: try {
230: stmt = conn.createStatement();
231: stmt.execute("DROP TABLE " + name);
232: stmt.close();
233: //logger.log(BasicLevel.INFO, "Table "+name+" dropped");
234: } catch (Exception e) {
235: //logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e);
236: }
237: try {
238: stmt = conn.createStatement();
239: stmt
240: .execute("create table "
241: + name
242: + "(c_field1 integer, c_field2 integer, c_field3 integer not null primary key )");
243:
244: stmt.close();
245: conn.close(); // release connection
246: } catch (Exception e) {
247: //logger.log(BasicLevel.ERROR, "Exception in createTable : "+e);
248: throw new RemoteException("Exception in createTable : " + e);
249: }
250: //logger.log(BasicLevel.INFO, "Table "+name+" created");
251: }
252:
253: }
|