KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2004 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: Ttier.java,v 1.1 2004/12/08 13:25:41 joaninh 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  * Tables creation for the test beans/relation/tier.
38  * (test about legacy CMP 2and EJBQL).
39  */

40
41 public class Ttier extends Tmanager {
42     private static final String JavaDoc T_TIER = "JT2_TIERS";
43     private static final String JavaDoc T_TIERMOR = "JT2_TIEMOR";
44     private static final String JavaDoc T_TIERPHY = "JT2_TIEPHY";
45
46     /**
47      * Entry point
48      * @throws NamingException
49      * @throws RemoteException
50      */

51     public static void init() throws NamingException JavaDoc, RemoteException JavaDoc {
52         mgrInit();
53         createTables();
54     }
55
56     /**
57      * create tables for the test beans/relation/tier
58      * @throws RemoteException
59      */

60     private static void createTables() throws RemoteException JavaDoc {
61
62         // get connection
63
Connection JavaDoc conn = null;
64         try {
65             conn = dataSource.getConnection();
66         } catch (Exception JavaDoc e) {
67             throw new RemoteException JavaDoc("Cannot get Connection");
68         }
69
70         Statement JavaDoc stmt;
71         try {
72             stmt = conn.createStatement();
73             stmt.execute("DROP TABLE " + T_TIER);
74             logger.log(BasicLevel.INFO, "Table " + T_TIER + " dropped");
75             stmt.execute("DROP TABLE " + T_TIERMOR);
76             logger.log(BasicLevel.INFO, "Table " + T_TIERMOR + " dropped");
77             stmt.execute("DROP TABLE " + T_TIERPHY);
78             logger.log(BasicLevel.INFO, "Table " + T_TIERPHY + " dropped");
79             stmt.close();
80         } catch (Exception JavaDoc e) {
81             logger.log(BasicLevel.DEBUG, "Exception in drop Tables : " + e);
82         }
83         try {
84             // T_TIER table associated to the bean Tier
85
stmt = conn.createStatement();
86             stmt.execute("create table " + T_TIER
87                          + "(NUMINTTIE INTEGER NOT NULL,"
88                          + "EMAILTIE VARCHAR(40), "
89                          + "PRIMARY KEY (NUMINTTIE))");
90             stmt.execute("insert into " + T_TIER + " values(1, 'admin@bull.net')");
91             stmt.execute("insert into " + T_TIER + " values(2, 'admin@objectweb.org')");
92             stmt.execute("insert into " + T_TIER + " values(100, 'helene.joanin@bull.net')");
93             stmt.execute("insert into " + T_TIER + " values(101, 'adriana.danes@bull.net')");
94             logger.log(BasicLevel.INFO, "Table " + T_TIER + " created");
95             // T_TIERMOR table associated to the bean Tiemor
96
stmt = conn.createStatement();
97             stmt.execute("create table " + T_TIERMOR
98                          + "(NUMINTTIE INTEGER NOT NULL,"
99                          + "RAISOCTIE VARCHAR(40), "
100                          + "PRIMARY KEY (NUMINTTIE))");
101             stmt.execute("insert into " + T_TIERMOR + " values(1, 'bull')");
102             stmt.execute("insert into " + T_TIERMOR + " values(2, 'objectweb')");
103             logger.log(BasicLevel.INFO, "Table " + T_TIERMOR + " created");
104             // T_TIERPHY table associated to the bean Tiephy
105
stmt = conn.createStatement();
106             stmt.execute("create table " + T_TIERPHY
107                          + "(NUMINTTIE INTEGER NOT NULL,"
108                          + "NOMUSATIE VARCHAR(40), "
109                          + "PRIMARY KEY (NUMINTTIE))");
110             stmt.execute("insert into " + T_TIERPHY + " values(100, 'helene joanin')");
111             stmt.execute("insert into " + T_TIERPHY + " values(101, 'adriana danes')");
112             logger.log(BasicLevel.INFO, "Table " + T_TIERPHY + " created");
113             stmt.close();
114             conn.close(); // release connection
115
} catch (Exception JavaDoc e) {
116             logger.log(BasicLevel.ERROR, "Exception in create/init Table : " + e);
117             throw new RemoteException JavaDoc("Exception in create/init Table : " + e);
118         }
119     }
120
121 }
122
123
124
Popular Tags