Skip to content

Commit

Permalink
add docu to disable autocreate
Browse files Browse the repository at this point in the history
add disable key to control auto-creation of defaults bean.
add conditional creating of beans
define own bean interface for StorageFoundation Supplier
remove Component annotation to prevent two beans..
  • Loading branch information
zdenek-jonas committed Apr 24, 2024
1 parent 5cabb32 commit 317ff89
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 5 deletions.
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 autoCreateDefaultStorage = true;

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 autoCreateDefaultStorage;
}

public void setAutoCreateDefaultStorage(boolean autoCreateDefaultStorage)
{
this.autoCreateDefaultStorage = 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,22 @@
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<?>> extends java.util.function.Supplier<T>
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package test.eclipse.store.integrations.spring.boot;

/*-
* #%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.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

0 comments on commit 317ff89

Please sign in to comment.