@@ -0,0 +1,2642 @@
+package fr.openwide.core.basicapp.core.util.transaction.service;%0A%0Aimport java.util.List;%0Aimport java.util.Set;%0A%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.context.ApplicationContext;%0Aimport org.springframework.stereotype.Service;%0A%0Aimport com.google.common.collect.Sets;%0A%0Aimport fr.openwide.core.commons.util.collections.CollectionUtils;%0Aimport fr.openwide.core.jpa.more.business.history.util.FactoredHistoryLogBeforeCommitWithDifferencesTask;%0Aimport fr.openwide.core.jpa.more.business.history.util.HistoryLogBeforeCommitWithDifferencesTask;%0Aimport fr.openwide.core.jpa.more.util.transaction.model.ITransactionSynchronizationBeforeCommitTask;%0Aimport fr.openwide.core.jpa.more.util.transaction.model.ITransactionSynchronizationTask;%0Aimport fr.openwide.core.jpa.more.util.transaction.model.TransactionSynchronizationTasks;%0Aimport fr.openwide.core.jpa.more.util.transaction.service.ITransactionSynchronizationTaskMergerService;%0Aimport fr.openwide.core.spring.util.SpringBeanUtils;%0A%0A@Service%0Apublic class TransactionSynchronizationTaskMergerServiceImpl implements ITransactionSynchronizationTaskMergerService %7B%0A%09%0A%09@Autowired%0A%09private ApplicationContext applicationContext;%0A%0A%09@Override%0A%09public void merge(TransactionSynchronizationTasks tasks) %7B%0A%09%09mergeBeforeCommit(tasks.getBeforeCommitTasks());%0A%09%09simpleMerge(tasks.getAfterCommitTasks());%0A%09%7D%0A%0A%09private void mergeBeforeCommit(List%3CITransactionSynchronizationBeforeCommitTask%3E tasks) %7B%0A%09%09if (!tasks.isEmpty()) %7B%0A%09%09%09// We simply use .hashcode() and .equals() to remove the duplicates%0A%09%09%09Set%3CITransactionSynchronizationBeforeCommitTask%3E merged = Sets.newLinkedHashSet();%0A%09%09%09Set%3CHistoryLogBeforeCommitWithDifferencesTask%3C?, ?, ?, ?, ?%3E%3E differenceTasks = Sets.newLinkedHashSet();%0A%09%09%09for (ITransactionSynchronizationBeforeCommitTask task : tasks) %7B%0A%09%09%09%09if (task instanceof HistoryLogBeforeCommitWithDifferencesTask) %7B%0A%09%09%09%09%09differenceTasks.add((HistoryLogBeforeCommitWithDifferencesTask%3C?, ?, ?, ?, ?%3E)task);%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09merged.add(task);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09if (!differenceTasks.isEmpty()) %7B%0A%09%09%09%09FactoredHistoryLogBeforeCommitWithDifferencesTask factoredTask%0A%09%09%09%09%09%09= new FactoredHistoryLogBeforeCommitWithDifferencesTask(differenceTasks);%0A%09%09%09%09SpringBeanUtils.autowireBean(applicationContext, factoredTask);%0A%09%09%09%09merged.add(factoredTask);%0A%09%09%09%7D%0A%09%09%09CollectionUtils.replaceAll(tasks, merged);%0A%09%09%7D%0A%09%7D%0A%0A%09private %3CT extends ITransactionSynchronizationTask%3E void simpleMerge(List%3CT%3E tasks) %7B%0A%09%09if (!tasks.isEmpty()) %7B%0A%09%09%09// On We simply use .hashcode() and .equals() to remove the duplicates%0A%09%09%09CollectionUtils.replaceAll(tasks, Sets.newHashSet(tasks));%0A%09%09%7D%0A%09%7D%0A%0A%7D%0A

Add TransactionSynchronizationTaskMergerServiceImpl