Title: RE: [jBoss-User] JBOSS and Oracle

Here are answers to your questions,

1. I have tried both 8.1.6 and 8.1.7 using both the thin and OCI drivers.
2. I do have "jboss.xa.xidclass=oracle.jdbc.xa.OracleXid" in jboss.properties ?
3. I am using the following for my data source oracle.jdbc.xa.client.OracleXADataSource
I cannot use Minerva because I need to cast to an Oracle-specific class for my current
BLOB/CLOB code. Notice also, that I do not mess with setAutoCommit()
4. See below
5. I have tried both thin and OCI, now I am using the OCI

I have the following issues with this code.
1) Transaction context is not propogating properly. In other BMP entity beans I create product and version records
which serve as the FK parents for this bean's record. The ONLY way I can get the insert to happen is if I mark
the create method as being RequiredNew (which basically means I CANNOT write code that inserts a product, version, and part in the same transaction)

2) In high volume situations, I get errors from the Oracle transaction manager. I think it is running out of resources. I think if I change the user interface of this bean to only use a Value object vs. multiple get/set pairs, I could then mark the getValueobject method as non-transaction. I think the container is repeatedly calling ejbStore on each get call, or something like that. My real problem is in another bean that stores images related to the HTML stored in this bean. I have a servlet doing multiple lookups against a media bean. Might have to move that to a pure JDBC solution and bypass the media EJB bean.


Here is a COMPLETE SOURCE entity bean that writes data to a CLOB in a Oracle database. The value object is just a regular bean that mirrors the API of the main EJB.

Remote Interface
================
/*
 * DocumentVersion.java
 *
 * Created on January 8, 2001, 3:56 PM
 */

package mil.army.atsc.atia.ddc.ejb.interfaces;

import java.rmi.RemoteException;
import javax.ejb.EJBObject;
import mil.army.atsc.atia.ddc.ejb.value.DocumentPartValue;
import mil.army.atsc.atia.ddc.ejb.value.DocumentPartContent;

/**
 *
 * @author  boltd
 * @version
 */
public interface DocumentPart extends EJBObject{
   

    /** Getter for property productId.
     * @return Value of property productId.
 */
    public String getProductId() throws RemoteException;
   

    /** Setter for property productId.
     * @param productId New value of property productId.
 */
    public void setProductId(String productId) throws RemoteException;
   

    /** Getter for property documentVersionId.
     * @return Value of property documentVersionId.
 */
    public int getDocumentVersionId() throws RemoteException;
   

    /** Setter for property documentVersionId.
     * @param documentVersionId New value of property documentVersionId.
 */
    public void setDocumentVersionId(int documentVersionId) throws RemoteException;
   

    /** Getter for property DocumentSectionHTMLText.
     * @return Value of property DocumentSectionHTMLText.
 */
    public String getDocumentSectionHTMLText() throws RemoteException;
   

    /** Setter for property DocumentSectionHTMLText.
     * @param DocumentSectionHTMLText New value of property DocumentSectionHTMLText.
 */
    public void setDocumentSectionHTMLText(String productStatusCode) throws RemoteException;


    /** Getter for property documentSectionName.
     * @return Value of property documentSectionName.
 */
    public String getDocumentSectionName() throws RemoteException;
   

    /** Setter for property documentSectionName.
     * @param documentSectionName New value of property documentSectionName.
 */
    public void setDocumentSectionName(String documentSectionName) throws RemoteException;
   




    /** Getter for property documentSectionId.
     * @return Value of property documentSectionId.
 */
    public int getDocumentSectionId()  throws RemoteException;   
   

    /** Setter for property documentSectionId.
     * @param documentSectionId New value of property documentSectionId.
 */
    public void setDocumentSectionId(int documentSectionId)  throws RemoteException;   


    public DocumentPartValue createValueObject() throws RemoteException;

    /** The following business methods encapsulate support for accessing the
     * Microsoft Word and HTML/image data from a given document_part. These
     * features are encapsulated in dependent classes due to the issues related
     * to handling BLOB data directly in EJBs
     * @throws RemoteException
 * @return  */
   
    /** getDocumentContent allows access to the Word document content
     * for this part */
    public DocumentPartContent getDocumentContent() throws RemoteException;
   
    /** setDocumentContent allows changing the Word document content
     * for this part */
    public void setDocumentContent(DocumentPartContent doc) throws RemoteException;

}

