aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/configuration
diff options
context:
space:
mode:
authorGravatar Alexander Alexeev2016-11-18 15:36:16 +0700
committerGravatar Vitaly Takmazov2016-11-23 13:02:59 +0300
commit606e2a8d6fc8af288632e2857d3a89770fdbb69c (patch)
treef160cbe3f09459f2dd0dff441c5fbb8336c8a3d4 /juick-server/src/main/java/com/juick/configuration
parentd64b673c0d69309ff7ad75ffd1d3d7c3f664c8a1 (diff)
SearchService stub for most cases
Diffstat (limited to 'juick-server/src/main/java/com/juick/configuration')
-rw-r--r--juick-server/src/main/java/com/juick/configuration/DataConfiguration.java22
-rw-r--r--juick-server/src/main/java/com/juick/configuration/SearchConfiguration.java28
2 files changed, 29 insertions, 21 deletions
diff --git a/juick-server/src/main/java/com/juick/configuration/DataConfiguration.java b/juick-server/src/main/java/com/juick/configuration/DataConfiguration.java
index 89fda764..150ced69 100644
--- a/juick-server/src/main/java/com/juick/configuration/DataConfiguration.java
+++ b/juick-server/src/main/java/com/juick/configuration/DataConfiguration.java
@@ -1,5 +1,6 @@
package com.juick.configuration;
+import com.juick.service.search.SearchService;
import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@@ -13,6 +14,8 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.TransactionManagementConfigurer;
import javax.annotation.Resource;
+import java.util.Collections;
+import java.util.List;
/**
* Created by aalexeev on 11/11/16.
@@ -55,4 +58,23 @@ public class DataConfiguration implements TransactionManagementConfigurer {
public JdbcTemplate jdbcTemplate() {
return new JdbcTemplate(dataSource());
}
+
+ @Bean
+ public SearchService emptySearchService() {
+ return new SearchService() {
+ @Override
+ public void setMaxResult(int maxResult) {
+ }
+
+ @Override
+ public List<Integer> searchInAllMessages(String searchString, int messageIdBefore) {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public List<Integer> searchByStringAndUser(String searchString, int userId, int messageIdBefore) {
+ return Collections.emptyList();
+ }
+ };
+ }
}
diff --git a/juick-server/src/main/java/com/juick/configuration/SearchConfiguration.java b/juick-server/src/main/java/com/juick/configuration/SearchConfiguration.java
index 40473433..1cf5c1a1 100644
--- a/juick-server/src/main/java/com/juick/configuration/SearchConfiguration.java
+++ b/juick-server/src/main/java/com/juick/configuration/SearchConfiguration.java
@@ -9,8 +9,6 @@ import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import javax.annotation.Resource;
-import java.util.Collections;
-import java.util.List;
/**
* Created by aalexeev on 11/18/16.
@@ -21,34 +19,22 @@ public class SearchConfiguration {
@Resource
private Environment env;
+ // NOTE: The close() method will be called automatically with default @Bean settings
+ // But Datasource interface has no close() method
@Bean
- public SearchService searchService() {
+ public BasicDataSource searchDataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(env.getProperty("sphinx_driver", "com.mysql.jdbc.Driver"));
- dataSource.setUrl(env.getProperty("sphinx_url", "jdbc:mysql://127.0.0.1:9306?autoReconnect=true&useUnicode=yes&characterEncoding=utf8&maxAllowedPacket=512000"));
+ dataSource.setUrl(env.getProperty("sphinx_url"));
dataSource.setUsername(env.getProperty("sphinx_user", ""));
dataSource.setPassword(env.getProperty("sphinx_password", ""));
- return new SphinxSearchServiceImpl(dataSource);
+ return dataSource;
}
@Bean
- public SearchService emptySearchService() {
- return new SearchService() {
- @Override
- public void setMaxResult(int maxResult) {
- }
-
- @Override
- public List<Integer> searchInAllMessages(String searchString, int messageIdBefore) {
- return Collections.emptyList();
- }
-
- @Override
- public List<Integer> searchByStringAndUser(String searchString, int userId, int messageIdBefore) {
- return Collections.emptyList();
- }
- };
+ public SearchService searchService() {
+ return new SphinxSearchServiceImpl(searchDataSource());
}
}