package org.jboss.test.entity.beans;
import java.sql.Connection;
import java.sql.Statement;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import org.jboss.test.entity.interfaces.TestEntityValue;
public abstract class TestEntityBean
implements EntityBean
{
public String ejbCreate(TestEntityValue value)
throws CreateException
{
setEntityID(value.getEntityID());
setValue1(value.getValue1());
return null;
}
public void ejbPostCreate(TestEntityValue value)
throws CreateException
{
}
public abstract String getEntityID();
public abstract void setEntityID(String entityID);
public abstract String getValue1();
public abstract void setValue1(String value1);
public void ejbHomeRemoveExternal(String entityID)
{
Connection connection = null;
Statement statement = null;
try
{
DataSource dataSource = (DataSource) new InitialContext().lookup("java:/DefaultDS");
connection = dataSource.getConnection();
statement = connection.createStatement();
int rows = statement.executeUpdate("delete from test_entity_testentity "
+ "where entityID = '" + entityID + "'");
if (rows != 1)
throw new Exception("Wrong number of rows deleted: " + rows);
}
catch (Exception e)
{
throw new EJBException(e);
}
finally
{
try
{
if (statement != null)
statement.close();
if (connection != null)
connection.close();
}
catch (Exception e)
{
throw new EJBException(e);
}
}
}
public void ejbHomeChangeValue1(String entityID, String value1)
{
Connection connection = null;
Statement statement = null;
try
{
DataSource dataSource = (DataSource) new InitialContext().lookup("java:/DefaultDS");
connection = dataSource.getConnection();
statement = connection.createStatement();
int rows = statement.executeUpdate("update test_entity_testentity set value1 = '" + value1 +
"' where entityID = '" + entityID + "'");
if (rows != 1)
throw new Exception("Wrong number of rows updated: " + rows);
}
catch (Exception e)
{
throw new EJBException(e);
}
finally
{
try
{
if (statement != null)
statement.close();
if (connection != null)
connection.close();
}
catch (Exception e)
{
throw new EJBException(e);
}
}
}
}