Home Interface
==============
/*
 * ProductHome.java
 *
 * Created on January 4, 2001, 7:34 PM
 */

package mil.army.atsc.atia.ddc.ejb.interfaces;

import javax.ejb.EJBHome;
import java.rmi.RemoteException;
import javax.ejb.FinderException;
import javax.ejb.CreateException;
import java.util.Collection;

import mil.army.atsc.atia.ddc.ejb.DocumentVersionPK;
import mil.army.atsc.atia.ddc.ejb.DocumentPartPK;
import mil.army.atsc.atia.ddc.ejb.ProductPK;
/**
 *
 * @author  boltd
 * @version
 */
public interface DocumentPartHome extends javax.ejb.EJBHome
{
    public DocumentPart create(
        String productId,
        int documentVersionId,
        int documentSectionId,
        String documentSectionName,
        String documentSectionHTMLText
        ) throws RemoteException, CreateException;
   
    public DocumentPart findByPrimaryKey(DocumentPartPK primaryKey) throws RemoteException, FinderException;

    public Collection findAll() throws RemoteException, FinderException;

    public Collection findByKeyword(String keyword) throws RemoteException, FinderException;

    public Collection findByProduct(ProductPK pk) throws RemoteException, FinderException;

    public Collection findByVersion(DocumentVersionPK pk) throws RemoteException, FinderException;
}

Primary Key Class
=================
package mil.army.atsc.atia.ddc.ejb;

/*
 * ProductPK.java
 *
 * Created on January 4, 2001, 7:36 PM
 */

import java.io.Serializable;
/**
 *
 * @author  boltd
 * @version
 */
public class DocumentPartPK implements Serializable {

    public String productId;
    public int documentVersionId;
    public int documentSectionId;
   
    /** Creates new ProductPK */
    public DocumentPartPK() {
    }

    public DocumentPartPK(String productId,int documentVersionId,int documentSectionId) {
        this.productId = productId;
        this.documentVersionId = documentVersionId;
        this.documentSectionId = documentSectionId;
    }

    public String getProductId()
    {
        return productId;
    }
   
    public int getDocumentVersionId()
    {
        return documentVersionId;
    }

    public int getDocumentSectionId()
    {
        return documentSectionId;
    }
   
    public int hashCode()
    {
        StringBuffer buf = new StringBuffer(50);
        buf.append(productId);
        buf.append("|");
        buf.append(documentVersionId);
        buf.append("|");
        buf.append(documentSectionId);
        return buf.toString().hashCode();
    }
   
    public boolean equals(Object other)
    {
        if ((other == null) || !(other instanceof DocumentPartPK))
            return false; // Not an object of the correct type

        DocumentPartPK otherPK = (DocumentPartPK)other;
        return (
            (productId.equals(otherPK.productId))
            &&
            (documentVersionId == otherPK.documentVersionId)
            &&
            (documentSectionId == otherPK.documentSectionId)
            );
    }

    public String toString()
    {
        return "Product: " + productId + " Version: " + documentVersionId
        + " Sequence: " + documentSectionId;
    }

}

EJB Implementation
==================
/*
 * ProductEJB.java
 *
 * Created on January 4, 2001, 7:56 PM
 */

package mil.army.atsc.atia.ddc.ejb;

import java.sql.*;
import java.util.*;
import javax.sql.*;
import javax.naming.*;
import javax.ejb.*;
import java.rmi.RemoteException;
import java.io.*;

import mil.army.atsc.atia.ddc.jndi.JNDINames;
import mil.army.atsc.atia.ddc.ejb.interfaces.DocumentPart;
import mil.army.atsc.atia.ddc.ejb.value.DocumentPartValue;
import mil.army.atsc.atia.ddc.ejb.value.DocumentPartContent;
import oracle.sql.*;
import oracle.jdbc.driver.*;


/** This class is ORACLE specific
 *
 * @author  boltd
 * @version
 */
public class DocumentPartEJB implements EntityBean {

    private String productId;
    private int documentVersionId;
    private EntityContext ctx;
    private DocumentPartContent documentContent = null;
   

    /** Holds value of property documentSectionId. */
    private int documentSectionId;
   
    /** Holds value of property documentSectionSourceCode. */
    private String documentSectionSourceCode;
   
