// QueryBean.java
package miaJ2ee.ejb.server;
import java.util.ArrayList;
import javax.ejb.SessionBean; import javax.ejb.SessionContext;
import miaJ2ee.data.common.DataTransferObject; import miaJ2ee.ejb.client.QueryException; import miaJ2ee.dao.DataAccessObjectFactory;
import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator;
/** * QueryBean is the bean class for a stateless * session bean. */ public class QueryBean implements SessionBean { /** * Logger for this class. */ private static final Logger logger = Logger.getLogger("miaJ2ee.ejb.server.QueryBean");
/** * Info indicator for this class. */ private final boolean info = logger.isInfoEnabled();
public SessionContext context;
public void ejbActivate(){} public void ejbPassivate(){} public void ejbRemove(){}
public void ejbCreate() { PropertyConfigurator.configure("miaJ2ee.properties"); }
public void setSessionContext(SessionContext ctx) { context = ctx; }
/** * Get a DataTransferObject from the database. */ public DataTransferObject getObject(DataTransferObject data) throws QueryException { if (this.info) { logger.info("getObject() -- " + "Creating data access object by calling " + "DataAccessObjectFactory.createDao()..."); }
try
{
return DataAccessObjectFactory.createDao(data.getType()).getObject(data);
}
catch (Exception e)
{
throw new QueryException(e);
}
}
/** * Get an ArrayList of DataTransferObjects from the database. */ public ArrayList getObjectList(DataTransferObject data) throws QueryException { if (this.info) { logger.info("getObjectList() -- " + "Creating data access object by calling " + "DataAccessObjectFactory.createDao()..."); }
try
{
return DataAccessObjectFactory.createDao(data.getType()).getObjectList(data);
}
catch (Exception e)
{
throw new QueryException(e);
}
}
}
My EJB container is Sybase EAServer, so I had to write a custom appender that writes to my server's log file.
At 03:35 PM 04/19/2004 -0400, you wrote:
Hi, I am trying to put logger inside a stateless session bean, like
public class LegacyServiceBean implements SessionBean{ private Logger logger = Logger.getLogger(LegacyServiceBean.class); }
When I use IBM's AAT(version 4.00.032) to assemble the ear for OS390, I got the following warning,
/J2EE1DOT2AppEJB.jar(Field: class$0, Class: LegacyServiceBean: CHKJ2200W: The field is static but not final. Read section 18.1.2 of the EJB 1.1 specification.
I did not spend much on studying this, I am sure other peoples should have encoutered this.
What is the correct way to use log4j inside EJB?
Thanks,
Bosheng
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]