001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: Trcycle.java 4305 2004-03-08 13:57:43Z joaninh $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.tables;
027:
028: import java.rmi.RemoteException;
029: import java.sql.Connection;
030: import java.sql.Statement;
031: import javax.naming.NamingException;
032: import org.objectweb.util.monolog.api.BasicLevel;
033:
034: /**
035: * Tables creation for the test beans/relation/rcycle.
036: * (test about legacy CMP 2, cyles in relations, and relation between the same bean).
037: */
038:
039: public class Trcycle extends Tmanager {
040:
041: /**
042: * Entry point
043: * @throws NamingException
044: * @throws RemoteException
045: */
046: public static void init() throws NamingException, RemoteException {
047: mgrInit();
048: createTables();
049: }
050:
051: /**
052: * create tables for the test beans/relation/rcycle (CMP2 legacy)
053: * @throws RemoteException
054: */
055: private static void createTables() throws RemoteException {
056:
057: // get connection
058: Connection conn = null;
059: try {
060: conn = dataSource.getConnection();
061: } catch (Exception e) {
062: throw new RemoteException("Cannot get Connection");
063: }
064:
065: Statement stmt;
066: // jt2_rcycle_person table associated to the bean Person
067: String personTname = "JT2_RCYCLE_PERSON";
068: // jt2_rcycle_j_par_child join table associated to the relation r-parents-children
069: String jointTname = "JT2_RCYCLE_J_PAR_CHILD";
070: try {
071: stmt = conn.createStatement();
072: stmt.execute("DROP TABLE " + personTname);
073: logger.log(BasicLevel.INFO, "Table " + personTname
074: + " dropped");
075: stmt.execute("DROP TABLE " + jointTname);
076: logger.log(BasicLevel.INFO, "Table " + jointTname
077: + " dropped");
078: stmt.close();
079: } catch (Exception e) {
080: logger.log(BasicLevel.DEBUG, "Exception in drop Tables : "
081: + e);
082: }
083: try {
084: // jt2_rcycle_person table associated to the bean Person
085: stmt = conn.createStatement();
086: stmt
087: .execute("create table " + personTname
088: + "(c_id integer not null primary key,"
089: + " c_name varchar(40),"
090: + " c_sex integer,"
091: + " cfk_spouse integer,"
092: + " cfk_guardian integer)");
093: stmt.execute("insert into " + personTname
094: + " values(1, 'Laurent Eric', 1, 2, null)");
095: stmt
096: .execute("insert into "
097: + personTname
098: + " values(2, 'Joanin-Laurent Helene', 2, 1, null)");
099: stmt.execute("insert into " + personTname
100: + " values(3, 'Laurent Guilhem', 1, null, 1)");
101: stmt.execute("insert into " + personTname
102: + " values(4, 'Laurent Malva', 2, null, 1)");
103: logger.log(BasicLevel.INFO, "Table " + personTname
104: + " created");
105: // jt2_rcycle_j_par_child join table associated to the relation r-parents-children
106: stmt.execute("create table " + jointTname
107: + "(cfk_parents integer,"
108: + " cfk_children integer)");
109: stmt.execute("insert into " + jointTname + " values(1, 3)");
110: stmt.execute("insert into " + jointTname + " values(1, 4)");
111: stmt.execute("insert into " + jointTname + " values(2, 3)");
112: stmt.execute("insert into " + jointTname + " values(2, 4)");
113: logger.log(BasicLevel.INFO, "Table " + jointTname
114: + " created");
115: stmt.close();
116: conn.close(); // release connection
117: } catch (Exception e) {
118: logger.log(BasicLevel.ERROR, "Exception in create Table : "
119: + e);
120: throw new RemoteException("Exception in create Table : "
121: + e);
122: }
123: }
124:
125: }
|