    /** Holds value of property documentSectionName. */
    private String documentSectionName;
   
 
    /** Holds value of property documentSectionHTMLText. */
    private String documentSectionHTMLText;
   
    // ProductHome Interface begins here
    public DocumentPartPK ejbCreate(
        String productId,
        int documentVersionId,
        int documentSectionId,
        String documentSectionName,
        String documentSectionHTMLText) throws RemoteException, CreateException
    {
        // Attempt to INSERT into the database
        Connection con = null;
        PreparedStatement stmt = null;
        Statement s2 = null;
        ResultSet rs = null;
        Writer out = null;
        try
        {
            System.out.println("DocumentPartEJB.ejbCreate() getting connection");
            con = this.getConnection();
            System.out.println("DocumentPartEJB.ejbCreate() got connection");
            String sql =
                "INSERT INTO document_part ("+
                "product_id, " +
                "document_version_id, " +
                "document_section_seq_id, " +
                "document_section_nm, " +
                "document_section_html_tx) " +
                "VALUES ( " +
                "?,?,?,?,empty_clob())";
          
            stmt = con.prepareStatement(sql);
            stmt.setString(1,productId);
            stmt.setInt(2,documentVersionId);
            stmt.setInt(3,documentSectionId);
            stmt.setString(4,documentSectionName);
            //
            // Attempt to add the record to the database
            //
            if (stmt.executeUpdate() != 1)
                throw new CreateException("Failed to add DocumentPart to DB");

            sql = "SELECT document_section_html_tx from document_part " +
                "where product_id = '" + productId + "' AND document_version_id= " +
                documentVersionId + " AND document_section_seq_id = " +
                documentSectionId + " FOR UPDATE";
           
            s2 = con.createStatement();
            rs = s2.executeQuery(sql);
           
            if (!rs.next())
                throw new CreateException("Could not create part");
            System.out.println("DocumentPartEJB.ejbCreate() starting CLOB");
           
            // Get the CLOB locator from the table
            CLOB clob = ((OracleResultSet)rs).getCLOB(1);
            out = clob.getCharacterOutputStream();
            out.write(documentSectionHTMLText);
            System.out.println("DocumentPartEJB.ejbCreate() done CLOB");
           
            documentContent = new DocumentPartContent(
                productId, documentVersionId, documentSectionId);
            documentContent.createPartContent(con);
        }
        catch (SQLException se)
        {
            ctx.setRollbackOnly();
            se.printStackTrace();
            throw new CreateException("Failed to create part " + se.getMessage());
        }
        catch (Exception se)
        {
            ctx.setRollbackOnly();
            se.printStackTrace();
            throw new CreateException("Failed to create part " + se.getMessage());
        }
        finally
        {
            try
                {
                System.out.println("DocumentPartEJB.ejbCreate() drop connection");
                if (out != null) out.close();
                if (rs != null) rs.close();
                if (s2 != null) s2.close();
                if (stmt != null) stmt.close();
                if (con != null) con.close();
                }
            catch (SQLException se) {
                se.printStackTrace();}
            catch (IOException se) {
                se.printStackTrace();}
        }       

        // Save off the fields
        this.productId = productId;
        this.documentVersionId = documentVersionId;
        this.documentSectionId = documentSectionId;
        this.documentSectionName = documentSectionName;
        this.documentSectionHTMLText = documentSectionHTMLText;
       
        return new DocumentPartPK(productId,documentVersionId,documentSectionId);
    }

    public void ejbPostCreate(
        String productId,
        int documentVersionId,
        int documentSectionId,
        String documentSectionName,
        String documentSectionHTMLText) throws RemoteException, CreateException
    {
    }
   
