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: Toboolean.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 'oboolean' bean of 'etype'.
039: * @author Helene Joanin
040: */
041: public class Toboolean extends Tmanager {
042:
043: /**
044: * Entry point
045: */
046: public static void init() throws NamingException, RemoteException {
047: mgrInit();
048: createTable("JT_EtypeObooleanEC");
049: }
050:
051: /**
052: * create a table for the plong 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 = "number";
080: break;
081: case Env.DB_POSGRESQL:
082: cTypeName = "boolean";
083: break;
084: default:
085: cTypeName = "bit"; // standard jdbc type name
086: }
087: stmt = conn.createStatement();
088: stmt.execute("create table " + name
089: + "( c_pk varchar(30) not null primary key, c_f1 "
090: + cTypeName + ")");
091: if ((dbType == Env.DB_ORACLE) || (dbType == Env.DB_MYSQL)) {
092: stmt.execute("insert into " + name
093: + " values('pk1', 0)");
094: stmt.execute("insert into " + name
095: + " values('pk2', 1)");
096: stmt.execute("insert into " + name
097: + " values('pk3', 0)");
098: stmt.execute("insert into " + name
099: + " values('pk4', 1)");
100: stmt.execute("insert into " + name
101: + " values('pk5', 0)");
102: stmt.execute("insert into " + name
103: + " values('pktoremove', 1)");
104: stmt.execute("insert into " + name
105: + " values('pknull', NULL)");
106: stmt.execute("insert into " + name
107: + " values('pkchangenull', 1)");
108: } else {
109: stmt.execute("insert into " + name
110: + " values('pk1', 'false')");
111: stmt.execute("insert into " + name
112: + " values('pk2', 'true')");
113: stmt.execute("insert into " + name
114: + " values('pk3', 'false')");
115: stmt.execute("insert into " + name
116: + " values('pk4', 'true')");
117: stmt.execute("insert into " + name
118: + " values('pk5', 'false')");
119: stmt.execute("insert into " + name
120: + " values('pktoremove', 'true')");
121: stmt.execute("insert into " + name
122: + " values('pknull', NULL)");
123: stmt.execute("insert into " + name
124: + " values('pkchangenull', 'true')");
125: }
126: stmt.close();
127: conn.close(); // release connection
128: } catch (Exception e) {
129: logger.log(BasicLevel.ERROR, "Exception in createTable : "
130: + e);
131: throw new RemoteException("Exception in createTable : " + e);
132: }
133: logger.log(BasicLevel.INFO, "Table " + name + " created");
134: }
135:
136: }
|