> Does anyone have an implemented solution using EJBS to demonstrate how
> I would do this effeiciently. Right now we're not using any JAAS so I
> pass a createdBy username to a single method that calls all of the
> others setters for datetime and so on.
I'm looking into this. I did it a bit different since I don't use the
standard names. I inherit from AuditBean that has 4 CMP fields for each
audit field, plus I added 4 xdoclet tags to connect the dots as it were.
Then I inherit from AuditBean if I want to have auditing fields to a
dependent bean.
This will add <audit>...</audit> tags in jbosscmp-jdbc.xml as needed.
Additionally, you need to set the securityDomain value in the jboss xdoclet
which adds the security-domain tag to jboss.xml
> I tried to use inheritance but it didn't work at first and I didnt' have
> time to figure it out. If anyone has an example of this that uses XDoclet
> as well this would be really great.
How's this?
import java.rmi.RemoteException;
import java.sql.Timestamp;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
/**
* The AuditBean serves as a parent to other Pekunia entity beans.
* It provides CMP fields for the standard audit fields provided
* by JBoss if there is a security context running for the
* application.
*
* @ejb.bean
* name="Audit"
* display-name="AuditBean"
* description="Base bean serving as parent for others"
* jndi-name="ejb/pekunia/AuditBean"
* type="CMP"
* cmp-version="2.x"
* view-type="both"
*
* @jboss.audit-created-by
* field-name="createdBy"
* column-name="createdby"
* jdbc-type="VARCHAR"
* sql-type="VARCHAR(20)"
*
* @jboss.audit-created-time
* field-name="createdTime"
* column-name="createdon"
* jdbc-type="TIMESTAMP"
* sql-type="TIMESTAMP"
*
* @jboss.audit-updated-by
* field-name="updatedBy"
* column-name="updatedby"
* jdbc-type="VARCHAR"
* sql-type="VARCHAR(20)"
*
* @jboss.audit-updated-time
* field-name="updatedTime"
* column-name="updatedon"
* jdbc-type="TIMESTAMP"
* sql-type="TIMESTAMP"
*/
public abstract class AuditBean
implements EntityBean
{
// ELIDED ctor and ejbXXX stuff
/**
* Getter for CMP Field createdBy
* @return identity of creator
*
* @ejb.persistence
* column-name = "createdby"
* jdbc-type = "VARCHAR"
* sql-type = "VARCHAR(20)"
*
* @ejb.interface-method
* view-type="both"
*/
public abstract String getCreatedBy();
/**
* Getter for CMP Field createdTime
* @return creation time
*
* @ejb.persistence
* column-name = "createdon"
* jdbc-type = "TIMESTAMP"
* sql-type = "TIMESTAMP"
* read-only = "true"
*
* @ejb.interface-method
* view-type="both"
*/
public abstract Timestamp getCreatedTime();
/**
* Getter for CMP Field updatedBy
* @return identity of updater
*
* @ejb.persistence
* column-name = "updatedby"
* jdbc-type = "TIMESTAMP"
* sql-type = "TIMESTAMP"
* read-only = "true"
*
* @ejb.interface-method
* view-type="both"
*/
public abstract String getUpdatedBy();
/**
* Getter for CMP Field updatedTime
* @return update time
*
* @ejb.persistence
* column-name = "updatedon"
* jdbc-type = "TIMESTAMP"
* sql-type = "TIMESTAMP"
* read-only = "true"
*
* @ejb.interface-method
* view-type="both"
*/
public abstract Timestamp getUpdatedTime();
/**
* Setter for CMP Field createdBy
* @param value new creator
*
* @ejb.interface-method
* view-type="local"
*/
public abstract void setCreatedBy(String value);
/**
* Setter for CMP Field createdTime
* @param value new creation time
*
* @ejb.interface-method
* view-type="local"
*/
public abstract void setCreatedTime(Timestamp value);
/**
* Remember entity context
* @param ctx the context
*/
public void setEntityContext(EntityContext ctx) throws EJBException,
RemoteException
{
context = ctx;
}
/**
* Setter for CMP Field updatedBy
* @param value new updater
*
* @ejb.interface-method
* view-type="local"
*/
public abstract void setUpdatedBy(String value);
/**
* Setter for CMP Field updatedTime
* @param value new update time
*
* @ejb.interface-method
* view-type="local"
*/
public abstract void setUpdatedTime(Timestamp value);
private EntityContext context = null;
}

Signature
Ruurd
.o.
..o
ooo