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: Tcluster.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: public class Tcluster extends Tmanager {
37:
38: /**
39: * Entry point
40: */
41: public static void init() throws NamingException, RemoteException {
42: mgrInit();
43: createTable("clusterIdentityEC");
44: }
45:
46: /**
47: * create a table for the Identity bean of cluster
48: * Notice that 1 table is shared by all beans.
49: */
50: private static void createTable(String name) throws RemoteException {
51:
52: // get connection
53: Connection conn = null;
54: try {
55: conn = dataSource.getConnection();
56: } catch (Exception e) {
57: throw new RemoteException("Cannot get Connection");
58: }
59:
60: Statement stmt;
61: try {
62: stmt = conn.createStatement();
63: stmt.execute("DROP TABLE " + name);
64: stmt.close();
65: logger.log(BasicLevel.INFO, "Table " + name + " dropped");
66: } catch (Exception e) {
67: logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"
68: + e);
69: }
70: try {
71: stmt = conn.createStatement();
72: stmt.execute("create table " + name
73: + "(c_name varchar(30) not null primary key,"
74: + "c_number integer )");
75: stmt.execute("insert into " + name
76: + " values('name1', 1000)");
77: stmt.execute("insert into " + name
78: + " values('name2', 1000)");
79: stmt.execute("insert into " + name
80: + " values('name3', 1000)");
81: stmt.execute("insert into " + name
82: + " values('name11', 5000)");
83: stmt.execute("insert into " + name
84: + " values('name12', 5000)");
85: stmt.execute("insert into " + name
86: + " values('name13', 5000)");
87:
88: stmt.close();
89: conn.close(); // release connection
90: } catch (Exception e) {
91: logger.log(BasicLevel.ERROR, "Exception in createTable : "
92: + e);
93: throw new RemoteException("Exception in createTable : " + e);
94: }
95: logger.log(BasicLevel.INFO, "Table " + name + " created");
96: }
97:
98: }
|