Skip to content

Commit

Permalink
replace overrideable method for data settings, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
agrgr committed Jan 8, 2024
1 parent a8290b3 commit 0877dd8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 95 deletions.
81 changes: 32 additions & 49 deletions src/main/asciidoc/reference/configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ In this case extending `AbstractAerospikeDataConfiguration` class is required to
[[configuration.overriding-configuration]]
== Overriding configuration

Configuration can also be set by overriding `getHosts()` and `nameSpace()` methods
as well as `aerospikeDataSettings()` method of the `AbstractAerospikeDataConfiguration` class.
Configuration can also be set by overriding `getHosts()`, `nameSpace()` and `configureDataSettings()` methods of the `AbstractAerospikeDataConfiguration` class.

Here is an example:

Expand All @@ -61,22 +60,20 @@ class ApplicationConfig extends AbstractAerospikeDataConfiguration {
}
@Override
public AerospikeDataSettings aerospikeDataSettings() {
AerospikeDataSettings settings = new AerospikeDataSettings();
settings.setScansEnabled(false);
settings.setCreateIndexesOnStartup(true);
settings.setIndexCacheRefreshSeconds(3600);
settings.setServerVersionRefreshSeconds(3600);
settings.setQueryMaxRecords(10000L);
settings.setBatchWriteSize(100);
settings.setKeepOriginalKeyTypes(false);
return settings;
public void configureDataSettings(AerospikeDataSettings aerospikeDataSettings) {
aerospikeDataSettings.setScansEnabled(false);
aerospikeDataSettings.setCreateIndexesOnStartup(true);
aerospikeDataSettings.setIndexCacheRefreshSeconds(3600);
aerospikeDataSettings.setServerVersionRefreshSeconds(3600);
aerospikeDataSettings.setQueryMaxRecords(10000L);
aerospikeDataSettings.setBatchWriteSize(100);
aerospikeDataSettings.setKeepOriginalKeyTypes(false);
}
}
----

NOTE: Return values of `getHosts()`, `nameSpace()` and `aerospikeDataSettings()` methods
of the `AbstractAerospikeDataConfiguration` class have precedence over `hosts` and `namespace` parameters
NOTE: Return values of `getHosts()`, `nameSpace()` and `configureDataSettings()` methods
of the `AbstractAerospikeDataConfiguration` class have precedence over the parameters
set via application.properties.

[[configuration.parameters]]
Expand Down Expand Up @@ -171,7 +168,7 @@ and then the condition is applied to see if they match.

Due to the cost of performing this operation, scans from Spring Data Aerospike are disabled by default.

NOTE: Another way of defining the parameter is overriding the `aerospikeDataSettings()` method.
NOTE: Another way of defining the parameter is overriding the `configureDataSettings()` method.
It has precedence over reading from application.properties. Here is an example:

