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: Tbeanexc.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 Tbeanexc extends Tmanager {
037:
038: /**
039: * Entry point
040: */
041: public static void init() throws NamingException, RemoteException {
042: mgrInit();
043: createTable("beanexcAccountEB");
044: createTable("beanexcAccountEC");
045: }
046:
047: /**
048: * create a table for CMP 1.x
049: */
050: private static void createTable(String name) throws RemoteException {
051:
052: // get connection
053: Connection conn = null;
054: try {
055: conn = dataSource.getConnection();
056: } catch (Exception e) {
057: throw new RemoteException("Cannot get Connection");
058: }
059:
060: Statement stmt;
061: try {
062: stmt = conn.createStatement();
063: stmt.execute("DROP TABLE " + name);
064: stmt.close();
065: logger.log(BasicLevel.INFO, "Table " + name + " dropped");
066: } catch (Exception e) {
067: logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"
068: + e);
069: }
070: try {
071: stmt = conn.createStatement();
072: stmt.execute("create table " + name
073: + "(c_number integer not null primary key,"
074: + "c_customer varchar(30), c_balance integer )");
075: stmt.execute("insert into " + name
076: + " values(101,'Antoine de St Exupery',900)");
077: stmt.execute("insert into " + name
078: + " values(102,'Alexandre Dumas fils',500)");
079: stmt.execute("insert into " + name
080: + " values(103,'Conan Doyle',800)");
081: stmt.execute("insert into " + name
082: + " values(104,'Alfred de Musset',140)");
083: stmt.execute("insert into " + name
084: + " values(105,'Phileas Lebegue',235)");
085: stmt.execute("insert into " + name
086: + " values(81, 'Philippe Coq',20)");
087: stmt.execute("insert into " + name
088: + " values(82, 'Philippe Durieux',20)");
089: stmt.execute("insert into " + name
090: + " values(83, 'Helene Joanin',20)");
091: stmt.execute("insert into " + name
092: + " values(84, 'Adriana Danes',20)");
093: stmt.execute("insert into " + name
094: + " values(85, 'Francois Exertier',20)");
095: stmt.execute("insert into " + name
096: + " values(86, 'John Doo', 20)");
097: stmt.execute("insert into " + name
098: + " values(87, 'Jim', 20)");
099: // Those following values are used to test ejbRemove() throwing RemoveException
100: stmt
101: .execute("insert into "
102: + name
103: + " values(999990, 'For exception in ejbRemove', 20)");
104: stmt
105: .execute("insert into "
106: + name
107: + " values(999991, 'For exception in ejbRemove', 20)");
108: stmt
109: .execute("insert into "
110: + name
111: + " values(999992, 'For exception in ejbRemove', 20)");
112: stmt
113: .execute("insert into "
114: + name
115: + " values(999993, 'For exception in ejbRemove', 20)");
116: stmt.close();
117: conn.close(); // release connection
118: } catch (Exception e) {
119: logger.log(BasicLevel.ERROR, "Exception in createTable : "
120: + e);
121: throw new RemoteException("Exception in createTable : " + e);
122: }
123: logger.log(BasicLevel.INFO, "Table " + name + " created");
124: }
125:
126: }
|