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: Tlcp.java 3462 2003-10-06 15:06:00Z 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/lcp.
036: * (test about CMP 2 and relationships).
037: */
038:
039: public class Tlcp 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: try {
067: stmt = conn.createStatement();
068: stmt.execute("DROP TABLE JT2_SIMPLEPARENT");
069: logger.log(BasicLevel.INFO,
070: "Table JT2_SIMPLEPARENT dropped");
071: stmt.execute("DROP TABLE JT2_SIMPLECHILD");
072: logger
073: .log(BasicLevel.INFO,
074: "Table JT2_SIMPLECHILD dropped");
075: stmt.close();
076: } catch (Exception e) {
077: logger.log(BasicLevel.DEBUG, "Exception in drop Tables : "
078: + e);
079: }
080: try {
081: //
082: stmt = conn.createStatement();
083: String tname = "JT2_SIMPLEPARENT";
084: stmt.execute("create table " + tname
085: + "(SP_PK_ID VARCHAR(32) NOT NULL,"
086: + " SP_DESC VARCHAR(32),"
087: + " PRIMARY KEY (SP_PK_ID))");
088: stmt
089: .execute("insert into " + tname
090: + " values('p0', 'p0')");
091: stmt
092: .execute("insert into " + tname
093: + " values('p1', 'p1')");
094: stmt
095: .execute("insert into " + tname
096: + " values('p2', 'p2')");
097: logger.log(BasicLevel.INFO, "Table " + tname + " created");
098: //
099: tname = "JT2_SIMPLECHILD";
100: stmt.execute("create table " + tname
101: + "(SC_PK_ID VARCHAR(32) NOT NULL,"
102: + "SP_FK_ID VARCHAR(32)," + "SC_DESC VARCHAR(32),"
103: + "PRIMARY KEY (SC_PK_ID))");
104: stmt.execute("insert into " + tname
105: + " values('c0', NULL, 'c0')");
106: stmt.execute("insert into " + tname
107: + " values('c1_1', 'p1', 'c1_1')");
108: stmt.execute("insert into " + tname
109: + " values('c1_2', 'p1', 'c1_2')");
110: stmt.execute("insert into " + tname
111: + " values('c2_1', 'p2', 'c2_1')");
112: stmt.execute("insert into " + tname
113: + " values('c2_2', 'p2', 'c2_2')");
114: logger.log(BasicLevel.INFO, "Table " + tname + " 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: }
|