///////////////////////////////////////////////////////////////////////////////
// File     : EJB_DOUBLE_UNIQUEBean.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 DOUBLE_UNIQUE table.
 * <br><i>Ejen EJB 1.1 (BMP) demonstration</i>
 * @version 1.0
 * @author (unknown)
 * @see org.ejb.test.DOUBLE_UNIQUEValues
 * @see org.ejb.test.EJB_DOUBLE_UNIQUEHome
 * @see org.ejb.test.EJB_DOUBLE_UNIQUE
 * @see org.ejb.test.EJB_DOUBLE_UNIQUE_PK
 * @see org.ejb.test.EJB_TABLEAbstractBean
 */
public class EJB_DOUBLE_UNIQUEBean extends EJB_TABLEAbstractBean {

    /** INSERT statement used in ejbCreate method (no sequence field, if any) */
    protected static final String SQL_INSERT = "INSERT INTO DOUBLE_UNIQUE (ID0,ID1,I,J) VALUES (?,?,?,?)";
    /** SELECT statement used in ejbLoad method */
    protected static final String SQL_SELECT = "SELECT I,J FROM DOUBLE_UNIQUE WHERE ID0=? AND ID1=?";
    /** UPDATE statement used in ejbStore method */
    protected static final String SQL_UPDATE = "UPDATE DOUBLE_UNIQUE SET I=?,J=? WHERE ID0=? AND ID1=?";
    /** DELETE statement used in ejbRemove method */
    protected static final String SQL_DELETE = "DELETE FROM DOUBLE_UNIQUE WHERE ID0=? AND ID1=?";
    /** SELECT statement used in ejbFindByPrimaryKey method */
    protected static final String SQL_SELECT_FIND_BY_PRIMARY_KEY = "SELECT ID0 FROM DOUBLE_UNIQUE WHERE ID0=? AND ID1=?";
    /** SELECT statement used in ejbFindAll method */
    protected static final String SQL_SELECT_FIND_ALL = "SELECT ID0,ID1 FROM DOUBLE_UNIQUE";

    /** Full JNDI name of the DataSource */
    protected static final String DATA_SOURCE_JNDI_NAME = "java:/DefaultDS";

    /** Values object variable */
    protected DOUBLE_UNIQUEValues _values = null;

    /**
     * Default constructor (empty).
     */
    public EJB_DOUBLE_UNIQUEBean() {}

    /**
     * Returns a values object that contains all DOUBLE_UNIQUE fields
     *         (except primary key fields).
     * @return object values that contains all DOUBLE_UNIQUE fields
     *         (except primary key fields).
     */
    public DOUBLE_UNIQUEValues getAll() {
        return _values;
    }

    /**
     * Sets a values object that contains all DOUBLE_UNIQUE
     *        fields for update (except primary key fields).
     * @param DOUBLE_UNIQUEValues values object that contains all
     *        DOUBLE_UNIQUE fields for update (except primary key fields).
     */
    public void setAll(DOUBLE_UNIQUEValues values) {
        _values = values;
        _dirty = true;
    }

    /**
     * Creates a new DOUBLE_UNIQUE row.
     * @param pk primary key of the new row to be created.
     * @param values a values object that contains values for the
     *        DOUBLE_UNIQUE 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_DOUBLE_UNIQUE_PK ejbCreate(EJB_DOUBLE_UNIQUE_PK pk, DOUBLE_UNIQUEValues values) throws CreateException {
        _values = values;
        Connection conn = null;
        PreparedStatement pstmt = null;
        try {
            conn = _dataSource.getConnection();
            pstmt = conn.prepareStatement(SQL_INSERT);
            pstmt.setInt(1, pk.getId0());
            pstmt.setInt(2, pk.getId1());
            pstmt.setInt(3, _values.getI());
            pstmt.setInt(4, _values.getJ());
            if (pstmt.executeUpdate() != 1)
                throw new CreateException("Failed to create new DOUBLE_UNIQUE 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 DOUBLE_UNIQUE row.
     */
    public void ejbPostCreate(EJB_DOUBLE_UNIQUE_PK pk, DOUBLE_UNIQUEValues values) {}

