mirror of
https://github.com/Athou/commafeed.git
synced 2026-09-23 12:35:07 +00:00
remove deprecated usage of saveOrUpdate in preparation of hibernate 7
This commit is contained in:
@@ -5,7 +5,6 @@ import java.util.Collection;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.jpa.SpecHints;
|
||||
|
||||
import com.commafeed.backend.model.AbstractModel;
|
||||
@@ -35,15 +34,6 @@ public abstract class GenericDAO<T extends AbstractModel> {
|
||||
return new JPADeleteClause(entityManager, entityPath);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void saveOrUpdate(T model) {
|
||||
entityManager.unwrap(Session.class).saveOrUpdate(model);
|
||||
}
|
||||
|
||||
public void saveOrUpdate(Collection<T> models) {
|
||||
models.forEach(this::saveOrUpdate);
|
||||
}
|
||||
|
||||
public void persist(T model) {
|
||||
entityManager.persist(model);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class OPMLImporter {
|
||||
category.setParent(parent);
|
||||
category.setUser(user);
|
||||
category.setPosition(position);
|
||||
feedCategoryDAO.saveOrUpdate(category);
|
||||
feedCategoryDAO.persist(category);
|
||||
}
|
||||
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
|
||||
@@ -35,7 +35,7 @@ public class FeedEntryContentService {
|
||||
if (existing.isPresent()) {
|
||||
return existing.get();
|
||||
} else {
|
||||
feedEntryContentDAO.saveOrUpdate(entryContent);
|
||||
feedEntryContentDAO.persist(entryContent);
|
||||
return entryContent;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class FeedEntryService {
|
||||
feedEntry.setFeed(feed);
|
||||
feedEntry.setContent(feedEntryContentService.findOrCreate(entry.content(), feed.getLink()));
|
||||
|
||||
feedEntryDAO.saveOrUpdate(feedEntry);
|
||||
feedEntryDAO.persist(feedEntry);
|
||||
return feedEntry;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class FeedEntryService {
|
||||
if (!matches) {
|
||||
FeedEntryStatus status = new FeedEntryStatus(sub.getUser(), sub, entry);
|
||||
status.setRead(true);
|
||||
feedEntryStatusDAO.saveOrUpdate(status);
|
||||
feedEntryStatusDAO.persist(status);
|
||||
}
|
||||
|
||||
return matches;
|
||||
@@ -83,7 +83,7 @@ public class FeedEntryService {
|
||||
FeedEntryStatus status = feedEntryStatusDAO.getStatus(user, sub, entry);
|
||||
if (status.isMarkable()) {
|
||||
status.setRead(read);
|
||||
feedEntryStatusDAO.saveOrUpdate(status);
|
||||
feedEntryStatusDAO.merge(status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public class FeedEntryService {
|
||||
|
||||
FeedEntryStatus status = feedEntryStatusDAO.getStatus(user, sub, entry);
|
||||
status.setStarred(starred);
|
||||
feedEntryStatusDAO.saveOrUpdate(status);
|
||||
feedEntryStatusDAO.merge(status);
|
||||
}
|
||||
|
||||
public void markSubscriptionEntries(User user, List<FeedSubscription> subscriptions, Instant olderThan, Instant insertedBefore,
|
||||
@@ -125,7 +125,9 @@ public class FeedEntryService {
|
||||
return insertedBefore == null || insertedDate == null || insertedDate.isBefore(insertedBefore);
|
||||
}).toList();
|
||||
|
||||
statusesToMark.forEach(s -> s.setRead(true));
|
||||
feedEntryStatusDAO.saveOrUpdate(statusesToMark);
|
||||
statusesToMark.forEach(s -> {
|
||||
s.setRead(true);
|
||||
feedEntryStatusDAO.merge(s);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class FeedEntryTagService {
|
||||
.toList();
|
||||
List<FeedEntryTag> removeList = existingTags.stream().filter(tag -> !tagNames.contains(tag.getName())).toList();
|
||||
|
||||
feedEntryTagDAO.saveOrUpdate(addList);
|
||||
addList.forEach(feedEntryTagDAO::persist);
|
||||
feedEntryTagDAO.delete(removeList);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,6 @@ public class FeedSubscriptionService {
|
||||
// upgrade feed to https if it was using http
|
||||
if (FeedUtils.isHttp(feed.getUrl()) && FeedUtils.isHttps(url)) {
|
||||
feed.setUrl(url);
|
||||
feedDAO.saveOrUpdate(feed);
|
||||
}
|
||||
|
||||
FeedSubscription sub = feedSubscriptionDAO.findByFeed(user, feed);
|
||||
@@ -84,9 +83,7 @@ public class FeedSubscriptionService {
|
||||
sub.setCategory(category);
|
||||
sub.setPosition(position);
|
||||
sub.setTitle(FeedUtils.truncate(title, 128));
|
||||
feedSubscriptionDAO.saveOrUpdate(sub);
|
||||
|
||||
return sub.getId();
|
||||
return feedSubscriptionDAO.merge(sub).getId();
|
||||
}
|
||||
|
||||
public boolean unsubscribe(User user, Long subId) {
|
||||
|
||||
@@ -132,9 +132,9 @@ public class UserService {
|
||||
user.setCreated(Instant.now());
|
||||
user.setSalt(salt);
|
||||
user.setPassword(encryptionService.getEncryptedPassword(password, salt));
|
||||
userDAO.saveOrUpdate(user);
|
||||
userDAO.persist(user);
|
||||
for (Role role : roles) {
|
||||
userRoleDAO.saveOrUpdate(new UserRole(user, role));
|
||||
userRoleDAO.persist(new UserRole(user, role));
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class PostLoginActivities {
|
||||
Instant lastLogin = user.getLastLogin();
|
||||
if (lastLogin == null || ChronoUnit.MINUTES.between(lastLogin, now) >= 30) {
|
||||
user.setLastLogin(now);
|
||||
unitOfWork.run(() -> userDAO.saveOrUpdate(user));
|
||||
unitOfWork.run(() -> userDAO.merge(user));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user