KickJava   Java API By Example, From Geeks To Geeks.

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


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: Tlcp.java,v 1.1 2003/10/06 15:06:00 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 import javax.naming.NamingException JavaDoc;
32 import org.objectweb.util.monolog.api.BasicLevel;
33
34 /**
35  * Tables creation for the test beans/relation/lcp.
36  * (test about CMP 2 and relationships).
37  */

38
39 public class Tlcp extends Tmanager {
40
41     /**
42      * Entry point
43      * @throws NamingException
44      * @throws RemoteException
45      */

46     public static void init() throws NamingException JavaDoc, RemoteException JavaDoc {
47         mgrInit();
48         createTables();
49     }
50
51     /**
52      * create tables for the test beans/relation/rcycle (CMP2 legacy)
53      * @throws RemoteException
54      */

55     private static void createTables() 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 JT2_SIMPLEPARENT");
69             logger.log(BasicLevel.INFO, "Table JT2_SIMPLEPARENT dropped");
70             stmt.execute("DROP TABLE JT2_SIMPLECHILD");
71             logger.log(BasicLevel.INFO, "Table JT2_SIMPLECHILD dropped");
72             stmt.close();
73         } catch (Exception JavaDoc e) {
74             logger.log(BasicLevel.DEBUG, "Exception in drop Tables : " + e);
75         }
76         try {
77             //
78
stmt = conn.createStatement();
79             String JavaDoc tname = "JT2_SIMPLEPARENT";
80             stmt.execute("create table " + tname
81                          + "(SP_PK_ID VARCHAR(32) NOT NULL,"
82                          + " SP_DESC VARCHAR(32),"
83                          + " PRIMARY KEY (SP_PK_ID))");
84             stmt.execute("insert into " + tname + " values('p0', 'p0')");
85             stmt.execute("insert into " + tname + " values('p1', 'p1')");
86             stmt.execute("insert into " + tname + " values('p2', 'p2')");
87             logger.log(BasicLevel.INFO, "Table " + tname + " created");
88             //
89
tname = "JT2_SIMPLECHILD";
90             stmt.execute("create table " + tname
91                          + "(SC_PK_ID VARCHAR(32) NOT NULL,"
92                          + "SP_FK_ID VARCHAR(32),"
93                          + "SC_DESC VARCHAR(32),"
94                          + "PRIMARY KEY (SC_PK_ID))");
95             stmt.execute("insert into " + tname + " values('c0', NULL, 'c0')");
96             stmt.execute("insert into " + tname + " values('c1_1', 'p1', 'c1_1')");
97             stmt.execute("insert into " + tname + " values('c1_2', 'p1', 'c1_2')");
98             stmt.execute("insert into " + tname + " values('c2_1', 'p2', 'c2_1')");
99             stmt.execute("insert into " + tname + " values('c2_2', 'p2', 'c2_2')");
100             logger.log(BasicLevel.INFO, "Table " + tname + " created");
101             stmt.close();
102             conn.close(); // release connection
103
} catch (Exception JavaDoc e) {
104             logger.log(BasicLevel.ERROR, "Exception in create Table : " + e);
105             throw new RemoteException JavaDoc("Exception in create Table : " + e);
106         }
107     }
108
109 }
110
111
112
Popular Tags