From 257d12d77d8b7951906ef69ce8760a1f6ce54b63 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Wed, 20 May 2009 06:29:44 +0000 Subject: [PATCH] http://sourceforge.net/tracker/?func=detail&aid=2794220&group_id=176962&atid=879332 --- .../org/adempiere/exceptions/DBException.java | 46 ++++++++++++------- base/src/org/compiere/model/MSequence.java | 14 ++++-- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/base/src/org/adempiere/exceptions/DBException.java b/base/src/org/adempiere/exceptions/DBException.java index a5be401ad4..fd73686540 100644 --- a/base/src/org/adempiere/exceptions/DBException.java +++ b/base/src/org/adempiere/exceptions/DBException.java @@ -25,10 +25,10 @@ import org.compiere.util.DB; /** * This RuntimeException is used to pass SQLException up the chain of calling * methods to determine what to do where needed. - * + * * @author Vincent Harcq * @version $Id: DBException.java,v 1.2 2006/07/30 00:54:35 jjanke Exp $ - * + * * @author Teo Sarca, SC ARHIPAC SERVICE SRL * @author Armen Rizal, GOODWILL CONSULTING * FR [2789943] Better DBException handling for PostgreSQL @@ -37,7 +37,7 @@ import org.compiere.util.DB; public class DBException extends AdempiereException { /** - * + * */ private static final long serialVersionUID = -1072176004008572154L; private String m_sql = null; @@ -54,7 +54,7 @@ public class DBException extends AdempiereException e.printStackTrace(); } } - + /** * Create a new DBException based on a SQLException and SQL Query * @param e exception @@ -70,7 +70,7 @@ public class DBException extends AdempiereException * Create a new DBException * @param msg Message */ - public DBException(String msg) + public DBException(String msg) { super(msg); } @@ -82,7 +82,7 @@ public class DBException extends AdempiereException { return m_sql; } - + /** * @return Wrapped SQLException or null */ @@ -98,7 +98,7 @@ public class DBException extends AdempiereException */ public int getErrorCode() { SQLException e = getSQLException(); - return (e != null ? e.getErrorCode() : -1); + return (e != null ? e.getErrorCode() : -1); } /** @@ -106,18 +106,18 @@ public class DBException extends AdempiereException */ public SQLException getNextException() { SQLException e = getSQLException(); - return (e != null ? e.getNextException() : null); + return (e != null ? e.getNextException() : null); } - + /** * @see java.sql.SQLException#getSQLState() */ public String getSQLState() { SQLException e = getSQLException(); - return (e != null ? e.getSQLState() : null); + return (e != null ? e.getSQLState() : null); } - - + + private static final boolean isErrorCode(Exception e, int errorCode) { if (e == null) { return false; @@ -134,7 +134,7 @@ public class DBException extends AdempiereException } return false; } - + private static final boolean isSQLState(Exception e, String SQLState) { if (e == null) { return false; @@ -151,7 +151,7 @@ public class DBException extends AdempiereException } return false; } - + /** * Check if Unique Constraint Exception (aka ORA-00001) * @param e exception @@ -162,15 +162,17 @@ public class DBException extends AdempiereException // return isErrorCode(e, 1); } - + /** * Check if "child record found" exception (aka ORA-02292) * @param e exception */ public static boolean isChildRecordFoundError(Exception e) { + if (DB.isPostgreSQL()) + return isSQLState(e, "23503"); return isErrorCode(e, 2292); } - + /** * Check if "invalid identifier" exception (aka ORA-00904) * @param e exception @@ -178,7 +180,7 @@ public class DBException extends AdempiereException public static boolean isInvalidIdentifierError(Exception e) { return isErrorCode(e, 904); } - + /** * Check if "invalid username/password" exception (aka ORA-01017) * @param e exception @@ -186,4 +188,14 @@ public class DBException extends AdempiereException public static boolean isInvalidUserPassError(Exception e) { return isErrorCode(e, 1017); } + + /** + * Check if "time out" exception (aka ORA-01013) + * @param e + */ + public static boolean isTimeout(Exception e) { + if (DB.isPostgreSQL()) + return isSQLState(e, "57014"); + return isErrorCode(e, 1013); + } } // DBException diff --git a/base/src/org/compiere/model/MSequence.java b/base/src/org/compiere/model/MSequence.java index 4cb8e58828..7ce7de1220 100644 --- a/base/src/org/compiere/model/MSequence.java +++ b/base/src/org/compiere/model/MSequence.java @@ -36,6 +36,8 @@ import java.util.Properties; import java.util.Vector; import java.util.logging.Level; +import org.adempiere.exceptions.AdempiereException; +import org.adempiere.exceptions.DBException; import org.compiere.db.CConnection; import org.compiere.util.CLogMgt; import org.compiere.util.CLogger; @@ -555,8 +557,11 @@ public class MSequence extends X_AD_Sequence } catch (Exception e) { - s_log.log(Level.SEVERE, "(Table) [" + trxName + "]", e); - next = -2; + s_log.log(Level.SEVERE, "(Table) [" + trxName + "]", e); + if (DBException.isTimeout(e)) + throw new AdempiereException("GenerateDocumentNoTimeOut", e); + else + throw new AdempiereException("GenerateDocumentNoError", e); } finally { @@ -838,7 +843,10 @@ public class MSequence extends X_AD_Sequence catch (Exception e) { s_log.log(Level.SEVERE, "(DocType) [" + trxName + "]", e); - next = -2; + if (DBException.isTimeout(e)) + throw new AdempiereException("GenerateDocumentNoTimeOut", e); + else + throw new AdempiereException("GenerateDocumentNoError", e); } finally {