001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.ejbconf.beans.ejb; // Generated package name
023:
024: import java.rmi.RemoteException;
025: import java.sql.Connection;
026: import java.sql.ResultSet;
027: import java.sql.Statement;
028: import javax.ejb.CreateException;
029: import javax.ejb.RemoveException;
030: import javax.ejb.SessionBean;
031: import javax.ejb.SessionContext;
032: import javax.naming.InitialContext;
033: import javax.sql.DataSource;
034:
035: /**
036: * ReadOnlyHelperSessionBean.java
037: *
038: *
039: * Created: Fri Apr 12 23:37:41 2002
040: *
041: * @author <a href="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
042: * @version
043: *
044: *
045: * @ejb:bean name="ReadOnlyHelper"
046: * jndi-name="ReadOnlyHelper"
047: * view-type="remote"
048: * type="Stateless"
049: */
050:
051: public class ReadOnlyHelperSessionBean implements SessionBean {
052: public ReadOnlyHelperSessionBean() {
053:
054: }
055:
056: /**
057: * Describe <code>ejbCreate</code> method here.
058: *
059: * @ejb:create-method
060: */
061: public void ejbCreate() {
062: }
063:
064: /**
065: * Describe <code>setUp</code> method here.
066: *
067: * @exception CreateException if an error occurs
068: * @ejb:interface-method
069: */
070: public void setUp()// throws CreateException
071: {
072: try {
073: DataSource ds = (DataSource) new InitialContext()
074: .lookup("java:/DefaultDS");
075: Connection c = ds.getConnection();
076: try {
077: Statement s = c.createStatement();
078: try {
079: s.execute("DELETE FROM READONLY");
080: s.execute("INSERT INTO READONLY VALUES (1, 1)");
081: } finally {
082: s.close();
083: } // end of try-catch
084: } finally {
085: c.close();
086: } // end of finally
087: } catch (Exception e) {
088: System.out
089: .println("could not create row for readonly bean");
090: e.printStackTrace();
091: //throw new CreateException("could not create row for readonly bean: " + e);
092: } // end of try-catch
093:
094: }
095:
096: /**
097: * Describe <code>checkValue</code> method here.
098: *
099: * @ejb:interface-method
100: */
101: public int checkValue() {
102: try {
103: DataSource ds = (DataSource) new InitialContext()
104: .lookup("java:/DefaultDS");
105: Connection c = ds.getConnection();
106: try {
107: Statement s = c.createStatement();
108: try {
109: ResultSet rs = s
110: .executeQuery("SELECT VALUE FROM READONLY WHERE ID=1");
111: try {
112: rs.next();
113: return rs.getInt(1);
114: } finally {
115: rs.close();
116: }
117: } finally {
118: s.close();
119: } // end of try-catch
120: } finally {
121: c.close();
122: } // end of finally
123: } catch (Exception e) {
124: System.out
125: .println("could not create row for readonly bean");
126: e.printStackTrace();
127: return -1;
128: //throw new CreateException("could not create row for readonly bean: " + e);
129: } // end of try-catch
130: }
131:
132: public void ejbActivate() {
133: }
134:
135: public void ejbPassivate() {
136: }
137:
138: public void ejbRemove() {
139: }
140:
141: public void setSessionContext(SessionContext ctx) {
142: }
143:
144: }// ReadOnlyHelperSessionBean
|