FR [ 1984794 ] DBException improvements
This commit is contained in:
parent
2abbe97cba
commit
ab2af4a206
|
@ -36,6 +36,7 @@ import org.compiere.dbPort.Convert;
|
||||||
import org.compiere.dbPort.Convert_Oracle;
|
import org.compiere.dbPort.Convert_Oracle;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.DBException;
|
||||||
import org.compiere.util.DisplayType;
|
import org.compiere.util.DisplayType;
|
||||||
import org.compiere.util.Ini;
|
import org.compiere.util.Ini;
|
||||||
import org.compiere.util.Language;
|
import org.compiere.util.Language;
|
||||||
|
@ -636,8 +637,7 @@ public class DB_Oracle implements AdempiereDatabase
|
||||||
{
|
{
|
||||||
exception = e;
|
exception = e;
|
||||||
conn = null;
|
conn = null;
|
||||||
if (e instanceof SQLException
|
if (DBException.isInvalidUserPassError(e))
|
||||||
&& ((SQLException)e).getErrorCode() == 1017) // invalid username/password
|
|
||||||
{
|
{
|
||||||
//log might cause infinite loop since it will try to acquire database connection again
|
//log might cause infinite loop since it will try to acquire database connection again
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1096,7 +1096,7 @@ public class GridTable extends AbstractTableModel
|
||||||
m_rowChanged = m_newRow;
|
m_rowChanged = m_newRow;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fireDataStatusEEvent("SaveErrorNoChange", "", false);
|
fireDataStatusEEvent("SaveErrorNoChange", "", true);
|
||||||
return SAVE_ERROR;
|
return SAVE_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1671,11 +1671,11 @@ public class GridTable extends AbstractTableModel
|
||||||
log.log(Level.SEVERE, "Inserted row not found");
|
log.log(Level.SEVERE, "Inserted row not found");
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
||||||
String msg = "SaveError";
|
String msg = "SaveError";
|
||||||
if (e.getErrorCode() == 1) // Unique Constraint
|
if (DBException.isUniqueContraintError(e)) // Unique Constraint
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, "Key Not Unique", e);
|
log.log(Level.SEVERE, "Key Not Unique", e);
|
||||||
msg = "SaveErrorNotUnique";
|
msg = "SaveErrorNotUnique";
|
||||||
|
@ -1802,10 +1802,7 @@ public class GridTable extends AbstractTableModel
|
||||||
msg = ppE.getValue();
|
msg = ppE.getValue();
|
||||||
info = ppE.getName();
|
info = ppE.getName();
|
||||||
// Unique Constraint
|
// Unique Constraint
|
||||||
Exception ex = CLogger.retrieveException();
|
if (DBException.isUniqueContraintError(CLogger.retrieveException()))
|
||||||
if (ex != null
|
|
||||||
&& ex instanceof SQLException
|
|
||||||
&& ((SQLException)ex).getErrorCode() == 1)
|
|
||||||
msg = "SaveErrorNotUnique";
|
msg = "SaveErrorNotUnique";
|
||||||
}
|
}
|
||||||
fireDataStatusEEvent(msg, info, true);
|
fireDataStatusEEvent(msg, info, true);
|
||||||
|
@ -2281,7 +2278,7 @@ public class GridTable extends AbstractTableModel
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, sql.toString(), e);
|
log.log(Level.SEVERE, sql.toString(), e);
|
||||||
String msg = "DeleteError";
|
String msg = "DeleteError";
|
||||||
if (e.getErrorCode() == 2292) // Child Record Found
|
if (DBException.isChildRecordFoundError(e))
|
||||||
msg = "DeleteErrorDependent";
|
msg = "DeleteErrorDependent";
|
||||||
fireDataStatusEEvent(msg, e.getLocalizedMessage(), true);
|
fireDataStatusEEvent(msg, e.getLocalizedMessage(), true);
|
||||||
return false;
|
return false;
|
||||||
|
@ -2924,7 +2921,7 @@ public class GridTable extends AbstractTableModel
|
||||||
catch (SQLException e0)
|
catch (SQLException e0)
|
||||||
{
|
{
|
||||||
// Zoom Query may have invalid where clause
|
// Zoom Query may have invalid where clause
|
||||||
if (e0.getErrorCode() == 904) // ORA-00904: "C_x_ID": invalid identifier
|
if (DBException.isInvalidIdentifierError(e0))
|
||||||
log.warning("Count - " + e0.getLocalizedMessage() + "\nSQL=" + m_SQL_Count);
|
log.warning("Count - " + e0.getLocalizedMessage() + "\nSQL=" + m_SQL_Count);
|
||||||
else
|
else
|
||||||
log.log(Level.SEVERE, "Count SQL=" + m_SQL_Count, e0);
|
log.log(Level.SEVERE, "Count SQL=" + m_SQL_Count, e0);
|
||||||
|
|
|
@ -16,14 +16,21 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.compiere.util;
|
package org.compiere.util;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import org.adempiere.exceptions.AdempiereException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This RuntimeException is used to pass SQLException up the chain of calling
|
* This RuntimeException is used to pass SQLException up the chain of calling
|
||||||
* methods to determine what to do where needed.
|
* methods to determine what to do where needed.
|
||||||
*
|
*
|
||||||
* @author Vincent Harcq
|
* @author Vincent Harcq
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
public class DBException extends RuntimeException {
|
public class DBException extends AdempiereException {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new DBException based on a SQLException
|
* Create a new DBException based on a SQLException
|
||||||
|
@ -43,4 +50,87 @@ public class DBException extends RuntimeException {
|
||||||
super(msg);
|
super(msg);
|
||||||
} // DBException
|
} // DBException
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Wrapped SQLException or null
|
||||||
|
*/
|
||||||
|
public SQLException getSQLException() {
|
||||||
|
Throwable cause = getCause();
|
||||||
|
if (cause instanceof SQLException)
|
||||||
|
return (SQLException)cause;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see java.sql.SQLException#getErrorCode()
|
||||||
|
*/
|
||||||
|
public int getErrorCode() {
|
||||||
|
SQLException e = getSQLException();
|
||||||
|
return (e != null ? e.getErrorCode() : -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see java.sql.SQLException#getNextException()
|
||||||
|
*/
|
||||||
|
public SQLException getNextException() {
|
||||||
|
SQLException e = getSQLException();
|
||||||
|
return (e != null ? e.getNextException() : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see java.sql.SQLException#getSQLState()
|
||||||
|
*/
|
||||||
|
public String getSQLState() {
|
||||||
|
SQLException e = getSQLException();
|
||||||
|
return (e != null ? e.getSQLState() : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static final boolean isErrorCode(Exception e, int errorCode) {
|
||||||
|
if (e == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (e instanceof SQLException) {
|
||||||
|
return ((SQLException)e).getErrorCode() == errorCode;
|
||||||
|
}
|
||||||
|
else if (e instanceof DBException) {
|
||||||
|
SQLException sqlEx = ((DBException)e).getSQLException();
|
||||||
|
if (sqlEx != null)
|
||||||
|
return sqlEx.getErrorCode() == errorCode;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if Unique Constraint Exception (aka ORA-00001)
|
||||||
|
* @param e exception
|
||||||
|
*/
|
||||||
|
public static boolean isUniqueContraintError(Exception e) {
|
||||||
|
return isErrorCode(e, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if "child record found" exception (aka ORA-02292)
|
||||||
|
* @param e exception
|
||||||
|
*/
|
||||||
|
public static boolean isChildRecordFoundError(Exception e) {
|
||||||
|
return isErrorCode(e, 2292);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if "invalid identifier" exception (aka ORA-00904)
|
||||||
|
* @param e exception
|
||||||
|
*/
|
||||||
|
public static boolean isInvalidIdentifierError(Exception e) {
|
||||||
|
return isErrorCode(e, 904);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if "invalid username/password" exception (aka ORA-01017)
|
||||||
|
* @param e exception
|
||||||
|
*/
|
||||||
|
public static boolean isInvalidUserPassError(Exception e) {
|
||||||
|
return isErrorCode(e, 1017);
|
||||||
|
}
|
||||||
} // DBException
|
} // DBException
|
||||||
|
|
Loading…
Reference in New Issue