FR [ 1720995 ] Add PO.saveEx() and PO.deleteEx() methods

This commit is contained in:
teo_sarca 2008-06-03 11:23:57 +00:00
parent 6391995ae6
commit 785797db9b
2 changed files with 152 additions and 1 deletions

View File

@ -0,0 +1,84 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2008 SC ARHIPAC SERVICE SRL. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.adempiere.exceptions;
import java.util.Properties;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.Msg;
/**
* Any exception that occurs inside the Adempiere core
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
*/
public class AdempiereException extends RuntimeException {
private static final long serialVersionUID = 1L;
/**
* Default Constructor (saved logger error will be used as message)
*/
public AdempiereException() {
this(getMessageFromLogger());
}
/**
* @param message
*/
public AdempiereException(String message) {
super(message);
}
/**
* @param cause
*/
public AdempiereException(Throwable cause) {
super(cause);
}
/**
* @param message
* @param cause
*/
public AdempiereException(String message, Throwable cause) {
super(message, cause);
}
@Override
public String getLocalizedMessage() {
String msg = super.getLocalizedMessage();
msg = Msg.parseTranslation(getCtx(), msg);
return msg;
}
protected Properties getCtx() {
return Env.getCtx();
}
/**
* @return error message from logger
* @see org.compiere.util.CLogger#retrieveError()
*/
private static String getMessageFromLogger() {
org.compiere.util.ValueNamePair err = CLogger.retrieveError();
String msg = null;
if (err != null)
msg = err.getName();
if (msg == null)
msg = "UnknownError";
return msg;
}
}

View File

@ -39,6 +39,7 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource; import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.Adempiere; import org.compiere.Adempiere;
import org.compiere.acct.Doc; import org.compiere.acct.Doc;
import org.compiere.util.CLogMgt; import org.compiere.util.CLogMgt;
@ -53,6 +54,7 @@ import org.compiere.util.Msg;
import org.compiere.util.SecureEngine; import org.compiere.util.SecureEngine;
import org.compiere.util.Trace; import org.compiere.util.Trace;
import org.compiere.util.Trx; import org.compiere.util.Trx;
import org.compiere.util.ValueNamePair;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
@ -63,7 +65,10 @@ import org.w3c.dom.Element;
* @author Jorg Janke * @author Jorg Janke
* @version $Id: PO.java,v 1.12 2006/08/09 16:38:47 jjanke Exp $ * @version $Id: PO.java,v 1.12 2006/08/09 16:38:47 jjanke Exp $
* *
* @author Teo Sarca - FR [ 1675490 ], BF [ 1704828 ] * @author Teo Sarca, SC ARHIPAC SERVICE SRL
* <li>FR [ 1675490 ] ModelValidator on modelChange after events
* <li>BF [ 1704828 ] PO.is_Changed() and PO.is_ValueChanged are not consistent
* <li>FR [ 1720995 ] Add PO.saveEx() and PO.deleteEx() methods
*/ */
public abstract class PO public abstract class PO
implements Serializable, Comparator, Evaluatee implements Serializable, Comparator, Evaluatee
@ -1948,6 +1953,24 @@ public abstract class PO
} }
} // save } // save
/**
* Update Value or create new record.
* @throws AdempiereException
* @see #save()
*/
public void saveEx() throws AdempiereException
{
if (!save()) {
String msg = null;
ValueNamePair err = CLogger.retrieveError();
if (err != null)
msg = err.getName();
if (msg == null)
msg = "SaveError";
throw new AdempiereException(msg);
}
}
/** /**
* Finish Save Process * Finish Save Process
* @param newRecord new * @param newRecord new
@ -2044,6 +2067,18 @@ public abstract class PO
return save(); return save();
} }
/**
* Update Value or create new record.
* @param trxName transaction
* @throws AdempiereException
* @see #saveEx(String)
*/
public void saveEx(String trxName) throws AdempiereException
{
set_TrxName(trxName);
saveEx();
}
/** /**
* Is there a Change to be saved? * Is there a Change to be saved?
* @return true if record changed * @return true if record changed
@ -2794,6 +2829,25 @@ public abstract class PO
return success; return success;
} // delete } // delete
/**
* Delete Current Record
* @param force delete also processed records
* @throws AdempiereException
* @see #delete(boolean)
*/
public void deleteEx(boolean force) throws AdempiereException
{
if (!delete(force)) {
String msg = null;
ValueNamePair err = CLogger.retrieveError();
if (err != null)
msg = err.getName();
if (msg == null)
msg = "DeleteError";
throw new AdempiereException(msg);
}
}
/** /**
* Delete Current Record * Delete Current Record
* @param force delete also processed records * @param force delete also processed records
@ -2806,6 +2860,19 @@ public abstract class PO
return delete (force); return delete (force);
} // delete } // delete
/**
* Delete Current Record
* @param force delete also processed records
* @param trxName transaction
* @throws AdempiereException
* @see {@link #deleteEx(boolean)}
*/
public void deleteEx(boolean force, String trxName) throws AdempiereException
{
set_TrxName(trxName);
deleteEx(force);
}
/** /**
* Executed before Delete operation. * Executed before Delete operation.
* @return true if record can be deleted * @return true if record can be deleted