    /** ejbFindByPrimaryKey finds an instance of a single product */
    public DocumentPartPK ejbFindByPrimaryKey(DocumentPartPK primaryKey) throws RemoteException, FinderException
    {
        // Attempt to find the product in the database
        Connection con = null;
        PreparedStatement stmt = null;
        ResultSet rs = null;
        try
        {
            con = this.getConnection();
            String sql =
                "SELECT product_id, document_version_id, document_section_seq_id from document_part " +
                "where product_id = ? and document_version_id = ? and document_section_seq_id = ?";
            stmt = con.prepareStatement(sql);
            stmt.setString(1,primaryKey.getProductId());
            stmt.setInt(2,primaryKey.getDocumentVersionId());
            stmt.setInt(3,primaryKey.getDocumentSectionId());
            rs = stmt.executeQuery();
           
            if (!rs.next())
                throw new FinderException("Part not found in database: " + primaryKey.toString());

            return primaryKey;
        }
        catch (SQLException se)
        {
            //se.printStackTrace();
            throw new FinderException("Failed to find Part " + se.getMessage());
        }
        finally
        {
        try
            {
            if (rs != null) rs.close();
            if (stmt != null) stmt.close();
            if (con != null) con.close();
            }
        catch (SQLException se)
            {se.printStackTrace();}
        }       
    }
    /** Return a list of all of the Products in the database */
    public Collection ejbFindAll() throws RemoteException, FinderException
    {
        // Attempt to find the product in the database
        Connection con = null;
        LinkedList data = new LinkedList();
        PreparedStatement stmt = null;
        ResultSet rs = null;
        try
        {
            con = this.getConnection();
            String sql =
                "SELECT product_id, document_version_id, document_section_seq_id from document_version " +
                "order by product_id, document_version_id, document_section_seq_id";
            stmt = con.prepareStatement(sql);
            rs = stmt.executeQuery();
            while (rs.next())
            {
                data.add(new DocumentPartPK(rs.getString(1),rs.getInt(2),rs.getInt(3)));
            }
            return data;
           
        }
        catch (SQLException se)
        {
            //se.printStackTrace();
            throw new FinderException("Failed to find part " + se.getMessage());
        }
        finally
        {
        try
            {
            if (rs != null) rs.close();
            if (stmt != null) stmt.close();
            if (con != null) con.close();
            }
        catch (SQLException se)
            {se.printStackTrace();}
        }       
    }

    /** Find all products by keyword on the product_id or title */
    public Collection ejbFindByKeyword(String keyword) throws RemoteException, FinderException
    {
        // Attempt to find the product in the database
        Connection con = null;
        LinkedList data = new LinkedList();
        PreparedStatement stmt = null;
        ResultSet rs = null;
        try
        {
            con = this.getConnection();
            String sql =
                "SELECT product_id, document_version_id, document_section_seq_id from document_version where " +
                "document_version_nm like '%" + keyword + "%' " +
                "order by product_id, document_version_id, document_section_seq_id";
            stmt = con.prepareStatement(sql);
            rs = stmt.executeQuery();
            while (rs.next())
            {
                data.add(new DocumentPartPK(rs.getString(1),rs.getInt(2),rs.getInt(3)));
            }
            return data;

        }
        catch (SQLException se)
        {
            //se.printStackTrace();
            throw new FinderException("Failed to find part " + se.getMessage());
        }
        finally
        {
        try
            {
            if (rs != null) rs.close();
            if (stmt != null) stmt.close();
            if (con != null) con.close();
            }
        catch (SQLException se)
            {se.printStackTrace();}
        }       
    }
   
    /** Find all products by Product ID */
    public Collection ejbFindByProduct(ProductPK pk) throws RemoteException, FinderException
    {
        // Attempt to find the product in the database
        Connection con = null;
        LinkedList data = new LinkedList();
        PreparedStatement stmt = null;
        ResultSet rs = null;
        try
        {
            con = this.getConnection();
            String sql =
                "SELECT product_id, document_version_id, document_section_seq_id from document_part where " +
                "product_id = ? "  +
                "order by product_id, document_version_id, document_section_seq_id";
            stmt = con.prepareStatement(sql);
            stmt.setString(1,pk.getProductId());
            rs = stmt.executeQuery();
            while (rs.next())
            {
                data.add(new DocumentPartPK(rs.getString(1),rs.getInt(2),rs.getInt(3)));
            }
            return data;
           
        }
        catch (SQLException se)
        {
            se.printStackTrace();
            throw new FinderException("Failed to find part " + se.getMessage());
        }
        finally
        {
        try
            {
            if (rs != null) rs.close();
            if (stmt != null) stmt.close();
            if (con != null) con.close();
            }
        catch (SQLException se)
            {se.printStackTrace();}
        }       
    }
    /** Find all products by Product ID */
    public Collection ejbFindByVersion(DocumentVersionPK pk) throws RemoteException, FinderException
    {
        // Attempt to find the product in the database
        Connection con = null;
        LinkedList data = new LinkedList();
        PreparedStatement stmt = null;
        ResultSet rs = null;
        try
        {
            con = this.getConnection();
            String sql =
                "SELECT product_id, document_version_id, document_section_seq_id from document_part where " +
                "product_id = ? and document_version_id = ? "  +
                "order by product_id, document_version_id, document_section_seq_id";
            stmt = con.prepareStatement(sql);
            stmt.setString(1,pk.getProductId());
            stmt.setInt(2,pk.getDocumentVersionId());
            rs = stmt.executeQuery();
            while (rs.next())
            {
                data.add(new DocumentPartPK(rs.getString(1),rs.getInt(2),rs.getInt(3)));
            }
            return data;
           
        }
        catch (SQLException se)
        {
            //se.printStackTrace();
            throw new FinderException("Failed to find part " + se.getMessage());
        }
        finally
        {
            try
            {
                if (rs != null) rs.close();
                if (stmt != null) stmt.close();
                if (con != null) con.close();
            }
            catch (SQLException se)
            {
                se.printStackTrace();
            }
        }       
    }

