forked from Archives/Athou_commafeed
fix postgresql deployment (fix #350)
This commit is contained in:
@@ -13,9 +13,11 @@ import javax.sql.DataSource;
|
|||||||
import liquibase.Liquibase;
|
import liquibase.Liquibase;
|
||||||
import liquibase.database.Database;
|
import liquibase.database.Database;
|
||||||
import liquibase.database.DatabaseFactory;
|
import liquibase.database.DatabaseFactory;
|
||||||
|
import liquibase.database.core.PostgresDatabase;
|
||||||
import liquibase.database.jvm.JdbcConnection;
|
import liquibase.database.jvm.JdbcConnection;
|
||||||
import liquibase.resource.ClassLoaderResourceAccessor;
|
import liquibase.resource.ClassLoaderResourceAccessor;
|
||||||
import liquibase.resource.ResourceAccessor;
|
import liquibase.resource.ResourceAccessor;
|
||||||
|
import liquibase.structure.DatabaseObject;
|
||||||
|
|
||||||
@Stateless
|
@Stateless
|
||||||
@TransactionManagement(TransactionManagementType.BEAN)
|
@TransactionManagement(TransactionManagementType.BEAN)
|
||||||
@@ -37,10 +39,21 @@ public class DatabaseUpdater {
|
|||||||
DataSource dataSource = (DataSource) context
|
DataSource dataSource = (DataSource) context
|
||||||
.lookup(datasourceName);
|
.lookup(datasourceName);
|
||||||
connection = dataSource.getConnection();
|
connection = dataSource.getConnection();
|
||||||
|
JdbcConnection jdbcConnection = new JdbcConnection(connection);
|
||||||
|
|
||||||
Database database = DatabaseFactory.getInstance()
|
Database database = DatabaseFactory.getInstance()
|
||||||
.findCorrectDatabaseImplementation(
|
.findCorrectDatabaseImplementation(
|
||||||
new JdbcConnection(connection));
|
jdbcConnection);
|
||||||
|
|
||||||
|
if (database instanceof PostgresDatabase) {
|
||||||
|
database = new PostgresDatabase() {
|
||||||
|
@Override
|
||||||
|
public String escapeObjectName(String objectName, Class<? extends DatabaseObject> objectType) {
|
||||||
|
return objectName;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
database.setConnection(jdbcConnection);
|
||||||
|
}
|
||||||
|
|
||||||
Liquibase liq = new Liquibase(
|
Liquibase liq = new Liquibase(
|
||||||
"changelogs/db.changelog-master.xml", accessor,
|
"changelogs/db.changelog-master.xml", accessor,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.ejb.Stateless;
|
import javax.ejb.Stateless;
|
||||||
|
import javax.inject.Inject;
|
||||||
import javax.persistence.NoResultException;
|
import javax.persistence.NoResultException;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
import javax.persistence.Tuple;
|
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.Feed_;
|
||||||
import com.commafeed.backend.model.User;
|
import com.commafeed.backend.model.User;
|
||||||
import com.commafeed.backend.model.UserSettings.ReadingOrder;
|
import com.commafeed.backend.model.UserSettings.ReadingOrder;
|
||||||
|
import com.commafeed.backend.services.ApplicationSettingsService;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@@ -47,6 +49,9 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
protected static Logger log = LoggerFactory
|
protected static Logger log = LoggerFactory
|
||||||
.getLogger(FeedEntryStatusDAO.class);
|
.getLogger(FeedEntryStatusDAO.class);
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ApplicationSettingsService applicationSettingsService;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public FeedEntryStatus findById(User user, Long id) {
|
public FeedEntryStatus findById(User user, Long id) {
|
||||||
|
|
||||||
@@ -92,7 +97,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
if (CollectionUtils.isEmpty(entries)) {
|
if (CollectionUtils.isEmpty(entries)) {
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
CriteriaQuery<FeedEntryStatus> query = builder.createQuery(getType());
|
CriteriaQuery<FeedEntryStatus> query = builder.createQuery(getType());
|
||||||
Root<FeedEntryStatus> root = query.from(getType());
|
Root<FeedEntryStatus> root = query.from(getType());
|
||||||
|
|
||||||
@@ -126,11 +131,11 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
|
|
||||||
public List<FeedEntryStatus> findByKeywords(User user, String keywords,
|
public List<FeedEntryStatus> findByKeywords(User user, String keywords,
|
||||||
int offset, int limit) {
|
int offset, int limit) {
|
||||||
|
|
||||||
String joinedKeywords = StringUtils.join(
|
String joinedKeywords = StringUtils.join(
|
||||||
keywords.toLowerCase().split(" "), "%");
|
keywords.toLowerCase().split(" "), "%");
|
||||||
joinedKeywords = "%" + joinedKeywords + "%";
|
joinedKeywords = "%" + joinedKeywords + "%";
|
||||||
|
|
||||||
CriteriaQuery<Tuple> query = builder.createTupleQuery();
|
CriteriaQuery<Tuple> query = builder.createTupleQuery();
|
||||||
Root<FeedEntry> root = query.from(FeedEntry.class);
|
Root<FeedEntry> root = query.from(FeedEntry.class);
|
||||||
|
|
||||||
@@ -148,7 +153,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
|
|
||||||
predicates
|
predicates
|
||||||
.add(builder.equal(subJoin.get(FeedSubscription_.user), user));
|
.add(builder.equal(subJoin.get(FeedSubscription_.user), user));
|
||||||
|
|
||||||
Predicate content = builder.like(
|
Predicate content = builder.like(
|
||||||
builder.lower(contentJoin.get(FeedEntryContent_.content)),
|
builder.lower(contentJoin.get(FeedEntryContent_.content)),
|
||||||
joinedKeywords);
|
joinedKeywords);
|
||||||
@@ -522,7 +527,10 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setTimeout(Query query) {
|
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,
|
public void markSubscriptionEntries(FeedSubscription subscription,
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public class ApplicationSettings extends AbstractModel {
|
|||||||
private boolean feedbackButton = true;
|
private boolean feedbackButton = true;
|
||||||
private String logLevel = Level.INFO.toString();
|
private String logLevel = Level.INFO.toString();
|
||||||
private boolean imageProxyEnabled;
|
private boolean imageProxyEnabled;
|
||||||
|
private int queryTimeout;
|
||||||
|
|
||||||
@Column(length = 255)
|
@Column(length = 255)
|
||||||
private String announcement;
|
private String announcement;
|
||||||
@@ -182,4 +183,12 @@ public class ApplicationSettings extends AbstractModel {
|
|||||||
this.imageProxyEnabled = imageProxyEnabled;
|
this.imageProxyEnabled = imageProxyEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getQueryTimeout() {
|
||||||
|
return queryTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQueryTimeout(int queryTimeout) {
|
||||||
|
this.queryTimeout = queryTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -218,17 +218,28 @@
|
|||||||
</changeSet>
|
</changeSet>
|
||||||
|
|
||||||
<changeSet author="athou" id="add-user-created">
|
<changeSet author="athou" id="add-user-created">
|
||||||
|
<validCheckSum>3:b1bbf8d559ac25b785751704f2d24a91</validCheckSum>
|
||||||
<addColumn tableName="USERS">
|
<addColumn tableName="USERS">
|
||||||
<column name="created" type="DATETIME" />
|
<column name="created" type="DATETIME" />
|
||||||
</addColumn>
|
</addColumn>
|
||||||
<sql>update USERS set created = lastLogin</sql>
|
|
||||||
</changeSet>
|
</changeSet>
|
||||||
|
|
||||||
<changeSet author="athou" id="add-proxy-setting">
|
<changeSet author="athou" id="add-proxy-setting">
|
||||||
<addColumn tableName="APPLICATIONSETTINGS">
|
<addColumn tableName="APPLICATIONSETTINGS">
|
||||||
<column name="imageProxyEnabled" type="BIT" />
|
<column name="imageProxyEnabled" type="BIT" />
|
||||||
</addColumn>
|
</addColumn>
|
||||||
<sql>update APPLICATIONSETTINGS set imageProxyEnabled=false</sql>
|
<update tableName="APPLICATIONSETTINGS">
|
||||||
|
<column name="imageProxyEnabled" valueBoolean="false"></column>
|
||||||
|
</update>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
<changeSet author="athou" id="add-query-timeout-setting">
|
||||||
|
<addColumn tableName="APPLICATIONSETTINGS">
|
||||||
|
<column name="queryTimeout" type="INT" />
|
||||||
|
</addColumn>
|
||||||
|
<update tableName="APPLICATIONSETTINGS">
|
||||||
|
<column name="queryTimeout" valueNumeric="0"></column>
|
||||||
|
</update>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
|
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
|
|||||||
Reference in New Issue
Block a user