h22595
s 00018/00008/00073
d D 1.2 99/10/08 11:50:32 monicap 3 1
c 
e
s 00000/00000/00000
d R 1.2 99/06/02 12:10:35 Codemgr 2 1
c SunPro Code Manager data about conflicts, renames, etc...
c Name history : 1 0 developer/onlineTraining/Programming/JDCBook/Code/seller/SessSynch/SellerBean.java
e
s 00081/00000/00000
d D 1.1 99/06/02 12:10:34 monicap 1 0
c date and time created 99/06/02 12:10:34 by monicap
e
u
U
f e 0
t
T
I 1
package seller;

import java.rmi.RemoteException;
import javax.ejb.*;
import java.util.*;
import java.text.NumberFormat;
import java.io.Serializable;
import javax.naming.*;
import javax.jts.*;
import auction.*;
import registration.*;

D 3
public class SellerBean implements SessionBean, SessionSynchronization {
E 3
I 3
public class SellerBean implements SessionBean, 
			SessionSynchronization {
E 3

    private transient SessionContext ctx;
    private transient Properties p = new Properties();
    private transient boolean success = true;

    public void afterBegin() {
    }

    public void beforeCompletion() {
	
	if (!success ) {
	   ctx.setRollbackOnly();
	}
    }

    public void afterCompletion(boolean state) {
    }

D 3
    public int insertItem(String seller, String password, String description, int auctiondays, double startprice, String summary) throws RemoteException { 
E 3
I 3
    public int insertItem(String seller, String password, 
			String description, int auctiondays, 
			double startprice, String summary) 
			throws RemoteException { 
E 3

        try{
        Context jndiCtx = new InitialContext(p);

D 3
	RegistrationHome rhome = (RegistrationHome) jndiCtx.lookup("registration");
E 3
I 3
	RegistrationHome rhome = (RegistrationHome) 
			jndiCtx.lookup("registration");
E 3
	RegistrationPK rpk=new RegistrationPK();
	rpk.theuser=seller;
	Registration newseller=rhome.findByPrimaryKey(rpk);

D 3
	if((newseller == null) || (!newseller.verifyPassword(password))) {
E 3
I 3
	if((newseller == null) || 
		(!newseller.verifyPassword(password))) {
E 3
            return(Auction.INVALID_USER);	
	}
	newseller.adjustAccount(-0.50);

D 3
        AuctionItemHome home = (AuctionItemHome) jndiCtx.lookup("auctionitems");
        AuctionItem ai= home.create(seller, description, auctiondays, startprice, summary);
E 3
I 3
        AuctionItemHome home = (AuctionItemHome) 
			jndiCtx.lookup("auctionitems");
        AuctionItem ai= home.create(seller, description, 
			auctiondays, startprice, summary);
E 3
	if(ai == null) {
	   success=false;
           return Auction.INVALID_ITEM;
	} 
	else {
           return(ai.getId()); 
	}

        }catch(Exception e){ 
           System.out.println("insert problem="+e);
	   success=false;
           return Auction.INVALID_ITEM;
        }
    }

    public void ejbCreate() throws CreateException, RemoteException {
D 3
        p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.TengahInitialContextFactory");
E 3
I 3
        p.put(Context.INITIAL_CONTEXT_FACTORY, 
		"weblogic.jndi.TengahInitialContextFactory");
E 3
    }

D 3
    public void setSessionContext(SessionContext ctx) throws RemoteException {
E 3
I 3
    public void setSessionContext(SessionContext ctx) 
		throws RemoteException {
E 3
        this.ctx = ctx;
    }

    public void unsetSessionContext() throws RemoteException {   
        ctx = null;  
    } 

    public void ejbRemove() {}
    public void ejbActivate() throws RemoteException { }
    public void ejbPassivate() throws RemoteException { }
}


E 1
