Bug 1139433 - Deadlock in deletion of RHQ_RESOURCE_ERROR, possibly in resource upgrade?

When saving a resource error, we first delete existing errors if the error type is one of:
* INVALID_PLUGIN_CONFIGURATION
* AVAILABILITY_CHECK
* UPGRADE
I'm not sure why we don't if the error type is DISABLED_TYPE.

The goal is to keep only one copy of these error types.

Here's my analysis of the deadlock report attached to the BZ.

Due to the type of locks (row locks) and the queries involved, it looks like the deadlock is the consequence of concurrent calls to ResourceManagerBean#clearResourceConfigErrorByType with the same parameters. Such concurrent calls would not necessarily lead to a deadlock. It would happen only if the row locking order is different. My knowledge of Oracle is limited but I'd say this is possible if the two queries get a different execution plan. I tried to figure out why the same query could lead to a different execution plan and one possible reason would be that one is using the index on resourceId and the other one is not.

This commit addresses the issue by changing the way previous errors are deleted. Now before delete we select an ordered list of primary keys. Then we delete the rows by primary key. Consequently, two competing sessions will never lock rows in different orders.

There's another issue due to the way resource errors are implemented. Two competing sessions will delete previous errors but both will insert a row. A DataPurgeJob task has been added to remove such duplicates, if any.