IDEMPIERE-1132 Improve AD_Index; AD_View; foreign keys management - Validation using unique AD_TableIndex

This commit is contained in:
Elaine Tan 2013-07-11 15:26:26 +08:00
parent adfba92a08
commit d2d8553156
2 changed files with 44 additions and 1 deletions

View File

@ -37,7 +37,7 @@ public class MTableIndex extends X_AD_TableIndex {
*/ */
public static MTableIndex[] get(MTable table) public static MTableIndex[] get(MTable table)
{ {
Query query = new Query(table.getCtx(), table, MTableIndex.COLUMNNAME_AD_Table_ID + "=?", table.get_TrxName()); Query query = new Query(table.getCtx(), MTableIndex.Table_Name, MTableIndex.COLUMNNAME_AD_Table_ID + "=?", table.get_TrxName());
query.setParameters(table.getAD_Table_ID()); query.setParameters(table.getAD_Table_ID());
query.setOnlyActiveRecords(true); query.setOnlyActiveRecords(true);
List<MTableIndex> list = query.<MTableIndex>list(); List<MTableIndex> list = query.<MTableIndex>list();

View File

@ -2112,6 +2112,7 @@ public abstract class PO
} }
else else
{ {
validateUniqueIndex();
if (localTrx != null) if (localTrx != null)
localTrx.rollback(); localTrx.rollback();
else else
@ -2131,6 +2132,7 @@ public abstract class PO
} }
else else
{ {
validateUniqueIndex();
if (localTrx != null) if (localTrx != null)
localTrx.rollback(); localTrx.rollback();
else else
@ -4410,4 +4412,45 @@ public abstract class PO
ois.defaultReadObject(); ois.defaultReadObject();
log = CLogger.getCLogger(getClass()); log = CLogger.getCLogger(getClass());
} }
private void validateUniqueIndex()
{
ValueNamePair ppE = CLogger.retrieveError();
if (ppE != null)
{
String msg = ppE.getValue();
String info = ppE.getName();
if ("DBExecuteError".equals(msg))
info = "DBExecuteError:" + info;
// Unique Constraint
if (DBException.isUniqueContraintError(CLogger.retrieveException()))
{
boolean found = false;
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 (index.getAD_Message_ID() > 0)
{
MMessage message = MMessage.get(getCtx(), index.getAD_Message_ID());
log.saveError("SaveError", message.getMsgText());
found = true;
break;
}
}
}
if (!found)
log.saveError(msg, info);
}
else
log.saveError(msg, info);
}
}
} // PO } // PO