From 97f3efbf7c999f3acde255b24dc26d882541fb96 Mon Sep 17 00:00:00 2001 From: Athou Date: Thu, 27 Jun 2013 23:30:16 +0200 Subject: [PATCH] fix postgresql deployment (fix #350) --- .../com/commafeed/backend/DatabaseUpdater.java | 15 ++++++++++++++- .../backend/dao/FeedEntryStatusDAO.java | 18 +++++++++++++----- .../backend/model/ApplicationSettings.java | 9 +++++++++ .../resources/changelogs/db.changelog-1.1.xml | 15 +++++++++++++-- 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/commafeed/backend/DatabaseUpdater.java b/src/main/java/com/commafeed/backend/DatabaseUpdater.java index 05c286ea..a27cb9f3 100644 --- a/src/main/java/com/commafeed/backend/DatabaseUpdater.java +++ b/src/main/java/com/commafeed/backend/DatabaseUpdater.java @@ -13,9 +13,11 @@ import javax.sql.DataSource; import liquibase.Liquibase; import liquibase.database.Database; import liquibase.database.DatabaseFactory; +import liquibase.database.core.PostgresDatabase; import liquibase.database.jvm.JdbcConnection; import liquibase.resource.ClassLoaderResourceAccessor; import liquibase.resource.ResourceAccessor; +import liquibase.structure.DatabaseObject; @Stateless @TransactionManagement(TransactionManagementType.BEAN) @@ -37,10 +39,21 @@ public class DatabaseUpdater { DataSource dataSource = (DataSource) context .lookup(datasourceName); connection = dataSource.getConnection(); + JdbcConnection jdbcConnection = new JdbcConnection(connection); Database database = DatabaseFactory.getInstance() .findCorrectDatabaseImplementation( - new JdbcConnection(connection)); + jdbcConnection); + + if (database instanceof PostgresDatabase) { + database = new PostgresDatabase() { + @Override + public String escapeObjectName(String objectName, Class objectType) { + return objectName; + } + }; + database.setConnection(jdbcConnection); + } Liquibase liq = new Liquibase( "changelogs/db.changelog-master.xml", accessor, diff --git a/src/main/java/com/commafeed/backend/dao/FeedEntryStatusDAO.java b/src/main/java/com/commafeed/backend/dao/FeedEntryStatusDAO.java index 4abff846..e8c91fa9 100644 --- a/src/main/java/com/commafeed/backend/dao/FeedEntryStatusDAO.java +++ b/src/main/java/com/commafeed/backend/dao/FeedEntryStatusDAO.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; import javax.ejb.Stateless; +import javax.inject.Inject; import javax.persistence.NoResultException; import javax.persistence.Query; import javax.persistence.Tuple; @@ -36,6 +37,7 @@ import com.commafeed.backend.model.FeedSubscription_; import com.commafeed.backend.model.Feed_; import com.commafeed.backend.model.User; import com.commafeed.backend.model.UserSettings.ReadingOrder; +import com.commafeed.backend.services.ApplicationSettingsService; import com.google.common.base.Function; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -47,6 +49,9 @@ public class FeedEntryStatusDAO extends GenericDAO { protected static Logger log = LoggerFactory .getLogger(FeedEntryStatusDAO.class); + @Inject + ApplicationSettingsService applicationSettingsService; + @SuppressWarnings("unchecked") public FeedEntryStatus findById(User user, Long id) { @@ -92,7 +97,7 @@ public class FeedEntryStatusDAO extends GenericDAO { if (CollectionUtils.isEmpty(entries)) { return results; } - + CriteriaQuery query = builder.createQuery(getType()); Root root = query.from(getType()); @@ -126,11 +131,11 @@ public class FeedEntryStatusDAO extends GenericDAO { public List findByKeywords(User user, String keywords, int offset, int limit) { - + String joinedKeywords = StringUtils.join( keywords.toLowerCase().split(" "), "%"); joinedKeywords = "%" + joinedKeywords + "%"; - + CriteriaQuery query = builder.createTupleQuery(); Root root = query.from(FeedEntry.class); @@ -148,7 +153,7 @@ public class FeedEntryStatusDAO extends GenericDAO { predicates .add(builder.equal(subJoin.get(FeedSubscription_.user), user)); - + Predicate content = builder.like( builder.lower(contentJoin.get(FeedEntryContent_.content)), joinedKeywords); @@ -522,7 +527,10 @@ public class FeedEntryStatusDAO extends GenericDAO { } private void setTimeout(Query query) { - query.setHint("javax.persistence.query.timeout", 20000); + int queryTimeout = applicationSettingsService.get().getQueryTimeout(); + if (queryTimeout > 0) { + query.setHint("javax.persistence.query.timeout", queryTimeout); + } } public void markSubscriptionEntries(FeedSubscription subscription, diff --git a/src/main/java/com/commafeed/backend/model/ApplicationSettings.java b/src/main/java/com/commafeed/backend/model/ApplicationSettings.java index 4e83086d..36ead44e 100644 --- a/src/main/java/com/commafeed/backend/model/ApplicationSettings.java +++ b/src/main/java/com/commafeed/backend/model/ApplicationSettings.java @@ -33,6 +33,7 @@ public class ApplicationSettings extends AbstractModel { private boolean feedbackButton = true; private String logLevel = Level.INFO.toString(); private boolean imageProxyEnabled; + private int queryTimeout; @Column(length = 255) private String announcement; @@ -182,4 +183,12 @@ public class ApplicationSettings extends AbstractModel { this.imageProxyEnabled = imageProxyEnabled; } + public int getQueryTimeout() { + return queryTimeout; + } + + public void setQueryTimeout(int queryTimeout) { + this.queryTimeout = queryTimeout; + } + } diff --git a/src/main/resources/changelogs/db.changelog-1.1.xml b/src/main/resources/changelogs/db.changelog-1.1.xml index d0ea06bb..4f313cfb 100644 --- a/src/main/resources/changelogs/db.changelog-1.1.xml +++ b/src/main/resources/changelogs/db.changelog-1.1.xml @@ -218,17 +218,28 @@ + 3:b1bbf8d559ac25b785751704f2d24a91 - update USERS set created = lastLogin - update APPLICATIONSETTINGS set imageProxyEnabled=false + + + + + + + + + + + +