///////////////////////////////////////////////////////////////////////////////
// File : EJB_POSITIONBean.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 POSITION table.
* <br><i>Ejen EJB 1.1 (BMP) demonstration</i>
* @version 1.0
* @author (unknown)
* @see org.ejb.test.POSITIONValues
* @see org.ejb.test.EJB_POSITIONHome
* @see org.ejb.test.EJB_POSITION
* @see org.ejb.test.EJB_POSITION_PK
* @see org.ejb.test.EJB_TABLEAbstractBean
*/
public class EJB_POSITIONBean extends EJB_TABLEAbstractBean {
/** INSERT statement used in ejbCreate method (no sequence field, if any) */
protected static final String SQL_INSERT = "INSERT INTO POSITION (DOCUMENTID,POSITION,PRODUCTID,QUANTITY,PRICE) VALUES (?,?,?,?,?)";
/** SELECT statement used in ejbLoad method */
protected static final String SQL_SELECT = "SELECT PRODUCTID,QUANTITY,PRICE FROM POSITION WHERE DOCUMENTID=? AND POSITION=?";
/** UPDATE statement used in ejbStore method */
protected static final String SQL_UPDATE = "UPDATE POSITION SET PRODUCTID=?,QUANTITY=?,PRICE=? WHERE DOCUMENTID=? AND POSITION=?";
/** DELETE statement used in ejbRemove method */
protected static final String SQL_DELETE = "DELETE FROM POSITION WHERE DOCUMENTID=? AND POSITION=?";
/** SELECT statement used in ejbFindByPrimaryKey method */
protected static final String SQL_SELECT_FIND_BY_PRIMARY_KEY = "SELECT DOCUMENTID FROM POSITION WHERE DOCUMENTID=? AND POSITION=?";
/** SELECT statement used in ejbFindAll method */
protected static final String SQL_SELECT_FIND_ALL = "SELECT DOCUMENTID,POSITION FROM POSITION";
/** Full JNDI name of the DataSource */
protected static final String DATA_SOURCE_JNDI_NAME = "java:/DefaultDS";
/** Values object variable */
protected POSITIONValues _values = null;
/**
* Default constructor (empty).
*/
public EJB_POSITIONBean() {}
/**
* Returns a values object that contains all POSITION fields
* (except primary key fields).
* @return object values that contains all POSITION fields
* (except primary key fields).
*/
public POSITIONValues getAll() {
return _values;
}
/**
* Sets a values object that contains all POSITION
* fields for update (except primary key fields).
* @param POSITIONValues values object that contains all
* POSITION fields for update (except primary key fields).
*/
public void setAll(POSITIONValues values) {
_values = values;
_dirty = true;
}
/**
* Creates a new POSITION row.
* @param pk primary key of the new row to be created.
* @param values a values object that contains values for the
* POSITION 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_POSITION_PK ejbCreate(EJB_POSITION_PK pk, POSITIONValues values) throws CreateException {
_values = values;
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = _dataSource.getConnection();
pstmt = conn.prepareStatement(SQL_INSERT);
pstmt.setInt(1, pk.getDocumentid());
pstmt.setInt(2, pk.getPosition());
pstmt.setInt(3, _values.getProductid());
pstmt.setInt(4, _values.getQuantity());
pstmt.setBigDecimal(5, _values.getPrice());
if (pstmt.executeUpdate() != 1)
throw new CreateException("Failed to create new POSITION 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 POSITION row.
*/
public void ejbPostCreate(EJB_POSITION_PK pk, POSITIONValues values) {}
/**
* Loads a POSITION row.
* @throws javax.ejb.EJBException SQL error or empty ResultSet.
*/
public void ejbLoad() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
EJB_POSITION_PK pk = (EJB_POSITION_PK)(_entityContext.getPrimaryKey());
try {
conn = _dataSource.getConnection();
pstmt = conn.prepareStatement(SQL_SELECT);
pstmt.setInt(1, pk.getDocumentid());
pstmt.setInt(2, pk.getPosition());
rs = pstmt.executeQuery();
if (!rs.next())
throw new EJBException("Failed to load POSITION row with pk:" + pk);
if (_values == null)
_values = new POSITIONValues(rs.getInt(1), rs.getInt(2), rs.getBigDecimal(3));
else {
_values.setProductid(rs.getInt(1));
_values.setQuantity(rs.getInt(2));
_values.setPrice(rs.getBigDecimal(3));
}
} 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 POSITION 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_POSITION_PK pk = (EJB_POSITION_PK)(_entityContext.getPrimaryKey());
try {
conn = _dataSource.getConnection();
pstmt = conn.prepareStatement(SQL_UPDATE);
pstmt.setInt(1, _values.getProductid());
pstmt.setInt(2, _values.getQuantity());
pstmt.setBigDecimal(3, _values.getPrice());
pstmt.setInt(4, pk.getDocumentid());
pstmt.setInt(5, pk.getPosition());
if (pstmt.executeUpdate() != 1)
throw new EJBException("Failed to update POSITION 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 POSITION row.
* @throws javax.ejb.EJBException SQL error or row count for DELETE != 1.
*/
public void ejbRemove() {
Connection conn = null;
PreparedStatement pstmt = null;
EJB_POSITION_PK pk = (EJB_POSITION_PK)(_entityContext.getPrimaryKey());
try {
conn = _dataSource.getConnection();
pstmt = conn.prepareStatement(SQL_DELETE);
pstmt.setInt(1, pk.getDocumentid());
pstmt.setInt(2, pk.getPosition());
if (pstmt.executeUpdate() != 1)
throw new EJBException("Failed to delete POSITION 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_POSITION_PK ejbFindByPrimaryKey(EJB_POSITION_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.getDocumentid());
pstmt.setInt(2, pk.getPosition());
rs = pstmt.executeQuery();
if (!rs.next())
throw new ObjectNotFoundException("No POSITION 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 documentid.
* @param documentid value of the DOCUMENTID column.
* @return primary keys collection of the founded rows.
* @throws javax.ejb.EJBException SQL error.
*/
public Collection ejbFindByDocumentid(int documentid) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = _dataSource.getConnection();
pstmt = conn.prepareStatement(SQL_SELECT_FIND_ALL + " WHERE DOCUMENTID=?");
pstmt.setInt(1, documentid);
rs = pstmt.executeQuery();
Vector v = new Vector(128);
while (rs.next())
v.addElement(new EJB_POSITION_PK(rs.getInt(1), rs.getInt(2)));
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 position.
* @param position value of the POSITION column.
* @return primary keys collection of the founded rows.
* @throws javax.ejb.EJBException SQL error.
*/
public Collection ejbFindByPosition(int position) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = _dataSource.getConnection();
pstmt = conn.prepareStatement(SQL_SELECT_FIND_ALL + " WHERE POSITION=?");
pstmt.setInt(1, position);
rs = pstmt.executeQuery();
Vector v = new Vector(128);
while (rs.next())
v.addElement(new EJB_POSITION_PK(rs.getInt(1), rs.getInt(2)));
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 productid.
* @param productid value of the PRODUCTID column.
* @return primary keys collection of the founded rows.
* @throws javax.ejb.EJBException SQL error.
*/
public Collection ejbFindByProductid(int productid) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = _dataSource.getConnection();
pstmt = conn.prepareStatement(SQL_SELECT_FIND_ALL + " WHERE PRODUCTID=?");
pstmt.setInt(1, productid);
rs = pstmt.executeQuery();
Vector v = new Vector(128);
while (rs.next())
v.addElement(new EJB_POSITION_PK(rs.getInt(1), rs.getInt(2)));
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 quantity.
* @param quantity value of the QUANTITY column.
* @return primary keys collection of the founded rows.
* @throws javax.ejb.EJBException SQL error.
*/
public Collection ejbFindByQuantity(int quantity) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = _dataSource.getConnection();
pstmt = conn.prepareStatement(SQL_SELECT_FIND_ALL + " WHERE QUANTITY=?");
pstmt.setInt(1, quantity);
rs = pstmt.executeQuery();
Vector v = new Vector(128);
while (rs.next())
v.addElement(new EJB_POSITION_PK(rs.getInt(1), rs.getInt(2)));
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 price.
* @param price value of the PRICE column.
* @return primary keys collection of the founded rows.
* @throws javax.ejb.EJBException SQL error.
*/
public Collection ejbFindByPrice(java.math.BigDecimal price) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = _dataSource.getConnection();
pstmt = conn.prepareStatement(SQL_SELECT_FIND_ALL + " WHERE PRICE=?");
pstmt.setBigDecimal(1, price);
rs = pstmt.executeQuery();
Vector v = new Vector(128);
while (rs.next())
v.addElement(new EJB_POSITION_PK(rs.getInt(1), rs.getInt(2)));
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 POSITION 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_POSITION_PK(rs.getInt(1), rs.getInt(2)));
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_POSITIONBean.html
(HTML view generated by ejen v.1.0.0).