Hi Fei:

Actually, I am re-writing the code in Richard
Monson-Haefel's book to be EJB2.0 compilant. I have
changed a few things like CabinPK to be just a
java.lang.String. I also had to define certain methods
as abstract as required by EJB2.0. But anyways I am
sending the files with all the xml descriptors.
Lemme know if you think there is anything wrong.

I am sending it over the mailing list in case anyone
else is looking at the same problem.

Thanks,
Devand
------------------
package com.titan.cabin;

import java.rmi.RemoteException;

public interface Cabin extends javax.ejb.EJBObject
{
    public String getName() throws RemoteException;
    public void setName(String str) throws
RemoteException;
    public int getDeck_level() throws RemoteException;
    public void setDeck_level(int level) throws
RemoteException;
    public int getShip_id() throws RemoteException;
    public void setShip_id(int sp) throws
RemoteException;
    public int getBed_count() throws RemoteException;
    public void setBed_count(int be) throws
RemoteException;
    public String getId() throws RemoteException;
    public void setId(String ID) throws
RemoteException;
}
-------------

package com.titan.cabin;

import javax.ejb.EntityContext;

//public class CabinBean implements
javax.ejb.EntityBean
abstract public class CabinBean implements
javax.ejb.EntityBean
{

    public String ejbCreate(int id)
    {
                        setId(id+"");
        // I have mad the primary key to be a String! So have
to return
        // it in ejbCreate!
                        return getId();
    }

    public void ejbPostCreate(int id)
    {
        //Nothing required here...
    }

    abstract public String getName();
    abstract public void setName(String str);
    abstract public int getShip_id();
    abstract public void setShip_id(int id);
    abstract public int getBed_count();
    abstract public void setBed_count(int count);
    abstract public int  getDeck_level();
    abstract public void setDeck_level(int level);
    abstract public String getId();
    abstract public void  setId(String id);

    /*
    public String getNAME()
    {
        return name;
    }

    public void setNAME(String str)
    {
        name = str;
    }

    public int getSHIP_ID()
    {
        return ship;
    }

    public void setSHIP_ID(int sp)
    {
        ship = sp;
    }

    public int getBED_COUNT()
    {
        return bedCount;
    }

    public void setBED_COUNT(int bc)
    {
        bedCount = bc;
    }

    public int getDECK_LEVEL()
    {
        return deckLevel;
    }

    public void setDECK_LEVEL(int level)
    {
        deckLevel = level;
    }

    public String getID()
    {
        return id+"";
    }

    public void setID(String ID)
    {
        Integer i = new Integer(ID);
        this.id = i.intValue();
    }
    */
    public void setEntityContext(EntityContext ctx)
    {
        // Nothing to do here ...
    }

    public void unsetEntityContext()
    {
        // Nothing to do here ...
    }

    public void ejbActivate()
    {
        // Nothing to do here ...
    }

    public void ejbPassivate()
    {
        // Nothing to do here ...
    }

    public void ejbLoad()
    {
        // Nothing to do here ...
    }

    public void ejbStore()
    {
        // Nothig to do here ...
    }

    public void ejbRemove()
    {
        // Nothing to do here ...
    }
}

-------------
package com.titan.cabin;

import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.FinderException;

public interface CabinHome extends javax.ejb.EJBHome
{
        public Cabin create(int id)
                throws CreateException, RemoteException;
        public Cabin findByPrimaryKey(String pk)
                throws FinderException, RemoteException;
}
---------------

import com.titan.cabin.CabinHome;
import com.titan.cabin.Cabin;

import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
import java.rmi.RemoteException;
import javax.rmi.PortableRemoteObject;
import java.util.Properties;

