Skip to content

Commit 170e35a

Browse files
authored
Merge pull request #65 from xdev-software/lazy
Lazy
2 parents 8eaab25 + 5786404 commit 170e35a

File tree

253 files changed

+2408
-381
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

253 files changed

+2408
-381
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# 1.0.4
22

33
* Added possibility to use multiple storages
4+
* Added Lazy support
5+
* Updated EclipseStore to version 1.3.1
46

57
# 1.0.3
68

docs/modules/ROOT/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
* xref:installation.adoc[Installation]
33
* xref:configuration.adoc[Configuration]
44
* xref:working-copies.adoc[Working Copies]
5+
* xref:lazies.adoc[Lazy References]
56
* xref:migration.adoc[Migration]
67
* xref:known-issues.adoc[Known issues]

docs/modules/ROOT/pages/known-issues.adoc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
= Known issues
22

3-
== Lazy references
4-
5-
One of the core features of EclipseStore is its https://docs.eclipsestore.io/manual/storage/loading-data/lazy-loading/index.html[Lazy references].
6-
Unfortunately this requires our library to implement some kind of proxy.
7-
That's something that takes a lot of effort to implement in our {product-name}.
8-
9-
We created https://github.com/xdev-software/spring-data-eclipse-store/issues/31[an issue] for that but right now we *do not support Lazy references*.
10-
113
== Query annotations
124

135
In Spring-Data-JPA you can write a Query over methods of repositories like this:

docs/modules/ROOT/pages/lazies.adoc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
= Lazy References
2+
3+
Lazy Loading is an essential part of EclipseStore.
4+
The basic mechanism is best explained in the https://docs.eclipsestore.io/manual/storage/loading-data/lazy-loading/index.html[EclipseStore-Docs]. +
5+
In essence java objects which are wrapped in a *Lazy-Reference are not loaded with the startup of the EclipseStore-Storage but only if ``get()`` is called* on them.
6+
7+
Lazy References are essential for big data sets that can't get loaded into memory.
8+
Since {product-name} operates with xref:working-copies.adoc[working copies] using the EclipseStore-Lazy-References is not possible. +
9+
If you are using the EclipseStore-Lazy-References, all references would be resolved and loaded into memory as soon as a working copy is created, because the ``get()``-Method is called to create a full working copy.
10+
11+
That's why we implemented ``SpringDataEclipseStoreLazy``. +
12+
The usage is the same as with the EclipseStore-Lazies, but they are handled very differently.
13+
14+
Simply wrap any kind of java object in the SpringDataEclipseStoreLazy-Wrapper and the wrapped object has a lazy loading behaviour.
15+
16+
CAUTION: Lazy-References are not only loaded when needed, but also https://docs.eclipsestore.io/manual/storage/loading-data/lazy-loading/clearing-lazy-references.html#automatically[*cleared when they are no longer needed*]!
17+
18+
Example: ``SpringDataEclipseStoreLazy.build(new HashMap<String, Pet>())``
19+
20+
[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/complex/owner/Owner.java[Example from complex demo]"]
21+
----
22+
package software.xdev.spring.data.eclipse.store.demo.complex.owner;
23+
//...
24+
import software.xdev.spring.data.eclipse.store.repository.lazy.SpringDataEclipseStoreLazy;
25+
26+
public class Owner extends Person
27+
{
28+
private String address;
29+
30+
private Lazy<List<Pet>> pets = SpringDataEclipseStoreLazy.build(new ArrayList<>());
31+
//...
32+
----
33+
34+
== Internas
35+
36+
SpringDataEclipseStoreLazies work as a proxy for the EclipseStore-Lazies.
37+
As far as EclipseStore is concerned, a SpringDataEclipseStoreLazy-Object is a normal Java object that contains a Lazy-Reference.
38+
39+
But when {product-name} creates the working copy, *the SpringDataEclipseStoreLazy-Reference is not resolved* but instead only a reference to the original Lazy-Object in EclipseStore is loaded.
40+
As soon as ``get()`` is called on the SpringDataEclipseStoreLazy, a *new working copy of the lazy object* is created.

spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/complex/ComplexDemoApplication.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ public void run(final String... args)
103103
);
104104
}
105105
);
106+
107+
LOG.info("----Owner-Lazy Pet loading----");
108+
this.ownerRepository.findAll().forEach(
109+
o -> o.getPets().forEach(
110+
pet -> LOG.info(String.format(
111+
"Pet %s has owner %s %s",
112+
pet.getName(),
113+
o.getFirstName(),
114+
o.getLastName()))
115+
)
116+
);
106117
}
107118

108119
private static Visit createVisit()

spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/complex/owner/Owner.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
import java.util.List;
2020
import java.util.Optional;
2121

22+
import org.eclipse.serializer.reference.Lazy;
2223
import org.springframework.core.style.ToStringCreator;
2324
import org.springframework.util.Assert;
2425

2526
import software.xdev.spring.data.eclipse.store.demo.complex.model.Person;
27+
import software.xdev.spring.data.eclipse.store.repository.lazy.SpringDataEclipseStoreLazy;
2628

2729

2830
public class Owner extends Person
@@ -33,7 +35,7 @@ public class Owner extends Person
3335

3436
private String telephone;
3537

36-
private final List<Pet> pets = new ArrayList<>();
38+
private Lazy<List<Pet>> pets = SpringDataEclipseStoreLazy.build(new ArrayList<>());
3739