    // EJB Lifecycle code Begin Here

    /** Creates new ProductEJB */
    public DocumentPartEJB() {
    }

    public void ejbActivate() throws EJBException, RemoteException {
    }

    /** Load the product bean from the persistent store */
    public void ejbLoad() throws EJBException, RemoteException
    {
        Connection con = null;
        PreparedStatement stmt = null;
        ResultSet rs = null;
        try
        {
            System.out.println("DocumentPartEJB.ejbLoad() getting connection");
            con = this.getConnection();
            System.out.println("DocumentPartEJB.ejbLoad() got connection");
            String sql =
                "SELECT "+
                "product_id, " +
                "document_version_id, " +
                "document_section_seq_id, " +
                "document_section_nm, " +
                "document_section_html_tx " +
                "from document_part " +
                "where product_id = ? and document_version_id = ? and document_section_seq_id = ?";

            stmt = con.prepareStatement(sql);
            //
            DocumentPartPK pk = (DocumentPartPK)ctx.getPrimaryKey();
            stmt.setString(1,pk.productId);
            stmt.setInt(2,pk.documentVersionId);
            stmt.setInt(3,pk.documentSectionId);
           
            rs = stmt.executeQuery();
           
            if (!rs.next())
                throw new EJBException("Version: " + pk + " now found");
           
            // Save off the fields
            this.productId = rs.getString(1);
            this.documentVersionId = rs.getInt(2);
            this.documentSectionId = rs.getInt(3);
            this.documentSectionName = rs.getString(4);
            System.out.println("DocumentPartEJB.ejbLoad() starting CLOB");
            CLOB html = ((OracleResultSet)rs).getCLOB(5);
           
            Reader in = html.getCharacterStream();
            StringBuffer buf = new StringBuffer();

            // Read from the CLOB stream and write to the stringbuffer
            int chars = 0; // Number of chanracters read
            char[] charbuffer = new char[10];  //  Buffer holding characters being transferred
            while ((chars = in.read(charbuffer)) != -1) // Read from CLOB
            {
                buf.append(charbuffer,0,chars); // Write to StringBuffer
            }
            in.close();
            documentSectionHTMLText = new String(buf);
            System.out.println("DocumentPartEJB.ejbLoad() done CLOB");
           
            System.out.println("DocumentPartEJB.ejbLoad() starting BLOB");
            // load the content
            if (documentContent == null)
            {
                documentContent = new DocumentPartContent(productId,documentVersionId,documentSectionId);
            }
            documentContent.loadPartContent(con);
            System.out.println("DocumentPartEJB.ejbLoad() Done BLOB");
           
        }
        catch (SQLException se)
        {
            //se.printStackTrace();
            throw new EJBException("Failed to find part " + se.getMessage());
        }
        catch (IOException se)
        {
            //se.printStackTrace();
            throw new EJBException("Failed to find part " + se.getMessage());
        }
        finally
        {
            try
            {
                System.out.println("DocumentPartEJB.ejbLoad() dropping connection");
                if (rs != null) rs.close();
                if (stmt != null) stmt.close();
                if (con != null) con.close();
            }
            catch (SQLException se)
            {
                se.printStackTrace();
            }
        }       

    }
   
