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: * MERCHANF_BasicHomeInterfaceEBTABILITY 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: DBEnvSL.java 967 2002-12-05 16:31:57Z joaninh $
023: * --------------------------------------------------------------------------
024: */
025:
026: // DBEnvSL.java
027: // Stateless Session bean
028: package org.objectweb.jonas.jtests.tables;
029:
030: import java.rmi.RemoteException;
031: import javax.ejb.CreateException;
032: import javax.ejb.SessionBean;
033: import javax.ejb.SessionContext;
034: import javax.naming.Context;
035: import javax.naming.InitialContext;
036: import javax.naming.NamingException;
037: import javax.sql.DataSource;
038:
039: /**
040: * Session bean used to init all db tables
041: */
042: public class DBEnvSL implements SessionBean {
043:
044: SessionContext ejbContext;
045:
046: // ------------------------------------------------------------------
047: // SessionBean implementation
048: // ------------------------------------------------------------------
049:
050: public void setSessionContext(SessionContext ctx) {
051: ejbContext = ctx;
052: }
053:
054: public void ejbRemove() {
055: }
056:
057: public void ejbCreate() throws CreateException {
058: }
059:
060: public void ejbPassivate() {
061: }
062:
063: public void ejbActivate() {
064: }
065:
066: // ------------------------------------------------------------------
067: // Utility methods
068: // ------------------------------------------------------------------
069:
070: /**
071: * lookup DataSource in JNDI
072: */
073: public static DataSource getDataSource(String jndiName)
074: throws NamingException {
075: Context initialContext = new InitialContext();
076: DataSource ds = (DataSource) initialContext.lookup(jndiName);
077: return ds;
078: }
079:
080: // ------------------------------------------------------------------
081: // DBEnv implementation
082: // ------------------------------------------------------------------
083:
084: /**
085: * initTable
086: */
087: public void initTable(String container) throws RemoteException {
088: try {
089: Class.forName(
090: "org.objectweb.jonas.jtests.tables." + "T"
091: + container)
092: .getMethod("init", new Class[0]).invoke(null,
093: new Object[0]);
094: } catch (Exception e) {
095: System.err.println("Could not init table for " + container
096: + ": " + e);
097: throw new RemoteException("Could not init table for "
098: + container);
099: }
100: }
101: }
|