Skip to content

Commit

Permalink
Merge pull request #210 from xdev-software/#142-springboot-restservice
Browse files Browse the repository at this point in the history
#142 springboot restservice
  • Loading branch information
JohannesRabauer authored Dec 19, 2024
2 parents d3bc1b1 + affc348 commit 1f4359f
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 69 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 2.4.1

* Updated EclipseStore to v2.1.0
* Added EclipseStore-Rest-API to tests (storage-restservice-springboot)

# 2.4.0

* Updated org.springframework.boot.version to v3.4.0
Expand All @@ -8,6 +13,7 @@

* Auto-Fix problems with adding ids to entities with existing data store.

~~~~
# 2.3.0
* Add support for shutting down the storage during application shutdown
Expand Down
6 changes: 3 additions & 3 deletions docs/antora.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: ROOT
title: Spring-Data-Eclipse-Store
version: master
display_version: '2.4.0'
display_version: '2.4.1'
start_page: index.adoc
nav:
- modules/ROOT/nav.adoc
asciidoc:
attributes:
product-name: 'Spring-Data-Eclipse-Store'
display-version: '2.4.0'
maven-version: '2.4.0'
display-version: '2.4.1'
maven-version: '2.4.1'
page-editable: false
page-out-of-support: false
1 change: 1 addition & 0 deletions docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
** xref:features/queries.adoc[Queries]
** xref:features/transactions.adoc[Transactions]
** xref:features/versions.adoc[Versions]
** xref:features/rest-api.adoc[REST Interface]
* xref:migration.adoc[Migration from JPA]
* xref:known-issues.adoc[Known issues]
1 change: 1 addition & 0 deletions docs/modules/ROOT/pages/features/features.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
* xref:features/queries.adoc[Queries]
* xref:features/transactions.adoc[Transactions]
* xref:features/versions.adoc[Versions]
* xref:features/rest-api.adoc[REST Interface]
55 changes: 55 additions & 0 deletions docs/modules/ROOT/pages/features/rest-api.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
= REST Interface

To utilize the https://docs.eclipsestore.io/manual/storage/rest-interface/index.html[REST interface provided by EclipseStore], only a small adjustment is needed.

