01: /*
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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: Tpfloat.java 4406 2004-03-19 11:57:20Z benoitf $
23: * --------------------------------------------------------------------------
24: */
25:
26: package org.objectweb.jonas.jtests.tables;
27:
28: import java.rmi.RemoteException;
29: import java.sql.Connection;
30: import java.sql.Statement;
31:
32: import javax.naming.NamingException;
33:
34: import org.objectweb.util.monolog.api.BasicLevel;
35:
36: /**
37: * Class to create tables for the 'pfloat' bean of 'etype'.
38: * @author Helene Joanin
39: */
40: public class Tpfloat extends Tmanager {
41:
42: /**
43: * Entry point
44: */
45: public static void init() throws NamingException, RemoteException {
46: mgrInit();
47: createTable("JT_EtypePfloatEC");
48: }
49:
50: /**
51: * create a table for the pfloat bean of etype
52: */
53: private static void createTable(String name) throws RemoteException {
54:
55: // get connection
56: Connection conn = null;
57: try {
58: conn = dataSource.getConnection();
59: } catch (Exception e) {
60: throw new RemoteException("Cannot get Connection");
61: }
62:
63: Statement stmt;
64: try {
65: stmt = conn.createStatement();
66: stmt.execute("DROP TABLE " + name);
67: stmt.close();
68: logger.log(BasicLevel.INFO, "Table " + name + " dropped");
69: } catch (Exception e) {
70: logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"
71: + e);
72: }
73: try {
74: String cTypeName = "real"; // standard jdbc type name
75: stmt = conn.createStatement();
76: stmt.execute("create table " + name
77: + "( c_pk varchar(30) not null primary key, c_f1 "
78: + cTypeName + ")");
79: stmt.execute("insert into " + name + " values('pk1', 1.0)");
80: stmt.execute("insert into " + name + " values('pk2', 2.0)");
81: stmt.execute("insert into " + name + " values('pk3', 3.0)");
82: stmt.execute("insert into " + name + " values('pk4', 4.0)");
83: stmt.execute("insert into " + name + " values('pk5', 5.0)");
84: stmt.execute("insert into " + name
85: + " values('pk5bis', 5.0)");
86: stmt.execute("insert into " + name
87: + " values('pktoremove', 10000.0)");
88:
89: stmt.close();
90: conn.close(); // release connection
91: } catch (Exception e) {
92: logger.log(BasicLevel.ERROR, "Exception in createTable : "
93: + e);
94: throw new RemoteException("Exception in createTable : " + e);
95: }
96: logger.log(BasicLevel.INFO, "Table " + name + " created");
97: }
98:
99: }
|