    public void ejbPassivate() throws EJBException, RemoteException {
    }
   
    /** Remove the product bean from the persistent store */
    public void ejbRemove() throws RemoveException, EJBException, RemoteException
    {
        // Attempt to find the product in the database
        Connection con = null;
        PreparedStatement stmt = null;
        try
        {
            con = this.getConnection();
            DocumentPartPK pk = (DocumentPartPK)ctx.getPrimaryKey();

            String sql =
                "DELETE from document_part where product_id = ? and document_version_id = ? and document_section_seq_id = ?";

            stmt = con.prepareStatement(sql);

            stmt.setString(1,pk.productId);
            stmt.setInt(2,pk.documentVersionId);
            stmt.setInt(3,pk.documentSectionId);
           
            if (stmt.executeUpdate() != 1)
                throw new EJBException("Could not remove part");

        }
        catch (SQLException se)
        {
            //se.printStackTrace();
            throw new RemoveException("Failed to remove part " + se.getMessage());
        }
        finally
        {
            try
            {
                if (stmt != null) stmt.close();
                if (con != null) con.close();
            }
            catch (SQLException se)
            {
                se.printStackTrace();
            }
        }       
    }

    /** Save the product bean to the persistent store */
    public void ejbStore() throws EJBException, RemoteException
    {
        // Attempt to INSERT into the database
        Connection con = null;
        PreparedStatement stmt = null;
        Statement s2 = null;
        ResultSet rs = null;
       
        try
        {
            System.out.println("DocumentPartEJB.ejbStore() getting connection");
            con = this.getConnection();
            System.out.println("DocumentPartEJB.ejbStore() got connection");
            String sql =
                "UPDATE document_part set "+
                "product_id=?, " +
                "document_version_id=?, " +
                "document_section_seq_id=?, " +
                "document_section_nm=?, " +
                "document_section_html_tx=empty_clob() " +
                "where product_id = ? and document_version_id = ? and document_section_seq_id = ?";
          
            stmt = con.prepareStatement(sql);
            stmt.setString(1,productId);
            stmt.setInt(2,documentVersionId);
            stmt.setInt(3,documentSectionId);
            stmt.setString(4,documentSectionName);
            // Params for the WHERE clause
            stmt.setString(5,productId);
            stmt.setInt(6,documentVersionId);
            stmt.setInt(7,documentSectionId);
            //
            // Attempt to add the record to the database
            //
            stmt.executeUpdate();

            System.out.println("DocumentPartEJB.ejbStore() SELECT FOR UPDATE CLOB");

            sql = "SELECT document_section_html_tx from document_part " +
                "where product_id = '" + productId + "' AND document_version_id= " +
                documentVersionId + " AND document_section_seq_id = " +
                documentSectionId + " FOR UPDATE";
           
            s2 = con.createStatement();
            rs = s2.executeQuery(sql);
           
            if (!rs.next())
                throw new EJBException("Could not create part");
           
            System.out.println("DocumentPartEJB.ejbStore() starting CLOB");
            // Get the CLOB locator from the table
            CLOB clob = ((OracleResultSet)rs).getCLOB(1);
            clob.putString(1,documentSectionHTMLText);
           
            // Check the CLOB size
            rs.close();
            s2.close();
            System.out.println("DocumentPartEJB.ejbStore() Done CLOB");
           
            System.out.println("DocumentPartEJB.ejbStore() starting BLOB");
            // Determine if we need to save the content off
            if (documentContent.isDirty())
            {
                documentContent.savePartContent(con);
            }
            System.out.println("DocumentPartEJB.ejbStore() done BLOB");
           
        }
        catch (SQLException se)
        {
            //se.printStackTrace();
            throw new EJBException("Failed to update part " + se.getMessage());
        }
        finally
        {
            try
                {
                System.out.println("DocumentPartEJB.ejbStore() freeing connection");
                if (rs != null) rs.close();
                if (s2 != null) s2.close();
                if (stmt != null) stmt.close();
                if (con != null) con.close();
                }
            catch (SQLException se) {
                se.printStackTrace();}
        }       
    }
   
    public void setEntityContext(javax.ejb.EntityContext entityContext) throws EJBException, RemoteException {
        ctx = entityContext;
    }
   
    public void unsetEntityContext() throws EJBException, RemoteException {
        ctx = null;
    }

