use of cz.o2.proxima.repository.TransactionMode in project proxima-platform by O2-Czech-Republic.
the class TransactionResourceManager method findFamilyForTransactionalAttribute.
private Map<AttributeDescriptor<?>, DirectAttributeFamilyDescriptor> findFamilyForTransactionalAttribute(List<AttributeDescriptor<?>> attributes) {
Preconditions.checkArgument(!attributes.isEmpty(), "Cannot return families for empty attribute list");
TransactionMode mode = attributes.get(0).getTransactionMode();
Preconditions.checkArgument(attributes.stream().allMatch(a -> a.getTransactionMode() == mode), "All passed attributes must have the same transaction mode. Got attributes %s.", attributes);
List<DirectAttributeFamilyDescriptor> candidates = attributes.stream().flatMap(a -> a.getTransactionalManagerFamilies().stream()).distinct().map(direct::findFamilyByName).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
List<AttributeDescriptor<?>> requestResponseState = candidates.stream().flatMap(f -> f.getAttributes().stream().filter(a -> !a.equals(commitDesc))).sorted(Comparator.comparing(AttributeDescriptor::getName)).collect(Collectors.toList());
Preconditions.checkState(requestResponseState.equals(Lists.newArrayList(requestDesc, responseDesc, stateDesc)), "Should have received only families for unique transactional attributes, " + "got %s for %s with transactional mode %s", candidates, attributes, mode);
Map<AttributeDescriptor<?>, DirectAttributeFamilyDescriptor> res = candidates.stream().flatMap(f -> f.getAttributes().stream().map(a -> Pair.of(a, f))).collect(Collectors.toMap(Pair::getFirst, Pair::getSecond));
direct.getRepository().getAllFamilies(true).filter(af -> af.getAttributes().contains(commitDesc)).forEach(af -> res.put(commitDesc, direct.getFamilyByName(af.getName())));
return res;
}
Aggregations