Polish
This commit is contained in:
parent
d89048300a
commit
ba85cefce3
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.couchbase;
|
package org.springframework.boot.autoconfigure.couchbase;
|
||||||
|
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
import com.couchbase.client.core.env.KeyValueServiceConfig;
|
import com.couchbase.client.core.env.KeyValueServiceConfig;
|
||||||
import com.couchbase.client.core.env.QueryServiceConfig;
|
import com.couchbase.client.core.env.QueryServiceConfig;
|
||||||
import com.couchbase.client.core.env.ViewServiceConfig;
|
import com.couchbase.client.core.env.ViewServiceConfig;
|
||||||
|
@ -31,6 +33,8 @@ import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties.Endpoints;
|
||||||
|
import org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties.Endpoints.CouchbaseService;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Conditional;
|
import org.springframework.context.annotation.Conditional;
|
||||||
|
@ -106,21 +110,15 @@ public class CouchbaseAutoConfiguration {
|
||||||
if (timeouts.getConnect() != null) {
|
if (timeouts.getConnect() != null) {
|
||||||
builder = builder.connectTimeout(timeouts.getConnect().toMillis());
|
builder = builder.connectTimeout(timeouts.getConnect().toMillis());
|
||||||
}
|
}
|
||||||
builder = builder.keyValueServiceConfig(KeyValueServiceConfig.create(
|
builder = builder.keyValueServiceConfig(
|
||||||
endpoints.getKeyValue()));
|
KeyValueServiceConfig.create(endpoints.getKeyValue()));
|
||||||
if (timeouts.getKeyValue() != null) {
|
if (timeouts.getKeyValue() != null) {
|
||||||
builder = builder.kvTimeout(timeouts.getKeyValue().toMillis());
|
builder = builder.kvTimeout(timeouts.getKeyValue().toMillis());
|
||||||
}
|
}
|
||||||
CouchbaseServiceConfig queryConfig = determineCouchbaseServiceConfig(
|
|
||||||
endpoints.getQueryservice(), endpoints.getQuery());
|
|
||||||
builder = builder.queryServiceConfig(QueryServiceConfig.create(
|
|
||||||
queryConfig.minEndpoints, queryConfig.maxEndpoints));
|
|
||||||
if (timeouts.getQuery() != null) {
|
if (timeouts.getQuery() != null) {
|
||||||
CouchbaseServiceConfig viewConfig = determineCouchbaseServiceConfig(
|
builder = builder.queryTimeout(timeouts.getQuery().toMillis());
|
||||||
endpoints.getViewservice(), endpoints.getView());
|
builder = builder.queryServiceConfig(getQueryServiceConfig(endpoints));
|
||||||
builder = builder.queryTimeout(timeouts.getQuery().toMillis())
|
builder = builder.viewServiceConfig(getViewServiceConfig(endpoints));
|
||||||
.viewServiceConfig(ViewServiceConfig.create(
|
|
||||||
viewConfig.minEndpoints, viewConfig.maxEndpoints));
|
|
||||||
}
|
}
|
||||||
if (timeouts.getSocketConnect() != null) {
|
if (timeouts.getSocketConnect() != null) {
|
||||||
builder = builder.socketConnectTimeout(
|
builder = builder.socketConnectTimeout(
|
||||||
|
@ -131,37 +129,37 @@ public class CouchbaseAutoConfiguration {
|
||||||
}
|
}
|
||||||
CouchbaseProperties.Ssl ssl = properties.getEnv().getSsl();
|
CouchbaseProperties.Ssl ssl = properties.getEnv().getSsl();
|
||||||
if (ssl.getEnabled()) {
|
if (ssl.getEnabled()) {
|
||||||
builder.sslEnabled(true);
|
builder = builder.sslEnabled(true);
|
||||||
if (ssl.getKeyStore() != null) {
|
if (ssl.getKeyStore() != null) {
|
||||||
builder.sslKeystoreFile(ssl.getKeyStore());
|
builder = builder.sslKeystoreFile(ssl.getKeyStore());
|
||||||
}
|
}
|
||||||
if (ssl.getKeyStorePassword() != null) {
|
if (ssl.getKeyStorePassword() != null) {
|
||||||
builder.sslKeystorePassword(ssl.getKeyStorePassword());
|
builder = builder.sslKeystorePassword(ssl.getKeyStorePassword());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CouchbaseServiceConfig determineCouchbaseServiceConfig(
|
@SuppressWarnings("deprecation")
|
||||||
CouchbaseProperties.Endpoints.CouchbaseService couchbaseService,
|
private QueryServiceConfig getQueryServiceConfig(Endpoints endpoints) {
|
||||||
Integer fallback) {
|
return getServiceConfig(endpoints.getQueryservice(), endpoints.getQuery(),
|
||||||
if (couchbaseService.getMinEndpoints() != 1
|
QueryServiceConfig::create);
|
||||||
|| couchbaseService.getMaxEndpoints() != 1) {
|
}
|
||||||
return new CouchbaseServiceConfig(couchbaseService.getMinEndpoints(),
|
|
||||||
couchbaseService.getMaxEndpoints());
|
@SuppressWarnings("deprecation")
|
||||||
|
private ViewServiceConfig getViewServiceConfig(Endpoints endpoints) {
|
||||||
|
return getServiceConfig(endpoints.getViewservice(), endpoints.getView(),
|
||||||
|
ViewServiceConfig::create);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> T getServiceConfig(CouchbaseService service, Integer fallback,
|
||||||
|
BiFunction<Integer, Integer, T> factory) {
|
||||||
|
if (service.getMinEndpoints() != 1 || service.getMaxEndpoints() != 1) {
|
||||||
|
return factory.apply(service.getMinEndpoints(),
|
||||||
|
service.getMaxEndpoints());
|
||||||
}
|
}
|
||||||
int endpoints = (fallback != null ? fallback : 1);
|
int endpoints = (fallback != null ? fallback : 1);
|
||||||
return new CouchbaseServiceConfig(endpoints, endpoints);
|
return factory.apply(endpoints, endpoints);
|
||||||
}
|
|
||||||
|
|
||||||
private static class CouchbaseServiceConfig {
|
|
||||||
private int minEndpoints;
|
|
||||||
private int maxEndpoints;
|
|
||||||
|
|
||||||
CouchbaseServiceConfig(int minEndpoints, int maxEndpoints) {
|
|
||||||
this.minEndpoints = minEndpoints;
|
|
||||||
this.maxEndpoints = maxEndpoints;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -209,7 +209,6 @@ public class CouchbaseProperties {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class Ssl {
|
public static class Ssl {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -80,7 +80,8 @@ public class LiquibaseAutoConfiguration {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnMissingBean(SpringLiquibase.class)
|
@ConditionalOnMissingBean(SpringLiquibase.class)
|
||||||
@EnableConfigurationProperties({ DataSourceProperties.class, LiquibaseProperties.class })
|
@EnableConfigurationProperties({ DataSourceProperties.class,
|
||||||
|
LiquibaseProperties.class })
|
||||||
@Import(LiquibaseJpaDependencyConfiguration.class)
|
@Import(LiquibaseJpaDependencyConfiguration.class)
|
||||||
public static class LiquibaseConfiguration {
|
public static class LiquibaseConfiguration {
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -139,7 +139,8 @@ public class QuartzAutoConfiguration {
|
||||||
ObjectProvider<PlatformTransactionManager> transactionManager) {
|
ObjectProvider<PlatformTransactionManager> transactionManager) {
|
||||||
return (schedulerFactoryBean) -> {
|
return (schedulerFactoryBean) -> {
|
||||||
if (properties.getJobStoreType() == JobStoreType.JDBC) {
|
if (properties.getJobStoreType() == JobStoreType.JDBC) {
|
||||||
DataSource dataSourceToUse = getDataSource(dataSource, quartzDataSource);
|
DataSource dataSourceToUse = getDataSource(dataSource,
|
||||||
|
quartzDataSource);
|
||||||
schedulerFactoryBean.setDataSource(dataSourceToUse);
|
schedulerFactoryBean.setDataSource(dataSourceToUse);
|
||||||
PlatformTransactionManager txManager = transactionManager
|
PlatformTransactionManager txManager = transactionManager
|
||||||
.getIfUnique();
|
.getIfUnique();
|
||||||
|
@ -159,9 +160,9 @@ public class QuartzAutoConfiguration {
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public QuartzDataSourceInitializer quartzDataSourceInitializer(
|
public QuartzDataSourceInitializer quartzDataSourceInitializer(
|
||||||
DataSource dataSource, @QuartzDataSource ObjectProvider<DataSource> quartzDataSource,
|
DataSource dataSource,
|
||||||
ResourceLoader resourceLoader,
|
@QuartzDataSource ObjectProvider<DataSource> quartzDataSource,
|
||||||
QuartzProperties properties) {
|
ResourceLoader resourceLoader, QuartzProperties properties) {
|
||||||
DataSource dataSourceToUse = getDataSource(dataSource, quartzDataSource);
|
DataSource dataSourceToUse = getDataSource(dataSource, quartzDataSource);
|
||||||
return new QuartzDataSourceInitializer(dataSourceToUse, resourceLoader,
|
return new QuartzDataSourceInitializer(dataSourceToUse, resourceLoader,
|
||||||
properties);
|
properties);
|
||||||
|
|
|
@ -25,8 +25,9 @@ import java.lang.annotation.Target;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Qualifier annotation for a DataSource to be injected into Quartz auto-configuration. Can be used on
|
* Qualifier annotation for a DataSource to be injected into Quartz auto-configuration.
|
||||||
* a secondary data source, if there is another one marked as {@code @Primary}.
|
* Can be used on a secondary data source, if there is another one marked as
|
||||||
|
* {@code @Primary}.
|
||||||
*
|
*
|
||||||
* @author Madhura Bhave
|
* @author Madhura Bhave
|
||||||
* @since 2.0.2
|
* @since 2.0.2
|
||||||
|
@ -37,4 +38,5 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
@Documented
|
@Documented
|
||||||
@Qualifier
|
@Qualifier
|
||||||
public @interface QuartzDataSource {
|
public @interface QuartzDataSource {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -250,8 +250,7 @@ public class LiquibaseAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void liquibaseDataSourceWithoutDataSourceAutoConfiguration() {
|
public void liquibaseDataSourceWithoutDataSourceAutoConfiguration() {
|
||||||
this.contextRunner
|
this.contextRunner.withUserConfiguration(LiquibaseDataSourceConfiguration.class)
|
||||||
.withUserConfiguration(LiquibaseDataSourceConfiguration.class)
|
|
||||||
.run((context) -> {
|
.run((context) -> {
|
||||||
SpringLiquibase liquibase = context.getBean(SpringLiquibase.class);
|
SpringLiquibase liquibase = context.getBean(SpringLiquibase.class);
|
||||||
assertThat(liquibase.getDataSource())
|
assertThat(liquibase.getDataSource())
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -211,8 +211,7 @@ public class QuartzAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dataSourceWithQuartzDataSourceQualifierUsedWhenMultiplePresent() {
|
public void dataSourceWithQuartzDataSourceQualifierUsedWhenMultiplePresent() {
|
||||||
load(MultipleDataSourceConfiguration.class,
|
load(MultipleDataSourceConfiguration.class, "spring.quartz.job-store-type=jdbc");
|
||||||
"spring.quartz.job-store-type=jdbc");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void load(String... environment) {
|
private void load(String... environment) {
|
||||||
|
@ -354,7 +353,8 @@ public class QuartzAutoConfigurationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
protected static class MultipleDataSourceConfiguration extends BaseQuartzConfiguration {
|
protected static class MultipleDataSourceConfiguration
|
||||||
|
extends BaseQuartzConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@Primary
|
@Primary
|
||||||
|
@ -362,7 +362,6 @@ public class QuartzAutoConfigurationTests {
|
||||||
return new HikariDataSource();
|
return new HikariDataSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@QuartzDataSource
|
@QuartzDataSource
|
||||||
@Bean
|
@Bean
|
||||||
public DataSource quartzDataSource() {
|
public DataSource quartzDataSource() {
|
||||||
|
|
Loading…
Reference in New Issue