    // Business Methods begin here
    /** Getter for property productId.
     * @return Value of property productId.
 */
    public String getProductId()
    {
        return productId;
    }
   

    /** Setter for property productId.
     * @param productId New value of property productId.
 */
    public void setProductId(String productId)
    {
        this.productId = productId;
        documentContent.setProductId(productId);
    }
   

    /** Getter for property documentVersionId.
     * @return Value of property documentVersionId.
 */
    public int getDocumentVersionId()
    {
        return documentVersionId;
    }
   

    /** Setter for property documentVersionId.
     * @param documentVersionId New value of property documentVersionId.
 */
    public void setDocumentVersionId(int documentVersionId)    {
        this.documentVersionId = documentVersionId;
        documentContent.setDocumentVersionId(documentVersionId);
    }

    public DocumentPartValue createValueObject()
    {
        return new DocumentPartValue(
            productId,
            documentVersionId,
            documentSectionId,
            documentSectionName,
            documentSectionHTMLText);
    }
   
    /** Getter for property documentSectionId.
     * @return Value of property documentSectionId.
 */
    public int getDocumentSectionId() {
        return documentSectionId;
    }
   
    /** Setter for property documentSectionId.
     * @param documentSectionId New value of property documentSectionId.
 */
    public void setDocumentSectionId(int documentSectionId) {
        this.documentSectionId = documentSectionId;
        documentContent.setDocumentSectionId(documentSectionId);
    }
   
    /** Getter for property documentSectionName.
     * @return Value of property documentSectionName.
 */
    public String getDocumentSectionName() {
        return documentSectionName;
    }
   
    /** Setter for property documentSectionName.
     * @param documentSectionName New value of property documentSectionName.
 */
    public void setDocumentSectionName(String documentSectionName) {
        this.documentSectionName = documentSectionName;
    }
   
    /** Getter for property documentSectionHTMLText.
     * @return Value of property documentSectionHTMLText.
 */
    public String getDocumentSectionHTMLText() {
        return documentSectionHTMLText;
    }
   
    /** Setter for property documentSectionHTMLText.
     * @param documentSectionHTMLText New value of property documentSectionHTMLText.
 */
    public void setDocumentSectionHTMLText(String documentSectionHTMLText) {
        this.documentSectionHTMLText = documentSectionHTMLText;
    }

    /** manageDocumentContent allows a client to access and update the binary
     * content associated with this DocumentPart instance.
     */
    public DocumentPartContent getDocumentContent()
    {
        return this.documentContent;
    }

    public void setDocumentContent(DocumentPartContent doc)
    {
        documentContent = doc;
        documentContent.setDirty(true);
    }

    // The following is code I received from the JBOSS-user mailing list
    private Connection getConnection() throws SQLException
    {
        DataSource ds = null;
        try
        {
            Context ctx = new InitialContext();
            ds = (DataSource)ctx.lookup(JNDINames.DB_POOL);
        }
        catch(NamingException ne)
        {
        }
        finally
        {
            System.out.println("getConnection() getting from datasource");
            return ds.getConnection();
        }
    }

}

ejb-jar.xml entries
===================
<entity>
        <display-name>ddc/DocumentPart</display-name>
        <ejb-name>ddc/DocumentPart</ejb-name>
        <home>mil.army.atsc.atia.ddc.ejb.interfaces.DocumentPartHome</home>
        <remote>mil.army.atsc.atia.ddc.ejb.interfaces.DocumentPart</remote>
        <ejb-class>mil.army.atsc.atia.ddc.ejb.DocumentPartEJB</ejb-class>
        <persistence-type>Bean</persistence-type>
        <prim-key-class>mil.army.atsc.atia.ddc.ejb.DocumentPartPK</prim-key-class>
        <reentrant>false</reentrant>
        <resource-ref>
                <res-ref-name>StaffingDB</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Container</res-auth>
        </resource-ref>
</entity>

...
<container-transaction>
        <method>
                <ejb-name>ddc/DocumentPart</ejb-name>
                <method-name>create</method-name>
        </method>
        <trans-attribute>RequiresNew</trans-attribute>
</container-transaction>
<container-transaction>
        <method>
                <ejb-name>ddc/DocumentPart</ejb-name>
                <method-name>*</method-name>
        </method>
        <trans-attribute>Required</trans-attribute>
</container-transaction>

Reply via email to