KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > ftables > DBEnvSL


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  * MERCHANF_BasicHomeInterfaceEBTABILITY 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: DBEnvSL.java,v 1.2 2004/01/21 14:51:28 legrasi Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 // DBEnvSL.java
27
// Stateless Session bean
28

29 package org.objectweb.jonas.jtests.ftables;
30
31 import java.rmi.RemoteException JavaDoc;
32 import javax.ejb.CreateException JavaDoc;
33 import javax.ejb.SessionBean JavaDoc;
34 import javax.ejb.SessionContext JavaDoc;
35 import javax.naming.Context JavaDoc;
36 import javax.naming.InitialContext JavaDoc;
37 import javax.naming.NamingException JavaDoc;
38 import javax.sql.DataSource JavaDoc;
39
40
41 /**
42  * Session bean used to init all db tables
43  */

44 public class DBEnvSL implements SessionBean JavaDoc {
45
46     SessionContext JavaDoc ejbContext;
47
48     // ------------------------------------------------------------------
49
// SessionBean implementation
50
// ------------------------------------------------------------------
51

52     public void setSessionContext(SessionContext JavaDoc ctx) {
53     ejbContext = ctx;
54     }
55
56     public void ejbRemove() {
57     }
58     
59     public void ejbCreate() throws CreateException JavaDoc {
60     }
61
62     public void ejbPassivate() {
63     }
64
65     public void ejbActivate() {
66     }
67
68     // ------------------------------------------------------------------
69
// Utility methods
70
// ------------------------------------------------------------------
71

72     /**
73      * lookup DataSource in JNDI
74      */

75     public static DataSource JavaDoc getDataSource(String JavaDoc jndiName) throws NamingException JavaDoc {
76     Context JavaDoc initialContext = new InitialContext JavaDoc();
77     DataSource JavaDoc ds = (DataSource JavaDoc)initialContext.lookup(jndiName);
78     return ds;
79     }
80
81     // ------------------------------------------------------------------
82
// DBEnv implementation
83
// ------------------------------------------------------------------
84

85     /**
86      * initTable
87      */

88     public void initTable(String JavaDoc container) throws RemoteException JavaDoc {
89         try {
90             Class.forName("org.objectweb.jonas.jtests.ftables."+"T"+container)
91                 .getMethod("init", new Class JavaDoc[0])
92                 .invoke(null, new Object JavaDoc[0]);
93         } catch(Exception JavaDoc e) {
94             System.err.println("Could not init table for " + container + ": " + e);
95             throw new RemoteException JavaDoc("Could not init table for " + container);
96         }
97     }
98 }
99
100
101
Popular Tags