I have worked on the priority calculation myself some time ago. At this time I only did some small modifications to the calculation to get a special usecase working. As it always seamed to me that there still is something wrong with this calculation (e.g. cpactf test29 of dependend shows sporadic failures) I will review things in details this time. First looking at the theortical possibilities to define order of database operations.
Sequence of different types of database operations
There are 3 types of database operations to consider: create, update and delete. Of these operations all create operations have to be exectuted first then all updates and last all delete operations.
Sequence of database operations for different entity types
We do not need to take care on sequence of entity types for update operations but for create and delete operations the sequence of entity types is important. E.g. we can not create an entity which refers to another entity that is not persistent yet. Same applies for delete where an entity can not be deleted that is refered by one that is still persistent. Problem to take care of are circulare references like bidirectional 1:1. Having said that circulare references may also involve more than 2 entity types and may also involve multiple entities of the same type. Possible strategies are:
1. Execute operations in the same sequence the user calls methods on Database interface.
2. Calculate sequence of operations based on mapping information once before first operation when all mapping information is available.
3. Calculate sequence of operations based on mapping information for every transaction only for the entity types involved.
Sequence of database operations for entities of the same type
Similar to sequence of database operations of different entity types we only need to care on create and delete. Update can also be ignored here. Circulare references are also a problem for entities of the same type as stated above. Possible strategies are:
1. Execute operations in the same sequence the user calls methods on Database interface.
2. Calculate sequence of operations based on mapping information and entity values for every transaction.
Will continue with analysis of current implementation and problems involved with the different strategies soon.
test case that simulates the problem.