///////////////////////////////////////////////////////////////////////////////
// File : EJB_DOCUMENTBean.java
// Creation : 2002.04.29 (generated by ejen 1.0.0)
package org.ejb.test;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.ObjectNotFoundException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Vector;
import java.util.Collection;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* Entity bean class that maps the DOCUMENT table.
* <br><i>Ejen EJB 1.1 (BMP) demonstration</i>
* @version 1.0
* @author (unknown)
* @see org.ejb.test.DOCUMENTValues
* @see org.ejb.test.EJB_DOCUMENTHome
* @see org.ejb.test.EJB_DOCUMENT
* @see org.ejb.test.EJB_DOCUMENT_PK
* @see org.ejb.test.EJB_TABLEAbstractBean
*/
public class EJB_DOCUMENTBean extends EJB_TABLEAbstractBean {
/** INSERT statement used in ejbCreate method (no sequence field, if any) */
protected static final String SQL_INSERT = "INSERT INTO DOCUMENT (ID,ADDRESSID,TOTAL) VALUES (?,?,?)";
/** SELECT statement used in ejbLoad method */
protected static final String SQL_SELECT = "SELECT ADDRESSID,TOTAL FROM DOCUMENT WHERE ID=?";
/** UPDATE statement used in ejbStore method */
protected static final String SQL_UPDATE = "UPDATE DOCUMENT SET ADDRESSID=?,TOTAL=? WHERE ID=?";
/** DELETE statement used in ejbRemove method */
protected static final String SQL_DELETE = "DELETE FROM DOCUMENT WHERE ID=?";
/** SELECT statement used in ejbFindByPrimaryKey method */
protected static final String SQL_SELECT_FIND_BY_PRIMARY_KEY = "SELECT ID FROM DOCUMENT WHERE ID=?";
/** SELECT statement used in ejbFindAll method */
protected static final String SQL_SELECT_FIND_ALL = "SELECT ID FROM DOCUMENT";
/** Full JNDI name of the DataSource */
protected static final String DATA_SOURCE_JNDI_NAME = "java:/DefaultDS";
/** Values object variable */
protected DOCUMENTValues _values = null;
/**
* Default constructor (empty).
*/
public EJB_DOCUMENTBean() {}
/**
* Returns a values object that contains all DOCUMENT fields
* (except primary key fields).
* @return object values that contains all DOCUMENT fields
* (except primary key fields).
*/
public DOCUMENTValues getAll() {
return _values;
}
/**
* Sets a values object that contains all DOCUMENT
* fields for update (except primary key fields).
* @param DOCUMENTValues values object that contains all
* DOCUMENT fields for update (except primary key fields).
*/
public void setAll(DOCUMENTValues values) {
_values = values;
_dirty = true;
}
/**
* Creates a new DOCUMENT row.
* @param pk primary key of the new row to be created.
* @param values a values object that contains values for the
* DOCUMENT row to be created.
* @return remote interface of the created entity bean (that maps the new row).
* @throws javax.ejb.CreateException row count for INSERT != 1.
* @throws javax.ejb.EJBException SQL error.
*/
public EJB_DOCUMENT_PK ejbCreate(EJB_DOCUMENT_PK pk, DOCUMENTValues values) throws CreateException {
_values = values;
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = _dataSource.getConnection();
pstmt = conn.prepareStatement(SQL_INSERT);
pstmt.setInt(1, pk.getId());
pstmt.setInt(2, _values.getAddressid());
pstmt.setBigDecimal(3, _values.getTotal());
if (pstmt.executeUpdate() != 1)
throw new CreateException("Failed to create new DOCUMENT row");
return pk;
} catch(SQLException e) {
throw new EJBException(e);
} finally {
try { if (pstmt != null) pstmt.close(); } catch (SQLException e) { e.printStackTrace(); }
try { if (conn != null) conn.close(); } catch (SQLException e) { e.printStackTrace(); }
}
}
/**
* Post-creation method (empty).
* @param pk primary key of the new row to be created.
* @param values a values object that contains values for the newly
* created DOCUMENT row.
*/
public void ejbPostCreate(EJB_DOCUMENT_PK pk, DOCUMENTValues values) {}
/**
* Loads a DOCUMENT row.
* @throws javax.ejb.EJBException SQL error or empty ResultSet.
*/
public void ejbLoad() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
EJB_DOCUMENT_PK pk = (EJB_DOCUMENT_PK)(_entityContext.getPrimaryKey());
try {
conn = _dataSource.getConnection();
pstmt = conn.prepareStatement(SQL_SELECT);
pstmt.setInt(1, pk.getId());
rs = pstmt.executeQuery();
if (!rs.next())
throw new EJBException("Failed to load DOCUMENT row with pk:" + pk);
if (_values == null)
_values = new DOCUMENTValues(rs.getInt(1), rs.getBigDecimal(2));
else {
_values.setAddressid(rs.getInt(1));
_values.setTotal(rs.getBigDecimal(2));
}
} catch(SQLException e) {
throw new EJBException(e);
} finally {
try { if (rs != null) rs.close(); } catch (SQLException e) { e.printStackTrace(); }
try { if (pstmt != null) pstmt.close(); } catch (SQLException e) { e.printStackTrace(); }
try { if (conn != null) conn.close(); } catch (SQLException e) { e.printStackTrace(); }
}
}
/**
* Updates a DOCUMENT row.
* @throws javax.ejb.EJBException SQL error or row count for UPDATE != 1.
*/
public void ejbStore() {
if (!_dirty)
return;
Connection conn = null;
PreparedStatement pstmt = null;
EJB_DOCUMENT_PK pk = (EJB_DOCUMENT_PK)(_entityContext.getPrimaryKey());
try {
conn = _dataSource.getConnection();
pstmt = conn.prepareStatement(SQL_UPDATE);
pstmt.setInt(1, _values.getAddressid());
pstmt.setBigDecimal(2, _values.getTotal());
pstmt.setInt(3, pk.getId());
if (pstmt.executeUpdate() != 1)
throw new EJBException("Failed to update DOCUMENT row with pk:" + pk);
_dirty = false;
} catch(SQLException e) {
throw new EJBException(e);
} finally {
try { if (pstmt != null) pstmt.close(); } catch (SQLException e) { e.printStackTrace(); }
try { if (conn != null) conn.close(); } catch (SQLException e) { e.printStackTrace(); }
}
}
/**
* Deletes a DOCUMENT row.
* @throws javax.ejb.EJBException SQL error or row count for DELETE != 1.
*/
public void ejbRemove() {
Connection conn = null;
PreparedStatement pstmt = null;
EJB_DOCUMENT_PK pk = (EJB_DOCUMENT_PK)(_entityContext.getPrimaryKey());
try {
conn = _dataSource.getConnection();
pstmt = conn.prepareStatement(SQL_DELETE);
pstmt.setInt(1, pk.getId());
if (pstmt.executeUpdate() != 1)
throw new EJBException("Failed to delete DOCUMENT row with pk:" + pk);
} catch(SQLException e) {
throw new EJBException(e);
} finally {
try { if (pstmt != null) pstmt.close(); } catch (SQLException e) { e.printStackTrace(); }
try { if (conn != null) conn.close(); } catch (SQLException e) { e.printStackTrace(); }
}
}
/**
* Finds a single row, provided a primary key.
* @param pk the primary key that indentifies the row to retrieve.
* @return the primary key (same as parameter pk).
* @throws javax.ejb.ObjectNotFoundException no row with this primary key.
* @throws javax.ejb.EJBException SQL error.
*/
public EJB_DOCUMENT_PK ejbFindByPrimaryKey(EJB_DOCUMENT_PK pk) throws ObjectNotFoundException {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = _dataSource.getConnection();
pstmt = conn.prepareStatement(SQL_SELECT_FIND_BY_PRIMARY_KEY);
pstmt.setInt(1, pk.getId());
rs = pstmt.executeQuery();
if (!rs.next())
throw new ObjectNotFoundException("No DOCUMENT row with pk:" + pk);
return pk;
} catch(SQLException e) {
throw new EJBException(e);
} finally {
try { if (rs != null) rs.close(); } catch (SQLException e) { e.printStackTrace(); }
try { if (pstmt != null) pstmt.close(); } catch (SQLException e) { e.printStackTrace(); }
try { if (conn != null) conn.close(); } catch (SQLException e) { e.printStackTrace(); }
}
}
/**
* Finds rows by id.
* @param id value of the ID column.
* @return primary keys collection of the founded rows.
* @throws javax.ejb.EJBException SQL error.
*/
public Collection ejbFindById(int id) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = _dataSource.getConnection();
pstmt = conn.prepareStatement(SQL_SELECT_FIND_ALL + " WHERE ID=?");
pstmt.setInt(1, id);
rs = pstmt.executeQuery();
Vector v = new Vector(128);
while (rs.next())
v.addElement(new EJB_DOCUMENT_PK(rs.getInt(1)));
return v;
} catch(SQLException e) {
throw new EJBException(e);
} finally {
try { if (rs != null) rs.close(); } catch (SQLException e) { e.printStackTrace(); }
try { if (pstmt != null) pstmt.close(); } catch (SQLException e) { e.printStackTrace(); }
try { if (conn != null) conn.close(); } catch (SQLException e) { e.printStackTrace(); }
}
}
/**
* Finds rows by addressid.
* @param addressid value of the ADDRESSID column.
* @return primary keys collection of the founded rows.
* @throws javax.ejb.EJBException SQL error.
*/
public Collection ejbFindByAddressid(int addressid) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = _dataSource.getConnection();
pstmt = conn.prepareStatement(SQL_SELECT_FIND_ALL + " WHERE ADDRESSID=?");
pstmt.setInt(1, addressid);
rs = pstmt.executeQuery();
Vector v = new Vector(128);
while (rs.next())
v.addElement(new EJB_DOCUMENT_PK(rs.getInt(1)));
return v;
} catch(SQLException e) {
throw new EJBException(e);
} finally {
try { if (rs != null) rs.close(); } catch (SQLException e) { e.printStackTrace(); }
try { if (pstmt != null) pstmt.close(); } catch (SQLException e) { e.printStackTrace(); }
try { if (conn != null) conn.close(); } catch (SQLException e) { e.printStackTrace(); }
}
}
/**
* Finds rows by total.
* @param total value of the TOTAL column.
* @return primary keys collection of the founded rows.
* @throws javax.ejb.EJBException SQL error.
*/
public Collection ejbFindByTotal(java.math.BigDecimal total) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = _dataSource.getConnection();
pstmt = conn.prepareStatement(SQL_SELECT_FIND_ALL + " WHERE TOTAL=?");
pstmt.setBigDecimal(1, total);
rs = pstmt.executeQuery();
Vector v = new Vector(128);
while (rs.next())
v.addElement(new EJB_DOCUMENT_PK(rs.getInt(1)));
return v;
} catch(SQLException e) {
throw new EJBException(e);
} finally {
try { if (rs != null) rs.close(); } catch (SQLException e) { e.printStackTrace(); }
try { if (pstmt != null) pstmt.close(); } catch (SQLException e) { e.printStackTrace(); }
try { if (conn != null) conn.close(); } catch (SQLException e) { e.printStackTrace(); }
}
}
/**
* Finds all rows in the DOCUMENT table.
* @return primary keys collection of the founded rows.
* @throws javax.ejb.EJBException SQL error.
*/
public Collection ejbFindAll() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = _dataSource.getConnection();
pstmt = conn.prepareStatement(SQL_SELECT_FIND_ALL);
rs = pstmt.executeQuery();
Vector v = new Vector(128);
while (rs.next())
v.addElement(new EJB_DOCUMENT_PK(rs.getInt(1)));
return v;
} catch(SQLException e) {
throw new EJBException(e);
} finally {
try { if (rs != null) rs.close(); } catch (SQLException e) { e.printStackTrace(); }
try { if (pstmt != null) pstmt.close(); } catch (SQLException e) { e.printStackTrace(); }
try { if (conn != null) conn.close(); } catch (SQLException e) { e.printStackTrace(); }
}
}
/**
* Returns the full DataSource JNDI name.
* @return the JNDI name.
*/
protected String getDataSourceJNDIName() {
return DATA_SOURCE_JNDI_NAME;
}
}
EJB_DOCUMENTBean.html
(HTML view generated by ejen v.1.0.0).