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:
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.ftables;
027:
028: import java.rmi.RemoteException;
029: import java.sql.Connection;
030: import java.sql.Statement;
031: import javax.naming.NamingException;
032: import javax.sql.DataSource;
033:
034: //import org.objectweb.jonas.common.Log;
035: //import org.objectweb.util.monolog.api.Logger;
036: //import org.objectweb.util.monolog.api.BasicLevel;
037:
038: public class Tfannuaire extends Tmanager {
039:
040: /**
041: * Entry point
042: */
043: public static void init() throws NamingException, RemoteException {
044: mgrInit();
045:
046: createTable("fannuairePersonneEC");
047:
048: }
049:
050: /**
051: * create a table for CMP 1.x
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:
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"+e);
072: }
073: try {
074: stmt = conn.createStatement();
075: stmt.execute("create table " + name
076: + "(c_nom varchar(30) not null primary key,"
077: + "c_numero varchar(10))");
078:
079: stmt.execute("insert into " + name
080: + " values('Philippe Coq', '1235456')");
081: stmt.execute("insert into " + name
082: + " values('Philippe Durieux', '638')");
083: stmt.execute("insert into " + name
084: + " values('Adriana Danes', '1233456')");
085: stmt.execute("insert into " + name
086: + " values('Helene Joanin', '1230456')");
087: stmt.execute("insert into " + name
088: + " values('Gerard Vandome', '1232456')");
089: stmt.execute("insert into " + name
090: + " values('Francois Exertier', '1323456')");
091: stmt.execute("insert into " + name
092: + " values('Emmanuel Facarde', '1234356')");
093: stmt.execute("insert into " + name
094: + " values('Charly Mingus', '1238456')");
095: stmt.execute("insert into " + name
096: + " values('Thelonious Monk', '1239456')");
097: stmt.execute("insert into " + name
098: + " values('Jean-Luc Richard', '1203456')");
099:
100: // to get a big table
101: for (int i = 0; i < 1000; i++) {
102: stmt.execute("insert into " + name + " values('"
103: + Integer.toString(i) + "', 'FF')");
104: }
105:
106: stmt.close();
107: conn.close(); // release connection
108: } catch (Exception e) {
109: // logger.log(BasicLevel.ERROR, "Exception in createTable : \n"+e);
110: throw new RemoteException("Exception in createTable : " + e);
111: }
112: //logger.log(BasicLevel.INFO, "Table "+name+" created");
113: }
114:
115: }
|