3840
public String getAddress()
3941
{
@@ -52,7 +54,12 @@ public String getTelephone()
5254

5355
public List<Pet> getPets()
5456
{
55-
return this.pets;
57+
return this.pets.get();
58+
}
59+
60+
public void setPets(final List<Pet> pets)
61+
{
62+
this.pets = SpringDataEclipseStoreLazy.build(pets);
5663
}
5764

5865
public void addPet(final Pet pet)

spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/complex/owner/OwnerRepository.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package software.xdev.spring.data.eclipse.store.demo.complex.owner;
1717

18+
import java.util.List;
19+
1820
import org.springframework.data.domain.Page;
1921
import org.springframework.data.domain.Pageable;
2022
import org.springframework.data.repository.Repository;
@@ -28,5 +30,7 @@ public interface OwnerRepository extends Repository<Owner, Integer>
2830

2931
Page<Owner> findAll(Pageable pageable);
3032

33+
List<Owner> findAll();
34+
3135
void deleteAll();
3236
}

spring-data-eclipse-store-jpa/src/test/java/software/xdev/spring/data/eclipse/store/jpa/integration/repository/PersonToTestInEclipseStoreRepository.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreListCrudRepository;
44

55

6-
public interface PersonToTestInEclipseStoreRepository extends EclipseStoreListCrudRepository<PersonToTestInEclipseStore, String>
6+
public interface PersonToTestInEclipseStoreRepository
7+
extends EclipseStoreListCrudRepository<PersonToTestInEclipseStore, String>
78
{
89
}

spring-data-eclipse-store/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@
214214
<configuration>
215215
<properties>
216216
<email>${project.organization.url}</email>
217+
<year>2024</year>
217218
</properties>
218219
<licenseSets>
219220
<licenseSet>

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/aot/EclipseStoreRuntimeHints.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/core/IdentitySet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/AlreadyRegisteredException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/DataTypeNotSupportedException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/DifferentClassesException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/FieldAccessReflectionException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/IdFieldFinalException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/IdGeneratorNotSupportedException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.spring.data.eclipse.store.exceptions;
17+
18+
/**
19+
* Is used when a {@link software.xdev.spring.data.eclipse.store.repository.lazy.SpringDataEclipseStoreLazy} is not able
20+
* to get unlinked from the object tree.
21+
* <p>
22+
* This exception should not be created by the user, but only within the Spring-Data-Eclipse-Store-Library.
23+
* </p>
24+
*/
25+
public class LazyNotUnlinkableException extends RuntimeException
26+
{
27+
public LazyNotUnlinkableException(final String message, final Throwable e)
28+
{
29+
super(message, e);
30+
}
31+
}

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/MergeFailedException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/NoIdFieldFoundException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/NoPageableObjectFoundException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/NotComparableException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/StringBlankException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/importer/EclipseStoreDataImporter.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -205,8 +205,11 @@ private <T> void createRepositoryForType(
205205
storageInstance.getRegistry(),
206206
storageInstance,
207207
storageInstance,
208-
new SupportedChecker.Implementation()),
209-
domainClass);
208+
new SupportedChecker.Implementation(),
209+
storageInstance
210+
),
211+
domainClass
212+
);
210213
}
211214

212215
private record EntityManagerFactoryRepositoryListPair(

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/importer/EclipseStoreDataImporterComponent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -56,6 +56,7 @@ public EclipseStoreDataImporterComponent(
5656
*
5757
* @return all the newly created {@link SimpleEclipseStoreRepository} for the specific entities.
5858
*/
59+
@SuppressWarnings("java:S1452")
5960
public List<SimpleEclipseStoreRepository<?, ?>> importData()
6061
{
6162
final Map<String, EntityManagerFactory> beansOfEms =

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EclipseStoreStorage.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,6 +26,8 @@
2626
import org.eclipse.serializer.persistence.binary.jdk17.java.util.BinaryHandlerImmutableCollectionsList12;
2727
import org.eclipse.serializer.persistence.binary.jdk17.java.util.BinaryHandlerImmutableCollectionsSet12;
2828
import org.eclipse.serializer.persistence.types.Storer;
29+
import org.eclipse.serializer.reference.LazyReferenceManager;
30+
import org.eclipse.serializer.reference.ObjectSwizzling;
2931
import org.eclipse.store.storage.embedded.types.EmbeddedStorageFoundation;
3032
import org.eclipse.store.storage.types.StorageManager;
3133
import org.slf4j.Logger;
@@ -40,7 +42,7 @@
4042
import software.xdev.spring.data.eclipse.store.repository.support.reposyncer.SimpleRepositorySynchronizer;
4143

4244
public class EclipseStoreStorage
43-
implements EntityListProvider, IdSetterProvider, PersistableChecker
45+
implements EntityListProvider, IdSetterProvider, PersistableChecker, ObjectSwizzling
4446
{
4547
private static final Logger LOG = LoggerFactory.getLogger(EclipseStoreStorage.class);
4648
private final Map<Class<?>, String> entityClassToRepositoryName = new HashMap<>();
@@ -272,6 +274,7 @@ public synchronized void stop()
272274
this.registry.reset();
273275
this.entityClassToIdSetter.clear();
274276
LOG.info("Stopped storage.");
277+
LazyReferenceManager.get().stop();
275278
}
276279
else
277280
{
@@ -311,4 +314,11 @@ public boolean isPersistable(final Class<?> clazz)
311314
this.ensureEntitiesInRoot();
312315
return this.persistenceChecker.isPersistable(clazz);
313316
}
317+
318+
@Override
319+
public Object getObject(final long objectId)
320+
{
321+
this.ensureEntitiesInRoot();
322+
return this.storageManager.getObject(objectId);
323+
}
314324
}

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EntityListProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EntitySetCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/IdSetterProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/PersistableChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/Query.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2023 XDEV Software (https://xdev.software)
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)