Hi All,
I have some doubts on EJB, kindly look at the following points and the code
and let me know at your convenience. I am using weblogic5.10 as my
application server and jsps as client programs.

1. Is weblogic has separate way of ejb implementation?
2. Is it compulsory to write some code in container functions ( ejbLoad(),
ejbStore(), ejbCreate() etc., )  in BMP
3. Can write any number of ejb components
4. How do I handle long transactions in ejb when multiple users are doing
transactions(how do I prevent write-write conflict) ?
5. Is it better to write session beans for the above situation

Please go through the code attached kindly let me know if any problems with
code.

Thanks in advance, Vinod

************************************* bean
***********************************************


import java.util.*;
import javax.servlet.http.*;
import java.sql.*;
import java.lang.*;
import java.text.*;
import java.math.*;
import javax.ejb.*;
import java.rmi.RemoteException;
import javax.servlet.http.*;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.*;
import javax.sql.DataSource;



public class Test implements EntityBean
{
        final static private boolean VERBOSE = true;

    protected EntityContext entityContext;

    public int CMID,NUM,GENID;
    double
SV1SL,SV1SH,SV1SP,SV2SL,SV2SH,SV2SP,SV3SL,SV3SH,SV3SP,SV4SL,SV4SH,SV4SP,SV5S
L,SV5SH,SV5SP,TV1SL,TV1SH,TULF1,TV1FFC,TV2SL,TV2SH,TULF2,TV2FFC,TV3SL,TV3SH,
TULF3,TV3FFC,TV4SL,TV4SH,TULF4,TV4FFC,TV5SL,TV5SH,TULF5,TV5FFC;
        //PrintWriter out;

        public String NAME;
        Connection con=null;
        String strSec=null;
        //RandomAccessFile ra=null;
        String newLine = null;



        public Test2BeanPK ejbCreate(int cmid,double sv1sl,double sv1sh,double
sv1sp,double sv2sl,double sv2sh,double sv2sp,double sv3sl,double
sv3sh,double sv3sp,double sv4sl,double sv4sh,double sv4sp,double
sv5sl,double sv5sh,double sv5sp,double tv1sl,double tv1sh,double
tulf1,double tv1ffc,double tv2sl,double tv2sh,double tulf2,double
tv2ffc,double tv3sl,double tv3sh,double tulf3,double tv3ffc,double
tv4sl,double tv4sh,double tulf4,double tv4ffc,double tv5sl,double
tv5sh,double tulf5,double tv5ffc)
          throws RemoteException, EJBException, CreateException
         {


                if(con==null)
                {
                                try
                                {

                                getConnection();

                                }
                                catch(SQLException ee)
                                {
                                        System.out.println(ee.getMessage());

                                }

                }


                CMID=cmid;
                SV1SL=sv1sl;
                SV1SH=sv1sh;
                SV1SP=sv1sp;
                SV2SL=sv2sl;
                SV2SH=sv2sh;
                SV2SP=sv2sp;
                SV3SL=sv3sl;
                SV3SH=sv3sh;
                SV3SP=sv3sp;
                SV4SL=sv4sl;
                SV4SH=sv4sh;
                SV4SP=sv4sp;
                SV5SL=sv5sl;
                SV5SH=sv5sh;
                SV5SP=sv5sp;
                TV1SL=tv1sl;
                TV1SH=tv1sh;
                TULF1=tulf1;
                TV1FFC=tv1ffc;
                TV2SL=tv2sl;
                TV2SH=tv2sh;
                TULF2=tulf2;
                TV2FFC=tv2ffc;
                TV3SL=tv3sl;
                TV3SH=tv3sh;
                TULF3=tulf3;
                TV3FFC=tv3ffc;
                TV4SL=tv4sl;
                TV4SH=tv4sh;
                TULF4=tulf4;
                TV4FFC=tv4ffc;
                TV5SL=tv5sl;
                TV5SH=tv5sh;
                TULF5=tulf5;
                TV5FFC=tv5ffc;

            return new Test2BeanPK();
          }
         public Test2BeanPK ejbCreate(int genid,int num,String name)throws
RemoteException, EJBException, CreateException

         {


                if(con==null)
                {
                                try
                                {

                                getConnection();

                                }
                                catch(SQLException ee)
                                {
                                        System.out.println(ee.getMessage());

                                }

                }
                 GENID=genid;
                 NUM = num;
                 NAME = name;
                 return new Test2BeanPK();
         }

     public Test2BeanPK ejbCreate()throws RemoteException, EJBException,
CreateException
         {



                if(con==null)
                {
                                try
                                {

                                getConnection();

                                }
                                catch(SQLException ee)
                                {
                                        System.out.println(ee.getMessage());

                                }

                }
                return new Test2BeanPK();
         }


         /**
            * Required by the EJB specification, this method is not used
            * by this application.
     */

         public void ejbPostCreate(int cmid,double sv1sl,double sv1sh,double
sv1sp,double sv2sl,double sv2sh,double sv2sp,double sv3sl,double
sv3sh,double sv3sp,double sv4sl,double sv4sh,double sv4sp,double
sv5sl,double sv5sh,double sv5sp,double tv1sl,double tv1sh,double
tulf1,double tv1ffc,double tv2sl,double tv2sh,double tulf2,double
tv2ffc,double tv3sl,double tv3sh,double tulf3,double tv3ffc,double
tv4sl,double tv4sh,double tulf4,double tv4ffc,double tv5sl,double
tv5sh,double tulf5,double tv5ffc)
            throws EJBException
         {
            // do nothing
         }


