Handle Transaction Rollback

This commit is contained in:
hodianto 2018-08-04 07:58:06 +07:00
parent 2904e4a95c
commit 835ff26f95
3 changed files with 47 additions and 27 deletions

View File

@ -2,3 +2,4 @@
syntax: glob syntax: glob
*.class *.class
andromeida.midsuit.project/bin/andromedia/midsuit/factory/*.rej andromeida.midsuit.project/bin/andromedia/midsuit/factory/*.rej
andromeida.midsuit.project/src/andromedia/midsuit/factory/*.orig

View File

@ -12,6 +12,7 @@ import org.compiere.model.MRequisition;
import org.compiere.process.DocAction; import org.compiere.process.DocAction;
import org.compiere.process.ProcessInfoParameter; import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess; import org.compiere.process.SvrProcess;
import org.compiere.util.Trx;
import andromedia.midsuit.model.MID_MRequisitionTrx; import andromedia.midsuit.model.MID_MRequisitionTrx;
@ -40,48 +41,63 @@ public class MID_CompleteRecord extends SvrProcess{
switch(tableName){ switch(tableName){
case "C_Order" : case "C_Order" :
MOrder o = new MOrder(getCtx(), record_ID, get_TrxName()); MOrder o = new MOrder(getCtx(), record_ID, get_TrxName());
if(!o.processIt(DocAct)) if(!o.processIt(DocAct)) {
throw new AdempiereException( "Failed to Complete Document !!!"); Trx.get(get_TrxName(), false).rollback();
o.saveEx(); throw new AdempiereException(o.getProcessMsg());
}else
o.saveEx();
break; break;
case "M_InOut" : case "M_InOut" :
MInOut io = new MInOut(getCtx(), record_ID, get_TrxName()); MInOut io = new MInOut(getCtx(), record_ID, get_TrxName());
if(!io.processIt(DocAct)) if(!io.processIt(DocAct)) {
throw new AdempiereException( "Failed to Complete Document !!!"); Trx.get(get_TrxName(), false).rollback();
io.saveEx(); throw new AdempiereException(io.getProcessMsg());
}else
io.saveEx();
break; break;
case "C_Invoice" : case "C_Invoice" :
MInvoice inv = new MInvoice(getCtx(), record_ID, get_TrxName()); MInvoice inv = new MInvoice(getCtx(), record_ID, get_TrxName());
if(!inv.processIt(DocAct)) if(!inv.processIt(DocAct)) {
throw new AdempiereException( "Failed to Complete Document !!!"); Trx.get(get_TrxName(), false).rollback();
inv.saveEx(); throw new AdempiereException(inv.getProcessMsg());
}else
inv.saveEx();
break; break;
case "C_Payment" : case "C_Payment" :
MPayment p = new MPayment(getCtx(), record_ID, get_TrxName()); MPayment p = new MPayment(getCtx(), record_ID, get_TrxName());
if(!p.processIt(DocAct)) if(!p.processIt(DocAct)) {
throw new AdempiereException( "Failed to Complete Document !!!"); Trx.get(get_TrxName(), false).rollback();
p.saveEx(); throw new AdempiereException(p.getProcessMsg());
}else
p.saveEx();
break; break;
case "MID_Requisition" : case "MID_Requisition" :
MID_MRequisitionTrx rs = new MID_MRequisitionTrx(getCtx(), record_ID, get_TrxName()); MID_MRequisitionTrx rs = new MID_MRequisitionTrx(getCtx(), record_ID, get_TrxName());
if(!rs.processIt(DocAct)) if(!rs.processIt(DocAct)) {
throw new AdempiereException( "Failed to Complete Document !!!"); Trx.get(get_TrxName(), false).rollback();
rs.saveEx(); throw new AdempiereException(rs.getProcessMsg());
}else
rs.saveEx();
break; break;
case "M_Requisition" : case "M_Requisition" :
MRequisition req = new MRequisition(getCtx(), record_ID, get_TrxName()); MRequisition req = new MRequisition(getCtx(), record_ID, get_TrxName());
if(!req.processIt(DocAct)) if(!req.processIt(DocAct)) {
throw new AdempiereException( "Failed to Complete Document !!!"); Trx.get(get_TrxName(), false).rollback();
req.saveEx(); throw new AdempiereException(req.getProcessMsg());
}else
req.saveEx();
break; break;
case "M_RMA" : case "M_RMA" :
MRMA rma = new MRMA(getCtx(), record_ID, get_TrxName()); MRMA rma = new MRMA(getCtx(), record_ID, get_TrxName());
if(!rma.processIt(DocAct)) if(!rma.processIt(DocAct)) {
throw new AdempiereException( "Failed to Complete Document !!!"); Trx.get(get_TrxName(), false).rollback();
rma.saveEx(); throw new AdempiereException(rma.getProcessMsg());
}
else
rma.saveEx();
break; break;
default : throw new AdempiereException( "Failed to Complete Document !!!"); default : throw new AdempiereException( "Document For Table "+tableName+" Not Found !!!");
} }
return ""; return "";
} }

View File

@ -159,7 +159,10 @@ public class MID_InsertIntoAllTable extends SvrProcess{
} }
if(!po.save(get_TrxName())) if(!po.save(get_TrxName()))
throw new AdempiereException(po.get_Logger().retrieveError().getName()); throw new AdempiereException(po.get_Logger().retrieveError().getName());
else {
po.saveEx();
return String.valueOf(po.get_ValueAsInt(tableName+"_ID"));
}
// if(po.get_Value("DocAction")!=null) { // if(po.get_Value("DocAction")!=null) {
// Class<?> clazz = getClass(tableName); // Class<?> clazz = getClass(tableName);
// if (clazz == null) // if (clazz == null)
@ -177,10 +180,10 @@ public class MID_InsertIntoAllTable extends SvrProcess{
// } // }
// } // }
if(Trx.get(get_TrxName(), false).commit()){ // if(Trx.get(get_TrxName(), false).commit()){
return String.valueOf(po.get_ID()); // return String.valueOf(po.get_ID());
}else // }else
throw new AdempiereException(po.get_Logger().retrieveError().getName()); // throw new AdempiereException(po.get_Logger().retrieveError().getName());
} }