KickJava   Java API By Example, From Geeks To Geeks.

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


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: Trcycle.java,v 1.5 2004/03/08 13:57:43 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/rcycle.
36  * (test about legacy CMP 2, cyles in relations, and relation between the same bean).
37  */

38
39 public class Trcycle 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         // jt2_rcycle_person table associated to the bean Person
67
String JavaDoc personTname = "JT2_RCYCLE_PERSON";
68         // jt2_rcycle_j_par_child join table associated to the relation r-parents-children
69
String JavaDoc jointTname = "JT2_RCYCLE_J_PAR_CHILD";
70         try {
71             stmt = conn.createStatement();
72             stmt.execute("DROP TABLE " + personTname);
73             logger.log(BasicLevel.INFO, "Table " + personTname + " dropped");
74             stmt.execute("DROP TABLE " + jointTname);
75             logger.log(BasicLevel.INFO, "Table " + jointTname + " dropped");
76             stmt.close();
77         } catch (Exception JavaDoc e) {
78             logger.log(BasicLevel.DEBUG, "Exception in drop Tables : " + e);
79         }
80         try {
81             // jt2_rcycle_person table associated to the bean Person
82
stmt = conn.createStatement();
83             stmt.execute("create table " + personTname
84                          + "(c_id integer not null primary key,"
85                          + " c_name varchar(40),"
86                          + " c_sex integer,"
87                          + " cfk_spouse integer,"
88                          + " cfk_guardian integer)");
89             stmt.execute("insert into " + personTname + " values(1, 'Laurent Eric', 1, 2, null)");
90             stmt.execute("insert into " + personTname + " values(2, 'Joanin-Laurent Helene', 2, 1, null)");
91             stmt.execute("insert into " + personTname + " values(3, 'Laurent Guilhem', 1, null, 1)");
92             stmt.execute("insert into " + personTname + " values(4, 'Laurent Malva', 2, null, 1)");
93             logger.log(BasicLevel.INFO, "Table " + personTname + " created");
94             // jt2_rcycle_j_par_child join table associated to the relation r-parents-children
95
stmt.execute("create table " + jointTname
96                          + "(cfk_parents integer,"
97                          + " cfk_children integer)");
98             stmt.execute("insert into " + jointTname + " values(1, 3)");
99             stmt.execute("insert into " + jointTname + " values(1, 4)");
100             stmt.execute("insert into " + jointTname + " values(2, 3)");
101             stmt.execute("insert into " + jointTname + " values(2, 4)");
102             logger.log(BasicLevel.INFO, "Table " + jointTname + " created");
103             stmt.close();
104             conn.close(); // release connection
105
} catch (Exception JavaDoc e) {
106             logger.log(BasicLevel.ERROR, "Exception in create Table : " + e);
107             throw new RemoteException JavaDoc("Exception in create Table : " + e);
108         }
109     }
110
111 }
112
113
114
Popular Tags