         public void ejbPostCreate(int genid,int num, String name)
            throws EJBException
         {
                // do nothing
         }

         public void ejbPostCreate() throws EJBException
         {
                // do nothing
         }

         public Test2BeanPK ejbFindByPrimaryKey(Test2BeanPK pk) throws
FinderException
         {
                 return pk;
         }

         /**
            * Required by the EJB specification, this method is not used
            * by this application.
     */

         public void ejbActivate() throws EJBException
         {
            // do nothing
         }



         public void ejbLoad() throws EJBException
         {
            // do nothing


         }

         /**
                    * Required by the EJB specification, this method is not used
                    * by this application.
     */

         public void ejbPassivate() throws EJBException
         {

           // do nothing
         }

         public void ejbRemove() throws EJBException
         {
            // do nothing
         }

          public void ejbStore() throws EJBException {
            // do nothing
          }

          /**
             * Sets the EntityContext for the EJBean.
             *
             * @param ctx               EntityContext
          */
          public void setEntityContext(EntityContext ctx) throws EJBException {
            entityContext = ctx;
          }

          /**
             * Unsets the EntityContext for the EJBean.
      */
          public void unsetEntityContext() {
            entityContext=null;
          }

/*********** Business Methods ***************************************/



   public ResultSet executeQuery(String stmt)throws SQLException
   {
                String retVal = "";
                ResultSet rs=null;
                try
                {

                  Statement  s = con.createStatement();
                  rs = s.executeQuery(stmt);

                }

                catch (SQLException e) {retVal = e.toString();}
                catch (Exception e) {retVal = e.toString();}
                return(rs);
 }

/************** Executes an query update *******************/

public void updateQuery(String stmt)throws SQLException
 {

                String retVal = "";
                try
                {

                  Statement  s = con.createStatement();
                  s.executeUpdate(stmt);
                }

                catch (SQLException e) {retVal = e.toString();}
                catch (Exception e) {retVal = e.toString();}
  }
/************* to get an ID **************************************/

public String getID(String stmt)throws SQLException
   {
                String retVal = "";
                ResultSet rs=null;
                try
                {

                  Statement  s = con.createStatement();
                  rs = s.executeQuery("stmt");
                }

                catch (SQLException e) { return "SQL error";}
                catch (Exception e) {return e.getMessage();}
                rs.next();
                return(rs.getString(1));
  }






public Vector viewTest1(String strId, String strDate)

{

}



/*****************end of business methods*******************************/
     public double getRoundValue(double d)
    {
                BigDecimal rounder =new BigDecimal(0.00);
        try

        {
                rounder=new BigDecimal(d).setScale(2,BigDecimal.ROUND_HALF_DOWN);
         }
        catch(Exception e) { };
    return rounder.doubleValue();
    }

  public void getConnection()  throws SQLException
  {


    InitialContext initCtx = null;
    try {
      initCtx = new InitialContext();
      System.out.println("Attempting to lookup weblogic Database pool");
      DataSource ds =
(javax.sql.DataSource)initCtx.lookup("java:comp/env/jdbc/Test");

      System.out.println("Found Connection Pool");


      try
      {
                  System.out.println("Attempting to get connection from weblogic 
Database
pool");
                  this.con=ds.getConnection();
      }  catch(SQLException e) { System.out.println("Error getting
connection"+e); }
    System.out.println("Connection Retrieved");
    } catch(NamingException ne) {
      System.out.println("UNABLE to get a connection from OraclePool!");
        throw new EJBException(ne);
    } finally {
      try {
        if(initCtx != null) initCtx.close();
      } catch(NamingException ne) {
        System.out.println("Error closing context: " + ne);
        throw new EJBException(ne);
      }
    }
  }


 /************************************************************************/


  // Validation for the Integer values

  /*

        * @param     String id
        * @return    boolean
  */


   public  boolean intvalidate(String id)
   {

        try{
                Integer i = new Integer(id);
            }catch(NumberFormatException msg ){ return false; }
        return true;
        }

/*************************************************************************/

  public Vector viewTest(String strId, String strDate)
  {
          //not implemented
  }


  public Vector viewTest3(String strId, String strDate)
  {
          //not implemented
  }





public void closeAll() throws SQLException
{


        try
                                        {
                     if(con!=null)
                     {
                         con.close();
                         System.out.println("Connection closed");
                                     }
                                        }
                                        catch(SQLException ee)
                                        {
                                                System.out.println(ee.getMessage());

                }


}
} //end of TestBean

************************** jsp ******************************
<%


                 Context ctx=null;
                 Test test = null;
                 Vector vcData = new Vector();
      try {

             ctx = new InitialContext();
             TestBeanHome home = (TestBeanHome) ctx.lookup("TestBeanHome");
             test =  home.create();

             vcData =
bill2.viewTest(request.getParameter("coyID"),request.getParameter("month")+r
equest.getParameter("year"));

 %>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to