diff --git a/.config/pmd/ruleset.xml b/.config/pmd/ruleset.xml index 667f74e5..7a03f17c 100644 --- a/.config/pmd/ruleset.xml +++ b/.config/pmd/ruleset.xml @@ -151,5 +151,12 @@ + + + + + + + diff --git a/.github/workflows/broken-links.yml b/.github/workflows/broken-links.yml index c17c3978..8f98f1ad 100644 --- a/.github/workflows/broken-links.yml +++ b/.github/workflows/broken-links.yml @@ -11,6 +11,7 @@ permissions: jobs: link-checker: runs-on: ubuntu-latest + timeout-minutes: 15 steps: - uses: actions/checkout@v4 @@ -19,6 +20,8 @@ jobs: - name: Link Checker id: lychee uses: lycheeverse/lychee-action@v2 + with: + fail: false # Don't fail on broken links, create an issue instead - name: Find already existing issue id: find-issue diff --git a/.github/workflows/check-build.yml b/.github/workflows/check-build.yml index 24130cd2..33f70104 100644 --- a/.github/workflows/check-build.yml +++ b/.github/workflows/check-build.yml @@ -26,6 +26,7 @@ env: jobs: build: runs-on: ubuntu-latest + timeout-minutes: 30 strategy: matrix: @@ -73,6 +74,7 @@ jobs: checkstyle: runs-on: ubuntu-latest if: ${{ github.event_name != 'pull_request' || !startsWith(github.head_ref, 'renovate/') }} + timeout-minutes: 15 strategy: matrix: @@ -95,6 +97,7 @@ jobs: pmd: runs-on: ubuntu-latest if: ${{ github.event_name != 'pull_request' || !startsWith(github.head_ref, 'renovate/') }} + timeout-minutes: 15 strategy: matrix: @@ -114,9 +117,6 @@ jobs: - name: Run PMD run: ./mvnw -B test pmd:aggregate-pmd-no-fork pmd:check -P pmd -DskipTests -T2C - - name: Run CPD (Copy Paste Detector) - run: ./mvnw -B pmd:aggregate-cpd pmd:cpd-check -P pmd -DskipTests -T2C - - name: Upload report if: always() uses: actions/upload-artifact@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0bf3805c..236c0f59 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,6 +14,7 @@ permissions: jobs: check-code: runs-on: ubuntu-latest + timeout-minutes: 30 steps: - uses: actions/checkout@v4 @@ -48,6 +49,7 @@ jobs: prepare-release: runs-on: ubuntu-latest needs: [check-code] + timeout-minutes: 10 outputs: upload_url: ${{ steps.create_release.outputs.upload_url }} steps: @@ -109,6 +111,7 @@ jobs: publish-maven: runs-on: ubuntu-latest needs: [prepare-release] + timeout-minutes: 60 steps: - uses: actions/checkout@v4 @@ -140,6 +143,7 @@ jobs: publish-pages: runs-on: ubuntu-latest needs: [prepare-release] + timeout-minutes: 15 steps: - uses: actions/checkout@v4 @@ -169,6 +173,7 @@ jobs: after-release: runs-on: ubuntu-latest needs: [publish-maven] + timeout-minutes: 10 steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index b38f0d82..df6dbb7e 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -27,6 +27,7 @@ jobs: token-check: runs-on: ubuntu-latest if: ${{ !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'renovate/')) }} + timeout-minutes: 5 outputs: hasToken: ${{ steps.check-token.outputs.has }} steps: @@ -40,6 +41,7 @@ jobs: runs-on: ubuntu-latest needs: token-check if: ${{ needs.token-check.outputs.hasToken }} + timeout-minutes: 30 steps: - uses: actions/checkout@v4 with: diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index ff880f07..c9d7ec78 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -14,6 +14,7 @@ permissions: jobs: labels: runs-on: ubuntu-latest + timeout-minutes: 10 steps: - uses: actions/checkout@v4 with: diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index e3ed038b..03f5339e 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -9,6 +9,7 @@ env: jobs: publish-maven: runs-on: ubuntu-latest + timeout-minutes: 60 steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/update-from-template.yml b/.github/workflows/update-from-template.yml index aa33de40..6f9497eb 100644 --- a/.github/workflows/update-from-template.yml +++ b/.github/workflows/update-from-template.yml @@ -31,6 +31,7 @@ permissions: jobs: update: runs-on: ubuntu-latest + timeout-minutes: 60 outputs: update_branch_merged_commit: ${{ steps.manage-branches.outputs.update_branch_merged_commit }} create_update_branch_merged_pr: ${{ steps.manage-branches.outputs.create_update_branch_merged_pr }} @@ -180,6 +181,7 @@ jobs: needs: [update] if: needs.update.outputs.create_update_branch_merged_pr == 1 runs-on: ubuntu-latest + timeout-minutes: 60 steps: - uses: actions/checkout@v4 with: diff --git a/.gitignore b/.gitignore index 3370dfc0..5de618cb 100644 --- a/.gitignore +++ b/.gitignore @@ -67,6 +67,7 @@ spring-data-eclipse-store-demo/storage spring-data-eclipse-store-demo/storage-person spring-data-eclipse-store-demo/storage-invoice spring-data-eclipse-store-demo/storage-complex +spring-data-eclipse-store-demo/storage-lazy spring-data-eclipse-store-jpa/storage-eclipsestore spring-data-eclipse-store-jpa/storage-h2.mv.db spring-data-eclipse-store-jpa/storage-h2.trace.db diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml index eb3fcd83..5f35e018 100644 --- a/.idea/checkstyle-idea.xml +++ b/.idea/checkstyle-idea.xml @@ -1,7 +1,7 @@ - 10.15.0 + 10.20.1 JavaOnlyWithTests true true diff --git a/CHANGELOG.md b/CHANGELOG.md index 95b2e41f..90f08446 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 2.4.0 + +* Updated org.springframework.boot.version to v3.4.0 +* Updated EclipseStore to v2.0.0 +* Implemented Lazy Repositories with ``LazyEclipseStoreRepository`` + # 2.3.1 * Auto-Fix problems with adding ids to entities with existing data store. diff --git a/README.md b/README.md index 5cdd4105..e177eb9b 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,8 @@ instructions** are in the documentation](https://xdev-software.github.io/spring- | ``1.0.5-1.0.7`` | ``17`` | ``3.2.5`` | ``1.3.2`` | | ``1.0.8-1.0.10`` | ``17`` | ``3.3.1`` | ``1.3.2`` | | ``2.0.0-2.1.0`` | ``17`` | ``3.3.2`` | ``1.4.0`` | -| ``>= 2.2.0`` | ``17`` | ``3.3.4`` | ``1.4.0`` | +| ``2.2.0-2.3.1`` | ``17`` | ``3.3.4`` | ``1.4.0`` | +| ``>= 2.4.0`` | ``17`` | ``3.4.0`` | ``2.0.0`` | ## Demo @@ -65,6 +66,7 @@ the [demos](./spring-data-eclipse-store-demo): * [Simple demo](https://github.com/xdev-software/spring-data-eclipse-store/tree/develop/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/simple) * [Complex demo](https://github.com/xdev-software/spring-data-eclipse-store/tree/develop/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/complex) +* [Lazy demo](https://github.com/xdev-software/spring-data-eclipse-store/tree/develop/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy) * [Demo with coexisting JPA](https://github.com/xdev-software/spring-data-eclipse-store/tree/develop/spring-data-eclipse-store-jpa/src/main/java/software/xdev/spring/data/eclipse/store/jpa) * [Dual storage demo](https://github.com/xdev-software/spring-data-eclipse-store/tree/develop/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/dual/storage) diff --git a/docs/antora.yml b/docs/antora.yml index 4875528b..56709584 100644 --- a/docs/antora.yml +++ b/docs/antora.yml @@ -1,14 +1,14 @@ name: ROOT title: Spring-Data-Eclipse-Store version: master -display_version: '2.3.1' +display_version: '2.4.0' start_page: index.adoc nav: - modules/ROOT/nav.adoc asciidoc: attributes: product-name: 'Spring-Data-Eclipse-Store' - display-version: '2.3.1' - maven-version: '2.3.1' + display-version: '2.4.0' + maven-version: '2.4.0' page-editable: false page-out-of-support: false diff --git a/docs/modules/ROOT/pages/features/lazies.adoc b/docs/modules/ROOT/pages/features/lazies.adoc index 80a04834..371bd903 100644 --- a/docs/modules/ROOT/pages/features/lazies.adoc +++ b/docs/modules/ROOT/pages/features/lazies.adoc @@ -27,10 +27,38 @@ public class Owner extends Person { private String address; - private Lazy> pets = SpringDataEclipseStoreLazy.build(new ArrayList<>()); + private final Lazy> pets = SpringDataEclipseStoreLazy.build(new ArrayList<>()); //... ---- +== Repositories + +Entities in a repository are by default **not lazy**. +But we made it as easy as possible for you to make these entities lazy: Instead of extending the ``EclipseStoreRepository`` (or any similar class from the ``software.xdev.spring.data.eclipse.store.repository.interfaces``-Package), you simply extend the ``LazyEclipseStoreRepository``. + +=== https://github.com/xdev-software/spring-data-eclipse-store/tree/develop/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/CustomerRepository.java[Example from lazy demo] + +[source,java,title="https://github.com/xdev-software/spring-data-eclipse-store/tree/develop/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/simple/CustomerRepository.java[Before (not lazy)]"] +---- +public interface CustomerRepository extends CrudRepository +{ +} +---- + +[source,java,title="https://github.com/xdev-software/spring-data-eclipse-store/tree/develop/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/CustomerRepository.java[After (lazy)]"] +---- +public interface CustomerRepository extends LazyEclipseStoreCrudRepository +{ +} +---- + +Every instance of the ``Customer``-Entities are now wrapped in a https://docs.eclipsestore.io/manual/storage/loading-data/lazy-loading/index.html[``Lazy``-Reference]. +That means that these objects are **only loaded from the storage, if they are needed** e.g. when ``findAll`` is called. + +The method **``findById`` only loads the entities with the corresponding IDs**, because a separate list with all ids is stored. +But if any method like **``findByName`` or ``findByChild`` is used, all objects are loaded** from the storage. +This is currently the only way to get the actual values of the entities. + == Internals SpringDataEclipseStoreLazies work as a proxy for the EclipseStore-Lazies. diff --git a/docs/package.json b/docs/package.json index d8693534..a8b88ac2 100644 --- a/docs/package.json +++ b/docs/package.json @@ -3,7 +3,7 @@ "@antora/lunr-extension": "^1.0.0-alpha.8" }, "devDependencies": { - "@antora/cli": "3.1.9", - "@antora/site-generator": "3.1.9" + "@antora/cli": "3.1.10", + "@antora/site-generator": "3.1.10" } } \ No newline at end of file diff --git a/pom.xml b/pom.xml index c6b4bc29..a9c27307 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ software.xdev spring-data-eclipse-store-root - 2.3.2-SNAPSHOT + 2.4.0-SNAPSHOT pom @@ -45,12 +45,12 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.5.0 + 3.6.0 com.puppycrawl.tools checkstyle - 10.18.2 + 10.20.2 @@ -75,7 +75,7 @@ org.apache.maven.plugins maven-pmd-plugin - 3.25.0 + 3.26.0 true true @@ -93,12 +93,12 @@ net.sourceforge.pmd pmd-core - 7.6.0 + 7.8.0 net.sourceforge.pmd pmd-java - 7.6.0 + 7.8.0 @@ -110,7 +110,7 @@ org.apache.maven.plugins maven-jxr-plugin - 3.5.0 + 3.6.0 diff --git a/spring-data-eclipse-store-benchmark/pom.xml b/spring-data-eclipse-store-benchmark/pom.xml index 4032e860..e9a4cc1f 100644 --- a/spring-data-eclipse-store-benchmark/pom.xml +++ b/spring-data-eclipse-store-benchmark/pom.xml @@ -5,11 +5,11 @@ software.xdev spring-data-eclipse-store-root - 2.3.2-SNAPSHOT + 2.4.0-SNAPSHOT spring-data-eclipse-store-benchmark - 2.3.2-SNAPSHOT + 2.4.0-SNAPSHOT jar 2023 @@ -25,7 +25,7 @@ UTF-8 UTF-8 - 3.3.4 + 3.4.0 1.37 diff --git a/spring-data-eclipse-store-demo/pom.xml b/spring-data-eclipse-store-demo/pom.xml index 706e7357..b36c5664 100644 --- a/spring-data-eclipse-store-demo/pom.xml +++ b/spring-data-eclipse-store-demo/pom.xml @@ -7,11 +7,11 @@ software.xdev spring-data-eclipse-store-root - 2.3.2-SNAPSHOT + 2.4.0-SNAPSHOT spring-data-eclipse-store-demo - 2.3.2-SNAPSHOT + 2.4.0-SNAPSHOT jar @@ -28,7 +28,7 @@ software.xdev.spring.data.eclipse.store.demo.complex.ComplexDemoApplication - 3.3.4 + 3.4.0 @@ -113,7 +113,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.5.0 + 3.5.2 --add-opens java.base/java.util=ALL-UNNAMED diff --git a/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/Customer.java b/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/Customer.java new file mode 100644 index 00000000..191e38c8 --- /dev/null +++ b/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/Customer.java @@ -0,0 +1,31 @@ +package software.xdev.spring.data.eclipse.store.demo.lazy; + +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; + +import org.springframework.data.annotation.Id; + + +public class Customer +{ + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private String id; + + private final String firstName; + private final String lastName; + + public Customer(final String firstName, final String lastName) + { + this.firstName = firstName; + this.lastName = lastName; + } + + @Override + public String toString() + { + return String.format( + "Customer[id=%s, firstName='%s', lastName='%s']", + this.id, this.firstName, this.lastName); + } +} diff --git a/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/CustomerRepository.java b/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/CustomerRepository.java new file mode 100644 index 00000000..7c0edc1d --- /dev/null +++ b/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/CustomerRepository.java @@ -0,0 +1,8 @@ +package software.xdev.spring.data.eclipse.store.demo.lazy; + +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreCrudRepository; + + +public interface CustomerRepository extends LazyEclipseStoreCrudRepository +{ +} diff --git a/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/LazyConfiguration.java b/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/LazyConfiguration.java new file mode 100644 index 00000000..a17df36c --- /dev/null +++ b/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/LazyConfiguration.java @@ -0,0 +1,52 @@ +package software.xdev.spring.data.eclipse.store.demo.lazy; + +import java.nio.file.Path; + +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.types.Storage; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; + +import software.xdev.spring.data.eclipse.store.demo.dual.storage.person.PersistencePersonConfiguration; +import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration; +import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; + + +@Configuration +@EnableEclipseStoreRepositories +public class LazyConfiguration extends EclipseStoreClientConfiguration +{ + + public static final String STORAGE_PATH = "storage-lazy"; + + @Autowired + public LazyConfiguration( + final EclipseStoreProperties defaultEclipseStoreProperties, + final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider, + final ClassLoaderProvider classLoaderProvider + ) + { + super(defaultEclipseStoreProperties, defaultEclipseStoreProvider, classLoaderProvider); + } + /** + * This is one option how to configure the {@link EmbeddedStorageFoundation}. + *

+ * We create a completely new foundation. That means that all configuration (e.g. properties) are not used here. + * With this method you have complete control over the configuration. + *

