Skip to content

Commit 2eedf70

Browse files
Add LazyRepo demo
1 parent 2c36144 commit 2eedf70

8 files changed

Lines changed: 244 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ spring-data-eclipse-store-demo/storage
6767
spring-data-eclipse-store-demo/storage-person
6868
spring-data-eclipse-store-demo/storage-invoice
6969
spring-data-eclipse-store-demo/storage-complex
70+
spring-data-eclipse-store-demo/storage-lazy
7071
spring-data-eclipse-store-jpa/storage-eclipsestore
7172
spring-data-eclipse-store-jpa/storage-h2.mv.db
7273
spring-data-eclipse-store-jpa/storage-h2.trace.db
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package software.xdev.spring.data.eclipse.store.demo.lazy;
2+
3+
import jakarta.persistence.GeneratedValue;
4+
import jakarta.persistence.GenerationType;
5+
6+
import org.springframework.data.annotation.Id;
7+
8+
9+
public class Customer
10+
{
11+
@Id
12+
@GeneratedValue(strategy = GenerationType.AUTO)
13+
private String id;
14+
15+
private final String firstName;
16+
private final String lastName;
17+
18+
public Customer(final String firstName, final String lastName)
19+
{
20+
this.firstName = firstName;
21+
this.lastName = lastName;
22+
}
23+
24+
@Override
25+
public String toString()
26+
{
27+
return String.format(
28+
"Customer[id=%s, firstName='%s', lastName='%s']",
29+
this.id, this.firstName, this.lastName);
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package software.xdev.spring.data.eclipse.store.demo.lazy;
2+
3+
import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreCrudRepository;
4+
5+
6+
public interface CustomerRepository extends LazyEclipseStoreCrudRepository<Customer, String>
7+
{
8+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package software.xdev.spring.data.eclipse.store.demo.lazy;
2+
3+
import java.nio.file.Path;
4+
5+
import org.eclipse.serializer.reflect.ClassLoaderProvider;
6+
import org.eclipse.store.integrations.spring.boot.types.configuration.EclipseStoreProperties;
7+
import org.eclipse.store.integrations.spring.boot.types.factories.EmbeddedStorageFoundationFactory;
8+
import org.eclipse.store.storage.embedded.types.EmbeddedStorage;
9+
import org.eclipse.store.storage.embedded.types.EmbeddedStorageFoundation;
10+
import org.eclipse.store.storage.types.Storage;
11+
import org.springframework.beans.factory.ObjectProvider;
12+
import org.springframework.beans.factory.annotation.Autowired;
13+
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
14+
import org.springframework.context.annotation.Bean;
15+
import org.springframework.context.annotation.Configuration;
16+
import org.springframework.transaction.PlatformTransactionManager;
17+
18+
import software.xdev.spring.data.eclipse.store.demo.dual.storage.person.PersistencePersonConfiguration;
19+
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;
20+
import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories;
21+
22+
23+
@Configuration
24+
@EnableEclipseStoreRepositories
25+
public class LazyConfiguration extends EclipseStoreClientConfiguration
26+
{
27+
28+
public static final String STORAGE_PATH = "storage-lazy";
29+
30+
@Autowired
31+
public LazyConfiguration(
32+
final EclipseStoreProperties defaultEclipseStoreProperties,
33+
final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider,
34+
final ClassLoaderProvider classLoaderProvider
35+
)
36+
{
37+
super(defaultEclipseStoreProperties, defaultEclipseStoreProvider, classLoaderProvider);
38+
}
39+
/**
40+
* This is one option how to configure the {@link EmbeddedStorageFoundation}.
41+
* <p>
42+
* We create a completely new foundation. That means that all configuration (e.g. properties) are not used here.
43+
* With this method you have complete control over the configuration.
44+
* </p>
45+
* Another example: {@link PersistencePersonConfiguration#createEmbeddedStorageFoundation()}
46+
*/
47+
@Override
48+
public EmbeddedStorageFoundation<?> createEmbeddedStorageFoundation()
49+
{
50+
final EmbeddedStorageFoundation<?> storageFoundation =
51+
EmbeddedStorage.Foundation(Storage.Configuration(Storage.FileProvider(Path.of(STORAGE_PATH))));
52+
// This is only needed, if a different ClassLoader is used (e.g. when using spring-dev-tools)
53+
storageFoundation.getConnectionFoundation().setClassLoaderProvider(getClassLoaderProvider());
54+
return storageFoundation;
55+
}
56+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
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+
* https://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+
17+
package software.xdev.spring.data.eclipse.store.demo.lazy;
18+
19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
21+
import org.springframework.boot.CommandLineRunner;
22+
import org.springframework.boot.SpringApplication;
23+
import org.springframework.boot.autoconfigure.SpringBootApplication;
24+
25+
import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories;
26+
27+
28+
@SpringBootApplication
29+
public class LazyDemoApplication implements CommandLineRunner
30+
{
31+
private static final Logger LOG = LoggerFactory.getLogger(LazyDemoApplication.class);
32+
private final CustomerRepository customerRepository;
33+
private final PetRepository petRepository;
34+
35+
public LazyDemoApplication(
36+
final CustomerRepository customerRepository,
37+
final PetRepository petRepository
38+
)
39+
{
40+
this.customerRepository = customerRepository;
41+
this.petRepository = petRepository;
42+
}
43+
44+
public static void main(final String[] args)
45+
{
46+
SpringApplication.run(LazyDemoApplication.class, args);
47+
}
48+
49+
@Override
50+
public void run(final String... args)
51+
{
52+
this.customerRepository.deleteAll();
53+
54+
// save a couple of customers
55+
this.customerRepository.save(new Customer("Stevie", "Nicks"));
56+
this.customerRepository.save(new Customer("Mick", "Fleetwood"));
57+
58+
// fetch all customers
59+
LOG.info("Customers found with findAll():");
60+
this.customerRepository.findAll().forEach(c -> LOG.info(c.toString()));
61+
62+
// save a pet
63+
this.petRepository.save(new Pet("1", "Peter", 2));
64+
65+
// fetch all pets
66+
LOG.info("Pets found with findAll():");
67+
this.petRepository.findAll().forEach(p -> LOG.info(p.toString()));
68+
}
69+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package software.xdev.spring.data.eclipse.store.demo.lazy;
2+
3+
import org.springframework.data.annotation.Id;
4+
5+
6+
public class Pet
7+
{
8+
@Id
9+
private String id;
10+
11+
private String name;
12+
private Integer age;
13+
14+
public Pet()
15+
{
16+
}
17+
18+
public Pet(final String id, final String name, final Integer age)
19+
{
20+
this.id = id;
21+
this.name = name;
22+
this.age = age;
23+
}
24+
25+
@Override
26+
public String toString()
27+
{
28+
return String.format(
29+
"Pet[id=%s, name='%s', age='%s']",
30+
this.id, this.name, this.age);
31+
}
32+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package software.xdev.spring.data.eclipse.store.demo.lazy;
2+
3+
import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreCrudRepository;
4+
5+
6+
public interface PetRepository extends LazyEclipseStoreCrudRepository<Pet, String>
7+
{
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package software.xdev.spring.data.eclipse.store.demo.lazy.complex;
2+
3+
import java.io.File;
4+
5+
import org.junit.jupiter.api.BeforeAll;
6+
import org.junit.jupiter.api.Test;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.boot.test.context.SpringBootTest;
9+
10+
import software.xdev.spring.data.eclipse.store.demo.TestUtil;
11+
import software.xdev.spring.data.eclipse.store.demo.lazy.LazyConfiguration;
12+
import software.xdev.spring.data.eclipse.store.demo.lazy.LazyDemoApplication;
13+
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;
14+
15+
16+
@SpringBootTest(classes = LazyDemoApplication.class)
17+
class LazyDemoApplicationTest
18+
{
19+
private final EclipseStoreClientConfiguration configuration;
20+
21+
@Autowired
22+
public LazyDemoApplicationTest(final LazyConfiguration configuration)
23+
{
24+
this.configuration = configuration;
25+
}
26+
27+
@BeforeAll
28+
static void clearPreviousData()
29+
{
30+
TestUtil.deleteDirectory(new File("./" + LazyConfiguration.STORAGE_PATH));
31+
}
32+
33+
@Test
34+
void checkPossibilityToSimplyStartAndRestartApplication()
35+
{
36+
this.configuration.getStorageInstance().stop();
37+
LazyDemoApplication.main(new String[]{});
38+
}
39+
}

0 commit comments

Comments
 (0)