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