Skip to content

Commit

Permalink
remove warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Athou committed Jul 3, 2024
1 parent 6bff657 commit d4c9bd1
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 129 deletions.
4 changes: 2 additions & 2 deletions commafeed-server/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=commafeed
ports:
- 3306:3306
- "3306:3306"

postgresql:
image: postgres
Expand All @@ -16,4 +16,4 @@ services:
- POSTGRES_PASSWORD=root
- POSTGRES_DB=commafeed
ports:
- 5432:5432
- "5432:5432"
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public void initialize(Bootstrap<CommaFeedConfiguration> bootstrap) {
configureObjectMapper(bootstrap.getObjectMapper());

// run h2 migration as the first bundle because we need to migrate before hibernate is initialized
bootstrap.addBundle(new ConfiguredBundle<CommaFeedConfiguration>() {
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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,39 @@
@Singleton
public class FeedCategoryDAO extends GenericDAO<FeedCategory> {

private final QFeedCategory category = QFeedCategory.feedCategory;
private static final QFeedCategory CATEGORY = QFeedCategory.feedCategory;

@Inject
public FeedCategoryDAO(SessionFactory sessionFactory) {
super(sessionFactory);
}

public List<FeedCategory> 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<FeedCategory> 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<FeedCategory> findAllChildrenCategories(User user, FeedCategory parent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@
@Singleton
public class FeedDAO extends GenericDAO<Feed> {

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) {
super(sessionFactory);
}

public List<Feed> findNextUpdatable(int count, Instant lastLoginThreshold) {
JPAQuery<Feed> query = query().selectFrom(feed).where(feed.disabledUntil.isNull().or(feed.disabledUntil.lt(Instant.now())));
JPAQuery<Feed> 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<Long> 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()))
Expand All @@ -55,6 +55,6 @@ public Feed findByUrl(String normalizedUrl, String normalizedUrlHash) {

public List<Feed> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
@Singleton
public class FeedEntryContentDAO extends GenericDAO<FeedEntryContent> {

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) {
super(sessionFactory);
}

public List<FeedEntryContent> 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<Integer> subQuery = JPAExpressions.selectOne().from(entry).where(entry.content.id.eq(content.id));
List<Long> ids = query().select(content.id).from(content).where(subQuery.notExists()).limit(max).fetch();
JPQLSubQuery<Integer> subQuery = JPAExpressions.selectOne().from(ENTRY).where(ENTRY.content.id.eq(CONTENT.id));
List<Long> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,46 @@
@Singleton
public class FeedEntryDAO extends GenericDAO<FeedEntry> {

private final QFeedEntry entry = QFeedEntry.feedEntry;
private static final QFeedEntry ENTRY = QFeedEntry.feedEntry;

@Inject
public FeedEntryDAO(SessionFactory sessionFactory) {
super(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<FeedCapacity> findFeedsExceedingCapacity(long maxCapacity, long max) {
NumberExpression<Long> count = entry.id.count();
List<Tuple> tuples = query().select(entry.feed.id, count)
.from(entry)
.groupBy(entry.feed)
NumberExpression<Long> count = ENTRY.id.count();
List<Tuple> 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<FeedEntry> list = query().selectFrom(entry).where(entry.feed.id.eq(feedId)).limit(max).fetch();
List<FeedEntry> list = query().selectFrom(ENTRY).where(ENTRY.feed.id.eq(feedId)).limit(max).fetch();
return delete(list);
}

/**
* Delete entries older than a certain date
*/
public int deleteEntriesOlderThan(Instant olderThan, long max) {
List<FeedEntry> list = query().selectFrom(entry).where(entry.updated.lt(olderThan)).orderBy(entry.updated.asc()).limit(max).fetch();
List<FeedEntry> list = query().selectFrom(ENTRY).where(ENTRY.updated.lt(olderThan)).orderBy(ENTRY.updated.asc()).limit(max).fetch();
return delete(list);
}

/**
* Delete the oldest entries of a feed
*/
public int deleteOldEntries(Long feedId, long max) {
List<FeedEntry> list = query().selectFrom(entry).where(entry.feed.id.eq(feedId)).orderBy(entry.updated.asc()).limit(max).fetch();
List<FeedEntry> list = query().selectFrom(ENTRY).where(ENTRY.feed.id.eq(feedId)).orderBy(ENTRY.updated.asc()).limit(max).fetch();
return delete(list);
}

Expand Down
Loading

0 comments on commit d4c9bd1

Please sign in to comment.