KickJava   Java API By Example, From Geeks To Geeks.

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


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: Toser.java,v 1.7 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 'oser' bean of 'etype'.
39  * @author Helene Joanin
40  */

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

46     public static void init() throws NamingException JavaDoc, RemoteException JavaDoc {
47     mgrInit();
48     createTable("JT_EtypeOserEC");
49     }
50
51     /**
52      * create an empty table for the oser 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 = "raw(256)"; break;
78         case Env.DB_POSGRESQL: cTypeName = "bytea"; break;
79         case Env.DB_DB2: cTypeName = "varchar(128) for bit data"; break;
80         case Env.DB_MYSQL: cTypeName = "blob"; break;
81         default: cTypeName = "varbinary"; // standard jdbc type name
82
}
83         stmt = conn.createStatement();
84         stmt.execute("create table " + name +
85              "( c_pk varchar(30) not null primary key, c_f1 "+cTypeName+")");
86         stmt.close();
87         conn.close(); // release connection
88
} catch(Exception JavaDoc e) {
89         logger.log(BasicLevel.ERROR, "Exception in createTable : "+e);
90         throw new RemoteException JavaDoc("Exception in createTable : "+e);
91     }
92     logger.log(BasicLevel.INFO, "Table "+name+" created");
93     }
94
95 }
96
Popular Tags