IDEMPIERE-1132 Improve AD_Index; AD_View; foreign keys management - Validation using unique AD_TableIndex
This commit is contained in:
parent
adfba92a08
commit
d2d8553156
|
@ -37,7 +37,7 @@ public class MTableIndex extends X_AD_TableIndex {
|
|||
*/
|
||||
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.setOnlyActiveRecords(true);
|
||||
List<MTableIndex> list = query.<MTableIndex>list();
|
||||
|
|
|
@ -2112,6 +2112,7 @@ public abstract class PO
|
|||
}
|
||||
else
|
||||
{
|
||||
validateUniqueIndex();
|
||||
if (localTrx != null)
|
||||
localTrx.rollback();
|
||||
else
|
||||
|
@ -2131,6 +2132,7 @@ public abstract class PO
|
|||
}
|
||||
else
|
||||
{
|
||||
validateUniqueIndex();
|
||||
if (localTrx != null)
|
||||
localTrx.rollback();
|
||||
else
|
||||
|
@ -4410,4 +4412,45 @@ public abstract class PO
|
|||
ois.defaultReadObject();
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue