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