Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / March 2005

Tip: Looking for answers? Try searching our database.

Using EJBS for audit fields

Thread view: 
Phoenix Silver - 22 Mar 2005 00:27 GMT
Hi

I'm using CMP EJB 2.0 on JBOSS 4.  and we have the standard database
audit field columns,
'created_by','created_datetime','modified_by','modified_datetime'

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 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.

Phoenix
R.F. Pels - 22 Mar 2005 13:10 GMT
> 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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.