1 22 package org.jboss.test.ejbconf.beans.ejb; 24 import java.rmi.RemoteException ; 25 import java.sql.Connection ; 26 import java.sql.ResultSet ; 27 import java.sql.Statement ; 28 import javax.ejb.CreateException ; 29 import javax.ejb.RemoveException ; 30 import javax.ejb.SessionBean ; 31 import javax.ejb.SessionContext ; 32 import javax.naming.InitialContext ; 33 import javax.sql.DataSource ; 34 49 50 public class ReadOnlyHelperSessionBean implements SessionBean 51 { 52 public ReadOnlyHelperSessionBean () 53 { 54 55 } 56 57 62 public void ejbCreate() 63 { 64 } 65 66 72 public void setUp() { 74 try 75 { 76 DataSource ds = (DataSource )new InitialContext ().lookup("java:/DefaultDS"); 77 Connection c = ds.getConnection(); 78 try 79 { 80 Statement 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 } } 91 finally 92 { 93 c.close(); 94 } } 96 catch (Exception e) 97 { 98 System.out.println("could not create row for readonly bean"); 99 e.printStackTrace(); 100 } 103 104 } 105 106 111 public int checkValue() 112 { 113 try 114 { 115 DataSource ds = (DataSource )new InitialContext ().lookup("java:/DefaultDS"); 116 Connection c = ds.getConnection(); 117 try 118 { 119 Statement s = c.createStatement(); 120 try 121 { 122 ResultSet 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 } } 138 finally 139 { 140 c.close(); 141 } } 143 catch (Exception e) 144 { 145 System.out.println("could not create row for readonly bean"); 146 e.printStackTrace(); 147 return -1; 148 } } 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 ctx) 165 { 166 } 167 168 } | Popular Tags |