First add the dependency described in the https://docs.eclipsestore.io/manual/storage/rest-interface/setup.html#_spring_boot_rest_service[EclipseStore documentation]:
[source,xml,subs=attributes+,title="Maven [pom.xml]"]
----
<dependencies>
<dependency>
<groupId>org.eclipse.store</groupId>
<artifactId>storage-restservice-springboot</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
----
Next a few adjustments are needed in your configuration:
[source,java,title="https://github.com/xdev-software/spring-data-eclipse-store/blob/develop/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/complex/ComplexConfiguration.java[Example from complex demo]"]
----
package software.xdev.spring.data.eclipse.store.demo.complex;
//...
import org.eclipse.store.storage.restadapter.types.StorageRestAdapter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;
import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories;
@ComponentScan({"org.eclipse.store.storage.restservice.spring.boot.types.rest"})
@Configuration
@EnableEclipseStoreRepositories
public class ComplexConfiguration extends EclipseStoreClientConfiguration
{
//...
@Bean
@DependsOn({"embeddedStorageFoundationFactory"})
public Map<String, StorageRestAdapter> storageRestAdapters(final Map<String, EmbeddedStorageManager> storages)
{
return Map.of(
"defaultStorageManager", StorageRestAdapter.New(this.storageInstance.getInstanceOfStorageManager())
);
}
//...
----
After that the API is usable just like https://docs.eclipsestore.io/manual/storage/rest-interface/rest-api.html[plain EclipseStore].
The ``instance-name`` in this case would be ``default`` which means, the active URL in the ComplexDemo is ``http://localhost:8080/store-data/default/root``.
57 changes: 57 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<!-- Should be in sync with org.eclipse.store:integrations-spring-boot3 -->
<org.springframework.boot.version>3.4.0</org.springframework.boot.version>
<org.eclipse.store.version>2.1.0</org.eclipse.store.version>
<org.eclipse.serializer.version>2.1.0</org.eclipse.serializer.version>
<org.eclipse.storage-restservice-springboot.version>2.1.0</org.eclipse.storage-restservice-springboot.version>
</properties>

<modules>
Expand All @@ -37,6 +43,57 @@
</license>
</licenses>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.store</groupId>
<artifactId>storage-embedded</artifactId>
<version>${org.eclipse.store.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.store</groupId>
<artifactId>integrations-spring-boot3</artifactId>
<version>${org.eclipse.store.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.serializer</groupId>
<artifactId>serializer</artifactId>
<version>${org.eclipse.serializer.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.serializer</groupId>
<artifactId>persistence-binary-jdk17</artifactId>
<version>${org.eclipse.serializer.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.store</groupId>
<artifactId>storage-restservice-springboot</artifactId>
<version>${org.eclipse.storage-restservice-springboot.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${org.springframework.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${org.springframework.boot.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>

<profiles>
<profile>
<id>checkstyle</id>
Expand Down
18 changes: 0 additions & 18 deletions spring-data-eclipse-store-benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,9 @@
</organization>

<properties>
<javaVersion>17</javaVersion>
<maven.compiler.release>${javaVersion}</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<org.springframework.boot.version>3.4.0</org.springframework.boot.version>
<jmh.version>1.37</jmh.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${org.springframework.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>software.xdev</groupId>
Expand Down
34 changes: 8 additions & 26 deletions spring-data-eclipse-store-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,23 @@
</organization>

<properties>
<javaVersion>17</javaVersion>
<maven.compiler.release>${javaVersion}</maven.compiler.release>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<mainClass>software.xdev.spring.data.eclipse.store.demo.complex.ComplexDemoApplication</mainClass>

<org.springframework.boot.version>3.4.0</org.springframework.boot.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${org.springframework.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>software.xdev</groupId>
<artifactId>spring-data-eclipse-store</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.store</groupId>
<artifactId>storage-restservice-springboot</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand All @@ -73,12 +61,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
package software.xdev.spring.data.eclipse.store.demo.complex;

import java.nio.file.Path;
import java.util.Map;

import org.eclipse.serializer.reflect.ClassLoaderProvider;
import org.eclipse.store.integrations.spring.boot.types.configuration.EclipseStoreProperties;
import org.eclipse.store.integrations.spring.boot.types.factories.EmbeddedStorageFoundationFactory;
import org.eclipse.store.storage.embedded.types.EmbeddedStorage;
import org.eclipse.store.storage.embedded.types.EmbeddedStorageFoundation;
import org.eclipse.store.storage.embedded.types.EmbeddedStorageManager;
import org.eclipse.store.storage.restadapter.types.StorageRestAdapter;
import org.eclipse.store.storage.types.Storage;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.transaction.PlatformTransactionManager;

import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;
import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories;


@ComponentScan({"org.eclipse.store.storage.restservice.spring.boot.types.rest"})
@Configuration
@EnableEclipseStoreRepositories
public class ComplexConfiguration extends EclipseStoreClientConfiguration
Expand Down Expand Up @@ -53,6 +59,15 @@ public EmbeddedStorageFoundation<?> createEmbeddedStorageFoundation()
storageFoundation.getConnectionFoundation().setClassLoaderProvider(this.getClassLoaderProvider());
return storageFoundation;
}

@Bean
@DependsOn({"embeddedStorageFoundationFactory"})
public Map<String, StorageRestAdapter> storageRestAdapters(final Map<String, EmbeddedStorageManager> storages)
{
return Map.of(
"defaultStorageManager", StorageRestAdapter.New(this.storageInstance.getInstanceOfStorageManager())
);
}

/**
* Overriding {@link #transactionManager(ObjectProvider)} only to add the {@link Bean}-Annotation.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
package software.xdev.spring.data.eclipse.store.demo.complex;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

import java.io.File;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;

import software.xdev.spring.data.eclipse.store.demo.TestUtil;
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;


@SpringBootTest(classes = ComplexDemoApplication.class)
@SpringBootTest(
classes = ComplexDemoApplication.class,
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
class ComplexDemoApplicationTest
{
@LocalServerPort
private int port;
@Autowired
private TestRestTemplate restTemplate;

private final EclipseStoreClientConfiguration configuration;

@Autowired
Expand All @@ -34,4 +46,15 @@ void checkPossibilityToSimplyStartAndRestartApplication()
this.configuration.getStorageInstance().stop();
ComplexDemoApplication.main(new String[]{});
}

@Test
void restEndpoint()
{
assertThat(
this.restTemplate.getForObject(
"http://localhost:" + this.port + "/store-data/default/root",
String.class
)
).contains("ROOT");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server:
port: 0
20 changes: 0 additions & 20 deletions spring-data-eclipse-store-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,9 @@
</organization>

<properties>
<javaVersion>17</javaVersion>
<maven.compiler.release>${javaVersion}</maven.compiler.release>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<mainClass>software.xdev.spring.data.eclipse.store.demo.complex.ComplexDemoApplication</mainClass>

<org.springframework.boot.version>3.4.0</org.springframework.boot.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${org.springframework.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public EclipseStoreStorage(final EclipseStoreClientConfiguration storeConfigurat
this.classLoaderProvider = storeConfiguration.getClassLoaderProvider();
}

private StorageManager getInstanceOfStorageManager()
public StorageManager getInstanceOfStorageManager()
{
this.ensureEntitiesInRoot();
return this.storageManager;
Expand Down

0 comments on commit 1f4359f

Please sign in to comment.