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: Toser.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.jonas.jtests.util.Env;
035: import org.objectweb.util.monolog.api.BasicLevel;
036:
037: /**
038: * Class to create tables for the 'oser' bean of 'etype'.
039: * @author Helene Joanin
040: */
041: public class Toser extends Tmanager {
042:
043: /**
044: * Entry point
045: */
046: public static void init() throws NamingException, RemoteException {
047: mgrInit();
048: createTable("JT_EtypeOserEC");
049: }
050:
051: /**
052: * create an empty table for the oser bean of etype
053: */
054: private static void createTable(String name) 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: int dbType = Env.getDatabaseType(conn);
076: String cTypeName;
077: switch (dbType) {
078: case Env.DB_ORACLE:
079: cTypeName = "raw(256)";
080: break;
081: case Env.DB_POSGRESQL:
082: cTypeName = "bytea";
083: break;
084: case Env.DB_DB2:
085: cTypeName = "varchar(128) for bit data";
086: break;
087: case Env.DB_MYSQL:
088: cTypeName = "blob";
089: break;
090: default:
091: cTypeName = "varbinary"; // standard jdbc type name
092: }
093: stmt = conn.createStatement();
094: stmt.execute("create table " + name
095: + "( c_pk varchar(30) not null primary key, c_f1 "
096: + cTypeName + ")");
097: stmt.close();
098: conn.close(); // release connection
099: } catch (Exception e) {
100: logger.log(BasicLevel.ERROR, "Exception in createTable : "
101: + e);
102: throw new RemoteException("Exception in createTable : " + e);
103: }
104: logger.log(BasicLevel.INFO, "Table " + name + " created");
105: }
106:
107: }
|