FileDocCategorySizeDatePackage
ManagerCMTDBean.javaAPI DocExample7805Thu Dec 15 21:52:06 GMT 2005com.oreilly.jent.transactions.cmtd

ManagerCMTDBean

public class ManagerCMTDBean extends Object implements javax.ejb.SessionBean
In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product's documentation does require permission. We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "Java Enterprise in a Nutshell, Third Edition, by Jim Farley and William Crawford with Prakash Malani, John G. Norman, and Justin Gehtland. Copyright 2006 O'Reilly Media, Inc., 0-596-10142-2." If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com.

Fields Summary
protected static Logger
sLogger
protected javax.ejb.SessionContext
mSessionContext
Constructors Summary
Methods Summary
protected com.oreilly.jent.transactions.domain.PersonValuecreatePerson(com.oreilly.jent.transactions.domain.PersonValue aPersonValue)

        sLogger.info("5 creating person in manager cmtd bean ...");

        try {
            InitialContext aInitialContext = new InitialContext();
            PersonHome aPersonHome = (PersonHome) aInitialContext.lookup("java:comp/env/ejb/Person");
            Person p = aPersonHome.create(aPersonValue.getEmail(), aPersonValue.getPassword());
            p.setWorkPhone(aPersonValue.getWorkPhone());
            p.setHomePhone(aPersonValue.getHomePhone());

            sLogger.info("Created a person with id : " + p.getPersonId());
            aPersonValue.setPersonId(p.getPersonId());
        } catch (Exception e) {
            String aMessage = "exception occured in manager cmtd bean.createPersonNewTransaction ";
            sLogger.log(Level.SEVERE, aMessage, e);
            throw new EJBException(aMessage, e);
        }

        return aPersonValue;
    
public com.oreilly.jent.transactions.domain.PersonValuecreatePersonAndStatus(com.oreilly.jent.transactions.domain.PersonValue aPersonValue, com.oreilly.jent.transactions.domain.PersonStatusValue aPersonStatusValue)

        aPersonValue = createPersonNewTransaction(aPersonValue);
        aPersonStatusValue = createPersonStatus(aPersonValue, 
                                                aPersonStatusValue);
        return aPersonValue;
    
public com.oreilly.jent.transactions.domain.PersonValuecreatePersonAndStatusNew(com.oreilly.jent.transactions.domain.PersonValue aPersonValue, com.oreilly.jent.transactions.domain.PersonStatusValue aPersonStatusValue)

        aPersonValue = 
            ((ManagerCMTD) mSessionContext.getEJBObject()).createPersonNewTransaction(
                aPersonValue);
        aPersonStatusValue = createPersonStatus(aPersonValue, 
                                                aPersonStatusValue);
        return aPersonValue;
    
public com.oreilly.jent.transactions.domain.PersonValuecreatePersonNewTransaction(com.oreilly.jent.transactions.domain.PersonValue aPersonValue)

        return createPerson(aPersonValue);
    
public com.oreilly.jent.transactions.domain.PersonValuecreatePersonSameTransaction(com.oreilly.jent.transactions.domain.PersonValue aPersonValue)

        return createPerson(aPersonValue);
    
protected com.oreilly.jent.transactions.domain.PersonStatusValuecreatePersonStatus(com.oreilly.jent.transactions.domain.PersonValue aPersonValue, com.oreilly.jent.transactions.domain.PersonStatusValue aPersonStatusValue)

        try {
             InitialContext aInitialContext = new InitialContext();
             PersonHome aPersonHome = (PersonHome) aInitialContext.lookup("java:comp/env/ejb/Person");
             Person aPerson = aPersonHome.findByPrimaryKey(aPersonValue.getPersonId());

             PersonStatusHome aPersonStatusHome = (PersonStatusHome) aInitialContext.lookup(
                 "java:comp/env/ejb/PersonStatus"
             );
             PersonStatus aPersonStatus = aPersonStatusHome.create(aPerson);
             aPersonStatus.setStatus(aPersonStatusValue.getStatus());
             aPersonStatus.setStatusComment(aPersonStatusValue.getStatusComment());

             aPersonStatusValue.setId(aPersonStatus.getPersonStatusId());

             aPersonValue.setPersonStatusValue(aPersonStatusValue);
             return aPersonStatusValue;
         } catch (Exception e) {
             String aMessage = "exception occured in manager cmtd bean. create person and status";
             sLogger.log(Level.SEVERE, aMessage, e);
             throw new EJBException (aMessage, e);
         }
    
public voidejbActivate()

    
public voidejbCreate()


       

    
public voidejbPassivate()

    
public voidejbRemove()

    
public java.util.CollectiongetAllPersons()

        sLogger.info("creating person in manager cmtd bean. find all person...");
        Collection c = new ArrayList();
        try {
            InitialContext aInitialContext = new InitialContext();
            PersonHome aPersonHome = (PersonHome) aInitialContext.lookup("java:comp/env/ejb/Person");
            Collection aPersonCollection = aPersonHome.findAll();
            Iterator i = aPersonCollection.iterator();
            while (i.hasNext()) {
                Person aPerson = (Person) i.next();
                c.add(toValue(aPerson));
            }
        } catch (Exception e) {
            String aMessage = "exception occured in manager cmtd bean.find all person";
            sLogger.log(Level.SEVERE, aMessage, e);
            throw new EJBException(aMessage, e);
        }
        return c;
    
public voidsetSessionContext(javax.ejb.SessionContext aSessionContext)

        mSessionContext = aSessionContext;
    
protected com.oreilly.jent.transactions.domain.PersonValuetoValue(com.oreilly.jent.transactions.domain.Person aPerson)

        PersonValue aPersonValue = new PersonValue();
        if (aPerson != null) {
            aPersonValue.setEmail(aPerson.getEmail());
            aPersonValue.setFAX(aPerson.getFAX());
            aPersonValue.setHomePhone(aPerson.getHomePhone());
            //aPersonValue.setPassword(aPerson.getPassword());
            aPersonValue.setPersonId(aPerson.getPersonId());
            aPersonValue.setWorkPhone(aPerson.getWorkPhone());

            aPersonValue.setPersonStatusValue(toValue(aPerson.getPersonStatus()));
        }
        return aPersonValue;
    
protected com.oreilly.jent.transactions.domain.PersonStatusValuetoValue(com.oreilly.jent.transactions.domain.PersonStatus aLocal)

        PersonStatusValue aValue = new PersonStatusValue();
        if (aLocal != null) {
            aValue.setId(aLocal.getPersonStatusId());
            aValue.setStatus(aLocal.getStatus());
            aValue.setStatusComment(aLocal.getStatusComment());
        }
        return aValue;