-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c36144
commit 2eedf70
Showing
8 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/Customer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...o/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/CustomerRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Customer, String> | ||
{ | ||
} |
56 changes: 56 additions & 0 deletions
56
...mo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/LazyConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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.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.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}. | ||
* <p> | ||
* 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. | ||
* </p> | ||
* 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(getClassLoaderProvider()); | ||
return storageFoundation; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
.../src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/LazyDemoApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* 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; | ||
|
||
import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; | ||
|
||
|
||
@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())); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...lipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/Pet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...e-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/lazy/PetRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Pet, String> | ||
{ | ||
} |
39 changes: 39 additions & 0 deletions
39
...va/software/xdev/spring/data/eclipse/store/demo/lazy/complex/LazyDemoApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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[]{}); | ||
} | ||
} |