[source,java]
Expand All @@ -182,10 +179,8 @@ class ApplicationConfig extends AbstractAerospikeDataConfiguration {
@Override
public AerospikeDataSettings aerospikeDataSettings() {
AerospikeDataSettings settings = new AerospikeDataSettings();
settings.setScansEnabled(false);
return settings;
public void configureDataSettings(AerospikeDataSettings aerospikeDataSettings) {
aerospikeDataSettings.setScansEnabled(false);
}
}
----
Expand All @@ -206,7 +201,7 @@ spring-data-aerospike.data.create-indexes-on-startup=true

Create secondary indexes specified using `@Indexed` annotation on startup.

NOTE: Another way of defining the parameter is overriding the `aerospikeDataSettings()` method.
NOTE: Another way of defining the parameter is overriding the `configureDataSettings()` method.
It has precedence over reading from application.properties. Here is an example:

[source,java]
Expand All @@ -217,10 +212,8 @@ class ApplicationConfig extends AbstractAerospikeDataConfiguration {
@Override
public AerospikeDataSettings aerospikeDataSettings() {
AerospikeDataSettings settings = new AerospikeDataSettings();
settings.setCreateIndexesOnStartup(true);
return settings;
public void configureDataSettings(AerospikeDataSettings aerospikeDataSettings) {
aerospikeDataSettings.setCreateIndexesOnStartup(true);
}
}
----
Expand All @@ -238,7 +231,7 @@ spring-data-aerospike.data.index-cache-refresh-seconds=3600

Automatically refresh indexes cache every <N> seconds.

NOTE: Another way of defining the parameter is overriding the `aerospikeDataSettings()` method.
NOTE: Another way of defining the parameter is overriding the `configureDataSettings()` method.
It has precedence over reading from application.properties. Here is an example:

[source,java]
Expand All @@ -249,10 +242,8 @@ class ApplicationConfig extends AbstractAerospikeDataConfiguration {
@Override
public AerospikeDataSettings aerospikeDataSettings() {
AerospikeDataSettings settings = new AerospikeDataSettings();
settings.setIndexCacheRefreshSeconds(3600);
return settings;
public void configureDataSettings(AerospikeDataSettings aerospikeDataSettings) {
aerospikeDataSettings.setIndexCacheRefreshSeconds(3600);
}
}
----
Expand All @@ -270,7 +261,7 @@ spring-data-aerospike.data.server-version-refresh-seconds=3600

Automatically refresh cached server version every <N> seconds.

NOTE: Another way of defining the parameter is overriding the `aerospikeDataSettings()` method.
NOTE: Another way of defining the parameter is overriding the `configureDataSettings()` method.
It has precedence over reading from application.properties. Here is an example:

[source,java]
Expand All @@ -281,10 +272,8 @@ class ApplicationConfig extends AbstractAerospikeDataConfiguration {
@Override
public AerospikeDataSettings aerospikeDataSettings() {
AerospikeDataSettings settings = new AerospikeDataSettings();
settings.setServerVersionRefreshSeconds(3600);
return settings;
public void configureDataSettings(AerospikeDataSettings aerospikeDataSettings) {
aerospikeDataSettings.setServerVersionRefreshSeconds(3600);
}
}
----
Expand All @@ -302,7 +291,7 @@ spring-data-aerospike.data.query-max-records=10000

Limit amount of results returned by server. Non-positive value means no limit.

NOTE: Another way of defining the parameter is overriding the `aerospikeDataSettings()` method.
NOTE: Another way of defining the parameter is overriding the `configureDataSettings()` method.
It has precedence over reading from application.properties. Here is an example:

[source,java]
Expand All @@ -313,10 +302,8 @@ class ApplicationConfig extends AbstractAerospikeDataConfiguration {
@Override
public AerospikeDataSettings aerospikeDataSettings() {
AerospikeDataSettings settings = new AerospikeDataSettings();
settings.setQueryMaxRecords(10000L);
return settings;
public void configureDataSettings(AerospikeDataSettings aerospikeDataSettings) {
aerospikeDataSettings.setQueryMaxRecords(10000L);
}
}
----
Expand All @@ -334,7 +321,7 @@ spring-data-aerospike.data.batch-write-size=100

Maximum batch size for batch write operations. Non-positive value means no limit.

NOTE: Another way of defining the parameter is overriding the `aerospikeDataSettings()` method.
NOTE: Another way of defining the parameter is overriding the `configureDataSettings()` method.
It has precedence over reading from application.properties. Here is an example:

[source,java]
Expand All @@ -345,10 +332,8 @@ class ApplicationConfig extends AbstractAerospikeDataConfiguration {
@Override
public AerospikeDataSettings aerospikeDataSettings() {
AerospikeDataSettings settings = new AerospikeDataSettings();
settings.setBatchWriteSize(100);
return settings;
public void configureDataSettings(AerospikeDataSettings aerospikeDataSettings) {
aerospikeDataSettings.setBatchWriteSize(100);
}
}
----
Expand Down Expand Up @@ -392,7 +377,7 @@ This is transparent to the application but needs to be considered if using exter
|other types |`String` | `String`
|===

NOTE: Another way of defining the parameter is overriding the `aerospikeDataSettings()` method.
NOTE: Another way of defining the parameter is overriding the `configureDataSettings()` method.
It has precedence over reading from application.properties. Here is an example:

[source,java]
Expand All @@ -403,10 +388,8 @@ class ApplicationConfig extends AbstractAerospikeDataConfiguration {
@Override
public AerospikeDataSettings aerospikeDataSettings() {
AerospikeDataSettings settings = new AerospikeDataSettings();
settings.setKeepOriginalKeyTypes(false);
return settings;
public void configureDataSettings(AerospikeDataSettings aerospikeDataSettings) {
aerospikeDataSettings.setKeepOriginalKeyTypes(false);
}
}
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Getter
public class AerospikeConnectionSettings {

// String of hosts separated by ',' in form of hostname1[:tlsName1][:port1],...
// String of hosts separated by ',' in form of hostname1[:tlsName1]:port1,...
// An IP address must be given in one of the following formats:
// IPv4: xxx.xxx.xxx.xxx
// IPv6: [xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,11 @@ protected String nameSpace() {

/**
* Override this method to define data settings to be used.
*
* <p>The return value of this method overrides the values of 'spring-data-aerospike.data.*' parameters
* from application.properties.
*
* @return Collection of Host objects for Aerospike client to connect
*/
protected AerospikeDataSettings aerospikeDataSettings() {
return null;
protected void configureDataSettings(AerospikeDataSettings aerospikeDataSettings) {
}

/**
Expand Down Expand Up @@ -237,54 +235,24 @@ public AerospikeConnectionSettings readAerospikeSettings() {
@Bean
protected AerospikeSettings aerospikeSettings(AerospikeDataSettings dataSettings,
AerospikeConnectionSettings connectionSettings) {
AerospikeDataSettings manualDataSettings = aerospikeDataSettings();
// values set via aerospikeDataSettings() have precedence over the parameters from application.properties
if (manualDataSettings != null) {
overrideDataSettings(dataSettings, manualDataSettings);
}
// values set via configureDataSettings() have precedence over the parameters from application.properties
configureDataSettings(dataSettings);

Collection<Host> hosts;
// getHosts() return value has precedence over hosts parameter from application.properties
Collection<Host> hosts;
String hostsString;
if ((hosts = getHosts()) != null) {
connectionSettings.setHostsArray(hosts.toArray(new Host[0]));
} else {
connectionSettings.setHostsArray(Host.parseHosts(connectionSettings.getHosts(), getDefaultPort()));
} else if (!StringUtils.hasText(connectionSettings.getHosts())) {
throw new IllegalStateException("No hosts found, please set hosts parameter in application.properties or " +
"override getHosts() method");
}
connectionSettings.setHostsArray(Host.parseHosts(connectionSettings.getHosts(), getDefaultPort()));

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

return new AerospikeSettings(connectionSettings, dataSettings);
}

private void overrideDataSettings(AerospikeDataSettings dataSettings, AerospikeDataSettings manualDataSettings) {
if (dataSettings != null && manualDataSettings != null) {
AerospikeDataSettings defaultDataSettings = new AerospikeDataSettings();
if (defaultDataSettings.isScansEnabled() != manualDataSettings.isScansEnabled()) {
dataSettings.setScansEnabled(manualDataSettings.isScansEnabled());
}
if (defaultDataSettings.isSendKey() != manualDataSettings.isSendKey()) {
dataSettings.setSendKey(manualDataSettings.isSendKey());
}
if (defaultDataSettings.isCreateIndexesOnStartup() != manualDataSettings.isCreateIndexesOnStartup()) {
dataSettings.setCreateIndexesOnStartup(manualDataSettings.isCreateIndexesOnStartup());
}
if (defaultDataSettings.getIndexCacheRefreshSeconds() != manualDataSettings.getIndexCacheRefreshSeconds()) {
dataSettings.setIndexCacheRefreshSeconds(manualDataSettings.getIndexCacheRefreshSeconds());
}
if (defaultDataSettings.getServerVersionRefreshSeconds() != manualDataSettings.getServerVersionRefreshSeconds()) {
dataSettings.setServerVersionRefreshSeconds(manualDataSettings.getServerVersionRefreshSeconds());
}
if (defaultDataSettings.getQueryMaxRecords() != manualDataSettings.getQueryMaxRecords()) {
dataSettings.setQueryMaxRecords(manualDataSettings.getQueryMaxRecords());
}
if (defaultDataSettings.getBatchWriteSize() != manualDataSettings.getBatchWriteSize()) {
dataSettings.setBatchWriteSize(manualDataSettings.getBatchWriteSize());
}
if (defaultDataSettings.isKeepOriginalKeyTypes() != manualDataSettings.isKeepOriginalKeyTypes()) {
dataSettings.setKeepOriginalKeyTypes(manualDataSettings.isKeepOriginalKeyTypes());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ public class AerospikeDataSettings {

// Enable scan operation
boolean scansEnabled = false;
// Send user defined key in addition to hash digest on both reads and writes
boolean sendKey = true;
// Create secondary indexes specified using `@Indexed` annotation on startup
boolean createIndexesOnStartup = true;
// Automatically refresh indexes cache every <N> seconds
Expand Down

0 comments on commit 0877dd8

Please sign in to comment.