Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Spring Integration, supplier, autocreation #206

Merged
merged 9 commits into from
Apr 24, 2024
Merged
8 changes: 8 additions & 0 deletions docs/modules/misc/pages/integrations/spring-boot.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ a new `EmbeddedStorageManager` or `EmbeddedStorageFoundationFactory` to create a

It is also possible to obtain the entire configuration within the `StorageManagerConfiguration` Bean, enabling you to directly create a foundation and storage manager. This can be helpful if you need to stop storage at runtime and then restart it.

== Disable Auto StorageManager creation
If the user does not define any beans of type _EmbeddedStorageFoundation_ and _EmbeddedStorageManager_, these beans are automatically created. This behavior can be changed using the following configuration.
[source,properties]
----
org.eclipse.store.auto-create-default-storage=false
org.eclipse.store.auto-create-default-foundation=false
----

== Multiple Storage Managers

You can have a more than one Storage Manager in your application. This can be useful if you want to have different storage targets for different data. For example, you might want to have a datastore for your user data and another for your product data. You can do this by creating multiple configuration classes and multiple Storage Managers.
Expand Down
1 change: 1 addition & 0 deletions integrations/spring-boot3/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
exports org.eclipse.store.integrations.spring.boot.types.converter;
exports org.eclipse.store.integrations.spring.boot.types.factories;
exports org.eclipse.store.integrations.spring.boot.types.concurrent;
exports org.eclipse.store.integrations.spring.boot.types.suppliers;

requires transitive spring.beans;
requires transitive spring.boot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
import org.eclipse.store.integrations.spring.boot.types.configuration.EclipseStoreProperties;
import org.eclipse.store.integrations.spring.boot.types.factories.EmbeddedStorageFoundationFactory;
import org.eclipse.store.integrations.spring.boot.types.factories.EmbeddedStorageManagerFactory;
import org.eclipse.store.integrations.spring.boot.types.suppliers.EmbeddedStorageFoundationSupplier;
import org.eclipse.store.storage.embedded.types.EmbeddedStorageFoundation;
import org.eclipse.store.storage.embedded.types.EmbeddedStorageManager;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.function.Supplier;

@Configuration
@AutoConfigureAfter(EclipseStoreSpringBoot.class)
public class DefaultEclipseStoreConfiguration
Expand Down Expand Up @@ -57,7 +57,8 @@ public EclipseStoreProperties defaultEclipseStoreProperties()
@Bean
@Qualifier(DEFAULT_QUALIFIER)
@ConditionalOnMissingBean
public Supplier<EmbeddedStorageFoundation<?>> defaultStorageFoundationSupplier(
@ConditionalOnProperty(prefix = "org.eclipse.store", name = "auto-create-default-foundation", havingValue = "true", matchIfMissing = true)
public EmbeddedStorageFoundationSupplier<EmbeddedStorageFoundation<?>> defaultStorageFoundationSupplier(
@Qualifier(DEFAULT_QUALIFIER) EclipseStoreProperties eclipseStoreProperties,
EmbeddedStorageFoundationFactory foundationFactory
)
Expand All @@ -76,11 +77,12 @@ public Supplier<EmbeddedStorageFoundation<?>> defaultStorageFoundationSupplier(
@Bean
@Qualifier(DEFAULT_QUALIFIER)
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "org.eclipse.store", name = "auto-create-default-storage", havingValue = "true", matchIfMissing = true)
public EmbeddedStorageManager defaultStorageManager(
EmbeddedStorageManagerFactory embeddedStorageManagerFactory,
@Qualifier(DEFAULT_QUALIFIER) EclipseStoreProperties eclipseStoreProperties,
@Qualifier(DEFAULT_QUALIFIER)
Supplier<EmbeddedStorageFoundation<?>> embeddedStorageFoundationSupplier
EmbeddedStorageFoundationSupplier<EmbeddedStorageFoundation<?>> embeddedStorageFoundationSupplier
)
{
return embeddedStorageManagerFactory.createStorage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,20 @@ public class EclipseStoreProperties
*/
private boolean registerJdk8Handlers;

/**
* This flag determines if a default foundation should be automatically created.
* If no user-defined bean with EmbeddedStorageFoundation exists, a default one will be created.
* To prevent this automatic creation, set this flag to false.
*/
private boolean autoCreateDefaultFoundation = true;

/**
* This flag determines if a default storage should be automatically created.
* If no user-defined bean with EmbeddedStorage exists, a default one will be created.
* To prevent this automatic creation, set this flag to false.
*/
private boolean isAutoCreateDefaultStorage = true;
zdenek-jonas marked this conversation as resolved.
Show resolved Hide resolved

public Class<?> getRoot()
{
return this.root;
Expand Down Expand Up @@ -521,4 +535,24 @@ public void setRegisterJdk8Handlers(final boolean registerJdk8Handlers)
{
this.registerJdk8Handlers = registerJdk8Handlers;
}

public boolean isAutoCreateDefaultFoundation()
{
return autoCreateDefaultFoundation;
}

public void setAutoCreateDefaultFoundation(boolean autoCreateDefaultFoundation)
{
this.autoCreateDefaultFoundation = autoCreateDefaultFoundation;
}

public boolean isAutoCreateDefaultStorage()
{
return isAutoCreateDefaultStorage;
}

public void setAutoCreateDefaultStorage(boolean autoCreateDefaultStorage)
{
isAutoCreateDefaultStorage = autoCreateDefaultStorage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
* The {@code EclipseStoreConfigConverter} class is a Spring component that converts the Eclipse Store properties into a map.
* This map can then be used to configure the Eclipse Store.
*/
@Component
public class EclipseStoreConfigConverter
{

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.eclipse.store.integrations.spring.boot.types.suppliers;

/*-
* #%L
* EclipseStore Integrations SpringBoot
* %%
* Copyright (C) 2023 - 2024 MicroStream Software
* %%
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
* #L%
*/

import org.eclipse.store.storage.embedded.types.EmbeddedStorageFoundation;

@FunctionalInterface
public interface EmbeddedStorageFoundationSupplier<T extends EmbeddedStorageFoundation<?>>
zdenek-jonas marked this conversation as resolved.
Show resolved Hide resolved
{
T get();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package test.eclipse.store.integrations.spring.boot;

import org.eclipse.store.storage.embedded.types.EmbeddedStorageManager;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;

@TestPropertySource("classpath:application-storage-create-disable.properties")
@SpringBootTest
@ActiveProfiles("disable_auto_create")
public class DisableStorageAutoCreateTest
{

@Autowired
ApplicationContext context;

@Test
void name()
{
Assertions.assertThrows(NoSuchBeanDefinitionException.class, () -> context.getBean(EmbeddedStorageManager.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.eclipse.store.auto-create-default-storage=false
org.eclipse.store.auto-create-default-foundation=false
Loading