KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > ejbconf > beans > ejb > ReadOnlyHelperSessionBean


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.ejbconf.beans.ejb; // Generated package name
23

24 import java.rmi.RemoteException JavaDoc;
25 import java.sql.Connection JavaDoc;
26 import java.sql.ResultSet JavaDoc;
27 import java.sql.Statement JavaDoc;
28 import javax.ejb.CreateException JavaDoc;
29 import javax.ejb.RemoveException JavaDoc;
30 import javax.ejb.SessionBean JavaDoc;
31 import javax.ejb.SessionContext JavaDoc;
32 import javax.naming.InitialContext JavaDoc;
33 import javax.sql.DataSource JavaDoc;
34 /**
35  * ReadOnlyHelperSessionBean.java
36  *
37  *
38  * Created: Fri Apr 12 23:37:41 2002
39  *
40  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
41  * @version
42  *
43  *
44  * @ejb:bean name="ReadOnlyHelper"
45  * jndi-name="ReadOnlyHelper"
46  * view-type="remote"
47  * type="Stateless"
48  */

49
50 public class ReadOnlyHelperSessionBean implements SessionBean JavaDoc
51 {
52    public ReadOnlyHelperSessionBean ()
53    {
54       
55    }
56
57    /**
58     * Describe <code>ejbCreate</code> method here.
59     *
60     * @ejb:create-method
61     */

62    public void ejbCreate()
63    {
64    }
65
66    /**
67     * Describe <code>setUp</code> method here.
68     *
69     * @exception CreateException if an error occurs
70     * @ejb:interface-method
71     */

72    public void setUp()// throws CreateException
73
{
74       try
75       {
76          DataSource JavaDoc ds = (DataSource JavaDoc)new InitialContext JavaDoc().lookup("java:/DefaultDS");
77          Connection JavaDoc c = ds.getConnection();
78          try
79          {
80             Statement JavaDoc s = c.createStatement();
81             try
82             {
83                s.execute("DELETE FROM READONLY");
84                s.execute("INSERT INTO READONLY VALUES (1, 1)");
85             }
86             finally
87             {
88                s.close();
89             } // end of try-catch
90
}
91          finally
92          {
93             c.close();
94          } // end of finally
95
}
96       catch (Exception JavaDoc e)
97       {
98      System.out.println("could not create row for readonly bean");
99      e.printStackTrace();
100          //throw new CreateException("could not create row for readonly bean: " + e);
101
} // end of try-catch
102

103       
104    }
105
106    /**
107     * Describe <code>checkValue</code> method here.
108     *
109     * @ejb:interface-method
110     */

111    public int checkValue()
112    {
113       try
114       {
115          DataSource JavaDoc ds = (DataSource JavaDoc)new InitialContext JavaDoc().lookup("java:/DefaultDS");
116          Connection JavaDoc c = ds.getConnection();
117          try
118          {
119             Statement JavaDoc s = c.createStatement();
120             try
121             {
122                ResultSet JavaDoc rs = s.executeQuery("SELECT VALUE FROM READONLY WHERE ID=1");
123            try
124            {
125           rs.next();
126           return rs.getInt(1);
127            }
128            finally
129            {
130           rs.close();
131            }
132             }
133             finally
134             {
135                s.close();
136             } // end of try-catch
137
}
138          finally
139          {
140             c.close();
141          } // end of finally
142
}
143       catch (Exception JavaDoc e)
144       {
145      System.out.println("could not create row for readonly bean");
146      e.printStackTrace();
147      return -1;
148          //throw new CreateException("could not create row for readonly bean: " + e);
149
} // end of try-catch
150
}
151    
152    public void ejbActivate()
153    {
154    }
155    
156    public void ejbPassivate()
157    {
158    }
159    
160    public void ejbRemove()
161    {
162    }
163    
164    public void setSessionContext(SessionContext JavaDoc ctx)
165    {
166    }
167    
168 }// ReadOnlyHelperSessionBean
169
Popular Tags