    /**
     * Loads a DOUBLE_UNIQUE row.
     * @throws javax.ejb.EJBException SQL error or empty ResultSet.
     */
    public void ejbLoad() {
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        EJB_DOUBLE_UNIQUE_PK pk = (EJB_DOUBLE_UNIQUE_PK)(_entityContext.getPrimaryKey());
        try {
            conn = _dataSource.getConnection();
            pstmt = conn.prepareStatement(SQL_SELECT);
            pstmt.setInt(1, pk.getId0());
            pstmt.setInt(2, pk.getId1());
            rs = pstmt.executeQuery();
            if (!rs.next())
                throw new EJBException("Failed to load DOUBLE_UNIQUE row with pk:" + pk);
            if (_values == null)
                _values = new DOUBLE_UNIQUEValues(rs.getInt(1), rs.getInt(2));
            else {
                _values.setI(rs.getInt(1));
                _values.setJ(rs.getInt(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 DOUBLE_UNIQUE 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_DOUBLE_UNIQUE_PK pk = (EJB_DOUBLE_UNIQUE_PK)(_entityContext.getPrimaryKey());
        try {
            conn = _dataSource.getConnection();
            pstmt = conn.prepareStatement(SQL_UPDATE);
            pstmt.setInt(1, _values.getI());
            pstmt.setInt(2, _values.getJ());
            pstmt.setInt(3, pk.getId0());
            pstmt.setInt(4, pk.getId1());
            if (pstmt.executeUpdate() != 1)
                throw new EJBException("Failed to update DOUBLE_UNIQUE 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 DOUBLE_UNIQUE row.
     * @throws javax.ejb.EJBException SQL error or row count for DELETE != 1.
     */
    public void ejbRemove() {
        Connection conn = null;
        PreparedStatement pstmt = null;
        EJB_DOUBLE_UNIQUE_PK pk = (EJB_DOUBLE_UNIQUE_PK)(_entityContext.getPrimaryKey());
        try {
            conn = _dataSource.getConnection();
            pstmt = conn.prepareStatement(SQL_DELETE);
            pstmt.setInt(1, pk.getId0());
            pstmt.setInt(2, pk.getId1());
            if (pstmt.executeUpdate() != 1)
                throw new EJBException("Failed to delete DOUBLE_UNIQUE 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_DOUBLE_UNIQUE_PK ejbFindByPrimaryKey(EJB_DOUBLE_UNIQUE_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.getId0());
            pstmt.setInt(2, pk.getId1());
            rs = pstmt.executeQuery();
            if (!rs.next())
                throw new ObjectNotFoundException("No DOUBLE_UNIQUE 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 id0.
     * @param id0 value of the ID0 column.
     * @return primary keys collection of the founded rows.
     * @throws javax.ejb.EJBException SQL error.
     */
    public Collection ejbFindById0(int id0) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            conn = _dataSource.getConnection();
            pstmt = conn.prepareStatement(SQL_SELECT_FIND_ALL + " WHERE ID0=?");
            pstmt.setInt(1, id0);
            rs = pstmt.executeQuery();
            Vector v = new Vector(128);
            while (rs.next())
                v.addElement(new EJB_DOUBLE_UNIQUE_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 id1.
     * @param id1 value of the ID1 column.
     * @return primary keys collection of the founded rows.
     * @throws javax.ejb.EJBException SQL error.
     */
    public Collection ejbFindById1(int id1) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            conn = _dataSource.getConnection();
            pstmt = conn.prepareStatement(SQL_SELECT_FIND_ALL + " WHERE ID1=?");
            pstmt.setInt(1, id1);
            rs = pstmt.executeQuery();
            Vector v = new Vector(128);
            while (rs.next())
                v.addElement(new EJB_DOUBLE_UNIQUE_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 i.
     * @param i value of the I column.
     * @return primary keys collection of the founded rows.
     * @throws javax.ejb.EJBException SQL error.
     */
    public Collection ejbFindByI(int i) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            conn = _dataSource.getConnection();
            pstmt = conn.prepareStatement(SQL_SELECT_FIND_ALL + " WHERE I=?");
            pstmt.setInt(1, i);
            rs = pstmt.executeQuery();
            Vector v = new Vector(128);
            while (rs.next())
                v.addElement(new EJB_DOUBLE_UNIQUE_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 j.
     * @param j value of the J column.
     * @return primary keys collection of the founded rows.
     * @throws javax.ejb.EJBException SQL error.
     */
    public Collection ejbFindByJ(int j) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            conn = _dataSource.getConnection();
            pstmt = conn.prepareStatement(SQL_SELECT_FIND_ALL + " WHERE J=?");
            pstmt.setInt(1, j);
            rs = pstmt.executeQuery();
            Vector v = new Vector(128);
            while (rs.next())
                v.addElement(new EJB_DOUBLE_UNIQUE_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 DOUBLE_UNIQUE 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_DOUBLE_UNIQUE_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_DOUBLE_UNIQUEBean.html (HTML view generated by ejen v.1.0.0).