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: Tplong.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 'plong' bean of 'etype'.
039: * @author Helene Joanin
040: */
041: public class Tplong extends Tmanager {
042:
043: /**
044: * Entry point
045: */
046: public static void init() throws NamingException, RemoteException {
047: mgrInit();
048: createTable("JT_EtypePlongEC");
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 = "bigint";
083: break;
084: default:
085: cTypeName = "bigint"; // 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: stmt.execute("insert into " + name + " values('pk1', 1)");
092: stmt.execute("insert into " + name + " values('pk2', 2)");
093: stmt.execute("insert into " + name + " values('pk3', 3)");
094: stmt.execute("insert into " + name + " values('pk4', 4)");
095: stmt.execute("insert into " + name + " values('pk5', 5)");
096: stmt
097: .execute("insert into " + name
098: + " values('pk5bis', 5)");
099: stmt.execute("insert into " + name
100: + " values('pktoremove', 10000)");
101:
102: stmt.close();
103: conn.close(); // release connection
104: } catch (Exception e) {
105: logger.log(BasicLevel.ERROR, "Exception in createTable : "
106: + e);
107: throw new RemoteException("Exception in createTable : " + e);
108: }
109: logger.log(BasicLevel.INFO, "Table " + name + " created");
110: }
111:
112: }
|