1 22 package org.jboss.test.entity.beans; 23 24 import java.sql.Connection ; 25 import java.sql.Statement ; 26 27 import javax.ejb.CreateException ; 28 import javax.ejb.EJBException ; 29 import javax.ejb.EntityBean ; 30 31 import javax.naming.InitialContext ; 32 33 import javax.sql.DataSource ; 34 35 import org.jboss.test.entity.interfaces.TestEntityValue; 36 37 66 public abstract class TestEntityBean 67 implements EntityBean 68 { 69 72 public String ejbCreate(TestEntityValue value) 73 throws CreateException 74 { 75 setEntityID(value.getEntityID()); 76 setValue1(value.getValue1()); 77 return null; 78 } 79 80 public void ejbPostCreate(TestEntityValue value) 81 throws CreateException 82 { 83 } 84 85 89 public abstract String getEntityID(); 90 public abstract void setEntityID(String entityID); 91 92 97 public abstract String getValue1(); 98 99 102 public abstract void setValue1(String value1); 103 104 107 public void ejbHomeRemoveExternal(String entityID) 108 { 109 Connection connection = null; 110 Statement statement = null; 111 try 112 { 113 DataSource dataSource = (DataSource ) new InitialContext ().lookup("java:/DefaultDS"); 114 connection = dataSource.getConnection(); 115 statement = connection.createStatement(); 116 int rows = statement.executeUpdate("delete from test_entity_testentity " 117 + "where entityID = '" + entityID + "'"); 118 if (rows != 1) 119 throw new Exception ("Wrong number of rows deleted: " + rows); 120 } 121 catch (Exception e) 122 { 123 throw new EJBException (e); 124 } 125 finally 126 { 127 try 128 { 129 if (statement != null) 130 statement.close(); 131 if (connection != null) 132 connection.close(); 133 } 134 catch (Exception e) 135 { 136 throw new EJBException (e); 137 } 138 } 139 } 140 141 144 public void ejbHomeChangeValue1(String entityID, String value1) 145 { 146 Connection connection = null; 147 Statement statement = null; 148 try 149 { 150 DataSource dataSource = (DataSource ) new InitialContext ().lookup("java:/DefaultDS"); 151 connection = dataSource.getConnection(); 152 statement = connection.createStatement(); 153 int rows = statement.executeUpdate("update test_entity_testentity set value1 = '" + value1 + 154 "' where entityID = '" + entityID + "'"); 155 if (rows != 1) 156 throw new Exception ("Wrong number of rows updated: " + rows); 157 } 158 catch (Exception e) 159 { 160 throw new EJBException (e); 161 } 162 finally 163 { 164 try 165 { 166 if (statement != null) 167 statement.close(); 168 if (connection != null) 169 connection.close(); 170 } 171 catch (Exception e) 172 { 173 throw new EJBException (e); 174 } 175 } 176 } 177 } 178 | Popular Tags |