| Method from org.jboss.ejb.plugins.cmp.jdbc.CascadeDeleteStrategy Detail: |
abstract public void cascadeDelete(EntityEnterpriseContext ctx,
List oldValues) throws RemoveException, RemoteException
|
protected void executeDeleteSQL(String sql,
Object key) throws RemoveException {
Connection con = null;
PreparedStatement ps = null;
int rowsAffected = 0;
try
{
if(log.isDebugEnabled())
log.debug("Executing SQL: " + sql);
// get the connection
con = entity.getDataSource().getConnection();
ps = con.prepareStatement(sql);
// set the parameters
entity.setPrimaryKeyParameters(ps, 1, key);
// execute statement
rowsAffected = ps.executeUpdate();
}
catch(Exception e)
{
log.error("Could not remove " + key, e);
throw new RemoveException("Could not remove " + key);
}
finally
{
JDBCUtil.safeClose(ps);
JDBCUtil.safeClose(con);
}
// check results
if(rowsAffected == 0)
{
log.error("Could not remove entity " + key);
throw new RemoveException("Could not remove entity");
}
if(log.isDebugEnabled())
log.debug("Remove: Rows affected = " + rowsAffected);
}
|
public static CascadeDeleteStrategy getCascadeDeleteStrategy(JDBCCMRFieldBridge cmrField) throws DeploymentException {
CascadeDeleteStrategy result;
JDBCRelationshipRoleMetaData relatedRole = cmrField.getMetaData().getRelatedRole();
if(relatedRole.isBatchCascadeDelete())
{
result = new BatchCascadeDeleteStrategy(cmrField);
}
else if(relatedRole.isCascadeDelete())
{
result = new DefaultCascadeDeleteStrategy(cmrField);
}
else
{
result = new NoneCascadeDeleteStrategy(cmrField);
}
return result;
}
|
public void invokeRemoveRelated(Object relatedId) throws RemoveException, RemoteException {
EntityContainer container = relatedManager.getContainer();
/*
try
{
EntityCache instanceCache = (EntityCache) container.getInstanceCache();
SecurityActions actions = SecurityActions.UTIL.getSecurityActions();
org.jboss.invocation.Invocation invocation = new org.jboss.invocation.Invocation();
invocation.setId(instanceCache.createCacheKey(relatedId));
invocation.setArguments(new Object[]{});
invocation.setTransaction(container.getTransactionManager().getTransaction());
invocation.setPrincipal(actions.getPrincipal());
invocation.setCredential(actions.getCredential());
invocation.setType(invocationType);
invocation.setMethod(removeMethod);
container.invoke(invocation);
}
catch(EJBException e)
{
throw e;
}
catch(Exception e)
{
throw new EJBException("Error in remove instance", e);
}
*/
/**
* Have to remove through EJB[Local}Object interface since the proxy contains the 'removed' flag
* to be set on removal.
*/
if(container.getLocalProxyFactory() != null)
{
final EJBLocalObject ejbObject = container.getLocalProxyFactory().getEntityEJBLocalObject(relatedId);
ejbObject.remove();
}
else
{
final EJBObject ejbObject = (EJBObject)container.getProxyFactory().getEntityEJBObject(relatedId);
ejbObject.remove();
}
}
|
abstract public void removedIds(EntityEnterpriseContext ctx,
Object[] oldRelationRefs,
List ids)
|
protected void scheduleCascadeDelete(Object[] oldRelationsRef,
List values) {
Map oldRelations = (Map)oldRelationsRef[0];
if(oldRelations == null)
{
oldRelations = new HashMap();
oldRelationsRef[0] = oldRelations;
}
oldRelations.put(cmrField, values);
relatedManager.scheduleCascadeDelete(values);
}
|