KickJava   Java API By Example, From Geeks To Geeks.

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


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: Todouble.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 /**
39  * Class to create tables for the 'odouble' bean of 'etype'.
40  * @author Helene Joanin
41  */

42 public class Todouble extends Tmanager {
43
44     /**
45      * Entry point
46      */

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

55     private static void createTable(String JavaDoc name) throws RemoteException JavaDoc {
56
57     // get connection
58
Connection JavaDoc conn = null;
59     try {
60         conn = dataSource.getConnection();
61     } catch(Exception JavaDoc e) {
62         throw new RemoteException JavaDoc("Cannot get Connection");
63     }
64     
65     Statement JavaDoc stmt;
66     try {
67         stmt = conn.createStatement();
68         stmt.execute("DROP TABLE "+name);
69         stmt.close();
70         logger.log(BasicLevel.INFO, "Table "+name+" dropped");
71     } catch(Exception JavaDoc e) {
72         logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e);
73     }
74     try {
75         int dbType = Env.getDatabaseType(conn);
76         String JavaDoc cTypeName;
77         if ((dbType==Env.DB_ORACLE) || (dbType==Env.DB_POSGRESQL)) {
78         cTypeName = "double precision";
79         } else {
80         // standard jdbc type name
81
cTypeName = "double";
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.execute("insert into "+name+" values('pk1', 1.0)");
87         stmt.execute("insert into "+name+" values('pk2', 2.0)");
88         stmt.execute("insert into "+name+" values('pk3', 3.0)");
89         stmt.execute("insert into "+name+" values('pk4', 4.0)");
90         stmt.execute("insert into "+name+" values('pk5', 5.0)");
91         stmt.execute("insert into "+name+" values('pk5bis', 5.0)");
92         stmt.execute("insert into "+name+" values('pktoremove', 10000.0)");
93         stmt.execute("insert into "+name+" values('pknull', NULL)");
94         stmt.execute("insert into "+name+" values('pkchangenull', 1.0)");
95
96         stmt.close();
97         conn.close(); // release connection
98
} catch(Exception JavaDoc e) {
99         logger.log(BasicLevel.ERROR, "Exception in create/init Table : "+e);
100         throw new RemoteException JavaDoc("Exception in create/init Table : "+e);
101     }
102     logger.log(BasicLevel.INFO, "Table "+name+" created");
103     }
104
105 }
106
Popular Tags