From 02723131139806c761539a42a5fa80b68ecadee8 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 29 Jun 2017 14:03:04 +0300 Subject: project structure: split server into jdbc + web --- .../com/juick/configuration/DataConfiguration.java | 80 ---------------------- .../juick/configuration/SearchConfiguration.java | 43 ------------ .../juick/configuration/UpdaterConfiguration.java | 30 -------- 3 files changed, 153 deletions(-) delete mode 100644 juick-server/src/main/java/com/juick/configuration/DataConfiguration.java delete mode 100644 juick-server/src/main/java/com/juick/configuration/SearchConfiguration.java delete mode 100644 juick-server/src/main/java/com/juick/configuration/UpdaterConfiguration.java (limited to 'juick-server/src/main/java/com/juick/configuration') diff --git a/juick-server/src/main/java/com/juick/configuration/DataConfiguration.java b/juick-server/src/main/java/com/juick/configuration/DataConfiguration.java deleted file mode 100644 index 4258703d..00000000 --- a/juick-server/src/main/java/com/juick/configuration/DataConfiguration.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.juick.configuration; - -import com.juick.database.MySqlUpdater; -import com.juick.service.search.SearchService; -import org.apache.commons.dbcp2.BasicDataSource; -import org.apache.commons.lang3.StringUtils; -import org.springframework.context.annotation.*; -import org.springframework.core.env.Environment; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.datasource.DataSourceTransactionManager; -import org.springframework.transaction.PlatformTransactionManager; -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. - */ -@Configuration -@EnableTransactionManagement -@PropertySource(value = {"classpath:juick.conf"}) -@ComponentScan(basePackages = {"com.juick.service"}) -public class DataConfiguration implements TransactionManagementConfigurer { - @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 BasicDataSource dataSource() { - BasicDataSource dataSource = new BasicDataSource(); - - dataSource.setDriverClassName(env.getProperty("datasource_driver", "com.mysql.jdbc.Driver")); - dataSource.setUrl(env.getProperty("datasource_url")); - dataSource.setUsername(env.getProperty("datasource_user", StringUtils.EMPTY)); - dataSource.setPassword(env.getProperty("datasource_password", StringUtils.EMPTY)); - - dataSource.setValidationQuery("select 1"); - - return dataSource; - } - - @Bean - public PlatformTransactionManager transactionManager() { - return new DataSourceTransactionManager(dataSource()); - } - - @Override - public PlatformTransactionManager annotationDrivenTransactionManager() { - return transactionManager(); - } - - @Bean - @DependsOn("dataSource") - public JdbcTemplate jdbcTemplate() { - return new JdbcTemplate(dataSource()); - } - - @Bean - public SearchService emptySearchService() { - return new SearchService() { - @Override - public void setMaxResult(int maxResult) { - } - - @Override - public List searchInAllMessages(String searchString, int messageIdBefore) { - return Collections.emptyList(); - } - - @Override - public List 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 deleted file mode 100644 index e6b446b6..00000000 --- a/juick-server/src/main/java/com/juick/configuration/SearchConfiguration.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.juick.configuration; - -import com.juick.service.search.SearchService; -import com.juick.service.search.SphinxSearchServiceImpl; -import org.apache.commons.dbcp2.BasicDataSource; -import org.apache.commons.lang3.StringUtils; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.DependsOn; -import org.springframework.context.annotation.PropertySource; -import org.springframework.core.env.Environment; - -import javax.annotation.Resource; - -/** - * Created by aalexeev on 11/18/16. - */ -@Configuration -@PropertySource(value = {"classpath:juick.conf"}) -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 BasicDataSource searchDataSource() { - BasicDataSource dataSource = new BasicDataSource(); - - dataSource.setDriverClassName(env.getProperty("sphinx_driver", "com.mysql.jdbc.Driver")); - dataSource.setUrl(env.getProperty("sphinx_url")); - dataSource.setUsername(env.getProperty("sphinx_user", StringUtils.EMPTY)); - dataSource.setPassword(env.getProperty("sphinx_password", StringUtils.EMPTY)); - - return dataSource; - } - - @Bean - @DependsOn("searchDataSource") - public SearchService searchService() { - return new SphinxSearchServiceImpl(searchDataSource()); - } -} diff --git a/juick-server/src/main/java/com/juick/configuration/UpdaterConfiguration.java b/juick-server/src/main/java/com/juick/configuration/UpdaterConfiguration.java deleted file mode 100644 index b3c0424c..00000000 --- a/juick-server/src/main/java/com/juick/configuration/UpdaterConfiguration.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.juick.configuration; - -import com.juick.database.MySqlUpdater; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.DependsOn; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.transaction.PlatformTransactionManager; - -import javax.inject.Inject; - -/** - * Created by aalexeev on 12/13/16. - */ -@Configuration -public class UpdaterConfiguration { - @Inject - JdbcTemplate jdbcTemplate; - @Inject - PlatformTransactionManager transactionManager; - - @Bean - @DependsOn({"jdbcTemplate", "transactionManager"}) - public MySqlUpdater updater() { - return new MySqlUpdater( - jdbcTemplate, - transactionManager, - "update.sql"); - } -} -- cgit v1.2.3