KickJava   Java API By Example, From Geeks To Geeks.

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


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: Tmou.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.util.monolog.api.BasicLevel;
35
36 /**
37  * Class to create tables for the 'mou' bean.
38  * @author Philippe Durieux
39  */

40 public class Tmou extends Tmanager {
41
42     /**
43      * Entry point
44      */

45     public static void init() throws NamingException JavaDoc, RemoteException JavaDoc {
46         mgrInit();
47         createTableA();
48         createTableB();
49     }
50
51     /**
52      * create a table for the bean A
53      */

54     private static void createTableA() throws RemoteException JavaDoc {
55
56         String JavaDoc name = "JT2_MOU_A1";
57
58         // get connection
59
Connection JavaDoc conn = null;
60         try {
61             conn = dataSource.getConnection();
62         } catch(Exception JavaDoc e) {
63             throw new RemoteException JavaDoc("Cannot get Connection");
64         }
65     
66         Statement JavaDoc stmt;
67         try {
68             stmt = conn.createStatement();
69             stmt.execute("DROP TABLE " + name);
70             stmt.close();
71             logger.log(BasicLevel.INFO, "Table "+name+" dropped");
72         } catch(Exception JavaDoc e) {
73             logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e);
74         }
75         try {
76             stmt = conn.createStatement();
77             stmt.execute("create table " + name +
78                          "( c_ida varchar(30) not null primary key, cfk_idb varchar(30) not null )");
79             stmt.close();
80             conn.close(); // release connection
81
} catch(Exception JavaDoc e) {
82             logger.log(BasicLevel.ERROR, "Exception in createTable : "+e);
83             throw new RemoteException JavaDoc("Exception in createTable : "+e);
84         }
85         logger.log(BasicLevel.INFO, "Table "+name+" created");
86     }
87
88     /**
89      * create a table for the bean B
90      */

91     private static void createTableB() throws RemoteException JavaDoc {
92
93         String JavaDoc name = "JT2_MOU_B1";
94
95         // get connection
96
Connection JavaDoc conn = null;
97         try {
98             conn = dataSource.getConnection();
99         } catch(Exception JavaDoc e) {
100             throw new RemoteException JavaDoc("Cannot get Connection");
101         }
102     
103         Statement JavaDoc stmt;
104         try {
105             stmt = conn.createStatement();
106             stmt.execute("DROP TABLE " + name);
107             stmt.close();
108             logger.log(BasicLevel.INFO, "Table "+name+" dropped");
109         } catch(Exception JavaDoc e) {
110             logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e);
111         }
112         try {
113             stmt = conn.createStatement();
114             stmt.execute("create table " + name +
115                          "( c_idb varchar(30) not null primary key )");
116             stmt.close();
117             conn.close(); // release connection
118
} catch(Exception JavaDoc e) {
119             logger.log(BasicLevel.ERROR, "Exception in createTable : "+e);
120             throw new RemoteException JavaDoc("Exception in createTable : "+e);
121         }
122         logger.log(BasicLevel.INFO, "Table "+name+" created");
123     }
124
125 }
126
Popular Tags