Skip to content

Commit 4121076

Browse files
Merge pull request #75 from xdev-software/develop
v1.0.5
2 parents 18ccbaf + 15bf717 commit 4121076

File tree

56 files changed

+1858
-317
lines changed

Some content is hidden

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

56 files changed

+1858
-317
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ instructions** are in the documentation](https://xdev-software.github.io/spring-
5151
| Spring-Data-Eclipse-Store | Java | Spring Data | EclipseStore |
5252
|---------------------------|--------|-------------|--------------|
5353
| ``<= 1.0.2`` | ``17`` | ``3.2.2`` | ``1.1.0`` |
54-
| ``>= 1.0.3`` | ``17`` | ``3.2.3`` | ``1.2.0`` |
54+
| ``1.0.3/1.0.4`` | ``17`` | ``3.2.3`` | ``1.2.0`` |
55+
| ``>= 1.0.5`` | ``17`` | ``3.2.5`` | ``1.3.2`` |
5556

5657
## Demo
5758

docs/antora.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
name: ROOT
22
title: Spring-Data-Eclipse-Store
33
version: master
4-
display_version: '1.0.3'
4+
display_version: '1.0.5'
55
start_page: index.adoc
66
nav:
77
- modules/ROOT/nav.adoc
88
asciidoc:
99
attributes:
1010
product-name: 'Spring-Data-Eclipse-Store'
11-
display-version: '1.0.3'
12-
maven-version: '1.0.3'
11+
display-version: '1.0.5'
12+
maven-version: '1.0.5'
1313
page-editable: false
1414
page-out-of-support: false

docs/modules/ROOT/nav.adoc

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

docs/modules/ROOT/pages/configuration.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import org.eclipse.store.storage.embedded.types.EmbeddedStorageFoundation;
1515
import org.eclipse.store.storage.types.Storage;
1616
...
1717
@Configuration
18-
@EnableEclipseStoreRepositories(clientConfigurationClass = DemoConfiguration.class)
18+
@EnableEclipseStoreRepositories
1919
public class DemoConfiguration extends EclipseStoreClientConfiguration
2020
{
2121
@Override

docs/modules/ROOT/pages/installation.adoc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ Also see the https://github.com/xdev-software/spring-data-eclipse-store/releases
2323

2424
After adding the library in your dependencies, using it is as easy as adding the ``@EnableEclipseStoreRepositories`` annotation to your ``@SpringBootApplication`` annotation.
2525

26-
[NOTE]
27-
====
28-
Since the library is using reflection to copy data, the following JVM-Arguments may have to be set.
26+
=== Merge behavior
27+
28+
To merge data of the xref:working-copies.adoc[working copy] into the original object graph, the library is using reflection.
29+
Therefore, the following *JVM-Arguments* may have to be set:
2930

3031
[source,title="JVM Arguments"]
3132
----
@@ -34,6 +35,11 @@ Since the library is using reflection to copy data, the following JVM-Arguments
3435
--add-opens=java.base/java.lang=ALL-UNNAMED
3536
--add-opens=java.base/java.time=ALL-UNNAMED
3637
----
38+
39+
[NOTE]
40+
====
41+
To access ``private`` variables, the library uses reflection and sets the access level to ``public`` (see https://github.com/xdev-software/spring-data-eclipse-store/blob/develop/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/access/modifier/FieldAccessibleMaker.java[FieldAccessibleMaker]).
42+
For performance reasons, *this change stays permanent* during runtime.
3743
====
3844

3945
== Demo

docs/modules/ROOT/pages/lazies.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class Owner extends Person
3131
//...
3232
----
3333

34-
== Internas
34+
== Internals
3535

3636
SpringDataEclipseStoreLazies work as a proxy for the EclipseStore-Lazies.
3737
As far as EclipseStore is concerned, a SpringDataEclipseStoreLazy-Object is a normal Java object that contains a Lazy-Reference.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
= Transactions
2+
3+
[quote,https://docs.spring.io/spring-framework/reference/data-access/transaction.html[spring - Transaction Management]]
4+
5+
____
6+
Comprehensive transaction support is among the *most compelling reasons* to use the Spring Framework.
7+
____
8+
9+
That's why we implemented *Spring Transactions*.
10+
11+
Just like Spring JPA you can use https://docs.spring.io/spring-framework/reference/data-access/transaction/declarative.html[declarative] or https://docs.spring.io/spring-framework/reference/data-access/transaction/programmatic.html[programmatic] transaction management.
12+
13+
[source,java,title="https://github.com/xdev-software/spring-data-eclipse-store/blob/develop/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/complex/VetService.java[Declarative example from complex demo]"]
14+
----
15+
import org.springframework.stereotype.Service;
16+
import org.springframework.transaction.annotation.Transactional;
17+
//...
18+
@Service
19+
@Transactional
20+
public class VetService
21+
{
22+
//...
23+
public void saveNewEntries()
24+
{
25+
final Vet vet = this.createVet();
26+
this.vetRepository.save(vet);
27+
}
28+
//...
29+
----
30+
31+
[source,java,title="https://github.com/xdev-software/spring-data-eclipse-store/blob/develop/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/complex/OwnerService.java[Programmatic example from complex demo]"]
32+
----
33+
import org.springframework.stereotype.Service;
34+
import org.springframework.transaction.PlatformTransactionManager;
35+
//...
36+
@Service
37+
public class OwnerService
38+
{
39+
private final PlatformTransactionManager transactionManager;
40+
41+
@Autowired
42+
public OwnerService(
43+
final OwnerRepository ownerRepository,
44+
final PlatformTransactionManager transactionManager)
45+
{
46+
this.ownerRepository = ownerRepository;
47+
this.transactionManager = transactionManager;
48+
}
49+
//...
50+
public void deleteAll()
51+
{
52+
new TransactionTemplate(this.transactionManager).execute(
53+
status ->
54+
{
55+
this.ownerRepository.deleteAll();
56+
return null;
57+
});
58+
}
59+
//...
60+
----
61+
62+
CAUTION: If you are using transaction, you need to define a ``Bean`` for ``PlatformTransactionManager``! This is easiest achieved by extending the ``EclipseStoreClientConfiguration``. See https://github.com/xdev-software/spring-data-eclipse-store/blob/develop/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/complex/ComplexConfiguration.java[the complex demo].

spring-data-eclipse-store-benchmark/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2121
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2222

23-
<org.springframework.boot.version>3.2.3</org.springframework.boot.version>
23+
<org.springframework.boot.version>3.2.5</org.springframework.boot.version>
2424
<jmh.version>1.37</jmh.version>
2525
</properties>
2626

spring-data-eclipse-store-demo/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

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

26-
<org.springframework.boot.version>3.2.3</org.springframework.boot.version>
26+
<org.springframework.boot.version>3.2.5</org.springframework.boot.version>
2727
</properties>
2828

2929
<dependencyManagement>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package software.xdev.spring.data.eclipse.store.demo.complex;
2+
3+
import org.eclipse.store.integrations.spring.boot.types.configuration.EclipseStoreProperties;
4+
import org.eclipse.store.integrations.spring.boot.types.factories.EmbeddedStorageFoundationFactory;
5+
import org.springframework.beans.factory.ObjectProvider;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
import org.springframework.transaction.PlatformTransactionManager;
11+
12+
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;
13+
import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories;
14+
15+
16+
@Configuration
17+
@EnableEclipseStoreRepositories
18+
public class ComplexConfiguration extends EclipseStoreClientConfiguration
19+
{
20+
@Autowired
21+
public ComplexConfiguration(
22+
final EclipseStoreProperties defaultEclipseStoreProperties,
23+
final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider
24+
)
25+
{
26+
super(defaultEclipseStoreProperties, defaultEclipseStoreProvider);
27+
}
28+
29+
/**
30+
* Overriding {@link #transactionManager(ObjectProvider)} only to add the {@link Bean}-Annotation.
31+
*/
32+
@Bean
33+
@Override
34+
public PlatformTransactionManager transactionManager(
35+
final ObjectProvider<TransactionManagerCustomizers> transactionManagerCustomizers
36+
)
37+
{
38+
return super.transactionManager(transactionManagerCustomizers);
39+
}
40+
}

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

Lines changed: 30 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,27 @@
1616

1717
package software.xdev.spring.data.eclipse.store.demo.complex;
1818

19-
import java.time.LocalDate;
20-
21-
import org.slf4j.Logger;
22-
import org.slf4j.LoggerFactory;
19+
import org.springframework.beans.factory.annotation.Autowired;
2320
import org.springframework.boot.CommandLineRunner;
2421
import org.springframework.boot.SpringApplication;
2522
import org.springframework.boot.autoconfigure.SpringBootApplication;
2623
import org.springframework.context.ConfigurableApplicationContext;
27-
import org.springframework.data.domain.Pageable;
28-
29-
import software.xdev.spring.data.eclipse.store.demo.complex.owner.Owner;
30-
import software.xdev.spring.data.eclipse.store.demo.complex.owner.OwnerRepository;
31-
import software.xdev.spring.data.eclipse.store.demo.complex.owner.Pet;
32-
import software.xdev.spring.data.eclipse.store.demo.complex.owner.PetType;
33-
import software.xdev.spring.data.eclipse.store.demo.complex.owner.Visit;
34-
import software.xdev.spring.data.eclipse.store.demo.complex.vet.Specialty;
35-
import software.xdev.spring.data.eclipse.store.demo.complex.vet.Vet;
36-
import software.xdev.spring.data.eclipse.store.demo.complex.vet.VetRepository;
37-
import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories;
3824

3925

4026
@SpringBootApplication
41-
@EnableEclipseStoreRepositories
4227
public class ComplexDemoApplication implements CommandLineRunner
4328
{
44-
private static final Logger LOG = LoggerFactory.getLogger(ComplexDemoApplication.class);
45-
private final OwnerRepository ownerRepository;
46-
private final VetRepository vetRepository;
29+
private final OwnerService ownerService;
30+
private final VetService vetService;
4731

48-
public ComplexDemoApplication(final OwnerRepository ownerRepository, final VetRepository vetRepository)
32+
@Autowired
33+
public ComplexDemoApplication(
34+
final OwnerService ownerService,
35+
final VetService vetService
36+
)
4937
{
50-
this.ownerRepository = ownerRepository;
51-
this.vetRepository = vetRepository;
38+
this.ownerService = ownerService;
39+
this.vetService = vetService;
5240
}
5341

5442
public static void main(final String[] args)
@@ -60,94 +48,31 @@ public static void main(final String[] args)
6048
@Override
6149
public void run(final String... args)
6250
{
63-
LOG.info("----Vets-BeforeDeleteAll----");
64-
this.vetRepository.findAll().forEach(i -> LOG.info(i.toString()));
65-
this.vetRepository.deleteAll();
66-
67-
LOG.info("----Vets-AfterDeleteAll----");
68-
this.vetRepository.findAll().forEach(i -> LOG.info(i.toString()));
69-
70-
final Vet vet = createVet();
71-
this.vetRepository.save(vet);
72-
73-
LOG.info("----Vets-AfterSave----");
74-
this.vetRepository.findAll().forEach(i -> LOG.info(i.toString()));
75-
76-
LOG.info("----Owner-BeforeDeleteAll----");
77-
this.ownerRepository.findAll(Pageable.unpaged()).forEach(i -> LOG.info(i.toString()));
78-
this.ownerRepository.deleteAll();
79-
80-
LOG.info("----Owner-AfterDeleteAll----");
81-
this.ownerRepository.findAll(Pageable.unpaged()).forEach(i -> LOG.info(i.toString()));
82-
83-
final Owner owner = createOwner();
84-
this.ownerRepository.save(owner);
85-
86-
LOG.info("----Owner-AfterSave----");
87-
this.ownerRepository.findAll(Pageable.unpaged()).forEach(i -> LOG.info(i.toString()));
88-
89-
final Visit visit = createVisit();
90-
owner.addVisit("Peter", visit);
91-
this.ownerRepository.save(owner);
92-
93-
LOG.info("----Owner-AfterVisit----");
94-
this.ownerRepository
95-
.findByLastName("Nicks", Pageable.unpaged())
96-
.forEach(i ->
97-
{
98-
LOG.info(i.toString());
99-
i.getPets().forEach(p -> {
100-
LOG.info(p.toString());
101-
p.getVisits().forEach(v -> LOG.info(v.toString()));
102-
}
103-
);
104-
}
105-
);
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-
);
117-
}
118-
119-
private static Visit createVisit()
120-
{
121-
final Visit visit = new Visit();
122-
visit.setDate(LocalDate.now());
123-
visit.setDescription("Peter got his first parvovirus vaccine");
124-
return visit;
51+
this.vetCalls();
52+
this.ownerCalls();
12553
}
12654

127-
private static Vet createVet()
55+
/**
56+
* Some calls are transactional (delete and create) and some are not (log).
57+
*/
58+
private void ownerCalls()
12859
{
129-
final Vet vet = new Vet();
130-
vet.setFirstName("Mick");
131-
vet.setLastName("Fleetwood");
132-
final Specialty specialty = new Specialty();
133-
specialty.setName("Vaccination");
134-
vet.addSpecialty(specialty);
135-
return vet;
60+
this.ownerService.logOwners();
61+
this.ownerService.deleteAll();
62+
this.ownerService.logOwners();
63+
this.ownerService.createNewOwnerAndVisit();
64+
this.ownerService.logOwnersAndVisits();
13665
}
13766

138-
@SuppressWarnings("checkstyle:MagicNumber")
139-
private static Owner createOwner()
67+
/**
68+
* Each of these calls are one transaction.
69+
*/
70+
private void vetCalls()
14071
{
141-
final Owner owner = new Owner();
142-
owner.setFirstName("Stevie");
143-
owner.setLastName("Nicks");
144-
final Pet pet = new Pet();
145-
pet.setBirthDate(LocalDate.now().minusWeeks(6));
146-
pet.setName("Peter");
147-
final PetType petType = new PetType();
148-
petType.setName("Dog");
149-
pet.setType(petType);
150-
owner.addPet(pet);
151-
return owner;
72+
this.vetService.logVetEntries();
73+
this.vetService.deleteAll();
74+
this.vetService.logVetEntries();
75+
this.vetService.saveNewEntries();
76+
this.vetService.logVetEntries();
15277
}
15378
}

0 commit comments

Comments
 (0)