Hi all,

I asked few doubts regarding CMP 1.1 in my previous mail. My third query
went answered. Somebody plz  clarify on that.

3) I was goin thru AggregateEntity Pattern. The pattern directs to use a
Coarse Grained Object composed of various Fine Grained Object. And the
Aggregate Entity(EJB) will have Coarse Grained Object as one of its
instance(one of strategy). In this case how will I map the Coarse Grained
Object to the persistence Schema.

I have presented an EJB(see below) demonstrating the usuage of reference to
a Remote Object within a CMP. This is a test sample and it works well. Plz
let me know whether the approach is correct.

And if I implement Address as an Dependent Object instead of entity bean,
then again how do I persist the information from the dependent object to the
Database.


Thanks,


Shreedhar Natarajan


/* Source */

package com.ami.customer.customer;

import java.rmi.*;
import java.util.*;

import javax.ejb.*;
import javax.naming.*;
import javax.rmi.*;
import com.ami.customer.address.*;
import com.ami.customer.valueobjects.AddressVO;

/**
 *
 */
public class CustomerEJB implements EntityBean
{
    private Context initialContext;
    private EntityContext ejbContext;

    /*
      For every customer id there is an entity in the Address table.
       Customer id links the customer table and the address table
    */

    public String id;
    public transient Address address; // Remote reference to the address
ejb.

    public String ejbCreate(String _id, AddressVO _addressVO) throws
CreateException
    {
        this.id = _id;

        try
        {
            createAddress(_addressVO);
        }
        catch(Exception e)
        {
            throw new CreateException(e.getMessage());
        }




        return null;
    }

    public void ejbPostCreate(String _id, AddressVO _addressVO) throws
CreateException
    {
        // Nothing to do here

    }

    public void ejbActivate() throws EJBException
    {
    }

    public void ejbPassivate() throws EJBException
    {
        this.address = null;
    }

    public void ejbRemove() throws EJBException
    {
         this.address=null;
    }

    public void ejbLoad() throws EJBException
    {

        try
        {
                        if (this.address == null)
                    this.loadAddress();
        }
        catch(Exception e)
        {
            throw new EJBException(e);
        }


    }

    public void ejbStore() throws EJBException
    {

    }

    public void setEntityContext(EntityContext ctx) throws EJBException
    {
        ejbContext = ctx;
    }

    public void unsetEntityContext() throws EJBException
    {
        ejbContext = null;
    }

    public AddressVO getAddress()
    {
        try
        {
            return address.getAddress() ;
        }
        catch(Exception exception)
        {
            throw new EJBException(exception);
        }
    }

    /**
     * Set address
     *
     * @param address
     */


    public void createAddress(AddressVO _addressVO) throws Exception
    {
        try
        {
            InitialContext jndiContext = new InitialContext();
            Object addrRef =
jndiContext.lookup("java:comp/env/ejb/Address");
            AddressHome addressHome =
                        (AddressHome) PortableRemoteObject.narrow( addrRef,
AddressHome.class);
            this.address = addressHome.create(this.id,_addressVO);
        }
        catch(Exception e)
        {
            throw e;
        }


    }
    public void loadAddress() throws Exception
    {

                        InitialContext jndiContext = new InitialContext();
                        Object addrRef =
jndiContext.lookup("java:comp/env/ejb/Address");
                        AddressHome addressHome =
                                (AddressHome) PortableRemoteObject.narrow(
addrRef, AddressHome.class);
                        this.address =
addressHome.findByPrimaryKey(this.id);


    }


}



// End of Source

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