001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2004 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: Ttier.java 5872 2004-12-08 13:25:41Z 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:
032: import javax.naming.NamingException;
033:
034: import org.objectweb.util.monolog.api.BasicLevel;
035:
036: /**
037: * Tables creation for the test beans/relation/tier.
038: * (test about legacy CMP 2and EJBQL).
039: */
040:
041: public class Ttier extends Tmanager {
042: private static final String T_TIER = "JT2_TIERS";
043: private static final String T_TIERMOR = "JT2_TIEMOR";
044: private static final String T_TIERPHY = "JT2_TIEPHY";
045:
046: /**
047: * Entry point
048: * @throws NamingException
049: * @throws RemoteException
050: */
051: public static void init() throws NamingException, RemoteException {
052: mgrInit();
053: createTables();
054: }
055:
056: /**
057: * create tables for the test beans/relation/tier
058: * @throws RemoteException
059: */
060: private static void createTables() throws RemoteException {
061:
062: // get connection
063: Connection conn = null;
064: try {
065: conn = dataSource.getConnection();
066: } catch (Exception e) {
067: throw new RemoteException("Cannot get Connection");
068: }
069:
070: Statement stmt;
071: try {
072: stmt = conn.createStatement();
073: stmt.execute("DROP TABLE " + T_TIER);
074: logger.log(BasicLevel.INFO, "Table " + T_TIER + " dropped");
075: stmt.execute("DROP TABLE " + T_TIERMOR);
076: logger.log(BasicLevel.INFO, "Table " + T_TIERMOR
077: + " dropped");
078: stmt.execute("DROP TABLE " + T_TIERPHY);
079: logger.log(BasicLevel.INFO, "Table " + T_TIERPHY
080: + " dropped");
081: stmt.close();
082: } catch (Exception e) {
083: logger.log(BasicLevel.DEBUG, "Exception in drop Tables : "
084: + e);
085: }
086: try {
087: // T_TIER table associated to the bean Tier
088: stmt = conn.createStatement();
089: stmt.execute("create table " + T_TIER
090: + "(NUMINTTIE INTEGER NOT NULL,"
091: + "EMAILTIE VARCHAR(40), "
092: + "PRIMARY KEY (NUMINTTIE))");
093: stmt.execute("insert into " + T_TIER
094: + " values(1, 'admin@bull.net')");
095: stmt.execute("insert into " + T_TIER
096: + " values(2, 'admin@objectweb.org')");
097: stmt.execute("insert into " + T_TIER
098: + " values(100, 'helene.joanin@bull.net')");
099: stmt.execute("insert into " + T_TIER
100: + " values(101, 'adriana.danes@bull.net')");
101: logger.log(BasicLevel.INFO, "Table " + T_TIER + " created");
102: // T_TIERMOR table associated to the bean Tiemor
103: stmt = conn.createStatement();
104: stmt.execute("create table " + T_TIERMOR
105: + "(NUMINTTIE INTEGER NOT NULL,"
106: + "RAISOCTIE VARCHAR(40), "
107: + "PRIMARY KEY (NUMINTTIE))");
108: stmt.execute("insert into " + T_TIERMOR
109: + " values(1, 'bull')");
110: stmt.execute("insert into " + T_TIERMOR
111: + " values(2, 'objectweb')");
112: logger.log(BasicLevel.INFO, "Table " + T_TIERMOR
113: + " created");
114: // T_TIERPHY table associated to the bean Tiephy
115: stmt = conn.createStatement();
116: stmt.execute("create table " + T_TIERPHY
117: + "(NUMINTTIE INTEGER NOT NULL,"
118: + "NOMUSATIE VARCHAR(40), "
119: + "PRIMARY KEY (NUMINTTIE))");
120: stmt.execute("insert into " + T_TIERPHY
121: + " values(100, 'helene joanin')");
122: stmt.execute("insert into " + T_TIERPHY
123: + " values(101, 'adriana danes')");
124: logger.log(BasicLevel.INFO, "Table " + T_TIERPHY
125: + " created");
126: stmt.close();
127: conn.close(); // release connection
128: } catch (Exception e) {
129: logger.log(BasicLevel.ERROR,
130: "Exception in create/init Table : " + e);
131: throw new RemoteException(
132: "Exception in create/init Table : " + e);
133: }
134: }
135:
136: }
|