Hi.

  Unfortunately i did not receive any answers to the question about referential 
integrity i had posted more than week ago 
(http://www.jboss.org/index.html?module=bb&op=viewtopic&t=60776). The matter is 
in making it impossible to delete an entity bean instance while it is 
referenced from some other entity bean instance. Actually, this is common 
behavior of any relational database, but this contradicts with ejb spec which 
states that 

anonymous wrote : ...After the Bean Provider?s ejbRemove method returns (and 
prior to returning to the client), the container must remove the entity object 
from all relationships in which it participates, and then remove its persistent 
representation.

 The only solution i can see is to opt for capabilities of underling ER 
persistence layer and to to implement special interceptor to be inserted in the 
entity bean's interceptors chain.  As far as i understood JBoss CMP APIs i 
sketched it as following:


  | /*
  |  * Created on 04.03.2005 13:45:27
  |  *
  |  */
  | package test.ejb;
  | 
  | import java.rmi.RemoteException;
  | 
  | import org.jboss.ejb.EntityContainer;
  | import org.jboss.ejb.EntityEnterpriseContext;
  | import org.jboss.ejb.EntityPersistenceManager;
  | import org.jboss.ejb.plugins.AbstractInterceptor;
  | import org.jboss.ejb.plugins.CMPPersistenceManager;
  | import org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager;
  | import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge;
  | import org.jboss.invocation.Invocation;
  | 
  | /**
  |  * @author bushuyev
  |  *
  |  */
  | public class DeletionInterceptor extends AbstractInterceptor {
  | 
  |     private EntityPersistenceManager pm;
  |        
  |     public void start() throws Exception {
  |       if (this.container instanceof EntityContainer) {
  |          EntityContainer ec = (EntityContainer)container;
  |          this.pm = ec.getPersistenceManager();
  | 
  |       }
  |     }
  | 
  |     public Object invoke(Invocation invocation) throws Exception {
  | 
  |             if (invocation.getMethod() != null && 
invocation.getMethod().getName().equals("remove")) { //$NON-NLS-1$
  |                     org.jboss.ejb.EntityEnterpriseContext ctx = 
(EntityEnterpriseContext)invocation.getEnterpriseContext();
  | 
  | 
  |                     if (
  |                             
((JDBCCMRFieldBridge)((JDBCStoreManager)((CMPPersistenceManager)this.pm).
  |                                             
getPersistenceStore()).getEntityBridge().
  |                                             
getCMRFields()[0]).getRelatedCMRField().hasForeignKey()
  | 
  |                                             &&
  | 
  |                             
((JDBCStoreManager)((CMPPersistenceManager)this.pm).
  |                                             
getPersistenceStore()).getEntityBridge().
  |                                             
getCMRFields()[0].getInstanceValue(ctx) != null
  | 
  |                     ) {
  |                             throw new RemoteException("Can't delete 
"+ctx.getEJBContext().getEJBLocalHome()+" with id="+invocation.getId()+" cause 
it is referenced from 
"+((JDBCCMRFieldBridge)((JDBCStoreManager)((CMPPersistenceManager)this.pm).
  |                                             
getPersistenceStore()).getEntityBridge().getCMRFields()[0]).getRelatedCMRField().getEntity().getLocalInterface());
 //$NON-NLS-1$
  |                     }
  | 
  |             }
  | 
  |             return super.invoke(invocation);
  |     }
  |     
  |     
  |     public Object invokeHome(Invocation invocation) throws Exception {
  | 
  |             return super.invokeHome(invocation);
  |     }
  | }
  | 
  | 


Could somebody with thorough knowledge of JBoss CMP internals glance at this 
code and say if it is acceptable? Aren't there some issues with caching, lazy 
loading or something else which might prevent it from working correctly?

 wbr, eugen.

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3869356#3869356

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3869356


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to