mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
use @Transactional where possible
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
package com.commafeed.frontend.servlet;
|
package com.commafeed.frontend.servlet;
|
||||||
|
|
||||||
import com.commafeed.backend.dao.UnitOfWork;
|
|
||||||
import com.commafeed.backend.dao.UserSettingsDAO;
|
import com.commafeed.backend.dao.UserSettingsDAO;
|
||||||
import com.commafeed.backend.model.User;
|
import com.commafeed.backend.model.User;
|
||||||
import com.commafeed.backend.model.UserSettings;
|
import com.commafeed.backend.model.UserSettings;
|
||||||
import com.commafeed.security.AuthenticationContext;
|
import com.commafeed.security.AuthenticationContext;
|
||||||
|
|
||||||
import jakarta.inject.Singleton;
|
import jakarta.inject.Singleton;
|
||||||
|
import jakarta.transaction.Transactional;
|
||||||
import jakarta.ws.rs.GET;
|
import jakarta.ws.rs.GET;
|
||||||
import jakarta.ws.rs.Path;
|
import jakarta.ws.rs.Path;
|
||||||
import jakarta.ws.rs.Produces;
|
import jakarta.ws.rs.Produces;
|
||||||
@@ -20,16 +20,16 @@ public class CustomCssServlet {
|
|||||||
|
|
||||||
private final AuthenticationContext authenticationContext;
|
private final AuthenticationContext authenticationContext;
|
||||||
private final UserSettingsDAO userSettingsDAO;
|
private final UserSettingsDAO userSettingsDAO;
|
||||||
private final UnitOfWork unitOfWork;
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
|
@Transactional
|
||||||
public String get() {
|
public String get() {
|
||||||
User user = authenticationContext.getCurrentUser();
|
User user = authenticationContext.getCurrentUser();
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
UserSettings settings = unitOfWork.call(() -> userSettingsDAO.findByUser(user));
|
UserSettings settings = userSettingsDAO.findByUser(user);
|
||||||
if (settings == null) {
|
if (settings == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package com.commafeed.frontend.servlet;
|
package com.commafeed.frontend.servlet;
|
||||||
|
|
||||||
import com.commafeed.backend.dao.UnitOfWork;
|
|
||||||
import com.commafeed.backend.dao.UserSettingsDAO;
|
import com.commafeed.backend.dao.UserSettingsDAO;
|
||||||
import com.commafeed.backend.model.User;
|
import com.commafeed.backend.model.User;
|
||||||
import com.commafeed.backend.model.UserSettings;
|
import com.commafeed.backend.model.UserSettings;
|
||||||
import com.commafeed.security.AuthenticationContext;
|
import com.commafeed.security.AuthenticationContext;
|
||||||
|
|
||||||
import jakarta.inject.Singleton;
|
import jakarta.inject.Singleton;
|
||||||
|
import jakarta.transaction.Transactional;
|
||||||
import jakarta.ws.rs.GET;
|
import jakarta.ws.rs.GET;
|
||||||
import jakarta.ws.rs.Path;
|
import jakarta.ws.rs.Path;
|
||||||
import jakarta.ws.rs.Produces;
|
import jakarta.ws.rs.Produces;
|
||||||
@@ -20,16 +20,16 @@ public class CustomJsServlet {
|
|||||||
|
|
||||||
private final AuthenticationContext authenticationContext;
|
private final AuthenticationContext authenticationContext;
|
||||||
private final UserSettingsDAO userSettingsDAO;
|
private final UserSettingsDAO userSettingsDAO;
|
||||||
private final UnitOfWork unitOfWork;
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
|
@Transactional
|
||||||
public String get() {
|
public String get() {
|
||||||
User user = authenticationContext.getCurrentUser();
|
User user = authenticationContext.getCurrentUser();
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
UserSettings settings = unitOfWork.call(() -> userSettingsDAO.findByUser(user));
|
UserSettings settings = userSettingsDAO.findByUser(user);
|
||||||
if (settings == null) {
|
if (settings == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import com.commafeed.backend.dao.FeedCategoryDAO;
|
import com.commafeed.backend.dao.FeedCategoryDAO;
|
||||||
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
||||||
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||||
import com.commafeed.backend.dao.UnitOfWork;
|
|
||||||
import com.commafeed.backend.model.FeedCategory;
|
import com.commafeed.backend.model.FeedCategory;
|
||||||
import com.commafeed.backend.model.FeedEntryStatus;
|
import com.commafeed.backend.model.FeedEntryStatus;
|
||||||
import com.commafeed.backend.model.FeedSubscription;
|
import com.commafeed.backend.model.FeedSubscription;
|
||||||
@@ -20,6 +19,7 @@ import com.commafeed.security.AuthenticationContext;
|
|||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
import jakarta.inject.Singleton;
|
import jakarta.inject.Singleton;
|
||||||
|
import jakarta.transaction.Transactional;
|
||||||
import jakarta.ws.rs.DefaultValue;
|
import jakarta.ws.rs.DefaultValue;
|
||||||
import jakarta.ws.rs.GET;
|
import jakarta.ws.rs.GET;
|
||||||
import jakarta.ws.rs.Path;
|
import jakarta.ws.rs.Path;
|
||||||
@@ -33,7 +33,6 @@ import lombok.RequiredArgsConstructor;
|
|||||||
@Singleton
|
@Singleton
|
||||||
public class NextUnreadServlet {
|
public class NextUnreadServlet {
|
||||||
|
|
||||||
private final UnitOfWork unitOfWork;
|
|
||||||
private final FeedSubscriptionDAO feedSubscriptionDAO;
|
private final FeedSubscriptionDAO feedSubscriptionDAO;
|
||||||
private final FeedEntryStatusDAO feedEntryStatusDAO;
|
private final FeedEntryStatusDAO feedEntryStatusDAO;
|
||||||
private final FeedCategoryDAO feedCategoryDAO;
|
private final FeedCategoryDAO feedCategoryDAO;
|
||||||
@@ -42,36 +41,34 @@ public class NextUnreadServlet {
|
|||||||
private final UriInfo uri;
|
private final UriInfo uri;
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
|
@Transactional
|
||||||
public Response get(@QueryParam("category") String categoryId, @QueryParam("order") @DefaultValue("desc") ReadingOrder order) {
|
public Response get(@QueryParam("category") String categoryId, @QueryParam("order") @DefaultValue("desc") ReadingOrder order) {
|
||||||
User user = authenticationContext.getCurrentUser();
|
User user = authenticationContext.getCurrentUser();
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return Response.temporaryRedirect(uri.getBaseUri()).build();
|
return Response.temporaryRedirect(uri.getBaseUri()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
FeedEntryStatus status = unitOfWork.call(() -> {
|
|
||||||
FeedEntryStatus s = null;
|
FeedEntryStatus s = null;
|
||||||
if (StringUtils.isBlank(categoryId) || CategoryREST.ALL.equals(categoryId)) {
|
if (StringUtils.isBlank(categoryId) || CategoryREST.ALL.equals(categoryId)) {
|
||||||
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(user);
|
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(user);
|
||||||
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findBySubscriptions(user, subs, true, null, null, 0, 1, order, true,
|
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findBySubscriptions(user, subs, true, null, null, 0, 1, order, true, null,
|
||||||
null, null, null);
|
null, null);
|
||||||
s = Iterables.getFirst(statuses, null);
|
s = Iterables.getFirst(statuses, null);
|
||||||
} else {
|
} else {
|
||||||
FeedCategory category = feedCategoryDAO.findById(user, Long.valueOf(categoryId));
|
FeedCategory category = feedCategoryDAO.findById(user, Long.valueOf(categoryId));
|
||||||
if (category != null) {
|
if (category != null) {
|
||||||
List<FeedCategory> children = feedCategoryDAO.findAllChildrenCategories(user, category);
|
List<FeedCategory> children = feedCategoryDAO.findAllChildrenCategories(user, category);
|
||||||
List<FeedSubscription> subscriptions = feedSubscriptionDAO.findByCategories(user, children);
|
List<FeedSubscription> subscriptions = feedSubscriptionDAO.findByCategories(user, children);
|
||||||
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findBySubscriptions(user, subscriptions, true, null, null, 0, 1,
|
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findBySubscriptions(user, subscriptions, true, null, null, 0, 1, order,
|
||||||
order, true, null, null, null);
|
true, null, null, null);
|
||||||
s = Iterables.getFirst(statuses, null);
|
s = Iterables.getFirst(statuses, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
feedEntryService.markEntry(user, s.getEntry().getId(), true);
|
feedEntryService.markEntry(user, s.getEntry().getId(), true);
|
||||||
}
|
}
|
||||||
return s;
|
|
||||||
});
|
|
||||||
|
|
||||||
String url = status == null ? uri.getBaseUri().toString() : status.getEntry().getUrl();
|
String url = s == null ? uri.getBaseUri().toString() : s.getEntry().getUrl();
|
||||||
return Response.temporaryRedirect(URI.create(url)).build();
|
return Response.temporaryRedirect(URI.create(url)).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user