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: Tobigd.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.util.monolog.api.BasicLevel;
035:
036: /**
037: * Class to create tables for the 'obigd' bean of 'etype'.
038: * @author Helene Joanin
039: */
040: public class Tobigd extends Tmanager {
041: /**
042: * Entry point
043: */
044: public static void init() throws NamingException, RemoteException {
045: mgrInit();
046: createTable("JT_EtypeObigdecimalEC");
047: }
048:
049: /**
050: * create a table for the plong bean of etype
051: */
052: private static void createTable(String name) throws RemoteException {
053:
054: // get connection
055: Connection conn = null;
056: try {
057: conn = dataSource.getConnection();
058: } catch (Exception e) {
059: throw new RemoteException("Cannot get Connection");
060: }
061:
062: Statement stmt;
063: try {
064: stmt = conn.createStatement();
065: stmt.execute("DROP TABLE " + name);
066: stmt.close();
067: logger.log(BasicLevel.INFO, "Table " + name + " dropped");
068: } catch (Exception e) {
069: logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"
070: + e);
071: }
072: try {
073: stmt = conn.createStatement();
074: stmt
075: .execute("create table "
076: + name
077: + "( c_pk varchar(30) not null primary key, c_f1 numeric )");
078: stmt.execute("insert into " + name + " values('pk1', 1)");
079: stmt.execute("insert into " + name + " values('pk2', 2)");
080: stmt.execute("insert into " + name + " values('pk3', 3)");
081: stmt.execute("insert into " + name + " values('pk4', 4)");
082: stmt.execute("insert into " + name + " values('pk5', 5)");
083: stmt
084: .execute("insert into " + name
085: + " values('pk5bis', 5)");
086: stmt.execute("insert into " + name
087: + " values('pktoremove', 10000)");
088: stmt.execute("insert into " + name
089: + " values('pknull', NULL)");
090: stmt.execute("insert into " + name
091: + " values('pkchangenull', 10000)");
092:
093: stmt.close();
094: conn.close(); // release connection
095: } catch (Exception e) {
096: logger.log(BasicLevel.ERROR, "Exception in createTable : "
097: + e);
098: throw new RemoteException("Exception in createTable : " + e);
099: }
100: logger.log(BasicLevel.INFO, "Table " + name + " created");
101: }
102:
103: }
|