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: Tpdouble.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 'pdouble' bean of 'etype'.
039: * @author Helene Joanin
040: */
041: public class Tpdouble extends Tmanager {
042:
043: /**
044: * Entry point
045: */
046: public static void init() throws NamingException, RemoteException {
047: mgrInit();
048: createTable("JT_EtypePdoubleEC");
049: }
050:
051: /**
052: * create a table for the pdouble 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: if ((dbType == Env.DB_ORACLE)
078: || (dbType == Env.DB_POSGRESQL)) {
079: cTypeName = "double precision";
080: } else {
081: // standard jdbc type name
082: cTypeName = "double";
083: }
084: stmt = conn.createStatement();
085: stmt.execute("create table " + name
086: + "( c_pk varchar(30) not null primary key, c_f1 "
087: + cTypeName + ")");
088: stmt.execute("insert into " + name + " values('pk1', 1.0)");
089: stmt.execute("insert into " + name + " values('pk2', 2.0)");
090: stmt.execute("insert into " + name + " values('pk3', 3.0)");
091: stmt.execute("insert into " + name + " values('pk4', 4.0)");
092: stmt.execute("insert into " + name + " values('pk5', 5.0)");
093: stmt.execute("insert into " + name
094: + " values('pk5bis', 5.0)");
095: stmt.execute("insert into " + name
096: + " values('pktoremove', 10000.0)");
097:
098: stmt.close();
099: conn.close(); // release connection
100: } catch (Exception e) {
101: logger.log(BasicLevel.ERROR, "Exception in createTable : "
102: + e);
103: throw new RemoteException("Exception in createTable : " + e);
104: }
105: logger.log(BasicLevel.INFO, "Table " + name + " created");
106: }
107:
108: }
|