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: Tmou.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: /**
037: * Class to create tables for the 'mou' bean.
038: * @author Philippe Durieux
039: */
040: public class Tmou extends Tmanager {
041:
042: /**
043: * Entry point
044: */
045: public static void init() throws NamingException, RemoteException {
046: mgrInit();
047: createTableA();
048: createTableB();
049: }
050:
051: /**
052: * create a table for the bean A
053: */
054: private static void createTableA() throws RemoteException {
055:
056: String name = "JT2_MOU_A1";
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"
074: + e);
075: }
076: try {
077: stmt = conn.createStatement();
078: stmt
079: .execute("create table "
080: + name
081: + "( c_ida varchar(30) not null primary key, cfk_idb varchar(30) not null )");
082: stmt.close();
083: conn.close(); // release connection
084: } catch (Exception e) {
085: logger.log(BasicLevel.ERROR, "Exception in createTable : "
086: + e);
087: throw new RemoteException("Exception in createTable : " + e);
088: }
089: logger.log(BasicLevel.INFO, "Table " + name + " created");
090: }
091:
092: /**
093: * create a table for the bean B
094: */
095: private static void createTableB() throws RemoteException {
096:
097: String name = "JT2_MOU_B1";
098:
099: // get connection
100: Connection conn = null;
101: try {
102: conn = dataSource.getConnection();
103: } catch (Exception e) {
104: throw new RemoteException("Cannot get Connection");
105: }
106:
107: Statement stmt;
108: try {
109: stmt = conn.createStatement();
110: stmt.execute("DROP TABLE " + name);
111: stmt.close();
112: logger.log(BasicLevel.INFO, "Table " + name + " dropped");
113: } catch (Exception e) {
114: logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"
115: + e);
116: }
117: try {
118: stmt = conn.createStatement();
119: stmt.execute("create table " + name
120: + "( c_idb varchar(30) not null primary key )");
121: stmt.close();
122: conn.close(); // release connection
123: } catch (Exception e) {
124: logger.log(BasicLevel.ERROR, "Exception in createTable : "
125: + e);
126: throw new RemoteException("Exception in createTable : " + e);
127: }
128: logger.log(BasicLevel.INFO, "Table " + name + " created");
129: }
130:
131: }
|