IDEMPIERE-1132 Improve AD_Index; AD_View; foreign keys management - Validation using unique AD_TableIndex
This commit is contained in:
parent
0bdbe4a99c
commit
a8731ef4a5
|
@ -338,6 +338,8 @@ public interface AdempiereDatabase
|
|||
* @return true if lock is granted
|
||||
*/
|
||||
public boolean forUpdate(PO po, int timeout);
|
||||
|
||||
public String getNameOfUniqueConstraintError(Exception e);
|
||||
|
||||
} // AdempiereDatabase
|
||||
|
||||
|
|
|
@ -4423,26 +4423,24 @@ public abstract class PO
|
|||
if ("DBExecuteError".equals(msg))
|
||||
info = "DBExecuteError:" + info;
|
||||
// Unique Constraint
|
||||
if (DBException.isUniqueContraintError(CLogger.retrieveException()))
|
||||
Exception e = CLogger.retrieveException();
|
||||
if (DBException.isUniqueContraintError(e))
|
||||
{
|
||||
boolean found = false;
|
||||
String dbIndexName = DB.getDatabase().getNameOfUniqueConstraintError(e);
|
||||
if (log.isLoggable(Level.FINE)) log.fine("dbIndexName=" + dbIndexName);
|
||||
MTableIndex[] indexes = MTableIndex.get(MTable.get(getCtx(), get_Table_ID()));
|
||||
for (MTableIndex index : indexes)
|
||||
{
|
||||
String indexName = index.getName().toLowerCase();
|
||||
if (DB.isPostgreSQL())
|
||||
indexName = "\"" + indexName + "\"";
|
||||
else
|
||||
indexName = "." + indexName + ")";
|
||||
if (info.toLowerCase().contains(indexName))
|
||||
if (dbIndexName.equalsIgnoreCase(index.getName()))
|
||||
{
|
||||
if (index.getAD_Message_ID() > 0)
|
||||
{
|
||||
MMessage message = MMessage.get(getCtx(), index.getAD_Message_ID());
|
||||
log.saveError("SaveError", message.getMsgText());
|
||||
log.saveError("SaveError", Msg.getMsg(getCtx(), message.getValue()));
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1380,4 +1380,16 @@ public class DB_Oracle implements AdempiereDatabase
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameOfUniqueConstraintError(Exception e) {
|
||||
String info = e.getMessage();
|
||||
int fromIndex = info.indexOf(".");
|
||||
if (fromIndex == -1)
|
||||
return info;
|
||||
int toIndex = info.indexOf(")", fromIndex + 1);
|
||||
if (toIndex == -1)
|
||||
return info;
|
||||
return info.substring(fromIndex + 1, toIndex);
|
||||
}
|
||||
} // DB_Oracle
|
||||
|
|
|
@ -1138,4 +1138,16 @@ public class DB_PostgreSQL implements AdempiereDatabase
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameOfUniqueConstraintError(Exception e) {
|
||||
String info = e.getMessage();
|
||||
int fromIndex = info.indexOf("\"");
|
||||
if (fromIndex == -1)
|
||||
return info;
|
||||
int toIndex = info.indexOf("\"", fromIndex + 1);
|
||||
if (toIndex == -1)
|
||||
return info;
|
||||
return info.substring(fromIndex + 1, toIndex);
|
||||
}
|
||||
} // DB_PostgreSQL
|
||||
|
|
Loading…
Reference in New Issue