aboutsummaryrefslogtreecommitdiff
path: root/juick-server-jdbc/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-11-13 15:23:06 +0300
committerGravatar Vitaly Takmazov2017-11-13 15:23:06 +0300
commitfc77902b14c16e7c911a0f2fe6a73e69b252f699 (patch)
tree4e86783db9b588af9f98a8a3e56a48be7a6d53a5 /juick-server-jdbc/src
parent4f32ea8c6889be56861a290e633a89c5b6740e3a (diff)
notifications: moved top service from cron
Diffstat (limited to 'juick-server-jdbc/src')
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/configuration/DataConfiguration.java3
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java14
-rw-r--r--juick-server-jdbc/src/test/java/com/juick/configuration/RepositoryConfiguration.java3
3 files changed, 18 insertions, 2 deletions
diff --git a/juick-server-jdbc/src/main/java/com/juick/configuration/DataConfiguration.java b/juick-server-jdbc/src/main/java/com/juick/configuration/DataConfiguration.java
index 27e60e9b..c728b527 100644
--- a/juick-server-jdbc/src/main/java/com/juick/configuration/DataConfiguration.java
+++ b/juick-server-jdbc/src/main/java/com/juick/configuration/DataConfiguration.java
@@ -28,6 +28,7 @@ import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.TransactionManagementConfigurer;
+import javax.sql.DataSource;
import java.util.Collections;
import java.util.List;
@@ -51,7 +52,7 @@ public class DataConfiguration implements TransactionManagementConfigurer {
// NOTE: The close() method will be called automatically with default @Bean settings
// But Datasource interface has no close() method
@Bean
- public BasicDataSource dataSource() {
+ public DataSource dataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(datasourceDriver);
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
index f71837a7..751b7fc3 100644
--- a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -870,4 +870,18 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
.addValue("before", before),
new MessageMapper());
}
+ @Transactional(readOnly = true)
+ @Override
+ public List<Integer> getPopularCandidates() {
+ return getJdbcTemplate().queryForList("SELECT replies.message_id FROM replies " +
+ "INNER JOIN messages ON replies.message_id = messages.message_id " +
+ "LEFT JOIN messages_tags ON messages_tags.message_id = messages.message_id " +
+ "WHERE COALESCE(messages_tags.tag_id, 0) != 2 AND replies.ts > DATE_ADD(now(), INTERVAL -2 HOUR) " +
+ "AND messages.popular=0 GROUP BY message_id having COUNT(DISTINCT(replies.user_id)) > 5 " +
+ "UNION ALL SELECT favorites.message_id FROM favorites " +
+ "INNER JOIN messages ON messages.message_id = favorites.message_id " +
+ "LEFT JOIN messages_tags ON messages_tags.message_id = messages.message_id " +
+ "WHERE COALESCE(messages_tags.tag_id, 0) != 2 AND favorites.ts > DATE_ADD(NOW(), INTERVAL -2 HOUR) " +
+ "GROUP BY message_id HAVING COUNT(DISTINCT favorites.user_id) > 1;", Integer.class);
+ }
}
diff --git a/juick-server-jdbc/src/test/java/com/juick/configuration/RepositoryConfiguration.java b/juick-server-jdbc/src/test/java/com/juick/configuration/RepositoryConfiguration.java
index dbd13098..94031944 100644
--- a/juick-server-jdbc/src/test/java/com/juick/configuration/RepositoryConfiguration.java
+++ b/juick-server-jdbc/src/test/java/com/juick/configuration/RepositoryConfiguration.java
@@ -28,6 +28,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
+import javax.sql.DataSource;
import java.util.Collections;
import java.util.List;
@@ -50,7 +51,7 @@ public class RepositoryConfiguration {
}
@Bean
- public DriverManagerDataSource dataSource() {
+ public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("net.sf.log4jdbc.DriverSpy");
dataSource.setUrl("jdbc:log4jdbc:mysql://localhost:33306/juick?autoReconnect=true&user=root");