+ * Another example: {@link PersistencePersonConfiguration#createEmbeddedStorageFoundation()} + */ + @Override + public EmbeddedStorageFoundation createEmbeddedStorageFoundation() + { + final EmbeddedStorageFoundation storageFoundation = + EmbeddedStorage.Foundation(Storage.Configuration(Storage.FileProvider(Path.of(STORAGE_PATH)))); + // This is only needed, if a different ClassLoader is used (e.g. when using spring-dev-tools) + storageFoundation.getConnectionFoundation().setClassLoaderProvider(this.getClassLoaderProvider()); + return storageFoundation; + } +} diff --git a/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/LazyDemoApplication.java b/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/LazyDemoApplication.java new file mode 100644 index 00000000..7fcd5ec8 --- /dev/null +++ b/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/LazyDemoApplication.java @@ -0,0 +1,67 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package software.xdev.spring.data.eclipse.store.demo.lazy; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + + +@SpringBootApplication +public class LazyDemoApplication implements CommandLineRunner +{ + private static final Logger LOG = LoggerFactory.getLogger(LazyDemoApplication.class); + private final CustomerRepository customerRepository; + private final PetRepository petRepository; + + public LazyDemoApplication( + final CustomerRepository customerRepository, + final PetRepository petRepository + ) + { + this.customerRepository = customerRepository; + this.petRepository = petRepository; + } + + public static void main(final String[] args) + { + SpringApplication.run(LazyDemoApplication.class, args); + } + + @Override + public void run(final String... args) + { + this.customerRepository.deleteAll(); + + // save a couple of customers + this.customerRepository.save(new Customer("Stevie", "Nicks")); + this.customerRepository.save(new Customer("Mick", "Fleetwood")); + + // fetch all customers + LOG.info("Customers found with findAll():"); + this.customerRepository.findAll().forEach(c -> LOG.info(c.toString())); + + // save a pet + this.petRepository.save(new Pet("1", "Peter", 2)); + + // fetch all pets + LOG.info("Pets found with findAll():"); + this.petRepository.findAll().forEach(p -> LOG.info(p.toString())); + } +} diff --git a/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/Pet.java b/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/Pet.java new file mode 100644 index 00000000..6a36915b --- /dev/null +++ b/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/Pet.java @@ -0,0 +1,32 @@ +package software.xdev.spring.data.eclipse.store.demo.lazy; + +import org.springframework.data.annotation.Id; + + +public class Pet +{ + @Id + private String id; + + private String name; + private Integer age; + + public Pet() + { + } + + public Pet(final String id, final String name, final Integer age) + { + this.id = id; + this.name = name; + this.age = age; + } + + @Override + public String toString() + { + return String.format( + "Pet[id=%s, name='%s', age='%s']", + this.id, this.name, this.age); + } +} diff --git a/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/PetRepository.java b/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/PetRepository.java new file mode 100644 index 00000000..2cba129d --- /dev/null +++ b/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/PetRepository.java @@ -0,0 +1,8 @@ +package software.xdev.spring.data.eclipse.store.demo.lazy; + +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreCrudRepository; + + +public interface PetRepository extends LazyEclipseStoreCrudRepository +{ +} diff --git a/spring-data-eclipse-store-demo/src/test/java/software/xdev/spring/data/eclipse/store/demo/lazy/complex/LazyDemoApplicationTest.java b/spring-data-eclipse-store-demo/src/test/java/software/xdev/spring/data/eclipse/store/demo/lazy/complex/LazyDemoApplicationTest.java new file mode 100644 index 00000000..f6a7cd6f --- /dev/null +++ b/spring-data-eclipse-store-demo/src/test/java/software/xdev/spring/data/eclipse/store/demo/lazy/complex/LazyDemoApplicationTest.java @@ -0,0 +1,39 @@ +package software.xdev.spring.data.eclipse.store.demo.lazy.complex; + +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 software.xdev.spring.data.eclipse.store.demo.TestUtil; +import software.xdev.spring.data.eclipse.store.demo.lazy.LazyConfiguration; +import software.xdev.spring.data.eclipse.store.demo.lazy.LazyDemoApplication; +import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration; + + +@SpringBootTest(classes = LazyDemoApplication.class) +class LazyDemoApplicationTest +{ + private final EclipseStoreClientConfiguration configuration; + + @Autowired + public LazyDemoApplicationTest(final LazyConfiguration configuration) + { + this.configuration = configuration; + } + + @BeforeAll + static void clearPreviousData() + { + TestUtil.deleteDirectory(new File("./" + LazyConfiguration.STORAGE_PATH)); + } + + @Test + void checkPossibilityToSimplyStartAndRestartApplication() + { + this.configuration.getStorageInstance().stop(); + LazyDemoApplication.main(new String[]{}); + } +} diff --git a/spring-data-eclipse-store-jpa/pom.xml b/spring-data-eclipse-store-jpa/pom.xml index 1c8f9a9a..d06dacf3 100644 --- a/spring-data-eclipse-store-jpa/pom.xml +++ b/spring-data-eclipse-store-jpa/pom.xml @@ -7,11 +7,11 @@ software.xdev spring-data-eclipse-store-root - 2.3.2-SNAPSHOT + 2.4.0-SNAPSHOT spring-data-eclipse-store-jpa - 2.3.2-SNAPSHOT + 2.4.0-SNAPSHOT jar 2023 @@ -30,7 +30,7 @@ software.xdev.spring.data.eclipse.store.demo.complex.ComplexDemoApplication - 3.3.4 + 3.4.0 diff --git a/spring-data-eclipse-store/pom.xml b/spring-data-eclipse-store/pom.xml index 8d3b0277..ed00db8c 100644 --- a/spring-data-eclipse-store/pom.xml +++ b/spring-data-eclipse-store/pom.xml @@ -6,7 +6,7 @@ software.xdev spring-data-eclipse-store - 2.3.2-SNAPSHOT + 2.4.0-SNAPSHOT jar spring-data-eclipse-store @@ -51,13 +51,13 @@ UTF-8 - 3.3.4 - 1.4.0 - 1.4.0 + 3.4.0 + 2.0.0 + 2.0.0 8.0.1.Final 6.0.1 6.0.0-M1 - 6.6.1.Final + 6.6.3.Final @@ -274,7 +274,7 @@ org.apache.maven.plugins maven-project-info-reports-plugin - 3.7.0 + 3.8.0 @@ -314,6 +314,8 @@ maven-compiler-plugin 3.13.0 + ${javaVersion} + ${javaVersion} ${maven.compiler.release} -proc:none @@ -323,11 +325,11 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.10.1 + 3.11.2 attach-javadocs - verify + package jar @@ -341,7 +343,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.5.0 + 3.5.2 --add-exports java.base/jdk.internal.misc=ALL-UNNAMED @@ -358,7 +360,7 @@ attach-sources - verify + package jar-no-fork @@ -435,12 +437,12 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.5.0 + 3.6.0 com.puppycrawl.tools checkstyle - 10.18.2 + 10.20.2 @@ -465,7 +467,7 @@ org.apache.maven.plugins maven-pmd-plugin - 3.25.0 + 3.26.0 true true @@ -482,12 +484,12 @@ net.sourceforge.pmd pmd-core - 7.6.0 + 7.8.0 net.sourceforge.pmd pmd-java - 7.6.0 + 7.8.0 @@ -499,7 +501,7 @@ org.apache.maven.plugins maven-jxr-plugin - 3.5.0 + 3.6.0 diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/core/EntityListProvider.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/core/EntityListProvider.java index 6114fef8..7a538164 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/core/EntityListProvider.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/core/EntityListProvider.java @@ -18,6 +18,4 @@ public interface EntityListProvider { EntityProvider getEntityProvider(final Class clazz); - - long getEntityCount(final Class clazz); } diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/core/EntityProvider.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/core/EntityProvider.java index 8a8ff19f..0fdfd649 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/core/EntityProvider.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/core/EntityProvider.java @@ -18,12 +18,12 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Objects; import java.util.Optional; -import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import software.xdev.spring.data.eclipse.store.repository.root.EntityData; +import software.xdev.spring.data.eclipse.store.repository.root.v2_4.EntityData; @SuppressWarnings("java:S119") @@ -38,7 +38,7 @@ public void addEntityData(final EntityData entityData) public Stream stream() { - return this.entityDataList.stream().map(EntityData::getEntities).flatMap(Set::stream); + return this.entityDataList.stream().flatMap(EntityData::getEntitiesAsStream); } public Collection toCollection() @@ -56,12 +56,13 @@ public long size() return this.stream().count(); } + @SuppressWarnings("unchecked") public Optional findAnyEntityWithId(final ID id) { return (Optional)this.entityDataList .stream() - .map(entityData -> entityData.getEntitiesById().get(id)) - .filter(e -> e != null) + .map(entityData -> entityData.getEntityById(id)) + .filter(Objects::nonNull) .findAny(); } } diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EclipseStoreMigrator.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EclipseStoreMigrator.java index f37eaf5d..695f0504 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EclipseStoreMigrator.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EclipseStoreMigrator.java @@ -25,13 +25,15 @@ import software.xdev.micromigration.version.MigrationVersion; import software.xdev.spring.data.eclipse.store.repository.root.VersionedRoot; import software.xdev.spring.data.eclipse.store.repository.root.update.scripts.v2_0_0_InitializeVersioning; +import software.xdev.spring.data.eclipse.store.repository.root.update.scripts.v2_4_0_InitializeLazy; public final class EclipseStoreMigrator { public static final VersionAgnosticMigrationScript[] SCRIPTS = new VersionAgnosticMigrationScript[]{ - new v2_0_0_InitializeVersioning() + new v2_0_0_InitializeVersioning(), + new v2_4_0_InitializeLazy() }; private EclipseStoreMigrator() diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EclipseStoreStorage.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EclipseStoreStorage.java index 4f902583..a92213b7 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EclipseStoreStorage.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EclipseStoreStorage.java @@ -38,8 +38,9 @@ import software.xdev.spring.data.eclipse.store.exceptions.InvalidRootException; import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration; import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreStorageFoundationProvider; -import software.xdev.spring.data.eclipse.store.repository.root.EntityData; +import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreRepository; import software.xdev.spring.data.eclipse.store.repository.root.VersionedRoot; +import software.xdev.spring.data.eclipse.store.repository.root.v2_4.EntityData; import software.xdev.spring.data.eclipse.store.repository.support.SimpleEclipseStoreRepository; import software.xdev.spring.data.eclipse.store.repository.support.concurrency.ReadWriteLock; import software.xdev.spring.data.eclipse.store.repository.support.concurrency.ReentrantJavaReadWriteLock; @@ -53,9 +54,14 @@ import software.xdev.spring.data.eclipse.store.repository.support.reposyncer.SimpleRepositorySynchronizer; -@SuppressWarnings("java:S119") +@SuppressWarnings({"java:S119", "PMD.GodClass"}) public class EclipseStoreStorage - implements EntityListProvider, IdManagerProvider, VersionManagerProvider, PersistableChecker, ObjectSwizzling + implements EntityListProvider, + IdManagerProvider, + VersionManagerProvider, + PersistableChecker, + ObjectSwizzling, + StorageCommunicator { private static final Logger LOG = LoggerFactory.getLogger(EclipseStoreStorage.class); private final Map, SimpleEclipseStoreRepository> entityClassToRepository = new HashMap<>(); @@ -106,8 +112,7 @@ private synchronized void ensureEntitiesInRoot() { if(this.storageManager == null) { - final EmbeddedStorageFoundation embeddedStorageFoundation = - this.startStorageManager(); + final EmbeddedStorageFoundation embeddedStorageFoundation = this.startStorageManager(); this.persistenceChecker = new RelayedPersistenceChecker(embeddedStorageFoundation); this.initRoot(); LOG.info( @@ -119,6 +124,7 @@ private synchronized void ensureEntitiesInRoot() } } + @SuppressWarnings("deprecation") private EmbeddedStorageFoundation startStorageManager() { LOG.info("Starting storage..."); @@ -155,9 +161,9 @@ else if(!(embeddedStorageManager.root() instanceof VersionedRoot)) return embeddedStorageFoundation; } - public SimpleEclipseStoreRepository getRepository(final Class entityClass) + public EclipseStoreRepository getRepository(final Class entityClass) { - return (SimpleEclipseStoreRepository)this.entityClassToRepository.get(entityClass); + return this.entityClassToRepository.get(entityClass); } private void initRoot() @@ -168,6 +174,19 @@ private void initRoot() } this.repositorySynchronizer = new SimpleRepositorySynchronizer(this.root.getCurrentRootData()); + this.ensureEntityData(); + this.entitySetCollector = + new EntitySetCollector( + this.root.getCurrentRootData()::getEntityData, + this.entityClassToRepository.keySet()); + if(LOG.isDebugEnabled()) + { + LOG.debug("Done initializing entity lists."); + } + } + + private void ensureEntityData() + { boolean entityListMustGetStored = false; for(final Class entityClass : this.entityClassToRepository.keySet()) { @@ -185,20 +204,20 @@ private void initRoot() { this.storageManager.store(this.root.getCurrentRootData().getEntityListsToStore()); } - this.entitySetCollector = - new EntitySetCollector( - this.root.getCurrentRootData()::getEntityData, - this.entityClassToRepository.keySet()); - if(LOG.isDebugEnabled()) - { - LOG.debug("Done initializing entity lists."); - } } - private void createNewEntityData(final Class entityClass, final VersionedRoot root) + public void createNewEntityData(final Class entityClass, final VersionedRoot root) { final IdManager idManager = this.ensureIdManager(entityClass); - root.getCurrentRootData().createNewEntityData(entityClass, idManager::getId); + final SimpleEclipseStoreRepository repository = this.entityClassToRepository.get(entityClass); + if(repository != null && repository.isLazy()) + { + root.getCurrentRootData().createNewLazyEntityData(entityClass, idManager.hasIdField() ? idManager : null); + } + else + { + root.getCurrentRootData().createNewEntityData(entityClass, idManager.hasIdField() ? idManager : null); + } } private void setIdManagerForEntityData(final Class entityClass, final VersionedRoot root) @@ -215,9 +234,10 @@ private void setIdManagerForEntityData(final Class entityClass, final } } - public synchronized void registerEntity( + @Override + public synchronized void registerEntity( final Class classToRegister, - final SimpleEclipseStoreRepository repository) + final SimpleEclipseStoreRepository repository) { if(this.entityClassToRepository.containsKey(classToRegister)) { @@ -236,9 +256,7 @@ public synchronized void registerEntity( private EntityData getEntityData(final Class clazz) { this.ensureEntitiesInRoot(); - return this.readWriteLock.read( - () -> this.root.getCurrentRootData().getEntityData(clazz) - ); + return this.readWriteLock.read(() -> this.root.getCurrentRootData().getEntityData(clazz)); } @Override @@ -248,20 +266,17 @@ public EntityProvider getEntityProvider(final Class clazz) return this.entitySetCollector.getRelatedIdentitySets(clazz); } - @SuppressWarnings("unchecked") @Override public long getEntityCount(final Class clazz) { this.ensureEntitiesInRoot(); - return this.readWriteLock.read( - () -> - { - final EntityData entityData = this.root.getCurrentRootData().getEntityData(clazz); - return entityData == null ? 0 : entityData.getEntityCount(); - } - ); + return this.readWriteLock.read(() -> { + final EntityData entityData = this.getEntityData(clazz); + return entityData == null ? 0 : entityData.getEntityCount(); + }); } + @Override public void store( final Collection nonEntitiesToStore, final Class clazz, @@ -272,7 +287,10 @@ public void store( () -> { final Collection entitiesAndPossiblyNonEntitiesToStore = - this.collectRootEntitiesToStore(clazz, entitiesToStore); + this.collectRootEntitiesToStore( + this.getEntityData(clazz), + clazz, + entitiesToStore); entitiesAndPossiblyNonEntitiesToStore.addAll(nonEntitiesToStore); if(LOG.isDebugEnabled()) { @@ -293,10 +311,10 @@ public void store( * Also collects the object-list to store, if necessary. */ private Collection collectRootEntitiesToStore( + final EntityData entityData, final Class clazz, final Iterable entitiesToStore) { - final EntityData entityData = this.getEntityData(clazz); final Collection objectsToStore = new ArrayList<>(); for(final T entityToStore : entitiesToStore) { @@ -310,13 +328,14 @@ private Collection collectRootEntitiesToStore( return objectsToStore; } - public void delete(final Class clazz, final T entityToRemove) + @Override + public void delete(final Class clazz, final T entityToRemove) { this.ensureEntitiesInRoot(); this.readWriteLock.write( () -> { - final EntityData entityData = this.getEntityData(clazz); + final EntityData entityData = this.getEntityData(clazz); this.storageManager.storeAll(entityData.removeEntityAndReturnObjectsToStore(entityToRemove)); if(LOG.isDebugEnabled()) { @@ -326,13 +345,14 @@ public void delete(final Class clazz, final T entityToRemove) ); } - public void deleteAll(final Class clazz) + @Override + public void deleteAll(final Class clazz) { this.ensureEntitiesInRoot(); this.readWriteLock.write( () -> { - final EntityData entityData = this.getEntityData(clazz); + final EntityData entityData = this.getEntityData(clazz); final long oldSize = entityData.getEntityCount(); this.storageManager.storeAll(entityData.removeAllEntitiesAndReturnObjectsToStore()); if(LOG.isDebugEnabled()) @@ -473,8 +493,18 @@ public Object getObject(final long objectId) return this.storageManager.getObject(objectId); } + @Override public ReadWriteLock getReadWriteLock() { return this.readWriteLock; } + + /** + * Warning! Please be very cautious if you access the root object. + * This should only be done if absolutely necessary! + */ + public VersionedRoot getRoot() + { + return this.root; + } } diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EntitySetCollector.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EntitySetCollector.java index 4ca0f8d4..10dae678 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EntitySetCollector.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EntitySetCollector.java @@ -24,7 +24,7 @@ import org.slf4j.LoggerFactory; import software.xdev.spring.data.eclipse.store.core.EntityProvider; -import software.xdev.spring.data.eclipse.store.repository.root.EntityData; +import software.xdev.spring.data.eclipse.store.repository.root.v2_4.EntityData; @SuppressWarnings("java:S119") diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/StorageCommunicator.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/StorageCommunicator.java new file mode 100644 index 00000000..4ce4eaae --- /dev/null +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/StorageCommunicator.java @@ -0,0 +1,42 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.repository; + +import java.util.Collection; + +import software.xdev.spring.data.eclipse.store.core.EntityProvider; +import software.xdev.spring.data.eclipse.store.repository.support.SimpleEclipseStoreRepository; +import software.xdev.spring.data.eclipse.store.repository.support.concurrency.ReadWriteLock; + + +public interface StorageCommunicator +{ + ReadWriteLock getReadWriteLock(); + + void store( + final Collection nonEntitiesToStore, final Class clazz, + final Iterable entitiesToStore); + + EntityProvider getEntityProvider(final Class clazz); + + long getEntityCount(Class domainClass); + + void delete(Class domainClass, T foundEntity); + + void deleteAll(Class domainClass); + + void registerEntity(Class domainClass, SimpleEclipseStoreRepository repository); +} diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/config/EclipseStoreClientConfiguration.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/config/EclipseStoreClientConfiguration.java index 7ec64a3d..b75a22b4 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/config/EclipseStoreClientConfiguration.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/config/EclipseStoreClientConfiguration.java @@ -15,10 +15,10 @@ */ package software.xdev.spring.data.eclipse.store.repository.config; -import org.eclipse.serializer.reflect.ClassLoaderProvider; import jakarta.validation.Validation; import jakarta.validation.Validator; +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.EmbeddedStorageFoundation; @@ -34,7 +34,6 @@ import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.event.EventListener; import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.TransactionManager; import software.xdev.spring.data.eclipse.store.repository.EclipseStoreStorage; import software.xdev.spring.data.eclipse.store.transactions.EclipseStoreTransactionManager; @@ -108,7 +107,7 @@ public EmbeddedStorageFoundationFactory getStoreProvider() public ClassLoaderProvider getClassLoaderProvider() { - return classLoaderProvider; + return this.classLoaderProvider; } /** @@ -134,7 +133,7 @@ public PlatformTransactionManager transactionManager( final ObjectProvider transactionManagerCustomizers) { final EclipseStoreTransactionManager tm = this.getTransactionManagerInstance(); - transactionManagerCustomizers.ifAvailable(customizers -> customizers.customize((TransactionManager)tm)); + transactionManagerCustomizers.ifAvailable(customizers -> customizers.customize(tm)); return tm; } diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/config/EclipseStoreRepositoryConfigurationExtension.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/config/EclipseStoreRepositoryConfigurationExtension.java index 9c56bed6..4a98e2cf 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/config/EclipseStoreRepositoryConfigurationExtension.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/config/EclipseStoreRepositoryConfigurationExtension.java @@ -34,9 +34,15 @@ import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreCrudRepository; import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreCustomRepository; import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreListCrudRepository; -import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreListPagingAndSortingRepositoryRepository; -import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStorePagingAndSortingRepositoryRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreListPagingAndSortingRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStorePagingAndSortingRepository; import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreCrudRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreCustomRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreListCrudRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreListPagingAndSortingRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStorePagingAndSortingRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreRepository; import software.xdev.spring.data.eclipse.store.repository.support.EclipseStoreRepositoryFactoryBean; @@ -58,6 +64,7 @@ public String getModuleName() */ @Override @Nonnull + @SuppressWarnings("deprecation") public String getModulePrefix() { return this.getModuleIdentifier(); @@ -118,10 +125,16 @@ protected Collection> getIdentifyingTypes() return List.of( EclipseStoreRepository.class, EclipseStoreCustomRepository.class, - EclipseStorePagingAndSortingRepositoryRepository.class, - EclipseStoreListPagingAndSortingRepositoryRepository.class, + EclipseStorePagingAndSortingRepository.class, + EclipseStoreListPagingAndSortingRepository.class, EclipseStoreCrudRepository.class, - EclipseStoreListCrudRepository.class + EclipseStoreListCrudRepository.class, + LazyEclipseStoreRepository.class, + LazyEclipseStoreCustomRepository.class, + LazyEclipseStorePagingAndSortingRepository.class, + LazyEclipseStoreListPagingAndSortingRepository.class, + LazyEclipseStoreCrudRepository.class, + LazyEclipseStoreListCrudRepository.class ); } diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/EclipseStoreListPagingAndSortingRepositoryRepository.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/EclipseStoreListPagingAndSortingRepository.java similarity index 92% rename from spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/EclipseStoreListPagingAndSortingRepositoryRepository.java rename to spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/EclipseStoreListPagingAndSortingRepository.java index 72be795d..8909e6a1 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/EclipseStoreListPagingAndSortingRepositoryRepository.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/EclipseStoreListPagingAndSortingRepository.java @@ -21,7 +21,7 @@ @SuppressWarnings("java:S119") @NoRepositoryBean -public interface EclipseStoreListPagingAndSortingRepositoryRepository +public interface EclipseStoreListPagingAndSortingRepository extends ListPagingAndSortingRepository { } diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/EclipseStorePagingAndSortingRepositoryRepository.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/EclipseStorePagingAndSortingRepository.java similarity index 92% rename from spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/EclipseStorePagingAndSortingRepositoryRepository.java rename to spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/EclipseStorePagingAndSortingRepository.java index a4c4b37c..9d72eb1d 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/EclipseStorePagingAndSortingRepositoryRepository.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/EclipseStorePagingAndSortingRepository.java @@ -21,7 +21,7 @@ @SuppressWarnings("java:S119") @NoRepositoryBean -public interface EclipseStorePagingAndSortingRepositoryRepository +public interface EclipseStorePagingAndSortingRepository extends PagingAndSortingRepository { } diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/EclipseStoreRepository.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/EclipseStoreRepository.java index 3fb889dd..75a41c4c 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/EclipseStoreRepository.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/EclipseStoreRepository.java @@ -23,7 +23,7 @@ public interface EclipseStoreRepository extends EclipseStoreListCrudRepository, - EclipseStoreListPagingAndSortingRepositoryRepository, + EclipseStoreListPagingAndSortingRepository, EclipseStoreQueryByExampleExecutor { } diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStoreCrudRepository.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStoreCrudRepository.java new file mode 100644 index 00000000..fc9d7e84 --- /dev/null +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStoreCrudRepository.java @@ -0,0 +1,81 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.repository.interfaces.lazy; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.NoRepositoryBean; + + +@SuppressWarnings("java:S119") +@NoRepositoryBean +public interface LazyEclipseStoreCrudRepository extends CrudRepository +{ + /** + * @inheritDoc Caution with referenced objects!
If you are deleting an object that is referenced by + * another object, the behavior of this function may differ from what you are used to! + *

+ * JPA would throw a {@code JdbcSQLIntegrityConstraintViolationException} but it would be very expensive to search + * the referencedObject in the complete object tree and throw the exception. + *

+ * That is why this library simply removes the element from the repository, but if it is still referenced by + * another + * object, this reference is still working and pointing to the object. That means that in fact this the + * object to remove could very well stay in the storage if it is referenced. + *

+ */ + @Override + void deleteById(ID id); + + /** + * @inheritDoc Caution with referenced objects!
If you are deleting an object that is referenced by + * another object, the behavior of this function may differ from what you are used to! + *

+ * For more information see {@link #deleteById(Object)} + *

+ */ + @Override + void delete(T entity); + + /** + * @inheritDoc Caution with referenced objects!
If you are deleting an object that is referenced by + * another object, the behavior of this function may differ from what you are used to! + *

+ * For more information see {@link #deleteById(Object)} + *

+ */ + @Override + void deleteAllById(Iterable ids); + + /** + * @inheritDoc Caution with referenced objects!
If you are deleting an object that is referenced by + * another object, the behavior of this function may differ from what you are used to! + *

+ * For more information see {@link #deleteById(Object)} + *

+ */ + @Override + void deleteAll(Iterable entities); + + /** + * @inheritDoc Caution with referenced objects!
If you are deleting an object that is referenced by + * another object, the behavior of this function may differ from what you are used to! + *

+ * For more information see {@link #deleteById(Object)} + *

+ */ + @Override + void deleteAll(); +} diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStoreCustomRepository.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStoreCustomRepository.java new file mode 100644 index 00000000..14feb516 --- /dev/null +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStoreCustomRepository.java @@ -0,0 +1,26 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.repository.interfaces.lazy; + +import org.springframework.data.repository.NoRepositoryBean; +import org.springframework.data.repository.Repository; + + +@SuppressWarnings("java:S119") +@NoRepositoryBean +public interface LazyEclipseStoreCustomRepository extends Repository +{ +} diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStoreListCrudRepository.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStoreListCrudRepository.java new file mode 100644 index 00000000..46e6e209 --- /dev/null +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStoreListCrudRepository.java @@ -0,0 +1,65 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.repository.interfaces.lazy; + +import org.springframework.data.repository.ListCrudRepository; +import org.springframework.data.repository.NoRepositoryBean; + + +@SuppressWarnings("java:S119") +@NoRepositoryBean +public interface LazyEclipseStoreListCrudRepository extends ListCrudRepository +{ + /** + * @inheritDoc Caution with referenced objects!
If you are deleting an object that is referenced by + * another object, the behavior of this function may differ from what you are used to! + *

+ * For more information see {@link LazyEclipseStoreCrudRepository#deleteById(Object)} + *

+ */ + @Override + void delete(T entity); + + /** + * @inheritDoc Caution with referenced objects!
If you are deleting an object that is referenced by + * another object, the behavior of this function may differ from what you are used to! + *

+ * For more information see {@link LazyEclipseStoreCrudRepository#deleteById(Object)} + *

+ */ + @Override + void deleteAllById(Iterable ids); + + /** + * @inheritDoc Caution with referenced objects!
If you are deleting an object that is referenced by + * another object, the behavior of this function may differ from what you are used to! + *

+ * For more information see {@link LazyEclipseStoreCrudRepository#deleteById(Object)} + *

+ */ + @Override + void deleteAll(Iterable entities); + + /** + * @inheritDoc Caution with referenced objects!
If you are deleting an object that is referenced by + * another object, the behavior of this function may differ from what you are used to! + *

+ * For more information see {@link LazyEclipseStoreCrudRepository#deleteById(Object)} + *

+ */ + @Override + void deleteAll(); +} diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStoreListPagingAndSortingRepository.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStoreListPagingAndSortingRepository.java new file mode 100644 index 00000000..9c25b3ff --- /dev/null +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStoreListPagingAndSortingRepository.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.repository.interfaces.lazy; + +import org.springframework.data.repository.ListPagingAndSortingRepository; +import org.springframework.data.repository.NoRepositoryBean; + + +@SuppressWarnings("java:S119") +@NoRepositoryBean +public interface LazyEclipseStoreListPagingAndSortingRepository + extends ListPagingAndSortingRepository +{ +} diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStorePagingAndSortingRepository.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStorePagingAndSortingRepository.java new file mode 100644 index 00000000..05f5752d --- /dev/null +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStorePagingAndSortingRepository.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.repository.interfaces.lazy; + +import org.springframework.data.repository.NoRepositoryBean; +import org.springframework.data.repository.PagingAndSortingRepository; + + +@SuppressWarnings("java:S119") +@NoRepositoryBean +public interface LazyEclipseStorePagingAndSortingRepository + extends PagingAndSortingRepository +{ +} diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStoreQueryByExampleExecutor.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStoreQueryByExampleExecutor.java new file mode 100644 index 00000000..d4ea57fd --- /dev/null +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStoreQueryByExampleExecutor.java @@ -0,0 +1,26 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.repository.interfaces.lazy; + +import org.springframework.data.repository.NoRepositoryBean; +import org.springframework.data.repository.query.QueryByExampleExecutor; + + +@SuppressWarnings("java:S119") +@NoRepositoryBean +public interface LazyEclipseStoreQueryByExampleExecutor extends QueryByExampleExecutor +{ +} diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStoreRepository.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStoreRepository.java new file mode 100644 index 00000000..b879c552 --- /dev/null +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/interfaces/lazy/LazyEclipseStoreRepository.java @@ -0,0 +1,32 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.repository.interfaces.lazy; + +import org.springframework.data.repository.NoRepositoryBean; + +import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreRepository; + + +@SuppressWarnings("java:S119") +@NoRepositoryBean +public interface LazyEclipseStoreRepository + extends + LazyEclipseStoreListCrudRepository, + LazyEclipseStoreListPagingAndSortingRepository, + LazyEclipseStoreQueryByExampleExecutor, + EclipseStoreRepository +{ +} diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/lazy/SpringDataEclipseStoreLazy.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/lazy/SpringDataEclipseStoreLazy.java index 2d29d410..182d2990 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/lazy/SpringDataEclipseStoreLazy.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/lazy/SpringDataEclipseStoreLazy.java @@ -17,7 +17,11 @@ import java.lang.reflect.Field; import java.util.Objects; +import java.util.concurrent.locks.ReentrantLock; +import java.util.function.Consumer; +import org.eclipse.serializer.collections.HashEnum; +import org.eclipse.serializer.collections.types.XGettingEnum; import org.eclipse.serializer.reference.Lazy; import org.eclipse.serializer.reference.ObjectSwizzling; import org.eclipse.serializer.reference.Swizzling; @@ -64,7 +68,7 @@ static SpringDataEclipseStoreLazy.Default buildWithLazy(final Lazy laz * * @param the type of the lazily referenced element */ - @SuppressWarnings({"java:S2065"}) + @SuppressWarnings({"java:S2065", "PMD.AvoidSynchronizedStatement"}) final class Default implements SpringDataEclipseStoreLazy { private T objectToBeWrapped; @@ -73,6 +77,8 @@ final class Default implements SpringDataEclipseStoreLazy private transient ObjectSwizzling loader; private transient WorkingCopier copier; private transient boolean isStored; + private final transient ReentrantLock usageMarksLock = new ReentrantLock(); + private final transient HashEnum usageMarks = HashEnum.New(); private Default(final Lazy lazySubject) { @@ -259,5 +265,65 @@ public boolean isOriginalObject() { return this.objectToBeWrapped != null; } + + // region Copied from org.eclipse.serializer.reference.UsageMarkable#Default + @Override + public int markUsedFor(final Object instance) + { + // lock internal instance to avoid side effect deadlocks + synchronized(this.usageMarks) + { + final boolean added = this.usageMarks.add(instance); + + return this.usageMarks.intSize() * (added ? 1 : -1); + } + } + + @Override + public int unmarkUsedFor(final Object instance) + { + // lock internal instance to avoid side effect deadlocks + synchronized(this.usageMarks) + { + final boolean removed = this.usageMarks.removeOne(instance); + + return this.usageMarks.intSize() * (removed ? 1 : -1); + } + } + + @Override + public boolean isUsed() + { + // lock internal instance to avoid side effect deadlocks + synchronized(this.usageMarks) + { + return !this.usageMarks.isEmpty(); + } + } + + @Override + public int markUnused() + { + // lock internal instance to avoid side effect deadlocks + synchronized(this.usageMarks) + { + final int currentSize = this.usageMarks.intSize(); + this.usageMarks.clear(); + + return currentSize; + } + } + + @Override + public void accessUsageMarks(final Consumer> logic) + { + // lock internal instance to avoid side effect deadlocks + synchronized(this.usageMarks) + { + // no null check to give logic a chance to notice no-marks case. + logic.accept(this.usageMarks); + } + } + // endregion } } diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/lazy/SpringDataEclipseStoreLazyBinaryHandler.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/lazy/SpringDataEclipseStoreLazyBinaryHandler.java index a6223a84..439b75c8 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/lazy/SpringDataEclipseStoreLazyBinaryHandler.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/lazy/SpringDataEclipseStoreLazyBinaryHandler.java @@ -154,7 +154,7 @@ private void updateStateT( } @Override - public final void complete( + public void complete( final Binary data, final SpringDataEclipseStoreLazy.Default instance, final PersistenceLoadHandler handler @@ -164,25 +164,25 @@ public final void complete( } @Override - public final boolean hasPersistedReferences() + public boolean hasPersistedReferences() { return true; } @Override - public final boolean hasPersistedVariableLength() + public boolean hasPersistedVariableLength() { return false; } @Override - public final boolean hasVaryingPersistedLengthInstances() + public boolean hasVaryingPersistedLengthInstances() { return false; } @Override - public final void iterateLoadableReferences( + public void iterateLoadableReferences( final Binary data, final PersistenceReferenceLoader iterator ) diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/query/by/example/EclipseStoreFetchableFluentQuery.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/query/by/example/EclipseStoreFetchableFluentQuery.java index 4e7d4aec..5fb5b877 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/query/by/example/EclipseStoreFetchableFluentQuery.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/query/by/example/EclipseStoreFetchableFluentQuery.java @@ -25,7 +25,7 @@ import org.springframework.data.domain.Sort; import org.springframework.data.repository.query.FluentQuery; -import software.xdev.spring.data.eclipse.store.repository.EclipseStoreStorage; +import software.xdev.spring.data.eclipse.store.repository.StorageCommunicator; import software.xdev.spring.data.eclipse.store.repository.query.criteria.CriteriaByExample; import software.xdev.spring.data.eclipse.store.repository.query.executors.CountQueryExecutor; import software.xdev.spring.data.eclipse.store.repository.query.executors.ExistsQueryExecutor; @@ -43,14 +43,14 @@ public class EclipseStoreFetchableFluentQuery implements FluentQ private final WorkingCopier copier; private final Example example; private final Class domainClass; - private final EclipseStoreStorage storage; + private final StorageCommunicator storage; private final Sort sort; public EclipseStoreFetchableFluentQuery( final WorkingCopier copier, final Example example, final Class domainClass, - final EclipseStoreStorage storage, + final StorageCommunicator storage, final Sort sort ) { diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/EntityData.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/EntityData.java index f0c3d60e..1ed25d39 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/EntityData.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/EntityData.java @@ -24,9 +24,13 @@ /** + * This is a object for all versions <2.4.0 and is used for upgrading to the new root. + * @deprecated should not be initialised anymore. Version for <2.4.0 + * * @param type of entity to store * @param type of id of the entity to store. Can be {@link Void} if no ID is used. */ +@Deprecated(forRemoval = false, since = "2.4.0") public class EntityData { private final IdentitySet entities; diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/RootDataV2.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/RootDataV2.java index 4cca1a0c..56e9e4e1 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/RootDataV2.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/RootDataV2.java @@ -21,9 +21,11 @@ /** - * This is the actually stored object. + * This is a object for all versions <2.4.0 and is used for upgrading to the new root. + * @deprecated should not be initialised anymore. Version for <2.4.0 */ -@SuppressWarnings("java:S119") +@Deprecated(forRemoval = false, since = "2.4.0") +@SuppressWarnings({"java:S119", "unchecked"}) public class RootDataV2 { private final Map> entityLists; @@ -33,7 +35,7 @@ public RootDataV2() this.entityLists = new HashMap<>(); } - public Object getEntityListsToStore() + public Map> getEntityListsToStore() { return this.entityLists; } diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/VersionedRoot.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/VersionedRoot.java index 19a70e75..5df1f28c 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/VersionedRoot.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/VersionedRoot.java @@ -19,15 +19,20 @@ import software.xdev.micromigration.version.Versioned; import software.xdev.spring.data.eclipse.store.repository.EclipseStoreMigrator; import software.xdev.spring.data.eclipse.store.repository.Root; +import software.xdev.spring.data.eclipse.store.repository.root.v2_4.RootDataV2_4; +@SuppressWarnings("deprecation") public class VersionedRoot implements Versioned { private MigrationVersion version; private Root rootDataV1; - private final RootDataV2 rootDataV2; + private RootDataV2 rootDataV2; + + @SuppressWarnings("checkstyle:MemberName") + private final RootDataV2_4 rootDataV2_4; public VersionedRoot() { @@ -40,7 +45,7 @@ public VersionedRoot() public VersionedRoot(final Root rootDataV1) { this.rootDataV1 = rootDataV1; - this.rootDataV2 = new RootDataV2(); + this.rootDataV2_4 = new RootDataV2_4(); if(rootDataV1 != null) { this.version = new MigrationVersion(0, 0, 0); @@ -56,19 +61,36 @@ public Root getRootDataV1() return this.rootDataV1; } + /** + * @deprecated and is only used in tests + */ + @SuppressWarnings("DeprecatedIsStillUsed") + @Deprecated + public void setRootDataV2(final RootDataV2 rootDataV2) + { + this.rootDataV2 = rootDataV2; + } + public RootDataV2 getRootDataV2() { return this.rootDataV2; } + @SuppressWarnings("checkstyle:MethodName") + public RootDataV2_4 getRootDataV2_4() + { + return this.rootDataV2_4; + } + public void clearOldRootData() { this.rootDataV1 = null; + this.rootDataV2 = null; } - public RootDataV2 getCurrentRootData() + public RootDataV2_4 getCurrentRootData() { - return this.rootDataV2; + return this.rootDataV2_4; } @Override diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/update/scripts/v2_0_0_InitializeVersioning.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/update/scripts/v2_0_0_InitializeVersioning.java index 7844a995..73eba636 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/update/scripts/v2_0_0_InitializeVersioning.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/update/scripts/v2_0_0_InitializeVersioning.java @@ -20,9 +20,9 @@ import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; import software.xdev.micromigration.scripts.Context; -import software.xdev.spring.data.eclipse.store.repository.root.EntityData; import software.xdev.spring.data.eclipse.store.repository.root.RootDataV2; import software.xdev.spring.data.eclipse.store.repository.root.VersionedRoot; +import software.xdev.spring.data.eclipse.store.repository.root.v2_4.EntityData; /** @@ -32,7 +32,7 @@ * All migration scripts must be added to * {@link software.xdev.spring.data.eclipse.store.repository.EclipseStoreMigrator#SCRIPTS}! */ -@SuppressWarnings("checkstyle:TypeName") +@SuppressWarnings({"checkstyle:TypeName", "deprecation"}) public class v2_0_0_InitializeVersioning extends LoggingUpdateScript { private static final Logger LOG = LoggerFactory.getLogger(v2_0_0_InitializeVersioning.class); @@ -44,10 +44,12 @@ public void loggedMigrate(final Context { - final EntityData entityData = versionedRoot.getRootDataV2().getEntityData(entityName); + final EntityData entityData = + versionedRoot.getCurrentRootData().getEntityData(entityName); if(entityData == null) { LOG.warn("Dropping entities {} because there is no repository in the new root.", entityName); + return; } entities.forEach(entity -> entityData.ensureEntityAndReturnObjectsToStore(entity)); context.getStorageManager().getNativeStorageManager().storeAll(entityData.getObjectsToStore()); @@ -57,7 +59,8 @@ public void loggedMigrate(final Context { - final EntityData entityData = versionedRoot.getRootDataV2().getEntityData(entityName); + final software.xdev.spring.data.eclipse.store.repository.root.EntityData entityData = + versionedRoot.getRootDataV2().getEntityData(entityName); entityData.setLastId(lastId); context.getStorageManager().store(entityData); LOG.info("Migrated last id of entities {}.", entityName); diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/update/scripts/v2_4_0_InitializeLazy.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/update/scripts/v2_4_0_InitializeLazy.java new file mode 100644 index 00000000..c34032e2 --- /dev/null +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/update/scripts/v2_4_0_InitializeLazy.java @@ -0,0 +1,60 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.repository.root.update.scripts; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; +import software.xdev.micromigration.scripts.Context; +import software.xdev.spring.data.eclipse.store.repository.root.RootDataV2; +import software.xdev.spring.data.eclipse.store.repository.root.VersionedRoot; + + +/** + * Copies elements from the old Root({@link software.xdev.spring.data.eclipse.store.repository.Root} to the newer + * version of Root({@link RootDataV2}). + *

+ * All migration scripts must be added to + * {@link software.xdev.spring.data.eclipse.store.repository.EclipseStoreMigrator#SCRIPTS}! + */ +@SuppressWarnings({"checkstyle:TypeName", "deprecation"}) +public class v2_4_0_InitializeLazy extends LoggingUpdateScript +{ + private static final Logger LOG = LoggerFactory.getLogger(v2_4_0_InitializeLazy.class); + + @Override + public void loggedMigrate(final Context context) + { + final VersionedRoot versionedRoot = context.getMigratingObject(); + if(versionedRoot.getRootDataV2() != null) + { + versionedRoot.getRootDataV2().getEntityListsToStore().forEach( + (entityName, entities) -> + { + final software.xdev.spring.data.eclipse.store.repository.root.v2_4.EntityData + newEntityData = versionedRoot.getCurrentRootData().getEntityData(entityName); + entities.getEntities().forEach(newEntityData::ensureEntityAndReturnObjectsToStore); + newEntityData.setLastId(entities.getLastId()); + context.getStorageManager().getNativeStorageManager().storeAll(newEntityData.getObjectsToStore()); + LOG.info("Migrated entities {}.", entityName); + } + ); + } + versionedRoot.clearOldRootData(); + context.getStorageManager().store(versionedRoot); + } +} diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/v2_4/EntityData.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/v2_4/EntityData.java new file mode 100644 index 00000000..609dc1c1 --- /dev/null +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/v2_4/EntityData.java @@ -0,0 +1,55 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.repository.root.v2_4; + +import java.util.Collection; +import java.util.stream.Stream; + +import software.xdev.spring.data.eclipse.store.repository.support.id.IdGetter; + + +/** + * @param type of entity to store + * @param type of id of the entity to store. Can be {@link Void} if no ID is used. + */ +public interface EntityData +{ + + /** + * Accepts {@code null} if no id field is defined + */ + void setIdGetter(final IdGetter idGetter); + + Stream getEntitiesAsStream(); + + boolean containsEntity(final T entity); + + ID getLastId(); + + long getEntityCount(); + + void setLastId(final Object lastId); + + Collection ensureEntityAndReturnObjectsToStore(final T entityToStore); + + Collection getObjectsToStore(); + + Collection removeEntityAndReturnObjectsToStore(final T entityToRemove); + + Collection removeAllEntitiesAndReturnObjectsToStore(); + + T getEntityById(ID id); +} diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/v2_4/LazyEntityData.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/v2_4/LazyEntityData.java new file mode 100644 index 00000000..d16da334 --- /dev/null +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/v2_4/LazyEntityData.java @@ -0,0 +1,194 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.repository.root.v2_4; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.stream.Stream; + +import org.eclipse.serializer.reference.Lazy; +import org.eclipse.serializer.reference.Referencing; + +import software.xdev.spring.data.eclipse.store.core.IdentitySet; +import software.xdev.spring.data.eclipse.store.repository.support.id.IdGetter; + + +/** + * @param type of entity to store + * @param type of id of the entity to store. Can be {@link Void} if no ID is used. + */ +public class LazyEntityData implements EntityData +{ + private final IdentitySet> entities; + private ID lastId; + /** + * "Why do you keep the entites at two places? This seems like a waste of space." - Yes, it seems like it is + * duplicated information, but we need to be able to find an entity based on its identity as fast as possible + * ({@link #entities} and also find an entity based on its id {@link #entitiesById}. We could use the BiMaps + * provided by google and apache, but they implemented this also with two seperate lists so there is no benefit in + * using these. + */ + private final HashMap> entitiesById; + + private transient IdGetter idGetter; + + public LazyEntityData() + { + this.entities = new IdentitySet<>(); + this.entitiesById = new HashMap<>(); + } + + /** + * Accepts {@code null} if no id field is defined + */ + @Override + public void setIdGetter(final IdGetter idGetter) + { + this.idGetter = idGetter; + + this.ensureEntitiesAndEntitiesByIdAreTheSameSize(); + } + + @Override + public Stream getEntitiesAsStream() + { + return this.entities.stream().map(Referencing::get); + } + + @Override + public boolean containsEntity(final T entity) + { + if(this.idGetter == null) + { + return this.entities + .stream() + .anyMatch(lazyEntity -> lazyEntity.get() == entity); + } + else + { + final ID id = this.idGetter.getId(entity); + final Lazy existingEntity = this.entitiesById.get(id); + return existingEntity != null && existingEntity.get() == entity; + } + } + + private void ensureEntitiesAndEntitiesByIdAreTheSameSize() + { + if(this.idGetter != null && this.entities.size() != this.entitiesById.size()) + { + this.entitiesById.clear(); + this.entities.forEach(entity -> this.entitiesById.put(this.idGetter.getId(entity.get()), entity)); + } + if(this.idGetter == null) + { + this.entitiesById.clear(); + } + } + + @Override + public ID getLastId() + { + return this.lastId; + } + + @Override + public T getEntityById(final ID id) + { + final Lazy lazyEntity = this.entitiesById.get(id); + return lazyEntity == null ? null : lazyEntity.get(); + } + + @Override + public long getEntityCount() + { + return this.entities.size(); + } + + @Override + public void setLastId(final Object lastId) + { + this.lastId = (ID)lastId; + } + + @Override + public Collection ensureEntityAndReturnObjectsToStore(final T entityToStore) + { + Collection listToSave = List.of(); + if(this.idGetter == null && !this.containsEntity(entityToStore)) + { + // Does not create a SpringDataEclipseStore.Lazy Instance, but a EclipseStore.Lazy because this is + // outside the scope of the SpringDataEclipseStore.Lazy. No conversion is taking place. + this.entities.add(Lazy.Reference(entityToStore)); + listToSave = this.getObjectsToStore(); + } + if(this.idGetter != null) + { + final Lazy existingEntity = this.entitiesById.get(this.idGetter.getId(entityToStore)); + if(existingEntity == null || existingEntity.get() != entityToStore) + { + this.entities.remove(existingEntity); + // Does not create a SpringDataEclipseStore.Lazy Instance, but a EclipseStore.Lazy because this is + // outside the scope of the SpringDataEclipseStore.Lazy. No conversion is taking place. + final Lazy newLazyInstance = Lazy.Reference(entityToStore); + this.entities.add(newLazyInstance); + this.entitiesById.put(this.idGetter.getId(entityToStore), newLazyInstance); + listToSave = this.getObjectsToStore(); + } + } + return listToSave; + } + + @Override + public Collection getObjectsToStore() + { + return List.of(this.entities.getInternalMap(), this.entitiesById); + } + + @Override + public Collection removeEntityAndReturnObjectsToStore(final T entityToRemove) + { + if(this.idGetter == null) + { + this.entities + .stream() + .filter(entity -> entity.get() == entityToRemove) + .findAny() + .ifPresent(this.entities::remove); + } + else + { + final ID id = this.idGetter.getId(entityToRemove); + final Lazy lazyReference = this.entitiesById.get(id); + this.entities.remove(lazyReference); + this.entitiesById.remove(id); + } + return this.getObjectsToStore(); + } + + @Override + public Collection removeAllEntitiesAndReturnObjectsToStore() + { + this.entities.clear(); + this.entitiesById.clear(); + return this.getObjectsToStore(); + } + + public HashMap> getNativeLazyEntitiesById() + { + return entitiesById; + } +} diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/v2_4/NonLazyEntityData.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/v2_4/NonLazyEntityData.java new file mode 100644 index 00000000..d71be4f7 --- /dev/null +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/v2_4/NonLazyEntityData.java @@ -0,0 +1,161 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.repository.root.v2_4; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.stream.Stream; + +import software.xdev.spring.data.eclipse.store.core.IdentitySet; +import software.xdev.spring.data.eclipse.store.repository.support.id.IdGetter; + + +/** + * @param type of entity to store + * @param type of id of the entity to store. Can be {@link Void} if no ID is used. + */ +public class NonLazyEntityData implements EntityData +{ + private final IdentitySet entities; + private ID lastId; + /** + * "Why do you keep the entites at two places? This seems like a waste of space." - Yes, it seems like it is + * duplicated information, but we need to be able to find an entity based on its identity as fast as possible + * ({@link #entities} and also find an entity based on its id {@link #entitiesById}. We could use the BiMaps + * provided by google and apache, but they implemented this also with two seperate lists so there is no benefit in + * using these. + */ + private final HashMap entitiesById; + + private transient IdGetter idGetter; + + public NonLazyEntityData() + { + this.entities = new IdentitySet<>(); + this.entitiesById = new HashMap<>(); + } + + /** + * Accepts {@code null} if no id field is defined + */ + @Override + public void setIdGetter(final IdGetter idGetter) + { + this.idGetter = idGetter; + + this.ensureEntitiesAndEntitiesByIdAreTheSameSize(); + } + + @Override + public Stream getEntitiesAsStream() + { + return this.entities.stream(); + } + + @Override + public boolean containsEntity(final T entity) + { + if(this.idGetter == null) + { + return this.entities.contains(entity); + } + else + { + final ID id = this.idGetter.getId(entity); + final T existingEntity = this.entitiesById.get(id); + return existingEntity != null && existingEntity == entity; + } + } + + private void ensureEntitiesAndEntitiesByIdAreTheSameSize() + { + if(this.idGetter != null && this.entities.size() != this.entitiesById.size()) + { + this.entitiesById.clear(); + this.entities.forEach(entity -> this.entitiesById.put(this.idGetter.getId(entity), entity)); + } + if(this.idGetter == null) + { + this.entitiesById.clear(); + } + } + + @Override + public ID getLastId() + { + return this.lastId; + } + + @Override + public long getEntityCount() + { + return this.entities.size(); + } + + @Override + public void setLastId(final Object lastId) + { + this.lastId = (ID)lastId; + } + + @Override + public Collection ensureEntityAndReturnObjectsToStore(final T entityToStore) + { + Collection listToSave = List.of(); + if(this.entities.add(entityToStore)) + { + listToSave = this.getObjectsToStore(); + } + if(this.idGetter != null && this.entitiesById.get(this.idGetter.getId(entityToStore)) != entityToStore) + { + this.entitiesById.put(this.idGetter.getId(entityToStore), entityToStore); + listToSave = this.getObjectsToStore(); + } + return listToSave; + } + + @Override + public Collection getObjectsToStore() + { + return List.of(this.entities.getInternalMap(), this.entitiesById); + } + + @Override + public T getEntityById(final ID id) + { + return this.entitiesById.get(id); + } + + @Override + public Collection removeEntityAndReturnObjectsToStore(final T entityToRemove) + { + this.entities.remove(entityToRemove); + if(this.idGetter != null) + { + this.entitiesById.remove(this.idGetter.getId(entityToRemove)); + } + return this.getObjectsToStore(); + } + + @Override + public Collection removeAllEntitiesAndReturnObjectsToStore() + { + this.entities.clear(); + this.entitiesById.clear(); + return this.getObjectsToStore(); + } +} diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/v2_4/RootDataV2_4.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/v2_4/RootDataV2_4.java new file mode 100644 index 00000000..3b5288d2 --- /dev/null +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/v2_4/RootDataV2_4.java @@ -0,0 +1,97 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.repository.root.v2_4; + +import java.util.HashMap; +import java.util.Map; + +import software.xdev.spring.data.eclipse.store.repository.support.id.IdGetter; + + +/** + * This is the actually stored object. + */ +@SuppressWarnings({"java:S119", "checkstyle:TypeName"}) +public class RootDataV2_4 +{ + private final Map> entityLists; + + public RootDataV2_4() + { + this.entityLists = new HashMap<>(); + } + + public Object getEntityListsToStore() + { + return this.entityLists; + } + + + public long getEntityTypesCount() + { + return this.entityLists.size(); + } + + public long getEntityCount() + { + return this.entityLists.values().stream().map(EntityData::getEntityCount).reduce(0L, Long::sum); + } + + public EntityData getEntityData(final Class entityClass) + { + return this.getEntityData(this.getEntityName(entityClass)); + } + + public EntityData getEntityData(final String entityClassName) + { + return (EntityData)this.entityLists.get(entityClassName); + } + + public void createNewEntityData(final Class entityClass, final IdGetter idGetter) + { + final NonLazyEntityData entityData = new NonLazyEntityData<>(); + entityData.setIdGetter(idGetter); + this.entityLists.put(this.getEntityName(entityClass), entityData); + } + + public void createNewLazyEntityData(final Class entityClass, final IdGetter idGetter) + { + final LazyEntityData entityData = new LazyEntityData<>(); + entityData.setIdGetter(idGetter); + this.entityLists.put(this.getEntityName(entityClass), entityData); + } + + private String getEntityName(final Class classToRegister) + { + return classToRegister.getName(); + } + + public Object getLastId(final Class entityClass) + { + final EntityData entityData = this.entityLists.get(this.getEntityName(entityClass)); + return entityData == null ? null : entityData.getLastId(); + } + + public void setLastId(final Class entityClass, final Object lastId) + { + this.entityLists.get(this.getEntityName(entityClass)).setLastId(lastId); + } + + public Object getObjectsToStoreAfterNewLastId(final Class entityClass) + { + return this.entityLists.get(this.getEntityName(entityClass)); + } +} diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/EclipseStoreQueryLookupStrategy.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/EclipseStoreQueryLookupStrategy.java index 2f132717..0d355883 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/EclipseStoreQueryLookupStrategy.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/EclipseStoreQueryLookupStrategy.java @@ -19,6 +19,7 @@ import jakarta.annotation.Nonnull; +import org.eclipse.serializer.reference.Lazy; import org.springframework.data.projection.ProjectionFactory; import org.springframework.data.repository.core.NamedQueries; import org.springframework.data.repository.core.RepositoryMetadata; @@ -57,6 +58,12 @@ public RepositoryQuery resolveQuery( { final QueryMethod queryMethod = new QueryMethod(method, metadata, factory); + Class domainType = metadata.getDomainType(); + if(domainType.equals(Lazy.class)) + { + domainType = metadata.getDomainTypeInformation().getTypeArguments().get(0).getType(); + } + final Query queryAnnotation = method.getAnnotation(Query.class); if(queryAnnotation != null) { @@ -64,7 +71,7 @@ public RepositoryQuery resolveQuery( { // Special case for Queries that have findAll and are annotated with Query return this.createFindAllEclipseStoreQueryProvider( - metadata.getDomainType(), + domainType, queryMethod, method ); @@ -72,13 +79,12 @@ public RepositoryQuery resolveQuery( return this.createHSqlQueryProvider( queryAnnotation.value(), - metadata.getDomainType(), + domainType, queryMethod ); } - return this.createStringBasedEclipseStoreQueryProvider( - metadata.getDomainType(), + domainType, queryMethod, method ); diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/EclipseStoreRepositoryFactory.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/EclipseStoreRepositoryFactory.java index 6e28a249..6d1e4c00 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/EclipseStoreRepositoryFactory.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/EclipseStoreRepositoryFactory.java @@ -35,6 +35,14 @@ import software.xdev.spring.data.eclipse.store.repository.EclipseStoreStorage; import software.xdev.spring.data.eclipse.store.repository.SupportedChecker; +import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreCrudRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreCustomRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreListCrudRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreListPagingAndSortingRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStorePagingAndSortingRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreQueryByExampleExecutor; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreRepository; import software.xdev.spring.data.eclipse.store.repository.support.copier.working.RecursiveWorkingCopier; import software.xdev.spring.data.eclipse.store.repository.support.copier.working.WorkingCopier; @@ -66,6 +74,7 @@ public EntityInformation getEntityInformation(@Nonnull final Clas return new PersistentEntityInformation<>(new BasicPersistentEntity<>(TypeInformation.of(domainClass))); } + @SuppressWarnings("deprecation") @Override @Nonnull protected Optional getQueryLookupStrategy( @@ -96,8 +105,9 @@ private WorkingCopier createWorkingCopier( @Nonnull protected Object getTargetRepository(@Nonnull final RepositoryInformation metadata) { - final SimpleEclipseStoreRepository existingRepository = - this.storage.getRepository(metadata.getDomainType()); + final Class domainType = metadata.getDomainType(); + + final EclipseStoreRepository existingRepository = this.storage.getRepository(domainType); if(existingRepository != null) { return existingRepository; @@ -106,10 +116,10 @@ protected Object getTargetRepository(@Nonnull final RepositoryInformation metada return this.getTargetRepositoryViaReflection( metadata, this.storage, - this.createWorkingCopier(metadata.getDomainType(), this.storage), - metadata.getDomainType(), + this.createWorkingCopier(domainType, this.storage), + domainType, this.transactionManager, - this.storage.ensureIdManager(metadata.getDomainType()) + this.storage.ensureIdManager(domainType) ); } @@ -117,9 +127,25 @@ protected Object getTargetRepository(@Nonnull final RepositoryInformation metada @Nonnull protected Class getRepositoryBaseClass(@Nonnull final RepositoryMetadata metadata) { + if(this.isLazyRepository(metadata)) + { + return LazySimpleEclipseStoreRepository.class; + } return SimpleEclipseStoreRepository.class; } + private boolean isLazyRepository(final RepositoryMetadata metadata) + { + final Class repositoryInterface = metadata.getRepositoryInterface(); + return LazyEclipseStoreCrudRepository.class.isAssignableFrom(repositoryInterface) + || LazyEclipseStoreCustomRepository.class.isAssignableFrom(repositoryInterface) + || LazyEclipseStoreListCrudRepository.class.isAssignableFrom(repositoryInterface) + || LazyEclipseStoreListPagingAndSortingRepository.class.isAssignableFrom(repositoryInterface) + || LazyEclipseStorePagingAndSortingRepository.class.isAssignableFrom(repositoryInterface) + || LazyEclipseStoreQueryByExampleExecutor.class.isAssignableFrom(repositoryInterface) + || LazyEclipseStoreRepository.class.isAssignableFrom(repositoryInterface); + } + @Override @Nonnull protected RepositoryInformation getRepositoryInformation( diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/LazySimpleEclipseStoreRepository.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/LazySimpleEclipseStoreRepository.java new file mode 100644 index 00000000..83ab2464 --- /dev/null +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/LazySimpleEclipseStoreRepository.java @@ -0,0 +1,56 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.repository.support; + +import software.xdev.spring.data.eclipse.store.repository.StorageCommunicator; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreCrudRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreListCrudRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreListPagingAndSortingRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStorePagingAndSortingRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreQueryByExampleExecutor; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreRepository; +import software.xdev.spring.data.eclipse.store.repository.support.copier.working.WorkingCopier; +import software.xdev.spring.data.eclipse.store.repository.support.id.IdManager; +import software.xdev.spring.data.eclipse.store.transactions.EclipseStoreTransactionManager; + + +@SuppressWarnings("java:S119") +public class LazySimpleEclipseStoreRepository + extends SimpleEclipseStoreRepository + implements + LazyEclipseStoreRepository, + LazyEclipseStorePagingAndSortingRepository, + LazyEclipseStoreListPagingAndSortingRepository, + LazyEclipseStoreCrudRepository, + LazyEclipseStoreListCrudRepository, + LazyEclipseStoreQueryByExampleExecutor +{ + public LazySimpleEclipseStoreRepository( + final StorageCommunicator storage, + final WorkingCopier copier, + final Class domainClass, + final EclipseStoreTransactionManager transactionManager, + final IdManager idManager) + { + super(storage, copier, domainClass, transactionManager, idManager); + } + + @Override + public boolean isLazy() + { + return true; + } +} diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/SimpleEclipseStoreRepository.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/SimpleEclipseStoreRepository.java index a8945976..820fde36 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/SimpleEclipseStoreRepository.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/SimpleEclipseStoreRepository.java @@ -34,12 +34,12 @@ import org.springframework.data.domain.Sort; import org.springframework.data.repository.query.FluentQuery; -import software.xdev.spring.data.eclipse.store.repository.EclipseStoreStorage; +import software.xdev.spring.data.eclipse.store.repository.StorageCommunicator; import software.xdev.spring.data.eclipse.store.repository.access.AccessHelper; import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreCrudRepository; import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreListCrudRepository; -import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreListPagingAndSortingRepositoryRepository; -import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStorePagingAndSortingRepositoryRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreListPagingAndSortingRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStorePagingAndSortingRepository; import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreQueryByExampleExecutor; import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreRepository; import software.xdev.spring.data.eclipse.store.repository.query.by.example.EclipseStoreFetchableFluentQuery; @@ -61,21 +61,21 @@ public class SimpleEclipseStoreRepository implements EclipseStoreRepository, - EclipseStorePagingAndSortingRepositoryRepository, - EclipseStoreListPagingAndSortingRepositoryRepository, + EclipseStorePagingAndSortingRepository, + EclipseStoreListPagingAndSortingRepository, EclipseStoreCrudRepository, EclipseStoreListCrudRepository, EclipseStoreQueryByExampleExecutor { private static final Logger LOG = LoggerFactory.getLogger(SimpleEclipseStoreRepository.class); - private final EclipseStoreStorage storage; + private final StorageCommunicator storage; private final Class domainClass; private final WorkingCopier copier; private final EclipseStoreTransactionManager transactionManager; private final IdManager idManager; public SimpleEclipseStoreRepository( - final EclipseStoreStorage storage, + final StorageCommunicator storage, final WorkingCopier copier, final Class domainClass, final EclipseStoreTransactionManager transactionManager, @@ -399,4 +399,9 @@ public R findBy( () -> queryFunction.apply(query) ); } + + public boolean isLazy() + { + return false; + } } diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/concurrency/ValueOperation.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/concurrency/ValueOperation.java index 8bb369f0..f9296950 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/concurrency/ValueOperation.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/concurrency/ValueOperation.java @@ -16,7 +16,7 @@ package software.xdev.spring.data.eclipse.store.repository.support.concurrency; /** - * Operation with a return value, used by {@link ReentrantJavaReadWriteLock} and {@link ReadWriteLockedStriped}. + * Operation with a return value, used by {@link ReentrantJavaReadWriteLock}. * * @param T the return type */ @@ -28,5 +28,5 @@ public interface ValueOperation * * @return the result of the operation */ - public T execute(); + T execute(); } diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/concurrency/VoidOperation.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/concurrency/VoidOperation.java index 829c5ab8..139743eb 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/concurrency/VoidOperation.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/concurrency/VoidOperation.java @@ -16,7 +16,7 @@ package software.xdev.spring.data.eclipse.store.repository.support.concurrency; /** - * Operation with no return value, used by {@link ReentrantJavaReadWriteLock} and {@link ReadWriteLockedStriped}. + * Operation with no return value, used by {@link ReentrantJavaReadWriteLock}. */ @FunctionalInterface public interface VoidOperation @@ -24,5 +24,5 @@ public interface VoidOperation /** * Execute an arbitrary operation */ - public void execute(); + void execute(); } diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/reposyncer/RepositorySynchronizer.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/reposyncer/RepositorySynchronizer.java index 8028edad..0e330e2b 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/reposyncer/RepositorySynchronizer.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/reposyncer/RepositorySynchronizer.java @@ -17,7 +17,7 @@ import java.util.Collection; -import software.xdev.spring.data.eclipse.store.repository.root.EntityData; +import software.xdev.spring.data.eclipse.store.repository.root.v2_4.EntityData; /** diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/reposyncer/SimpleRepositorySynchronizer.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/reposyncer/SimpleRepositorySynchronizer.java index b9857158..693ca96d 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/reposyncer/SimpleRepositorySynchronizer.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/reposyncer/SimpleRepositorySynchronizer.java @@ -23,18 +23,18 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import software.xdev.spring.data.eclipse.store.repository.root.EntityData; -import software.xdev.spring.data.eclipse.store.repository.root.RootDataV2; +import software.xdev.spring.data.eclipse.store.repository.root.v2_4.EntityData; +import software.xdev.spring.data.eclipse.store.repository.root.v2_4.RootDataV2_4; public class SimpleRepositorySynchronizer implements RepositorySynchronizer { private static final Logger LOG = LoggerFactory.getLogger(SimpleRepositorySynchronizer.class); - private final RootDataV2 root; + private final RootDataV2_4 root; private final HashSet> listsToStore; private final ObjectGraphTraverser buildObjectGraphTraverser; - public SimpleRepositorySynchronizer(final RootDataV2 root) + public SimpleRepositorySynchronizer(final RootDataV2_4 root) { this.root = root; this.listsToStore = new HashSet<>(); @@ -50,10 +50,10 @@ public SimpleRepositorySynchronizer(final RootDataV2 root) return; } final Class objectInGraphClass = (Class)objectInGraph.getClass(); - final EntityData entityDataForCurrentObject = + EntityData entityDataForCurrentObject = this.root.getEntityData(objectInGraphClass); if(entityDataForCurrentObject != null - && !entityDataForCurrentObject.getEntities().contains(objectInGraph)) + && !entityDataForCurrentObject.containsEntity(objectInGraph)) { entityDataForCurrentObject.ensureEntityAndReturnObjectsToStore(objectInGraph); this.listsToStore.add(entityDataForCurrentObject); diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/helper/DummyEntityProvider.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/helper/DummyEntityProvider.java index dca8ed1e..a7767bd6 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/helper/DummyEntityProvider.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/helper/DummyEntityProvider.java @@ -19,7 +19,8 @@ import java.util.List; import software.xdev.spring.data.eclipse.store.core.EntityProvider; -import software.xdev.spring.data.eclipse.store.repository.root.EntityData; +import software.xdev.spring.data.eclipse.store.repository.root.v2_4.EntityData; +import software.xdev.spring.data.eclipse.store.repository.root.v2_4.NonLazyEntityData; public class DummyEntityProvider extends EntityProvider @@ -27,9 +28,9 @@ public class DummyEntityProvider extends EntityProvider public DummyEntityProvider(final Collection collection) { super(); - final EntityData objects = new EntityData<>(); - objects.setIdGetter(i -> null); - objects.getEntities().addAll(collection); + final EntityData objects = new NonLazyEntityData<>(); + objects.setIdGetter(null); + collection.forEach(objects::ensureEntityAndReturnObjectsToStore); this.addEntityData(objects); } diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/lazy/LazyTest.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/lazy/LazyTest.java index f2b4d490..46771799 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/lazy/LazyTest.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/lazy/LazyTest.java @@ -19,7 +19,9 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Optional; import org.eclipse.serializer.collections.lazy.LazyArrayList; import org.eclipse.serializer.collections.lazy.LazyList; @@ -31,12 +33,16 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; +import software.xdev.spring.data.eclipse.store.exceptions.NoIdFieldFoundException; import software.xdev.spring.data.eclipse.store.helper.TestData; import software.xdev.spring.data.eclipse.store.helper.TestUtil; import software.xdev.spring.data.eclipse.store.integration.isolated.IsolatedTestAnnotations; import software.xdev.spring.data.eclipse.store.repository.lazy.SpringDataEclipseStoreLazy; +import software.xdev.spring.data.eclipse.store.repository.root.v2_4.EntityData; +import software.xdev.spring.data.eclipse.store.repository.root.v2_4.LazyEntityData; +@SuppressWarnings("checkstyle:MethodName") @IsolatedTestAnnotations @ContextConfiguration(classes = {LazyTestConfiguration.class}) class LazyTest @@ -299,7 +305,6 @@ void lazyClearBeforeSave() } @Test - @Disabled("This should work at some point. At least a warning should be displayed.") void lazyUseEclipseStoreLazy(@Autowired final ObjectWithLazyRepository repository) { final ObjectWithLazy newLazy = new ObjectWithLazy<>(); @@ -457,4 +462,80 @@ void lazyChangeAfterRestart(@Autowired final ObjectWithLazyRepository lazyObject = + SpringDataEclipseStoreLazy.build(objectToStore); + repository.save(lazyObject); + + TestUtil.doBeforeAndAfterRestartOfDatastore( + this.configuration, + () -> { + Assertions.assertEquals(1, repository.findAll().size()); + final Lazy reloadedObject = repository.findAll().get(0); + Assertions.assertEquals(objectToStore.getId(), reloadedObject.get().getId()); + Assertions.assertEquals(objectToStore.getName(), reloadedObject.get().getName()); + } + ); + } + + @Test + void simpleEntityWithIdLazyWrappedRepository_OnlyLoadOnDemand( + @Autowired final SimpleEntityWithIdLazyWrappedRepository repository) + { + final SimpleEntityWithId objectToStore = new SimpleEntityWithId(TestData.DUMMY_STRING); + final SpringDataEclipseStoreLazy.Default lazyObject = + SpringDataEclipseStoreLazy.build(objectToStore); + repository.save(lazyObject); + + restartDatastore(this.configuration); + + final Lazy reloadedObject = repository.findAll().get(0); + Assertions.assertFalse(reloadedObject.isLoaded()); + Assertions.assertEquals(objectToStore.getId(), reloadedObject.get().getId()); + Assertions.assertEquals(objectToStore.getName(), reloadedObject.get().getName()); + Assertions.assertTrue(reloadedObject.isLoaded()); + } + + @Test + void simpleEntityWithIdLazyWrappedRepository_FindById( + @Autowired final SimpleEntityWithIdLazyWrappedRepository repository) + { + final SimpleEntityWithId objectToStore1 = new SimpleEntityWithId(TestData.DUMMY_STRING); + repository.save(SpringDataEclipseStoreLazy.build(objectToStore1)); + + final List> all = repository.findAll(); + + Assertions.assertThrows(NoIdFieldFoundException.class, () -> repository.findById(all.get(0).get().getId())); + } + + @Test + void simpleEntityWithIdLazyRepository_FindById(@Autowired final SimpleEntityWithIdLazyRepository repository) + { + final SimpleEntityWithId objectToStore1 = new SimpleEntityWithId(TestData.DUMMY_STRING); + final Long object1Id = repository.save(objectToStore1).getId(); + final SimpleEntityWithId objectToStore2 = new SimpleEntityWithId(TestData.DUMMY_STRING); + final Long object2Id = repository.save(objectToStore2).getId(); + + TestUtil.doBeforeAndAfterRestartOfDatastore( + this.configuration, + () -> { + LazyReferenceManager.get().cleanUp(); + final Optional reloadedObject = repository.findById(object1Id); + Assertions.assertTrue(reloadedObject.isPresent()); + } + ); + final EntityData entityData = this.configuration.getStorageInstance() + .getRoot() + .getCurrentRootData() + .getEntityData(SimpleEntityWithId.class); + final HashMap> lazyEntitiesById = + ((LazyEntityData)entityData).getNativeLazyEntitiesById(); + Assertions.assertTrue(lazyEntitiesById.get(object1Id).isLoaded()); + Assertions.assertFalse(lazyEntitiesById.get(object2Id).isLoaded()); + } } diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/lazy/SimpleEntityWithId.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/lazy/SimpleEntityWithId.java new file mode 100644 index 00000000..c122e1a2 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/lazy/SimpleEntityWithId.java @@ -0,0 +1,55 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.lazy; + +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + + +public class SimpleEntityWithId +{ + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + private String name; + + public SimpleEntityWithId(final String name) + { + this.name = name; + } + + public String getName() + { + return this.name; + } + + public void setName(final String name) + { + this.name = name; + } + + public long getId() + { + return this.id; + } + + public void setId(final long id) + { + this.id = id; + } +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/CustomerWithChildRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/lazy/SimpleEntityWithIdLazyRepository.java similarity index 66% rename from spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/CustomerWithChildRepository.java rename to spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/lazy/SimpleEntityWithIdLazyRepository.java index 25e6e98d..78a0d6e3 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/CustomerWithChildRepository.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/lazy/SimpleEntityWithIdLazyRepository.java @@ -13,14 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package software.xdev.spring.data.eclipse.store.integration.shared.repositories; +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.lazy; -import java.util.Optional; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreRepository; -import org.springframework.data.repository.CrudRepository; - -public interface CustomerWithChildRepository extends CrudRepository +public interface SimpleEntityWithIdLazyRepository extends LazyEclipseStoreRepository { - Optional findByChild(Child child); } diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/lazy/SimpleEntityWithIdLazyWrappedRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/lazy/SimpleEntityWithIdLazyWrappedRepository.java new file mode 100644 index 00000000..8331f826 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/lazy/SimpleEntityWithIdLazyWrappedRepository.java @@ -0,0 +1,24 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.lazy; + +import org.eclipse.serializer.reference.Lazy; +import org.springframework.data.repository.ListCrudRepository; + + +public interface SimpleEntityWithIdLazyWrappedRepository extends ListCrudRepository, Long> +{ +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/migration/MigrationTest.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/migration/MigrationTest.java index 0a70c1f3..9d1a5c47 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/migration/MigrationTest.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/migration/MigrationTest.java @@ -30,12 +30,16 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.util.FileSystemUtils; +import software.xdev.micromigration.version.MigrationVersion; import software.xdev.spring.data.eclipse.store.helper.TestData; import software.xdev.spring.data.eclipse.store.helper.TestUtil; import software.xdev.spring.data.eclipse.store.integration.isolated.IsolatedTestAnnotations; import software.xdev.spring.data.eclipse.store.repository.Root; +import software.xdev.spring.data.eclipse.store.repository.root.RootDataV2; +import software.xdev.spring.data.eclipse.store.repository.root.VersionedRoot; +@SuppressWarnings({"deprecation", "checkstyle:MethodName"}) @IsolatedTestAnnotations @ContextConfiguration(classes = {MigrationTestConfiguration.class}) class MigrationTest @@ -53,9 +57,9 @@ public MigrationTest(final MigrationTestConfiguration configuration, final UserR } @Test - void simpleMigrateFromV000ToV200() throws IOException + void simpleMigrateFromV0_0_0ToNewest() throws IOException { - this.initOldData(); + this.initV1_0_0Data(); TestUtil.doBeforeAndAfterRestartOfDatastore( this.configuration, () -> { @@ -66,7 +70,21 @@ void simpleMigrateFromV000ToV200() throws IOException ); } - private void initOldData() throws IOException + @Test + void simpleMigrateFromV2_0_0ToNewest() throws IOException + { + this.initV2_0_0Data(); + TestUtil.doBeforeAndAfterRestartOfDatastore( + this.configuration, + () -> { + final List foundUsers = this.userRepository.findAll(); + Assertions.assertEquals(1, foundUsers.size()); + Assertions.assertEquals(TEST_USER, foundUsers.get(0)); + } + ); + } + + private void initV1_0_0Data() throws IOException { // Delete already created data this.configuration.getStorageInstance().stop(); @@ -84,4 +102,25 @@ private void initOldData() throws IOException storageManager.storeRoot(); } } + + private void initV2_0_0Data() throws IOException + { + // Delete already created data + this.configuration.getStorageInstance().stop(); + FileSystemUtils.deleteRecursively(Path.of(this.configuration.getStorageDirectory())); + + // Init old data + try(final EmbeddedStorageManager storageManager = + Foundation(Storage.Configuration(Storage.FileProvider(Path.of(this.configuration.getStorageDirectory())))) + .start()) + { + final VersionedRoot oldRoot = new VersionedRoot(); + oldRoot.setRootDataV2(new RootDataV2()); + oldRoot.getRootDataV2().createNewEntityData(User.class, e -> null); + oldRoot.getRootDataV2().getEntityData(User.class).ensureEntityAndReturnObjectsToStore(TEST_USER); + oldRoot.setVersion(new MigrationVersion(2, 0, 0)); + storageManager.setRoot(oldRoot); + storageManager.storeRoot(); + } + } } diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/tests/RealLifeTests.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/RealLifeExamplesTest.java similarity index 87% rename from spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/tests/RealLifeTests.java rename to spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/RealLifeExamplesTest.java index 46ee7c6b..49705a39 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/tests/RealLifeTests.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/RealLifeExamplesTest.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package software.xdev.spring.data.eclipse.store.integration.shared.tests; +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples; -import static software.xdev.spring.data.eclipse.store.integration.shared.repositories.real.life.example.Position.getPositionWithArticleWithName; +import static software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model.Position.getPositionWithArticleWithName; import java.util.ArrayList; import java.util.Arrays; @@ -24,23 +24,19 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; import software.xdev.spring.data.eclipse.store.helper.TestUtil; -import software.xdev.spring.data.eclipse.store.integration.shared.DefaultTestAnnotations; -import software.xdev.spring.data.eclipse.store.integration.shared.SharedTestConfiguration; -import software.xdev.spring.data.eclipse.store.integration.shared.repositories.real.life.example.Article; -import software.xdev.spring.data.eclipse.store.integration.shared.repositories.real.life.example.ArticleGroup; -import software.xdev.spring.data.eclipse.store.integration.shared.repositories.real.life.example.Invoice; -import software.xdev.spring.data.eclipse.store.integration.shared.repositories.real.life.example.InvoiceRepository; -import software.xdev.spring.data.eclipse.store.integration.shared.repositories.real.life.example.Position; -import software.xdev.spring.data.eclipse.store.integration.shared.repositories.real.life.example.PositionRepository; -import software.xdev.spring.data.eclipse.store.integration.shared.repositories.real.life.example.Warehouse; +import software.xdev.spring.data.eclipse.store.integration.TestConfiguration; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model.Article; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model.ArticleGroup; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model.Invoice; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model.InvoiceRepository; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model.Position; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model.PositionRepository; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model.Warehouse; -@SuppressWarnings("OptionalGetWithoutIsPresent") -@DefaultTestAnnotations -class RealLifeTests +public abstract class RealLifeExamplesTest { static final String STATIONERY = "Stationery"; static final String BUILDING_MATERIAL = "Building Material"; @@ -52,12 +48,19 @@ class RealLifeTests static final String SHOE_ARTICLE_NAME = "Shoe"; static final String SHOES_ARTICLE_GROUP = "Shoes"; - @Autowired - InvoiceRepository invoiceRepository; - @Autowired - PositionRepository positionRepository; - @Autowired - private SharedTestConfiguration configuration; + final InvoiceRepository invoiceRepository; + final PositionRepository positionRepository; + private final TestConfiguration configuration; + + public RealLifeExamplesTest( + final InvoiceRepository invoiceRepository, + final PositionRepository positionRepository, + final TestConfiguration configuration) + { + this.invoiceRepository = invoiceRepository; + this.positionRepository = positionRepository; + this.configuration = configuration; + } private Invoice buildDefaultModel() { diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/lazy/InvoiceLazyRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/lazy/InvoiceLazyRepository.java new file mode 100644 index 00000000..5cb3ffb6 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/lazy/InvoiceLazyRepository.java @@ -0,0 +1,25 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.lazy; + +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model.Invoice; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model.InvoiceRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreCrudRepository; + + +public interface InvoiceLazyRepository extends LazyEclipseStoreCrudRepository, InvoiceRepository +{ +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/lazy/PositionLazyRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/lazy/PositionLazyRepository.java new file mode 100644 index 00000000..4ade1081 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/lazy/PositionLazyRepository.java @@ -0,0 +1,25 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.lazy; + +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model.Position; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model.PositionRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreListCrudRepository; + + +public interface PositionLazyRepository extends LazyEclipseStoreListCrudRepository, PositionRepository +{ +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/lazy/RealLifeExamplesLazyTest.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/lazy/RealLifeExamplesLazyTest.java new file mode 100644 index 00000000..331fa50f --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/lazy/RealLifeExamplesLazyTest.java @@ -0,0 +1,37 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.lazy; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; + +import software.xdev.spring.data.eclipse.store.integration.isolated.IsolatedTestAnnotations; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.RealLifeExamplesTest; + + +@IsolatedTestAnnotations +@ContextConfiguration(classes = {RealLifeExamplesLazyTestConfiguration.class}) +class RealLifeExamplesLazyTest extends RealLifeExamplesTest +{ + @Autowired + public RealLifeExamplesLazyTest( + final InvoiceLazyRepository invoiceRepository, + final PositionLazyRepository positionRepository, + final RealLifeExamplesLazyTestConfiguration configuration) + { + super(invoiceRepository, positionRepository, configuration); + } +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/lazy/RealLifeExamplesLazyTestConfiguration.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/lazy/RealLifeExamplesLazyTestConfiguration.java new file mode 100644 index 00000000..c1b8ffa2 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/lazy/RealLifeExamplesLazyTestConfiguration.java @@ -0,0 +1,53 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.lazy; + +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.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.Configuration; +import org.springframework.transaction.PlatformTransactionManager; + +import software.xdev.spring.data.eclipse.store.integration.TestConfiguration; +import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; + + +@Configuration +@EnableEclipseStoreRepositories +public class RealLifeExamplesLazyTestConfiguration extends TestConfiguration +{ + @Autowired + protected RealLifeExamplesLazyTestConfiguration( + final EclipseStoreProperties defaultEclipseStoreProperties, + final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider, + final ClassLoaderProvider classLoaderProvider) + { + super(defaultEclipseStoreProperties, defaultEclipseStoreProvider, classLoaderProvider); + } + + @Bean + @Override + public PlatformTransactionManager transactionManager( + final ObjectProvider transactionManagerCustomizers + ) + { + return super.transactionManager(transactionManagerCustomizers); + } +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/Article.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/Article.java similarity index 94% rename from spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/Article.java rename to spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/Article.java index 21b89654..d4131d6e 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/Article.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/Article.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package software.xdev.spring.data.eclipse.store.integration.shared.repositories.real.life.example; +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model; import java.util.ArrayList; import java.util.Collections; diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/ArticleGroup.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/ArticleGroup.java similarity index 88% rename from spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/ArticleGroup.java rename to spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/ArticleGroup.java index dc73ba6d..9cae714f 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/ArticleGroup.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/ArticleGroup.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package software.xdev.spring.data.eclipse.store.integration.shared.repositories.real.life.example; +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model; public class ArticleGroup { diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/Invoice.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/Invoice.java similarity index 90% rename from spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/Invoice.java rename to spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/Invoice.java index 868061ee..f930fd25 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/Invoice.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/Invoice.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package software.xdev.spring.data.eclipse.store.integration.shared.repositories.real.life.example; +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model; import java.util.List; diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/InvoiceRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/InvoiceRepository.java similarity index 88% rename from spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/InvoiceRepository.java rename to spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/InvoiceRepository.java index baa35843..c1046fbd 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/InvoiceRepository.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/InvoiceRepository.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package software.xdev.spring.data.eclipse.store.integration.shared.repositories.real.life.example; +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model; import org.springframework.data.repository.CrudRepository; diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/Position.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/Position.java similarity index 93% rename from spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/Position.java rename to spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/Position.java index b0894b12..137328a5 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/Position.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/Position.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package software.xdev.spring.data.eclipse.store.integration.shared.repositories.real.life.example; +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model; import java.util.List; import java.util.Optional; diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/PositionRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/PositionRepository.java similarity index 88% rename from spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/PositionRepository.java rename to spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/PositionRepository.java index 883c4a42..f79de823 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/PositionRepository.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/PositionRepository.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package software.xdev.spring.data.eclipse.store.integration.shared.repositories.real.life.example; +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model; import org.springframework.data.repository.ListCrudRepository; diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/Warehouse.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/Warehouse.java similarity index 91% rename from spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/Warehouse.java rename to spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/Warehouse.java index 8d5b0663..bde4b9c3 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/real/life/example/Warehouse.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/model/Warehouse.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package software.xdev.spring.data.eclipse.store.integration.shared.repositories.real.life.example; +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model; import java.util.HashSet; import java.util.Set; diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/nonlazy/InvoiceNonLazyRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/nonlazy/InvoiceNonLazyRepository.java new file mode 100644 index 00000000..983bc4b0 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/nonlazy/InvoiceNonLazyRepository.java @@ -0,0 +1,26 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.nonlazy; + +import org.springframework.data.repository.CrudRepository; + +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model.Invoice; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model.InvoiceRepository; + + +public interface InvoiceNonLazyRepository extends CrudRepository, InvoiceRepository +{ +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/nonlazy/PositionNonLazyRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/nonlazy/PositionNonLazyRepository.java new file mode 100644 index 00000000..e265effd --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/nonlazy/PositionNonLazyRepository.java @@ -0,0 +1,26 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.nonlazy; + +import org.springframework.data.repository.ListCrudRepository; + +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model.Position; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.model.PositionRepository; + + +public interface PositionNonLazyRepository extends ListCrudRepository, PositionRepository +{ +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/nonlazy/RealLifeExamplesNonLazyTest.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/nonlazy/RealLifeExamplesNonLazyTest.java new file mode 100644 index 00000000..069c2803 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/nonlazy/RealLifeExamplesNonLazyTest.java @@ -0,0 +1,37 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.nonlazy; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; + +import software.xdev.spring.data.eclipse.store.integration.isolated.IsolatedTestAnnotations; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.RealLifeExamplesTest; + + +@IsolatedTestAnnotations +@ContextConfiguration(classes = {RealLifeExamplesNonLazyTestConfiguration.class}) +class RealLifeExamplesNonLazyTest extends RealLifeExamplesTest +{ + @Autowired + public RealLifeExamplesNonLazyTest( + final InvoiceNonLazyRepository invoiceRepository, + final PositionNonLazyRepository positionRepository, + final RealLifeExamplesNonLazyTestConfiguration configuration) + { + super(invoiceRepository, positionRepository, configuration); + } +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/nonlazy/RealLifeExamplesNonLazyTestConfiguration.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/nonlazy/RealLifeExamplesNonLazyTestConfiguration.java new file mode 100644 index 00000000..747328e2 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/real/life/examples/nonlazy/RealLifeExamplesNonLazyTestConfiguration.java @@ -0,0 +1,53 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.real.life.examples.nonlazy; + +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.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.Configuration; +import org.springframework.transaction.PlatformTransactionManager; + +import software.xdev.spring.data.eclipse.store.integration.TestConfiguration; +import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; + + +@Configuration +@EnableEclipseStoreRepositories +public class RealLifeExamplesNonLazyTestConfiguration extends TestConfiguration +{ + @Autowired + protected RealLifeExamplesNonLazyTestConfiguration( + final EclipseStoreProperties defaultEclipseStoreProperties, + final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider, + final ClassLoaderProvider classLoaderProvider) + { + super(defaultEclipseStoreProperties, defaultEclipseStoreProvider, classLoaderProvider); + } + + @Bean + @Override + public PlatformTransactionManager transactionManager( + final ObjectProvider transactionManagerCustomizers + ) + { + return super.transactionManager(transactionManagerCustomizers); + } +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/tests/SimpleMultipleTest.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/SimpleMultipleTest.java similarity index 82% rename from spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/tests/SimpleMultipleTest.java rename to spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/SimpleMultipleTest.java index a9650158..7165730d 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/tests/SimpleMultipleTest.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/SimpleMultipleTest.java @@ -13,33 +13,37 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package software.xdev.spring.data.eclipse.store.integration.shared.tests; +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple; import java.util.List; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; import software.xdev.spring.data.eclipse.store.helper.TestData; import software.xdev.spring.data.eclipse.store.helper.TestUtil; -import software.xdev.spring.data.eclipse.store.integration.shared.DefaultTestAnnotations; -import software.xdev.spring.data.eclipse.store.integration.shared.SharedTestConfiguration; -import software.xdev.spring.data.eclipse.store.integration.shared.repositories.Customer; -import software.xdev.spring.data.eclipse.store.integration.shared.repositories.CustomerRepository; -import software.xdev.spring.data.eclipse.store.integration.shared.repositories.Owner; -import software.xdev.spring.data.eclipse.store.integration.shared.repositories.OwnerRepository; +import software.xdev.spring.data.eclipse.store.integration.TestConfiguration; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.Customer; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.CustomerRepository; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.Owner; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.OwnerRepository; -@DefaultTestAnnotations -class SimpleMultipleTest +public abstract class SimpleMultipleTest { - @Autowired - private CustomerRepository customerRepository; - @Autowired - private OwnerRepository ownerRepository; - @Autowired - private SharedTestConfiguration configuration; + private final CustomerRepository customerRepository; + private final OwnerRepository ownerRepository; + private final TestConfiguration configuration; + + public SimpleMultipleTest( + final CustomerRepository customerRepository, + final OwnerRepository ownerRepository, + final TestConfiguration configuration) + { + this.customerRepository = customerRepository; + this.ownerRepository = ownerRepository; + this.configuration = configuration; + } @Test void testBasicSaveAndFindAll() @@ -48,8 +52,7 @@ void testBasicSaveAndFindAll() customer = new Customer(TestData.FIRST_NAME, TestData.LAST_NAME); this.customerRepository.save(customer); - final Owner - owner = new Owner(TestData.FIRST_NAME, TestData.LAST_NAME); + final Owner owner = new Owner(TestData.FIRST_NAME, TestData.LAST_NAME); this.ownerRepository.save(owner); TestUtil.doBeforeAndAfterRestartOfDatastore( diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/tests/SimpleSingleTest.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/SimpleSingleTest.java similarity index 83% rename from spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/tests/SimpleSingleTest.java rename to spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/SimpleSingleTest.java index 7aa33866..5ddf3ee9 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/tests/SimpleSingleTest.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/SimpleSingleTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package software.xdev.spring.data.eclipse.store.integration.shared.tests; +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple; import java.util.ArrayList; import java.util.List; @@ -21,30 +21,36 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; import software.xdev.spring.data.eclipse.store.helper.TestData; import software.xdev.spring.data.eclipse.store.helper.TestUtil; -import software.xdev.spring.data.eclipse.store.integration.shared.DefaultTestAnnotations; -import software.xdev.spring.data.eclipse.store.integration.shared.SharedTestConfiguration; -import software.xdev.spring.data.eclipse.store.integration.shared.repositories.Customer; -import software.xdev.spring.data.eclipse.store.integration.shared.repositories.CustomerAsRecord; -import software.xdev.spring.data.eclipse.store.integration.shared.repositories.CustomerAsRecordRepository; -import software.xdev.spring.data.eclipse.store.integration.shared.repositories.CustomerNotCrud; -import software.xdev.spring.data.eclipse.store.integration.shared.repositories.CustomerNotCrudRepository; -import software.xdev.spring.data.eclipse.store.integration.shared.repositories.CustomerRepository; +import software.xdev.spring.data.eclipse.store.integration.TestConfiguration; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.Customer; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.CustomerAsRecord; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.CustomerAsRecordRepository; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.CustomerNotCrud; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.CustomerNotCrudRepository; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.CustomerRepository; -@DefaultTestAnnotations -class SimpleSingleTest +public abstract class SimpleSingleTest { - @Autowired - private CustomerRepository repository; - @Autowired - private CustomerAsRecordRepository recordRepository; + private final CustomerRepository repository; + private final CustomerAsRecordRepository recordRepository; + private final CustomerNotCrudRepository notCrudRepository; + private final TestConfiguration configuration; - @Autowired - private SharedTestConfiguration configuration; + public SimpleSingleTest( + final CustomerRepository repository, + final CustomerAsRecordRepository recordRepository, + final CustomerNotCrudRepository notCrudRepository, + final TestConfiguration configuration) + { + this.repository = repository; + this.recordRepository = recordRepository; + this.notCrudRepository = notCrudRepository; + this.configuration = configuration; + } @Test void testNullFindAll() @@ -74,6 +80,7 @@ void testBasicSaveAndFindSingleRecords() ); } + @SuppressWarnings("OptionalGetWithoutIsPresent") @Test void testBasicSaveAndFindMultipleRecords() { @@ -176,15 +183,15 @@ void testDoubleSaveAndFindAll() } @Test - void testBasicSaveAndFindAllWithNotCrudRepository(@Autowired final CustomerNotCrudRepository notCrudRepository) + void testBasicSaveAndFindAllWithNotCrudRepository() { final CustomerNotCrud customer = new CustomerNotCrud(TestData.FIRST_NAME, TestData.LAST_NAME); - notCrudRepository.save(customer); + this.notCrudRepository.save(customer); TestUtil.doBeforeAndAfterRestartOfDatastore( this.configuration, () -> { - final List customers = TestUtil.iterableToList(notCrudRepository.findAll()); + final List customers = TestUtil.iterableToList(this.notCrudRepository.findAll()); Assertions.assertEquals(1, customers.size()); Assertions.assertEquals(customer, customers.get(0)); } diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/CustomerAsRecordLazyRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/CustomerAsRecordLazyRepository.java new file mode 100644 index 00000000..74cc9869 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/CustomerAsRecordLazyRepository.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.lazy; + +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.CustomerAsRecord; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.CustomerAsRecordRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreCrudRepository; + + +public interface CustomerAsRecordLazyRepository + extends LazyEclipseStoreCrudRepository, CustomerAsRecordRepository +{ +} + diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/CustomerLazyRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/CustomerLazyRepository.java new file mode 100644 index 00000000..1e4f230e --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/CustomerLazyRepository.java @@ -0,0 +1,29 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.lazy; + +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.Customer; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.CustomerRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreCrudRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStorePagingAndSortingRepository; + + +public interface CustomerLazyRepository + extends LazyEclipseStoreCrudRepository, + LazyEclipseStorePagingAndSortingRepository, + CustomerRepository +{ +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/CustomerNotCrudLazyRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/CustomerNotCrudLazyRepository.java new file mode 100644 index 00000000..98d4d9bd --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/CustomerNotCrudLazyRepository.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.lazy; + +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.CustomerNotCrud; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.CustomerNotCrudRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreRepository; + + +public interface CustomerNotCrudLazyRepository + extends LazyEclipseStoreRepository, CustomerNotCrudRepository +{ +} + diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/LazySimpleMultipleTest.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/LazySimpleMultipleTest.java new file mode 100644 index 00000000..2f593df9 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/LazySimpleMultipleTest.java @@ -0,0 +1,37 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.lazy; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; + +import software.xdev.spring.data.eclipse.store.integration.isolated.IsolatedTestAnnotations; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.SimpleMultipleTest; + + +@IsolatedTestAnnotations +@ContextConfiguration(classes = {SimpleLazyTestConfiguration.class}) +public class LazySimpleMultipleTest extends SimpleMultipleTest +{ + @Autowired + public LazySimpleMultipleTest( + final CustomerLazyRepository customerRepository, + final OwnerLazyRepository ownerRepository, + final SimpleLazyTestConfiguration configuration) + { + super(customerRepository, ownerRepository, configuration); + } +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/LazySimpleSingleTest.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/LazySimpleSingleTest.java new file mode 100644 index 00000000..f849bfb3 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/LazySimpleSingleTest.java @@ -0,0 +1,38 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.lazy; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; + +import software.xdev.spring.data.eclipse.store.integration.isolated.IsolatedTestAnnotations; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.SimpleSingleTest; + + +@IsolatedTestAnnotations +@ContextConfiguration(classes = {SimpleLazyTestConfiguration.class}) +public class LazySimpleSingleTest extends SimpleSingleTest +{ + @Autowired + public LazySimpleSingleTest( + final CustomerLazyRepository repository, + final CustomerAsRecordLazyRepository recordRepository, + final CustomerNotCrudLazyRepository notCrudRepository, + final SimpleLazyTestConfiguration configuration) + { + super(repository, recordRepository, notCrudRepository, configuration); + } +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/OwnerLazyRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/OwnerLazyRepository.java new file mode 100644 index 00000000..da58e2b1 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/OwnerLazyRepository.java @@ -0,0 +1,25 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.lazy; + +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.Owner; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.OwnerRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreCrudRepository; + + +public interface OwnerLazyRepository extends LazyEclipseStoreCrudRepository, OwnerRepository +{ +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/SimpleLazyTestConfiguration.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/SimpleLazyTestConfiguration.java new file mode 100644 index 00000000..ed62d6b3 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/lazy/SimpleLazyTestConfiguration.java @@ -0,0 +1,40 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.lazy; + +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.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; + +import software.xdev.spring.data.eclipse.store.integration.TestConfiguration; +import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; + + +@Configuration +@EnableEclipseStoreRepositories +public class SimpleLazyTestConfiguration extends TestConfiguration +{ + @Autowired + protected SimpleLazyTestConfiguration( + final EclipseStoreProperties defaultEclipseStoreProperties, + final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider, + final ClassLoaderProvider classLoaderProvider) + { + super(defaultEclipseStoreProperties, defaultEclipseStoreProvider, classLoaderProvider); + } +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/CustomerWithChild.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/Customer.java similarity index 76% rename from spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/CustomerWithChild.java rename to spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/Customer.java index 07f1ca9d..097d4766 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/CustomerWithChild.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/Customer.java @@ -13,24 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package software.xdev.spring.data.eclipse.store.integration.shared.repositories; +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model; import java.util.List; import java.util.Objects; -public class CustomerWithChild +public class Customer { private String firstName; private String lastName; - private Child child; - - public CustomerWithChild(final String firstName, final String lastName, final Child child) + public Customer(final String firstName, final String lastName) { this.firstName = firstName; this.lastName = lastName; - this.child = child; } public String getFirstName() @@ -53,16 +50,6 @@ public void setLastName(final String lastName) this.lastName = lastName; } - public Child getChild() - { - return this.child; - } - - public void setChild(final Child child) - { - this.child = child; - } - @Override public String toString() { @@ -82,7 +69,7 @@ public boolean equals(final Object o) { return false; } - final CustomerWithChild customer = (CustomerWithChild)o; + final Customer customer = (Customer)o; return Objects.equals(this.firstName, customer.firstName) && Objects.equals( this.lastName, customer.lastName); @@ -95,9 +82,7 @@ public int hashCode() } @SuppressWarnings("OptionalGetWithoutIsPresent") - public static CustomerWithChild getCustomerWithFirstName( - final List customers, - final String firstName) + public static Customer getCustomerWithFirstName(final List customers, final String firstName) { return customers.stream().filter(customer -> customer.getFirstName().equals(firstName)).findFirst().get(); } diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/CustomerAsRecord.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/CustomerAsRecord.java similarity index 91% rename from spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/CustomerAsRecord.java rename to spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/CustomerAsRecord.java index ab242afa..02aef14c 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/CustomerAsRecord.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/CustomerAsRecord.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package software.xdev.spring.data.eclipse.store.integration.shared.repositories; +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model; import java.util.List; diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/CustomerAsRecordRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/CustomerAsRecordRepository.java similarity index 90% rename from spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/CustomerAsRecordRepository.java rename to spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/CustomerAsRecordRepository.java index 8119fc23..fbdbcacd 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/CustomerAsRecordRepository.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/CustomerAsRecordRepository.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package software.xdev.spring.data.eclipse.store.integration.shared.repositories; +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model; import java.util.Optional; diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/CustomerNotCrud.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/CustomerNotCrud.java similarity index 94% rename from spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/CustomerNotCrud.java rename to spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/CustomerNotCrud.java index 00835cdc..c31e9f13 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/CustomerNotCrud.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/CustomerNotCrud.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package software.xdev.spring.data.eclipse.store.integration.shared.repositories; +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model; import java.util.Objects; diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/CustomerNotCrudRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/CustomerNotCrudRepository.java similarity index 85% rename from spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/CustomerNotCrudRepository.java rename to spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/CustomerNotCrudRepository.java index 29e21eb9..cbfb939b 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/CustomerNotCrudRepository.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/CustomerNotCrudRepository.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package software.xdev.spring.data.eclipse.store.integration.shared.repositories; +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model; import java.util.List; @@ -24,5 +24,5 @@ public interface CustomerNotCrudRepository extends Repository findAll(); - void save(CustomerNotCrud customer); + CustomerNotCrud save(CustomerNotCrud customer); } diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/CustomerRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/CustomerRepository.java new file mode 100644 index 00000000..23796129 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/CustomerRepository.java @@ -0,0 +1,33 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model; + +import java.util.Optional; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.PagingAndSortingRepository; + + +public interface CustomerRepository + extends CrudRepository, PagingAndSortingRepository +{ + Optional findByFirstName(String firstName); + + @Override + Page findAll(Pageable pageable); +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/Owner.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/Owner.java similarity index 95% rename from spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/Owner.java rename to spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/Owner.java index 43ac8d71..cd5c263b 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/Owner.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/Owner.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package software.xdev.spring.data.eclipse.store.integration.shared.repositories; +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model; import java.util.List; import java.util.Objects; diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/OwnerRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/OwnerRepository.java similarity index 89% rename from spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/OwnerRepository.java rename to spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/OwnerRepository.java index 72a47207..32e0af06 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/OwnerRepository.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/OwnerRepository.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package software.xdev.spring.data.eclipse.store.integration.shared.repositories; +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model; import org.springframework.data.repository.CrudRepository; diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/Child.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/ParentCustomer.java similarity index 72% rename from spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/Child.java rename to spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/ParentCustomer.java index 64521977..7970108c 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/Child.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/model/ParentCustomer.java @@ -13,17 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package software.xdev.spring.data.eclipse.store.integration.shared.repositories; +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model; +import java.util.List; import java.util.Objects; -public class Child +public class ParentCustomer { private String firstName; private String lastName; - public Child(final String firstName, final String lastName) + public ParentCustomer(final String firstName, final String lastName) { this.firstName = firstName; this.lastName = lastName; @@ -53,7 +54,7 @@ public void setLastName(final String lastName) public String toString() { return String.format( - "Child[firstName='%s', lastName='%s']", + "Customer[firstName='%s', lastName='%s']", this.firstName, this.lastName); } @@ -68,7 +69,7 @@ public boolean equals(final Object o) { return false; } - final Child customer = (Child)o; + final ParentCustomer customer = (ParentCustomer)o; return Objects.equals(this.firstName, customer.firstName) && Objects.equals( this.lastName, customer.lastName); @@ -79,4 +80,10 @@ public int hashCode() { return Objects.hash(this.firstName, this.lastName); } + + @SuppressWarnings("OptionalGetWithoutIsPresent") + public static ParentCustomer getCustomerWithFirstName(final List customers, final String firstName) + { + return customers.stream().filter(customer -> customer.getFirstName().equals(firstName)).findFirst().get(); + } } diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/CustomerAsRecordNonLazyRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/CustomerAsRecordNonLazyRepository.java new file mode 100644 index 00000000..df4ffff6 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/CustomerAsRecordNonLazyRepository.java @@ -0,0 +1,26 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.nonlazy; + +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.CustomerAsRecord; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.CustomerAsRecordRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreCrudRepository; + + +public interface CustomerAsRecordNonLazyRepository + extends EclipseStoreCrudRepository, CustomerAsRecordRepository +{ +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/CustomerNonLazyRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/CustomerNonLazyRepository.java new file mode 100644 index 00000000..ebb344b5 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/CustomerNonLazyRepository.java @@ -0,0 +1,29 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.nonlazy; + +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.Customer; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.CustomerRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreCrudRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStorePagingAndSortingRepository; + + +public interface CustomerNonLazyRepository + extends EclipseStoreCrudRepository, + EclipseStorePagingAndSortingRepository, + CustomerRepository +{ +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/CustomerNotCrudNonLazyRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/CustomerNotCrudNonLazyRepository.java new file mode 100644 index 00000000..cded5984 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/CustomerNotCrudNonLazyRepository.java @@ -0,0 +1,26 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.nonlazy; + +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.CustomerNotCrud; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.CustomerNotCrudRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreRepository; + + +public interface CustomerNotCrudNonLazyRepository + extends EclipseStoreRepository, CustomerNotCrudRepository +{ +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/NonLazySimpleMultipleTest.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/NonLazySimpleMultipleTest.java new file mode 100644 index 00000000..084fe2e3 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/NonLazySimpleMultipleTest.java @@ -0,0 +1,37 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.nonlazy; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; + +import software.xdev.spring.data.eclipse.store.integration.isolated.IsolatedTestAnnotations; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.SimpleMultipleTest; + + +@IsolatedTestAnnotations +@ContextConfiguration(classes = {SimpleNonLazyTestConfiguration.class}) +public class NonLazySimpleMultipleTest extends SimpleMultipleTest +{ + @Autowired + public NonLazySimpleMultipleTest( + final CustomerNonLazyRepository customerRepository, + final OwnerNonLazyRepository ownerRepository, + final SimpleNonLazyTestConfiguration configuration) + { + super(customerRepository, ownerRepository, configuration); + } +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/NonLazySimpleSingleTest.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/NonLazySimpleSingleTest.java new file mode 100644 index 00000000..65451986 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/NonLazySimpleSingleTest.java @@ -0,0 +1,38 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.nonlazy; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; + +import software.xdev.spring.data.eclipse.store.integration.isolated.IsolatedTestAnnotations; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.SimpleSingleTest; + + +@IsolatedTestAnnotations +@ContextConfiguration(classes = {SimpleNonLazyTestConfiguration.class}) +public class NonLazySimpleSingleTest extends SimpleSingleTest +{ + @Autowired + public NonLazySimpleSingleTest( + final CustomerNonLazyRepository repository, + final CustomerAsRecordNonLazyRepository recordRepository, + final CustomerNotCrudNonLazyRepository notCrudRepository, + final SimpleNonLazyTestConfiguration configuration) + { + super(repository, recordRepository, notCrudRepository, configuration); + } +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/OwnerNonLazyRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/OwnerNonLazyRepository.java new file mode 100644 index 00000000..6ab35324 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/OwnerNonLazyRepository.java @@ -0,0 +1,25 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.nonlazy; + +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.Owner; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.model.OwnerRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreCrudRepository; + + +public interface OwnerNonLazyRepository extends EclipseStoreCrudRepository, OwnerRepository +{ +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/SimpleNonLazyTestConfiguration.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/SimpleNonLazyTestConfiguration.java new file mode 100644 index 00000000..32207e9c --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/simple/nonlazy/SimpleNonLazyTestConfiguration.java @@ -0,0 +1,40 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.simple.nonlazy; + +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.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; + +import software.xdev.spring.data.eclipse.store.integration.TestConfiguration; +import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; + + +@Configuration +@EnableEclipseStoreRepositories +public class SimpleNonLazyTestConfiguration extends TestConfiguration +{ + @Autowired + protected SimpleNonLazyTestConfiguration( + final EclipseStoreProperties defaultEclipseStoreProperties, + final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider, + final ClassLoaderProvider classLoaderProvider) + { + super(defaultEclipseStoreProperties, defaultEclipseStoreProvider, classLoaderProvider); + } +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/interfaces/CustomerEclipseStoreListPagingAndSortingRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/interfaces/CustomerEclipseStoreListPagingAndSortingRepository.java index 575042ad..abb641ef 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/interfaces/CustomerEclipseStoreListPagingAndSortingRepository.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/interfaces/CustomerEclipseStoreListPagingAndSortingRepository.java @@ -15,10 +15,10 @@ */ package software.xdev.spring.data.eclipse.store.integration.shared.repositories.interfaces; -import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreListPagingAndSortingRepositoryRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreListPagingAndSortingRepository; public interface CustomerEclipseStoreListPagingAndSortingRepository extends - EclipseStoreListPagingAndSortingRepositoryRepository + EclipseStoreListPagingAndSortingRepository { } diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/interfaces/CustomerEclipseStorePagingAndSortingRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/interfaces/CustomerEclipseStorePagingAndSortingRepository.java index 53710546..6914d987 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/interfaces/CustomerEclipseStorePagingAndSortingRepository.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/repositories/interfaces/CustomerEclipseStorePagingAndSortingRepository.java @@ -15,10 +15,10 @@ */ package software.xdev.spring.data.eclipse.store.integration.shared.repositories.interfaces; -import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStorePagingAndSortingRepositoryRepository; +import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStorePagingAndSortingRepository; public interface CustomerEclipseStorePagingAndSortingRepository - extends EclipseStorePagingAndSortingRepositoryRepository + extends EclipseStorePagingAndSortingRepository { }