User: oberg
Date: 00/08/25 06:43:40
Added: src/main/org/jboss/test/idgen/ejb IdCounterBean.java
IdCounterBeanCMP.java IdGeneratorBean.java
Log:
Added perf tests and idgen
Revision Changes Path
1.1 jbosstest/src/main/org/jboss/test/idgen/ejb/IdCounterBean.java
Index: IdCounterBean.java
===================================================================
/*
* Copyright 1999 by dreamBean Software,
* All rights reserved.
*/
package org.jboss.test.idgen.ejb;
import java.rmi.RemoteException;
import javax.ejb.*;
import javax.naming.*;
import org.jboss.test.util.ejb.EntitySupport;
/**
*
* @see <related>
* @author $Author: oberg $
* @version $Revision: 1.1 $
*/
public abstract class IdCounterBean
extends EntitySupport
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
long nextId;
long size;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
public long getNext()
{
// Is sequence finished?
// If so start a new one
if (nextId == (getCurrent() + size))
{
setCurrent(nextId);
}
return nextId++;
}
public abstract long getCurrent();
public abstract void setCurrent(long current);
public abstract String getName();
public abstract void setName(String beanName);
public void ejbLoad()
throws RemoteException
{
nextId = getCurrent();
}
public void setEntityContext(EntityContext ctx)
throws RemoteException
{
super.setEntityContext(ctx);
try
{
size = ((Long)new
InitialContext().lookup("java:comp/env/size")).longValue();
} catch (Exception e)
{
throw new EJBException(e);
}
}
}
1.1
jbosstest/src/main/org/jboss/test/idgen/ejb/IdCounterBeanCMP.java
Index: IdCounterBeanCMP.java
===================================================================
/*
* Copyright 1999 by dreamBean Software,
* All rights reserved.
*/
package org.jboss.test.idgen.ejb;
import java.io.ObjectStreamException;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
/**
*
* @see <related>
* @author $Author: oberg $
* @version $Revision: 1.1 $
*/
public class IdCounterBeanCMP
extends IdCounterBean
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
public String name;
public long current;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
public long getCurrent()
{
return current;
}
public void setCurrent(long current)
{
this.current = current;
}
public String getName()
{
return name;
}
public void setName(String beanName)
{
this.name = beanName;
}
// EntityBean implementation -------------------------------------
public String ejbCreate(String name)
throws RemoteException, CreateException
{
setName(name);
current = 0;
return null;
}
public void ejbPostCreate(String name)
throws RemoteException, CreateException
{
}
}
1.1 jbosstest/src/main/org/jboss/test/idgen/ejb/IdGeneratorBean.java
Index: IdGeneratorBean.java
===================================================================
/*
* Copyright 1999 by dreamBean Software,
* All rights reserved.
*/
package org.jboss.test.idgen.ejb;
import java.rmi.*;
import javax.naming.*;
import javax.ejb.*;
import org.jboss.test.util.ejb.SessionSupport;
import org.jboss.test.idgen.interfaces.*;
/**
*
* @see <related>
* @author $Author: oberg $
* @version $Revision: 1.1 $
*/
public class IdGeneratorBean
extends SessionSupport
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
IdCounterHome counterHome;
// Static --------------------------------------------------------
static final String SIZE = "java:comp/env/size";
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
public long getNewId(String beanName)
throws RemoteException
{
IdCounter counter;
// Acquire counter
try
{
counter = counterHome.findByPrimaryKey(beanName);
} catch (FinderException e)
{
try
{
counter = counterHome.create(beanName);
} catch (CreateException ex)
{
throw new EJBException("Could not find or create
counter for "+beanName);
}
}
// Get id
return counter.getNext();
}
// SessionBean implementation ------------------------------------
public void setSessionContext(SessionContext context)
{
super.setSessionContext(context);
try
{
counterHome = (IdCounterHome)new
InitialContext().lookup("java:comp/env/ejb/IdCounter");
} catch (Exception e)
{
throw new EJBException(e);
}
}
}
/*
* $Id: IdGeneratorBean.java,v 1.1 2000/08/25 13:43:40 oberg Exp $
* Currently locked by:$Locker: $
* Revision:
* $Log: IdGeneratorBean.java,v $
* Revision 1.1 2000/08/25 13:43:40 oberg
* Added perf tests and idgen
*
*
*
*/