public class Client
{
    public static void main(String args[])
    {
        try
            {
                System.out.print("Looking up JNDI..");
                Context jndiContext = getInitialContext();
                Object obj =
(CabinHome)jndiContext.lookup("CabinHome");
                CabinHome home =
(CabinHome)PortableRemoteObject.narrow
                    (obj,CabinHome.class);
                System.out.println("Success!");
                Cabin cabin1 = home.create(1);
                System.out.println("Created Home!");
                cabin1.setName("Master Suite");
                cabin1.setDeck_level(1);
                cabin1.setShip_id(1);
                cabin1.setBed_count(3);
                System.out.println("Inserted the values in the
database");
                System.out.println("Trying to Lookup the Same
Information");
                Cabin cabin2 = home.findByPrimaryKey("1");
                System.out.println(cabin2.getName());
                System.out.println(cabin2.getDeck_level());
                System.out.println(cabin2.getShip_id());
                System.out.println(cabin2.getBed_count());
                System.out.println(cabin2.getId());
            }
        catch(java.rmi.RemoteException
re){re.printStackTrace();}
        catch(javax.naming.NamingException
ne){ne.printStackTrace();}
        catch(javax.ejb.CreateException
ce){ce.printStackTrace();}
        catch(javax.ejb.FinderException
fe){fe.printStackTrace();}
    }

    public static Context getInitialContext()
        throws javax.naming.NamingException
    {
        Properties p = new Properties();
        // This part is specific to weblogic.
        p.put(Context.INITIAL_CONTEXT_FACTORY,
              "weblogic.jndi.WLInitialContextFactory");
        p.put(Context.PROVIDER_URL,"t3://localhost:7001");
        // Till here!
        return new javax.naming.InitialContext(p);
    }
}
-----------------
<?xml version="1.0"?>

<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems,
Inc.//DTD Enterprise JavaBeans 2.0//EN"
"http://java.sun.com/dtd/ejb-jar_2_0.dtd">

<ejb-jar>
  <enterprise-beans>
          <entity>
                  <ejb-name>TapBean</ejb-name>
            <home>com.titan.cabin.CabinHome</home>
            <remote>com.titan.cabin.Cabin</remote>
            <ejb-class>com.titan.cabin.CabinBean</ejb-class>
            <persistence-type>Container</persistence-type>
            <prim-key-class>java.lang.String</prim-key-class>
            <reentrant>False</reentrant>
            <cmp-version>2.x</cmp-version>


<abstract-schema-name>cabin</abstract-schema-name>
            <cmp-field>
              <field-name>id</field-name>
            </cmp-field>
            <cmp-field>
              <field-name>ship_id</field-name>
            </cmp-field>
            <cmp-field>
              <field-name>bed_count</field-name>
            </cmp-field>
            <cmp-field>
              <field-name>name</field-name>
            </cmp-field>
            <cmp-field>
              <field-name>deck_level</field-name>
            </cmp-field>
            <primkey-field>id</primkey-field>
<!--
        These are required if I need to define some more
methods in my
        EJBHome file (CabinHome.java) which require database
operation
        since I have only, findByPrimaryKet() method I do not
need to do
        anything. Looks like I don't need to define that
method here!
        <query>
          <query-method>
          <method-name>findBigAccounts</method-name>
          <method-params>
          <method-param>double</method-param>
          </method-params>
          </query-method>
          <ejb-ql>
             <![CDATA[FROM AccountBean AS a WHERE
a.balance > ?1]]>
          </ejb-ql>
         </query>
         <query>
            <query-method>
            <method-name>findAccount</method-name>
            <method-params>
            <method-param>double</method-param>
            </method-params>
            </query-method>
            <ejb-ql>
              <![CDATA[FROM AccountBean AS a WHERE
a.balance = ?1]]>
            </ejb-ql>
         </query>

         <query>
           <query-method>
           <method-name>findNullAccounts</method-name>
           <method-params>
           </method-params>
           </query-method>
           <ejb-ql>
             <![CDATA[FROM AccountBean AS a WHERE
a.accountType IS NULL]]>
           </ejb-ql>
          </query>
-->

  </entity>
  </enterprise-beans>
  <assembly-descriptor>
   <container-transaction>
          <method>
            <ejb-name>TapBean</ejb-name>
            <method-intf>Remote</method-intf>
            <method-name>*</method-name>
         </method>
          <trans-attribute>Required</trans-attribute>
   </container-transaction>
  </assembly-descriptor>
</ejb-jar>
----------
<!DOCTYPE weblogic-rdbms-jar PUBLIC '-//BEA Systems,
Inc.//DTD WebLogic 6.0.0 EJB RDBMS Persistence//EN'
'http://www.bea.com/servers/wls600/dtd/weblogic-rdbms20-persistence-600.dtd'>

<weblogic-rdbms-jar>
  <weblogic-rdbms-bean>
    <ejb-name>TapBean</ejb-name>
    <data-source-name>insomnia</data-source-name>
    <table-name>cabin</table-name>

    <field-map>
      <cmp-field>id</cmp-field>
      <dbms-column>ID</dbms-column>
    </field-map>

    <field-map>
      <cmp-field>ship_id</cmp-field>
      <dbms-column>SHIP_ID</dbms-column>
    </field-map>

    <field-map>
      <cmp-field>bed_count</cmp-field>
      <dbms-column>BED_COUNT</dbms-column>
    </field-map>

    <field-map>
      <cmp-field>name</cmp-field>
      <dbms-column>NAME</dbms-column>
    </field-map>

    <field-map>
      <cmp-field>deck_level</cmp-field>
      <dbms-column>DECK_LEVEL</dbms-column>
    </field-map>

  </weblogic-rdbms-bean>
</weblogic-rdbms-jar>
----------

<?xml version="1.0"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC "-//BEA Systems,
Inc.//DTD WebLogic 6.0.0 EJB//EN"
"http://www.bea.com/servers/wls600/dtd/weblogic-ejb-jar.dtd"
>


<weblogic-ejb-jar>
  <weblogic-enterprise-bean>
    <ejb-name>
                        TapBean
    </ejb-name>

    <entity-descriptor>
      <entity-cache>
        <max-beans-in-cache>1000</max-beans-in-cache>
      </entity-cache>

      <persistence>
        <persistence-type>

<type-identifier>WebLogic_CMP_RDBMS</type-identifier>
          <type-version>6.0</type-version>

<type-storage>META-INF/weblogic-cmp-rdbms-jar.xml</type-storage>
        </persistence-type>
        <persistence-use>

<type-identifier>WebLogic_CMP_RDBMS</type-identifier>
          <type-version>6.0</type-version>
        </persistence-use>
      </persistence>

    </entity-descriptor>

    <jndi-name>CabinHome</jndi-name>

  </weblogic-enterprise-bean>

</weblogic-ejb-jar>
--------

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/?.refer=text

===========================================================================
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