Heng Sin Low 2009-05-20 06:29:44 +00:00
parent 82e632660e
commit 257d12d77d
2 changed files with 40 additions and 20 deletions

View File

@ -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

View File

@ -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
{