Skip to content

Commit

Permalink
Alternative approach
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Aug 4, 2023
1 parent 1011768 commit 7dc94a5
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@

package org.drools.persistence.api;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

public class TransactionManagerHelper {
Expand All @@ -39,10 +42,7 @@ public static void addToUpdatableSet(TransactionManager txm, Transformable trans
}
Set<Transformable> toBeUpdated = (Set<Transformable>) txm.getResource(APP_UPDETEABLE_RESOURCE);
if (toBeUpdated == null) {
toBeUpdated = new TreeSet<>((o1, o2) -> {
int result = o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName());
return result == 0 ? 1 : result;
});
toBeUpdated = new LinkedHashSet<>();
txm.putResource(APP_UPDETEABLE_RESOURCE, toBeUpdated);
}
toBeUpdated.add(transformable);
Expand All @@ -59,6 +59,15 @@ public static void removeFromUpdatableSet(TransactionManager txm, Transformable

@SuppressWarnings("unchecked")
public static Set<Transformable> getUpdateableSet(TransactionManager txm) {
return (Set<Transformable>) txm.getResource(APP_UPDETEABLE_RESOURCE);
Set<Transformable> result = (Set<Transformable>) txm.getResource(APP_UPDETEABLE_RESOURCE);
if (result != null) {
SortedSet<Transformable> sorted = new TreeSet<>((o1, o2) -> {
int compared = o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName());
return compared == 0 ? 1 : compared;
});
sorted.addAll(result);
return sorted;
}
return Collections.emptySet();
}
}

0 comments on commit 7dc94a5

Please sign in to comment.