diff --git a/commafeed-server/docker-compose.dev.yml b/commafeed-server/docker-compose.dev.yml index 6aa7ff216..9fdfb1a61 100644 --- a/commafeed-server/docker-compose.dev.yml +++ b/commafeed-server/docker-compose.dev.yml @@ -7,7 +7,7 @@ services: - MYSQL_ROOT_PASSWORD=root - MYSQL_DATABASE=commafeed ports: - - 3306:3306 + - "3306:3306" postgresql: image: postgres @@ -16,4 +16,4 @@ services: - POSTGRES_PASSWORD=root - POSTGRES_DB=commafeed ports: - - 5432:5432 + - "5432:5432" diff --git a/commafeed-server/src/main/java/com/commafeed/CommaFeedApplication.java b/commafeed-server/src/main/java/com/commafeed/CommaFeedApplication.java index bee52d184..4bd7183f1 100644 --- a/commafeed-server/src/main/java/com/commafeed/CommaFeedApplication.java +++ b/commafeed-server/src/main/java/com/commafeed/CommaFeedApplication.java @@ -98,9 +98,9 @@ public void initialize(Bootstrap bootstrap) { configureObjectMapper(bootstrap.getObjectMapper()); // run h2 migration as the first bundle because we need to migrate before hibernate is initialized - bootstrap.addBundle(new ConfiguredBundle() { + bootstrap.addBundle(new ConfiguredBundle<>() { @Override - public void run(CommaFeedConfiguration config, Environment environment) throws Exception { + public void run(CommaFeedConfiguration config, Environment environment) { DataSourceFactory dataSourceFactory = config.getDataSourceFactory(); String url = dataSourceFactory.getUrl(); if (isFileBasedH2(url)) { diff --git a/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedCategoryDAO.java b/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedCategoryDAO.java index d29f8dbc2..16bb496bf 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedCategoryDAO.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedCategoryDAO.java @@ -17,7 +17,7 @@ @Singleton public class FeedCategoryDAO extends GenericDAO { - private final QFeedCategory category = QFeedCategory.feedCategory; + private static final QFeedCategory CATEGORY = QFeedCategory.feedCategory; @Inject public FeedCategoryDAO(SessionFactory sessionFactory) { @@ -25,31 +25,31 @@ public FeedCategoryDAO(SessionFactory sessionFactory) { } public List findAll(User user) { - return query().selectFrom(category).where(category.user.eq(user)).join(category.user, QUser.user).fetchJoin().fetch(); + return query().selectFrom(CATEGORY).where(CATEGORY.user.eq(user)).join(CATEGORY.user, QUser.user).fetchJoin().fetch(); } public FeedCategory findById(User user, Long id) { - return query().selectFrom(category).where(category.user.eq(user), category.id.eq(id)).fetchOne(); + return query().selectFrom(CATEGORY).where(CATEGORY.user.eq(user), CATEGORY.id.eq(id)).fetchOne(); } public FeedCategory findByName(User user, String name, FeedCategory parent) { Predicate parentPredicate; if (parent == null) { - parentPredicate = category.parent.isNull(); + parentPredicate = CATEGORY.parent.isNull(); } else { - parentPredicate = category.parent.eq(parent); + parentPredicate = CATEGORY.parent.eq(parent); } - return query().selectFrom(category).where(category.user.eq(user), category.name.eq(name), parentPredicate).fetchOne(); + return query().selectFrom(CATEGORY).where(CATEGORY.user.eq(user), CATEGORY.name.eq(name), parentPredicate).fetchOne(); } public List findByParent(User user, FeedCategory parent) { Predicate parentPredicate; if (parent == null) { - parentPredicate = category.parent.isNull(); + parentPredicate = CATEGORY.parent.isNull(); } else { - parentPredicate = category.parent.eq(parent); + parentPredicate = CATEGORY.parent.eq(parent); } - return query().selectFrom(category).where(category.user.eq(user), parentPredicate).fetch(); + return query().selectFrom(CATEGORY).where(CATEGORY.user.eq(user), parentPredicate).fetch(); } public List findAllChildrenCategories(User user, FeedCategory parent) { diff --git a/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedDAO.java b/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedDAO.java index 21b7c1a25..f34a923e8 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedDAO.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedDAO.java @@ -18,8 +18,8 @@ @Singleton public class FeedDAO extends GenericDAO { - private final QFeed feed = QFeed.feed; - private final QFeedSubscription subscription = QFeedSubscription.feedSubscription; + private static final QFeed FEED = QFeed.feed; + private static final QFeedSubscription SUBSCRIPTION = QFeedSubscription.feedSubscription; @Inject public FeedDAO(SessionFactory sessionFactory) { @@ -27,25 +27,25 @@ public FeedDAO(SessionFactory sessionFactory) { } public List findNextUpdatable(int count, Instant lastLoginThreshold) { - JPAQuery query = query().selectFrom(feed).where(feed.disabledUntil.isNull().or(feed.disabledUntil.lt(Instant.now()))); + JPAQuery query = query().selectFrom(FEED).where(FEED.disabledUntil.isNull().or(FEED.disabledUntil.lt(Instant.now()))); if (lastLoginThreshold != null) { query.where(JPAExpressions.selectOne() - .from(subscription) - .join(subscription.user) - .where(subscription.feed.id.eq(feed.id), subscription.user.lastLogin.gt(lastLoginThreshold)) + .from(SUBSCRIPTION) + .join(SUBSCRIPTION.user) + .where(SUBSCRIPTION.feed.id.eq(FEED.id), SUBSCRIPTION.user.lastLogin.gt(lastLoginThreshold)) .exists()); } - return query.orderBy(feed.disabledUntil.asc()).limit(count).fetch(); + return query.orderBy(FEED.disabledUntil.asc()).limit(count).fetch(); } public void setDisabledUntil(List feedIds, Instant date) { - updateQuery(feed).set(feed.disabledUntil, date).where(feed.id.in(feedIds)).execute(); + updateQuery(FEED).set(FEED.disabledUntil, date).where(FEED.id.in(feedIds)).execute(); } public Feed findByUrl(String normalizedUrl, String normalizedUrlHash) { - return query().selectFrom(feed) - .where(feed.normalizedUrlHash.eq(normalizedUrlHash)) + return query().selectFrom(FEED) + .where(FEED.normalizedUrlHash.eq(normalizedUrlHash)) .fetch() .stream() .filter(f -> StringUtils.equals(normalizedUrl, f.getNormalizedUrl())) @@ -55,6 +55,6 @@ public Feed findByUrl(String normalizedUrl, String normalizedUrlHash) { public List findWithoutSubscriptions(int max) { QFeedSubscription sub = QFeedSubscription.feedSubscription; - return query().selectFrom(feed).where(JPAExpressions.selectOne().from(sub).where(sub.feed.eq(feed)).notExists()).limit(max).fetch(); + return query().selectFrom(FEED).where(JPAExpressions.selectOne().from(sub).where(sub.feed.eq(FEED)).notExists()).limit(max).fetch(); } } diff --git a/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedEntryContentDAO.java b/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedEntryContentDAO.java index 8659f9ba1..8d65b449b 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedEntryContentDAO.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedEntryContentDAO.java @@ -16,8 +16,8 @@ @Singleton public class FeedEntryContentDAO extends GenericDAO { - private final QFeedEntryContent content = QFeedEntryContent.feedEntryContent; - private final QFeedEntry entry = QFeedEntry.feedEntry; + private static final QFeedEntryContent CONTENT = QFeedEntryContent.feedEntryContent; + private static final QFeedEntry ENTRY = QFeedEntry.feedEntry; @Inject public FeedEntryContentDAO(SessionFactory sessionFactory) { @@ -25,13 +25,13 @@ public FeedEntryContentDAO(SessionFactory sessionFactory) { } public List findExisting(String contentHash, String titleHash) { - return query().select(content).from(content).where(content.contentHash.eq(contentHash), content.titleHash.eq(titleHash)).fetch(); + return query().select(CONTENT).from(CONTENT).where(CONTENT.contentHash.eq(contentHash), CONTENT.titleHash.eq(titleHash)).fetch(); } public long deleteWithoutEntries(int max) { - JPQLSubQuery subQuery = JPAExpressions.selectOne().from(entry).where(entry.content.id.eq(content.id)); - List ids = query().select(content.id).from(content).where(subQuery.notExists()).limit(max).fetch(); + JPQLSubQuery subQuery = JPAExpressions.selectOne().from(ENTRY).where(ENTRY.content.id.eq(CONTENT.id)); + List ids = query().select(CONTENT.id).from(CONTENT).where(subQuery.notExists()).limit(max).fetch(); - return deleteQuery(content).where(content.id.in(ids)).execute(); + return deleteQuery(CONTENT).where(CONTENT.id.in(ids)).execute(); } } diff --git a/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedEntryDAO.java b/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedEntryDAO.java index 0c57fd40d..d24148f54 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedEntryDAO.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedEntryDAO.java @@ -19,7 +19,7 @@ @Singleton public class FeedEntryDAO extends GenericDAO { - private final QFeedEntry entry = QFeedEntry.feedEntry; + private static final QFeedEntry ENTRY = QFeedEntry.feedEntry; @Inject public FeedEntryDAO(SessionFactory sessionFactory) { @@ -27,22 +27,22 @@ public FeedEntryDAO(SessionFactory sessionFactory) { } public FeedEntry findExisting(String guidHash, Feed feed) { - return query().select(entry).from(entry).where(entry.guidHash.eq(guidHash), entry.feed.eq(feed)).limit(1).fetchOne(); + return query().select(ENTRY).from(ENTRY).where(ENTRY.guidHash.eq(guidHash), ENTRY.feed.eq(feed)).limit(1).fetchOne(); } public List findFeedsExceedingCapacity(long maxCapacity, long max) { - NumberExpression count = entry.id.count(); - List tuples = query().select(entry.feed.id, count) - .from(entry) - .groupBy(entry.feed) + NumberExpression count = ENTRY.id.count(); + List tuples = query().select(ENTRY.feed.id, count) + .from(ENTRY) + .groupBy(ENTRY.feed) .having(count.gt(maxCapacity)) .limit(max) .fetch(); - return tuples.stream().map(t -> new FeedCapacity(t.get(entry.feed.id), t.get(count))).toList(); + return tuples.stream().map(t -> new FeedCapacity(t.get(ENTRY.feed.id), t.get(count))).toList(); } public int delete(Long feedId, long max) { - List list = query().selectFrom(entry).where(entry.feed.id.eq(feedId)).limit(max).fetch(); + List list = query().selectFrom(ENTRY).where(ENTRY.feed.id.eq(feedId)).limit(max).fetch(); return delete(list); } @@ -50,7 +50,7 @@ public int delete(Long feedId, long max) { * Delete entries older than a certain date */ public int deleteEntriesOlderThan(Instant olderThan, long max) { - List list = query().selectFrom(entry).where(entry.updated.lt(olderThan)).orderBy(entry.updated.asc()).limit(max).fetch(); + List list = query().selectFrom(ENTRY).where(ENTRY.updated.lt(olderThan)).orderBy(ENTRY.updated.asc()).limit(max).fetch(); return delete(list); } @@ -58,7 +58,7 @@ public int deleteEntriesOlderThan(Instant olderThan, long max) { * Delete the oldest entries of a feed */ public int deleteOldEntries(Long feedId, long max) { - List list = query().selectFrom(entry).where(entry.feed.id.eq(feedId)).orderBy(entry.updated.asc()).limit(max).fetch(); + List list = query().selectFrom(ENTRY).where(ENTRY.feed.id.eq(feedId)).orderBy(ENTRY.updated.asc()).limit(max).fetch(); return delete(list); } diff --git a/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedEntryStatusDAO.java b/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedEntryStatusDAO.java index 89faeeb32..a5ca86310 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedEntryStatusDAO.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedEntryStatusDAO.java @@ -35,16 +35,16 @@ @Singleton public class FeedEntryStatusDAO extends GenericDAO { + private static final QFeedEntryStatus STATUS = QFeedEntryStatus.feedEntryStatus; + private static final QFeedEntry ENTRY = QFeedEntry.feedEntry; + private static final QFeed FEED = QFeed.feed; + private static final QFeedSubscription SUBSCRIPTION = QFeedSubscription.feedSubscription; + private static final QFeedEntryContent CONTENT = QFeedEntryContent.feedEntryContent; + private static final QFeedEntryTag TAG = QFeedEntryTag.feedEntryTag; + private final FeedEntryTagDAO feedEntryTagDAO; private final CommaFeedConfiguration config; - private final QFeedEntryStatus status = QFeedEntryStatus.feedEntryStatus; - private final QFeedEntry entry = QFeedEntry.feedEntry; - private final QFeed feed = QFeed.feed; - private final QFeedSubscription subscription = QFeedSubscription.feedSubscription; - private final QFeedEntryContent content = QFeedEntryContent.feedEntryContent; - private final QFeedEntryTag entryTag = QFeedEntryTag.feedEntryTag; - @Inject public FeedEntryStatusDAO(SessionFactory sessionFactory, FeedEntryTagDAO feedEntryTagDAO, CommaFeedConfiguration config) { super(sessionFactory); @@ -53,7 +53,7 @@ public FeedEntryStatusDAO(SessionFactory sessionFactory, FeedEntryTagDAO feedEnt } public FeedEntryStatus getStatus(User user, FeedSubscription sub, FeedEntry entry) { - List statuses = query().selectFrom(status).where(status.entry.eq(entry), status.subscription.eq(sub)).fetch(); + List statuses = query().selectFrom(STATUS).where(STATUS.entry.eq(entry), STATUS.subscription.eq(sub)).fetch(); FeedEntryStatus status = Iterables.getFirst(statuses, null); return handleStatus(user, status, sub, entry); } @@ -85,19 +85,19 @@ private void fetchTags(User user, List statuses) { public List findStarred(User user, Instant newerThan, int offset, int limit, ReadingOrder order, boolean includeContent) { - JPAQuery query = query().selectFrom(status).where(status.user.eq(user), status.starred.isTrue()); + JPAQuery query = query().selectFrom(STATUS).where(STATUS.user.eq(user), STATUS.starred.isTrue()); if (includeContent) { - query.join(status.entry.content).fetchJoin(); + query.join(STATUS.entry.content).fetchJoin(); } if (newerThan != null) { - query.where(status.entryInserted.gt(newerThan)); + query.where(STATUS.entryInserted.gt(newerThan)); } if (order == ReadingOrder.asc) { - query.orderBy(status.entryUpdated.asc(), status.id.asc()); + query.orderBy(STATUS.entryUpdated.asc(), STATUS.id.asc()); } else { - query.orderBy(status.entryUpdated.desc(), status.id.desc()); + query.orderBy(STATUS.entryUpdated.desc(), STATUS.id.desc()); } if (offset > -1) { @@ -123,20 +123,20 @@ public List findBySubscriptions(User user, List keywords, Instant newerThan, int offset, int limit, ReadingOrder order, boolean includeContent, String tag, Long minEntryId, Long maxEntryId) { - JPAQuery query = query().select(entry, subscription, status).from(entry); - query.join(entry.feed, feed); - query.join(subscription).on(subscription.feed.eq(feed).and(subscription.user.eq(user))); - query.leftJoin(status).on(status.entry.eq(entry).and(status.subscription.eq(subscription))); - query.where(subscription.in(subs)); + JPAQuery query = query().select(ENTRY, SUBSCRIPTION, STATUS).from(ENTRY); + query.join(ENTRY.feed, FEED); + query.join(SUBSCRIPTION).on(SUBSCRIPTION.feed.eq(FEED).and(SUBSCRIPTION.user.eq(user))); + query.leftJoin(STATUS).on(STATUS.entry.eq(ENTRY).and(STATUS.subscription.eq(SUBSCRIPTION))); + query.where(SUBSCRIPTION.in(subs)); if (includeContent || CollectionUtils.isNotEmpty(keywords)) { - query.join(entry.content, content).fetchJoin(); + query.join(ENTRY.content, CONTENT).fetchJoin(); } if (CollectionUtils.isNotEmpty(keywords)) { for (FeedEntryKeyword keyword : keywords) { BooleanBuilder or = new BooleanBuilder(); - or.or(content.content.containsIgnoreCase(keyword.getKeyword())); - or.or(content.title.containsIgnoreCase(keyword.getKeyword())); + or.or(CONTENT.content.containsIgnoreCase(keyword.getKeyword())); + or.or(CONTENT.title.containsIgnoreCase(keyword.getKeyword())); if (keyword.getMode() == Mode.EXCLUDE) { or.not(); } @@ -150,28 +150,28 @@ public List findBySubscriptions(User user, List findBySubscriptions(User user, List statuses = new ArrayList<>(); List tuples = query.fetch(); for (Tuple tuple : tuples) { - FeedEntry e = tuple.get(entry); - FeedSubscription sub = tuple.get(subscription); - FeedEntryStatus s = handleStatus(user, tuple.get(status), sub, e); + FeedEntry e = tuple.get(ENTRY); + FeedSubscription sub = tuple.get(SUBSCRIPTION); + FeedEntryStatus s = handleStatus(user, tuple.get(STATUS), sub, e); statuses.add(s); } @@ -202,41 +202,41 @@ public List findBySubscriptions(User user, List query = query().select(entry.count(), entry.updated.max()) - .from(entry) - .join(entry.feed, feed) - .join(subscription) - .on(subscription.feed.eq(feed).and(subscription.eq(sub))) - .leftJoin(status) - .on(status.entry.eq(entry).and(status.subscription.eq(sub))) + JPAQuery query = query().select(ENTRY.count(), ENTRY.updated.max()) + .from(ENTRY) + .join(ENTRY.feed, FEED) + .join(SUBSCRIPTION) + .on(SUBSCRIPTION.feed.eq(FEED).and(SUBSCRIPTION.eq(sub))) + .leftJoin(STATUS) + .on(STATUS.entry.eq(ENTRY).and(STATUS.subscription.eq(sub))) .where(buildUnreadPredicate()); Tuple tuple = query.fetchOne(); - Long count = tuple.get(entry.count()); - Instant updated = tuple.get(entry.updated.max()); + Long count = tuple.get(ENTRY.count()); + Instant updated = tuple.get(ENTRY.updated.max()); return new UnreadCount(sub.getId(), count == null ? 0 : count, updated); } private BooleanBuilder buildUnreadPredicate() { BooleanBuilder or = new BooleanBuilder(); - or.or(status.read.isNull()); - or.or(status.read.isFalse()); + or.or(STATUS.read.isNull()); + or.or(STATUS.read.isFalse()); Instant unreadThreshold = config.getApplicationSettings().getUnreadThreshold(); if (unreadThreshold != null) { - return or.and(entry.updated.goe(unreadThreshold)); + return or.and(ENTRY.updated.goe(unreadThreshold)); } else { return or; } } public long deleteOldStatuses(Instant olderThan, int limit) { - List ids = query().select(status.id) - .from(status) - .where(status.entryInserted.lt(olderThan), status.starred.isFalse()) + List ids = query().select(STATUS.id) + .from(STATUS) + .where(STATUS.entryInserted.lt(olderThan), STATUS.starred.isFalse()) .limit(limit) .fetch(); - return deleteQuery(status).where(status.id.in(ids)).execute(); + return deleteQuery(STATUS).where(STATUS.id.in(ids)).execute(); } } diff --git a/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedEntryTagDAO.java b/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedEntryTagDAO.java index e60ff215e..5d87d7294 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedEntryTagDAO.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedEntryTagDAO.java @@ -17,7 +17,7 @@ @Singleton public class FeedEntryTagDAO extends GenericDAO { - private final QFeedEntryTag tag = QFeedEntryTag.feedEntryTag; + private static final QFeedEntryTag TAG = QFeedEntryTag.feedEntryTag; @Inject public FeedEntryTagDAO(SessionFactory sessionFactory) { @@ -25,16 +25,16 @@ public FeedEntryTagDAO(SessionFactory sessionFactory) { } public List findByUser(User user) { - return query().selectDistinct(tag.name).from(tag).where(tag.user.eq(user)).fetch(); + return query().selectDistinct(TAG.name).from(TAG).where(TAG.user.eq(user)).fetch(); } public List findByEntry(User user, FeedEntry entry) { - return query().selectFrom(tag).where(tag.user.eq(user), tag.entry.eq(entry)).fetch(); + return query().selectFrom(TAG).where(TAG.user.eq(user), TAG.entry.eq(entry)).fetch(); } public Map> findByEntries(User user, List entries) { - return query().selectFrom(tag) - .where(tag.user.eq(user), tag.entry.in(entries)) + return query().selectFrom(TAG) + .where(TAG.user.eq(user), TAG.entry.in(entries)) .fetch() .stream() .collect(Collectors.groupingBy(t -> t.getEntry().getId())); diff --git a/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedSubscriptionDAO.java b/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedSubscriptionDAO.java index 26ea8cd0e..05b1cde7b 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedSubscriptionDAO.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/dao/FeedSubscriptionDAO.java @@ -29,7 +29,7 @@ @Singleton public class FeedSubscriptionDAO extends GenericDAO { - private final QFeedSubscription sub = QFeedSubscription.feedSubscription; + private static final QFeedSubscription SUBSCRIPTION = QFeedSubscription.feedSubscription; private final SessionFactory sessionFactory; @@ -60,46 +60,48 @@ public boolean requiresPostCommitHandling(EntityPersister persister) { } public FeedSubscription findById(User user, Long id) { - List subs = query().selectFrom(sub) - .where(sub.user.eq(user), sub.id.eq(id)) - .leftJoin(sub.feed) + List subs = query().selectFrom(SUBSCRIPTION) + .where(SUBSCRIPTION.user.eq(user), SUBSCRIPTION.id.eq(id)) + .leftJoin(SUBSCRIPTION.feed) .fetchJoin() - .leftJoin(sub.category) + .leftJoin(SUBSCRIPTION.category) .fetchJoin() .fetch(); return initRelations(Iterables.getFirst(subs, null)); } public List findByFeed(Feed feed) { - return query().selectFrom(sub).where(sub.feed.eq(feed)).fetch(); + return query().selectFrom(SUBSCRIPTION).where(SUBSCRIPTION.feed.eq(feed)).fetch(); } public FeedSubscription findByFeed(User user, Feed feed) { - List subs = query().selectFrom(sub).where(sub.user.eq(user), sub.feed.eq(feed)).fetch(); + List subs = query().selectFrom(SUBSCRIPTION) + .where(SUBSCRIPTION.user.eq(user), SUBSCRIPTION.feed.eq(feed)) + .fetch(); return initRelations(Iterables.getFirst(subs, null)); } public List findAll(User user) { - List subs = query().selectFrom(sub) - .where(sub.user.eq(user)) - .leftJoin(sub.feed) + List subs = query().selectFrom(SUBSCRIPTION) + .where(SUBSCRIPTION.user.eq(user)) + .leftJoin(SUBSCRIPTION.feed) .fetchJoin() - .leftJoin(sub.category) + .leftJoin(SUBSCRIPTION.category) .fetchJoin() .fetch(); return initRelations(subs); } public Long count(User user) { - return query().select(sub.count()).from(sub).where(sub.user.eq(user)).fetchOne(); + return query().select(SUBSCRIPTION.count()).from(SUBSCRIPTION).where(SUBSCRIPTION.user.eq(user)).fetchOne(); } public List findByCategory(User user, FeedCategory category) { - JPQLQuery query = query().selectFrom(sub).where(sub.user.eq(user)); + JPQLQuery query = query().selectFrom(SUBSCRIPTION).where(SUBSCRIPTION.user.eq(user)); if (category == null) { - query.where(sub.category.isNull()); + query.where(SUBSCRIPTION.category.isNull()); } else { - query.where(sub.category.eq(category)); + query.where(SUBSCRIPTION.category.eq(category)); } return initRelations(query.fetch()); } diff --git a/commafeed-server/src/main/java/com/commafeed/backend/dao/UserDAO.java b/commafeed-server/src/main/java/com/commafeed/backend/dao/UserDAO.java index 679559b14..ae7d87f4e 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/dao/UserDAO.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/dao/UserDAO.java @@ -11,7 +11,7 @@ @Singleton public class UserDAO extends GenericDAO { - private final QUser user = QUser.user; + private static final QUser USER = QUser.user; @Inject public UserDAO(SessionFactory sessionFactory) { @@ -19,18 +19,18 @@ public UserDAO(SessionFactory sessionFactory) { } public User findByName(String name) { - return query().selectFrom(user).where(user.name.equalsIgnoreCase(name)).fetchOne(); + return query().selectFrom(USER).where(USER.name.equalsIgnoreCase(name)).fetchOne(); } public User findByApiKey(String key) { - return query().selectFrom(user).where(user.apiKey.equalsIgnoreCase(key)).fetchOne(); + return query().selectFrom(USER).where(USER.apiKey.equalsIgnoreCase(key)).fetchOne(); } public User findByEmail(String email) { - return query().selectFrom(user).where(user.email.equalsIgnoreCase(email)).fetchOne(); + return query().selectFrom(USER).where(USER.email.equalsIgnoreCase(email)).fetchOne(); } public long count() { - return query().select(user.count()).from(user).fetchOne(); + return query().select(USER.count()).from(USER).fetchOne(); } } diff --git a/commafeed-server/src/main/java/com/commafeed/backend/dao/UserRoleDAO.java b/commafeed-server/src/main/java/com/commafeed/backend/dao/UserRoleDAO.java index 362465662..37c23e929 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/dao/UserRoleDAO.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/dao/UserRoleDAO.java @@ -17,7 +17,7 @@ @Singleton public class UserRoleDAO extends GenericDAO { - private final QUserRole role = QUserRole.userRole; + private static final QUserRole ROLE = QUserRole.userRole; @Inject public UserRoleDAO(SessionFactory sessionFactory) { @@ -25,11 +25,11 @@ public UserRoleDAO(SessionFactory sessionFactory) { } public List findAll() { - return query().selectFrom(role).leftJoin(role.user).fetchJoin().distinct().fetch(); + return query().selectFrom(ROLE).leftJoin(ROLE.user).fetchJoin().distinct().fetch(); } public List findAll(User user) { - return query().selectFrom(role).where(role.user.eq(user)).distinct().fetch(); + return query().selectFrom(ROLE).where(ROLE.user.eq(user)).distinct().fetch(); } public Set findRoles(User user) { diff --git a/commafeed-server/src/main/java/com/commafeed/backend/dao/UserSettingsDAO.java b/commafeed-server/src/main/java/com/commafeed/backend/dao/UserSettingsDAO.java index 31c4d3d24..a95450ad4 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/dao/UserSettingsDAO.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/dao/UserSettingsDAO.java @@ -12,7 +12,7 @@ @Singleton public class UserSettingsDAO extends GenericDAO { - private final QUserSettings settings = QUserSettings.userSettings; + private static final QUserSettings SETTINGS = QUserSettings.userSettings; @Inject public UserSettingsDAO(SessionFactory sessionFactory) { @@ -20,6 +20,6 @@ public UserSettingsDAO(SessionFactory sessionFactory) { } public UserSettings findByUser(User user) { - return query().selectFrom(settings).where(settings.user.eq(user)).fetchFirst(); + return query().selectFrom(SETTINGS).where(SETTINGS.user.eq(user)).fetchFirst(); } } diff --git a/commafeed-server/src/main/java/com/commafeed/backend/feed/FeedRefreshUpdater.java b/commafeed-server/src/main/java/com/commafeed/backend/feed/FeedRefreshUpdater.java index ce6c582ef..ea891b03b 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/feed/FeedRefreshUpdater.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/feed/FeedRefreshUpdater.java @@ -120,10 +120,10 @@ private AddEntryResult addEntry(final Feed feed, final Entry entry, final List subscriptions) { .map(Feed::getLastUpdated) .filter(Objects::nonNull) .max(Comparator.naturalOrder()) - .map(d -> d.getEpochSecond()) + .map(Instant::getEpochSecond) .orElse(0L); } diff --git a/commafeed-server/src/test/java/com/commafeed/e2e/PlaywrightTestBase.java b/commafeed-server/src/test/java/com/commafeed/e2e/PlaywrightTestBase.java index 2552a2100..81735c3b1 100644 --- a/commafeed-server/src/test/java/com/commafeed/e2e/PlaywrightTestBase.java +++ b/commafeed-server/src/test/java/com/commafeed/e2e/PlaywrightTestBase.java @@ -54,6 +54,7 @@ static void closeBrowser() { } protected void customizeNewContextOptions(NewContextOptions options) { + // override in subclasses to customize the browser context } protected static class SaveArtifactsOnTestFailed implements TestWatcher, BeforeEachCallback {