forked from Coded/SIPRP
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.3 KiB
72 lines
1.3 KiB
/*
|
|
* DeleteHandler.java
|
|
*
|
|
* Created on 11 de Outubro de 2004, 16:04
|
|
*/
|
|
|
|
package siprp.data;
|
|
|
|
import com.evolute.utils.jdo.JDOObject;
|
|
import com.evolute.utils.jdo.JDOOperationHandlerInterface;
|
|
|
|
/**
|
|
*
|
|
* @author fpalma
|
|
*/
|
|
public class DisableDeleteHandler implements JDOOperationHandlerInterface
|
|
{
|
|
public static final DisableDeleteHandler INSTANCE = new DisableDeleteHandler();
|
|
|
|
/** Creates a new instance of DeleteHandler */
|
|
public DisableDeleteHandler()
|
|
{
|
|
}
|
|
|
|
public boolean handle( JDOObject object, int operation, int moment )
|
|
throws Exception
|
|
{
|
|
if( !( object instanceof DisableDeleteable ) )
|
|
{
|
|
return false;
|
|
}
|
|
switch( operation )
|
|
{
|
|
case OP_SAVE:
|
|
return save( object, moment );
|
|
|
|
case OP_DELETE:
|
|
return delete( object, moment );
|
|
|
|
}
|
|
return false;
|
|
}
|
|
|
|
protected boolean save( JDOObject object, int moment )
|
|
throws Exception
|
|
{
|
|
if( moment != MOMENT_BEFORE )
|
|
{
|
|
return false;
|
|
}
|
|
String old = (String) object.get( DisableDeleteable.INACTIVO );
|
|
if( old == null )
|
|
{
|
|
object.set( DisableDeleteable.INACTIVO, "n" );
|
|
}
|
|
return true;
|
|
}
|
|
|
|
protected boolean delete( JDOObject object, int moment )
|
|
throws Exception
|
|
{
|
|
if( moment != MOMENT_INSTEAD )
|
|
{
|
|
return false;
|
|
}
|
|
object.set( DisableDeleteable.INACTIVO, "y" );
|
|
object.save();
|
|
return true;
|
|
}
|
|
|
|
}
|