RED-6467: Implemented undeletion of dictionary entries via the criteria builder.
Hopefully, this solves the db-driver issue with large numbers of entries.
This commit is contained in:
parent
b14d56195e
commit
5092b00f41
@ -4,6 +4,8 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -33,6 +35,8 @@ public class EntryPersistenceService {
|
|||||||
private final FalseRecommendationEntryRepository falseRecommendationEntryRepository;
|
private final FalseRecommendationEntryRepository falseRecommendationEntryRepository;
|
||||||
private final JDBCWriteUtils jdbcWriteUtils;
|
private final JDBCWriteUtils jdbcWriteUtils;
|
||||||
|
|
||||||
|
private final EntityManager entityManager;
|
||||||
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void deleteEntries(String typeId, List<String> values, long version, DictionaryEntryType dictionaryEntryType) {
|
public void deleteEntries(String typeId, List<String> values, long version, DictionaryEntryType dictionaryEntryType) {
|
||||||
@ -108,7 +112,10 @@ public class EntryPersistenceService {
|
|||||||
|
|
||||||
switch (dictionaryEntryType) {
|
switch (dictionaryEntryType) {
|
||||||
case ENTRY -> {
|
case ENTRY -> {
|
||||||
var undeletedEntries = entryRepository.undeleteEntries(typeId, entries, version);
|
// TODO Remove all but one implementation for undeletion, once it is clear which one works
|
||||||
|
//var undeletedEntries = entryRepository.undeleteEntries(typeId, entries, version);
|
||||||
|
List<String> undeletedEntries = undeleteEntries(typeId, entries, version);
|
||||||
|
|
||||||
undeletedEntries.forEach(entries::remove);
|
undeletedEntries.forEach(entries::remove);
|
||||||
|
|
||||||
var entryEntities = entries.stream().map(e -> {
|
var entryEntities = entries.stream().map(e -> {
|
||||||
@ -154,6 +161,28 @@ public class EntryPersistenceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private List<String> undeleteEntries(String typeId, Set<String> entries, long version) {
|
||||||
|
|
||||||
|
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
|
||||||
|
var undeleteEntriesQuery = criteriaBuilder.createCriteriaUpdate(DictionaryEntryEntity.class);
|
||||||
|
var entryRoot = undeleteEntriesQuery.from(DictionaryEntryEntity.class);
|
||||||
|
|
||||||
|
var typeIdPred = criteriaBuilder.equal(entryRoot.get("typeId"), typeId);
|
||||||
|
var entriesPred = entryRoot.get("value").in(entries);
|
||||||
|
undeleteEntriesQuery.where(typeIdPred, entriesPred);
|
||||||
|
undeleteEntriesQuery.set("version", version);
|
||||||
|
undeleteEntriesQuery.set("deleted", false);
|
||||||
|
|
||||||
|
entityManager.createQuery(undeleteEntriesQuery).executeUpdate();
|
||||||
|
|
||||||
|
var existingEntriesQuery = criteriaBuilder.createQuery(DictionaryEntryEntity.class);
|
||||||
|
entryRoot = existingEntriesQuery.from(DictionaryEntryEntity.class);
|
||||||
|
undeleteEntriesQuery.where(typeIdPred, criteriaBuilder.equal(entryRoot.get("deleted"), false));
|
||||||
|
|
||||||
|
return entityManager.createQuery(existingEntriesQuery).getResultStream().map(DictionaryEntryEntity::getValue).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void cloneEntries(String originalTypeId, String newTypeId) {
|
public void cloneEntries(String originalTypeId, String newTypeId) {
|
||||||
|
|
||||||
entryRepository.cloneEntries(originalTypeId, newTypeId);
|
entryRepository.cloneEntries(originalTypeId, newTypeId);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user