Skip to content

Commit

Permalink
align configuration prefixes using Spring convention
Browse files Browse the repository at this point in the history
  • Loading branch information
agrgr committed Nov 21, 2024
1 parent c6d8aad commit ab50ca0
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public AerospikeTemplate aerospikeTemplate(IAerospikeClient aerospikeClient,
QueryEngine queryEngine, IndexRefresher indexRefresher,
ServerVersionSupport serverVersionSupport,
AerospikeSettings settings) {
return new AerospikeTemplate(aerospikeClient, settings.getConnectionSettings().getNamespace(),
return new AerospikeTemplate(aerospikeClient, settings.getDataSettings().getNamespace(),
mappingAerospikeConverter, aerospikeMappingContext, aerospikeExceptionTranslator, queryEngine,
indexRefresher, serverVersionSupport);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ReactiveAerospikeTemplate reactiveAerospikeTemplate(MappingAerospikeConve
ReactorIndexRefresher reactorIndexRefresher,
ServerVersionSupport serverVersionSupport,
AerospikeSettings settings) {
return new ReactiveAerospikeTemplate(aerospikeReactorClient, settings.getConnectionSettings().getNamespace(),
return new ReactiveAerospikeTemplate(aerospikeReactorClient, settings.getDataSettings().getNamespace(),
mappingAerospikeConverter, aerospikeMappingContext, aerospikeExceptionTranslator,
reactorQueryEngine, reactorIndexRefresher, serverVersionSupport);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public class AerospikeConnectionSettings {
// IPv6: [xxxx::xxxx]
// IPv6 addresses must be enclosed by brackets. tlsName is optional.
String hosts;
// Namespace
String namespace;
// Storing hosts
Host[] hostsArray;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.springframework.data.aerospike.config;

import com.aerospike.client.AerospikeClient;
import com.aerospike.client.AerospikeException;
import com.aerospike.client.Host;
import com.aerospike.client.IAerospikeClient;
import com.aerospike.client.async.EventLoops;
Expand All @@ -29,6 +30,8 @@
import io.netty.channel.kqueue.KQueueEventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanInstantiationException;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
Expand Down Expand Up @@ -70,9 +73,9 @@
@Configuration
public abstract class AerospikeDataConfigurationSupport {

public static final String CONFIG_PREFIX = "spring.aerospike";
public static final String CONFIG_PREFIX_DATA = CONFIG_PREFIX + ".data";
public static final String CONFIG_PREFIX_CONNECTION = CONFIG_PREFIX + ".connection";
public static final String CONFIG_PREFIX = "spring";
public static final String CONFIG_PREFIX_DATA = CONFIG_PREFIX + ".data.aerospike";
public static final String CONFIG_PREFIX_CONNECTION = CONFIG_PREFIX + ".aerospike";

@Bean(name = "aerospikeStatementBuilder")
public StatementBuilder statementBuilder(IndexesCache indexesCache) {
Expand All @@ -99,8 +102,11 @@ public MappingAerospikeConverter mappingAerospikeConverter(AerospikeMappingConte
}

@Bean(name = "aerospikeTypeAliasAccessor")
public AerospikeTypeAliasAccessor aerospikeTypeAliasAccessor() {
return new AerospikeTypeAliasAccessor();
public AerospikeTypeAliasAccessor aerospikeTypeAliasAccessor(AerospikeDataSettings dataSettings) {
String classKey = dataSettings.getClassKey();
return StringUtils.hasText(classKey)
? new AerospikeTypeAliasAccessor(classKey)
: new AerospikeTypeAliasAccessor();
}

@Bean(name = "aerospikeCustomConversions")
Expand All @@ -113,11 +119,26 @@ protected List<?> customConverters() {
}

@Bean(name = "aerospikeMappingContext")
public AerospikeMappingContext aerospikeMappingContext() throws ClassNotFoundException {
public AerospikeMappingContext aerospikeMappingContext(AerospikeDataSettings dataSettings)
throws AerospikeException
{
AerospikeMappingContext context = new AerospikeMappingContext();
context.setInitialEntitySet(getInitialEntitySet());
try {
context.setInitialEntitySet(getInitialEntitySet());
} catch (ClassNotFoundException e) {
throw new AerospikeException("Cannot set initialEntitySet in AerospikeMappingContext", e);
}
context.setSimpleTypeHolder(AerospikeSimpleTypes.HOLDER);
context.setFieldNamingStrategy(fieldNamingStrategy());
if (dataSettings.getFieldNamingStrategy() != null) {
try {
context.setFieldNamingStrategy(
(FieldNamingStrategy) BeanUtils.instantiateClass(dataSettings.getFieldNamingStrategy()));
} catch (BeanInstantiationException e) {
throw new AerospikeException("Cannot set fieldNamingStrategy in AerospikeMappingContext", e);
}
} else {
context.setFieldNamingStrategy(fieldNamingStrategy());
}
return context;
}

Expand Down Expand Up @@ -294,7 +315,7 @@ protected AerospikeSettings aerospikeSettings(AerospikeDataSettings dataSettings

// nameSpace() has precedence over namespace parameter from application.properties
String namespace;
if ((namespace = nameSpace()) != null) connectionSettings.setNamespace(namespace);
if ((namespace = nameSpace()) != null) dataSettings.setNamespace(namespace);

return new AerospikeSettings(connectionSettings, dataSettings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
@ConfigurationProperties(prefix = CONFIG_PREFIX_DATA)
public class AerospikeDataSettings {

// Namespace
String namespace;
// Enable scan operation
boolean scansEnabled = false;
// Create secondary indexes specified using `@Indexed` annotation on startup
Expand All @@ -45,4 +47,8 @@ public class AerospikeDataSettings {
// Writing unsorted maps (false) degrades performance of Map-related operations and does not allow comparing Maps,
// strongly recommended not to use except during upgrade from older versions of Spring Data Aerospike (if required)
boolean writeSortedMaps = true;
// Name for the bin to store entity's class
private String classKey = "@_class";
// Fully qualified name of the FieldNamingStrategy for entities
private Class<?> fieldNamingStrategy;
}
18 changes: 9 additions & 9 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
spring.aerospike.connection.hosts=localhost:3000
spring.aerospike.connection.namespace=test
spring.aerospike.data.scans-enabled=false
spring.aerospike.data.create-indexes-on-startup=true
spring.aerospike.data.index-cache-refresh-seconds=3600
spring.aerospike.data.server-version-refresh-seconds=3600
spring.aerospike.data.query-max-records=10000
spring.aerospike.data.batch-write-size=100
spring.aerospike.data.keep-original-key-types=false
spring.aerospike.hosts=localhost:3000
spring.data.aerospike.namespace=test
spring.data.aerospike.scans-enabled=false
spring.data.aerospike.create-indexes-on-startup=true
spring.data.aerospike.index-cache-refresh-seconds=3600
spring.data.aerospike.server-version-refresh-seconds=3600
spring.data.aerospike.query-max-records=10000
spring.data.aerospike.batch-write-size=100
spring.data.aerospike.keep-original-key-types=false
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public abstract class BaseIntegrationTests {
public static final String DIFFERENT_EXISTING_CACHE = "DIFFERENT-EXISTING-CACHE";
protected static final int MILLIS_TO_NANO = 1_000_000;

@Value("${spring.aerospike.connection.namespace}")
@Value("${spring.data.aerospike.namespace}")
protected String namespace;

protected String id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@EnableAutoConfiguration
public class CommonTestConfig {

@Value("${spring.aerospike.connection.namespace}")
@Value("${spring.data.aerospike.namespace}")
protected String namespace;

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Slf4j
@ContextConfiguration
@TestPropertySource(properties = {"spring.aerospike.data.server-version-refresh-seconds = 0"})
@TestPropertySource(properties = {"spring.data.aerospike.server-version-refresh-seconds = 0"})
public class IndexNotScheduledCacheRefreshTest extends BaseBlockingIntegrationTests {

String setName = "scheduled";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Slf4j
@ContextConfiguration
@TestPropertySource(properties = {"spring.aerospike.data.index-cache-refresh-seconds=4"})
@TestPropertySource(properties = {"spring.data.aerospike.index-cache-refresh-seconds=4"})
public class IndexScheduledCacheRefreshTest extends BaseBlockingIntegrationTests {

String setName = "scheduled";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;

@TestPropertySource(properties = {"spring.aerospike.data.create-indexes-on-startup=true"})
@TestPropertySource(properties = {"spring.data.aerospike.create-indexes-on-startup=true"})
// this test class requires secondary indexes created on startup
public class IndexedAnnotationTests extends BaseBlockingIntegrationTests {

Expand Down
18 changes: 9 additions & 9 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
spring.aerospike.connection.hosts=${embedded.aerospike.host}:${embedded.aerospike.port}
spring.aerospike.connection.namespace=${embedded.aerospike.namespace}
spring.aerospike.data.scans-enabled=true
spring.aerospike.data.create-indexes-on-startup=false
spring.aerospike.data.index-cache-refresh-seconds=0
spring.aerospike.data.server-version-refresh-seconds=0
spring.aerospike.data.query-max-records=5000
spring.aerospike.data.batch-write-size=100
spring.aerospike.data.keep-original-key-types=false
spring.aerospike.hosts=${embedded.aerospike.host}:${embedded.aerospike.port}
spring.data.aerospike.namespace=${embedded.aerospike.namespace}
spring.data.aerospike.scans-enabled=true
spring.data.aerospike.create-indexes-on-startup=false
spring.data.aerospike.index-cache-refresh-seconds=0
spring.data.aerospike.server-version-refresh-seconds=0
spring.data.aerospike.query-max-records=5000
spring.data.aerospike.batch-write-size=100
spring.data.aerospike.keep-original-key-types=false

0 comments on commit ab50ca0

Please sign in to comment.