FR [2789943] Better DBException handling for PostgreSQL

This commit is contained in:
armenrz 2009-05-11 08:23:27 +00:00
parent 1b04acd55e
commit 6c354f53f7
1 changed files with 24 additions and 0 deletions

View File

@ -19,6 +19,7 @@ package org.adempiere.exceptions;
import java.sql.SQLException; import java.sql.SQLException;
import org.compiere.util.CLogMgt; import org.compiere.util.CLogMgt;
import org.compiere.util.DB;
/** /**
@ -29,6 +30,9 @@ import org.compiere.util.CLogMgt;
* @version $Id: DBException.java,v 1.2 2006/07/30 00:54:35 jjanke Exp $ * @version $Id: DBException.java,v 1.2 2006/07/30 00:54:35 jjanke Exp $
* *
* @author Teo Sarca, SC ARHIPAC SERVICE SRL * @author Teo Sarca, SC ARHIPAC SERVICE SRL
* @author Armen Rizal, GOODWILL CONSULTING
* FR [2789943] Better DBException handling for PostgreSQL
* https://sourceforge.net/tracker/?func=detail&aid=2789943&group_id=176962&atid=879335
*/ */
public class DBException extends AdempiereException public class DBException extends AdempiereException
{ {
@ -131,11 +135,31 @@ public class DBException extends AdempiereException
return false; return false;
} }
private static final boolean isSQLState(Exception e, String SQLState) {
if (e == null) {
return false;
}
else if (e instanceof SQLException) {
return ((SQLException)e).getSQLState().equals(SQLState);
}
else if (e instanceof DBException) {
SQLException sqlEx = ((DBException)e).getSQLException();
if (sqlEx != null)
return sqlEx.getSQLState().equals(SQLState);
else
return false;
}
return false;
}
/** /**
* Check if Unique Constraint Exception (aka ORA-00001) * Check if Unique Constraint Exception (aka ORA-00001)
* @param e exception * @param e exception
*/ */
public static boolean isUniqueContraintError(Exception e) { public static boolean isUniqueContraintError(Exception e) {
if (DB.isPostgreSQL())
return isSQLState(e, "23505");
//
return isErrorCode(e, 1); return isErrorCode(e, 1);
} }