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: Tomu.java 7413 2005-09-26 09:24:54Z durieuxp $
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 'omu' bean.
038: * @author Philippe Durieux
039: */
040: public class Tomu extends Tmanager {
041:
042: /**
043: * Entry point
044: */
045: public static void init() throws NamingException, RemoteException {
046: mgrInit();
047: createTableA("JT2_OMU_A");
048: createTableB("JT2_OMU_B");
049: createTableA("JT2_OMU_Atx");
050: createTableB("JT2_OMU_Btx");
051: }
052:
053: /**
054: * create a table for the bean A
055: */
056: private static void createTableA(String name)
057: throws RemoteException {
058:
059: // get connection
060: Connection conn = null;
061: try {
062: conn = dataSource.getConnection();
063: } catch (Exception e) {
064: throw new RemoteException("Cannot get Connection");
065: }
066:
067: Statement stmt;
068: try {
069: stmt = conn.createStatement();
070: stmt.execute("DROP TABLE " + name);
071: stmt.close();
072: logger.log(BasicLevel.INFO, "Table " + name + " dropped");
073: } catch (Exception e) {
074: logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"
075: + e);
076: }
077: try {
078: stmt = conn.createStatement();
079: stmt.execute("create table " + name
080: + "( c_ida varchar(30) not null primary key )");
081: stmt.close();
082: conn.close(); // release connection
083: } catch (Exception e) {
084: logger.log(BasicLevel.ERROR, "Exception in createTable : "
085: + e);
086: throw new RemoteException("Exception in createTable : " + e);
087: }
088: logger.log(BasicLevel.INFO, "Table " + name + " created");
089: }
090:
091: /**
092: * create a table for the bean B
093: */
094: private static void createTableB(String name)
095: throws RemoteException {
096:
097: // get connection
098: Connection conn = null;
099: try {
100: conn = dataSource.getConnection();
101: } catch (Exception e) {
102: throw new RemoteException("Cannot get Connection");
103: }
104:
105: Statement stmt;
106: try {
107: stmt = conn.createStatement();
108: stmt.execute("DROP TABLE " + name);
109: stmt.close();
110: logger.log(BasicLevel.INFO, "Table " + name + " dropped");
111: } catch (Exception e) {
112: logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"
113: + e);
114: }
115: try {
116: stmt = conn.createStatement();
117: stmt
118: .execute("create table "
119: + name
120: + "( c_idb varchar(30) not null primary key, cfk_ida varchar(30) )");
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: }
|