KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > tables > Tplong


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: Tplong.java,v 1.6 2004/03/19 11:57:15 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.tables;
27
28 import java.rmi.RemoteException JavaDoc;
29 import java.sql.Connection JavaDoc;
30 import java.sql.Statement JavaDoc;
31
32 import javax.naming.NamingException JavaDoc;
33
34 import org.objectweb.jonas.jtests.util.Env;
35 import org.objectweb.util.monolog.api.BasicLevel;
36
37 /**
38  * Class to create tables for the 'plong' bean of 'etype'.
39  * @author Helene Joanin
40  */

41 public class Tplong extends Tmanager {
42
43     /**
44      * Entry point
45      */

46     public static void init() throws NamingException JavaDoc, RemoteException JavaDoc {
47     mgrInit();
48     createTable("JT_EtypePlongEC");
49     }
50
51     /**
52      * create a table for the plong bean of etype
53      */

54     private static void createTable(String JavaDoc name) throws RemoteException JavaDoc {
55
56     // get connection
57
Connection JavaDoc conn = null;
58     try {
59         conn = dataSource.getConnection();
60     } catch(Exception JavaDoc e) {
61         throw new RemoteException JavaDoc("Cannot get Connection");
62     }
63     
64     Statement JavaDoc stmt;
65     try {
66         stmt = conn.createStatement();
67         stmt.execute("DROP TABLE "+name);
68         stmt.close();
69         logger.log(BasicLevel.INFO, "Table "+name+" dropped");
70     } catch(Exception JavaDoc e) {
71         logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e);
72     }
73     try {
74         int dbType = Env.getDatabaseType(conn);
75         String JavaDoc cTypeName;
76         switch (dbType) {
77         case Env.DB_ORACLE: cTypeName = "number"; break;
78         case Env.DB_POSGRESQL: cTypeName = "bigint"; break;
79         default: cTypeName = "bigint"; // standard jdbc type name
80
}
81         stmt = conn.createStatement();
82         stmt.execute("create table " + name +
83              "( c_pk varchar(30) not null primary key, c_f1 "+cTypeName+")");
84         stmt.execute("insert into "+name+" values('pk1', 1)");
85         stmt.execute("insert into "+name+" values('pk2', 2)");
86         stmt.execute("insert into "+name+" values('pk3', 3)");
87         stmt.execute("insert into "+name+" values('pk4', 4)");
88         stmt.execute("insert into "+name+" values('pk5', 5)");
89         stmt.execute("insert into "+name+" values('pk5bis', 5)");
90         stmt.execute("insert into "+name+" values('pktoremove', 10000)");
91
92         stmt.close();
93         conn.close(); // release connection
94
} catch(Exception JavaDoc e) {
95         logger.log(BasicLevel.ERROR, "Exception in createTable : "+e);
96         throw new RemoteException JavaDoc("Exception in createTable : "+e);
97     }
98     logger.log(BasicLevel.INFO, "Table "+name+" created");
99     }
100
101 }
102
Popular Tags