Skip to content

Commit 4e7b481

Browse files
Merge pull request #17 from xdev-software/jpa-demo-test
Jpa demo test
2 parents 2cb1abb + bf19c5d commit 4e7b481

File tree

41 files changed

+1422
-63
lines changed

Some content is hidden

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

41 files changed

+1422
-63
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ target/
6868

6969
# EclipseStore
7070
storage
71+
storage-jpa
7172

7273
# == IntelliJ ==
7374
*.iml

.run/Run JPA Demo.run.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="Run JPA Demo" type="Application" factoryName="Application">
3+
<option name="MAIN_CLASS_NAME" value="software.xdev.spring.data.eclipse.store.jpa.JpaDemoApplication" />
4+
<module name="spring-data-eclipse-store-jpa" />
5+
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
6+
<extension name="coverage">
7+
<pattern>
8+
<option name="PATTERN" value="software.xdev.*" />
9+
<option name="ENABLED" value="true" />
10+
</pattern>
11+
</extension>
12+
<method v="2">
13+
<option name="Make" enabled="true" />
14+
</method>
15+
</configuration>
16+
</component>

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 1.0.1
22

33
* Fix for NullPointerException when storing an entity with Auto-ID and no previous action on the database.
4+
* Provide multiple Repository Interfaces, not only EclipseStoreRepository (e.g. EclipseStoreCrudRepository).
45

56
# 1.0.0
67

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ After adding the library in your dependencies, using it is as easy as adding the
6767

6868
## Demo
6969

70-
To see how easy it is to implement EclipseStore in your Spring project, take a look at the two
70+
To see how easy it is to implement EclipseStore in your Spring project, take a look at the three
7171
[demos](./spring-data-eclipse-store-demo):<br/>
72-
A [simple](./spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/simple)
73-
and a
74-
more [complex demo](./spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/complex).
72+
A [simple](./spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/simple), a
73+
more [complex demo](./spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/complex)
74+
and
75+
a [demo with coexisting JPA](./spring-data-eclipse-store-jpa/src/main/java/software/xdev/spring/data/eclipse/store/jpa).
7576

7677
> [!NOTE]
7778
> Since the library is using reflection to copy data, the following JVM-Arguments may have to be set:

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<module>spring-data-eclipse-store</module>
1919
<module>spring-data-eclipse-store-demo</module>
2020
<module>spring-data-eclipse-store-benchmark</module>
21+
<module>spring-data-eclipse-store-jpa</module>
2122
</modules>
2223

2324
<licenses>

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

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>software.xdev</groupId>
8+
<artifactId>spring-data-eclipse-store-jpa</artifactId>
9+
<version>1.0.1-SNAPSHOT</version>
10+
<packaging>jar</packaging>
11+
12+
<inceptionYear>2023</inceptionYear>
13+
14+
<organization>
15+
<name>XDEV Software</name>
16+
<url>https://xdev.software</url>
17+
</organization>
18+
19+
<properties>
20+
<javaVersion>17</javaVersion>
21+
<maven.compiler.release>${javaVersion}</maven.compiler.release>
22+
23+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
25+
26+
<mainClass>software.xdev.spring.data.eclipse.store.demo.complex.ComplexDemoApplication</mainClass>
27+
28+
<org.springframework.boot.version>3.2.2</org.springframework.boot.version>
29+
</properties>
30+
31+
<dependencyManagement>
32+
<dependencies>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-dependencies</artifactId>
36+
<version>${org.springframework.boot.version}</version>
37+
<type>pom</type>
38+
<scope>import</scope>
39+
</dependency>
40+
</dependencies>
41+
</dependencyManagement>
42+
43+
<dependencies>
44+
<dependency>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-autoconfigure</artifactId>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.springframework.boot</groupId>
50+
<artifactId>spring-boot-starter-data-jpa</artifactId>
51+
</dependency>
52+
<dependency>
53+
<groupId>com.h2database</groupId>
54+
<artifactId>h2</artifactId>
55+
</dependency>
56+
<dependency>
57+
<groupId>software.xdev</groupId>
58+
<artifactId>spring-data-eclipse-store</artifactId>
59+
<version>${project.version}</version>
60+
</dependency>
61+
62+
<dependency>
63+
<groupId>org.junit.jupiter</groupId>
64+
<artifactId>junit-jupiter-engine</artifactId>
65+
<scope>test</scope>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.junit.jupiter</groupId>
69+
<artifactId>junit-jupiter-api</artifactId>
70+
<scope>test</scope>
71+
</dependency>
72+
<dependency>
73+
<groupId>org.junit.jupiter</groupId>
74+
<artifactId>junit-jupiter-params</artifactId>
75+
<scope>test</scope>
76+
</dependency>
77+
<dependency>
78+
<groupId>org.springframework</groupId>
79+
<artifactId>spring-test</artifactId>
80+
<scope>test</scope>
81+
</dependency>
82+
</dependencies>
83+
84+
<build>
85+
<finalName>${project.artifactId}</finalName>
86+
87+
<plugins>
88+
<plugin>
89+
<groupId>org.apache.maven.plugins</groupId>
90+
<artifactId>maven-compiler-plugin</artifactId>
91+
<version>3.12.1</version>
92+
<configuration>
93+
<release>${maven.compiler.release}</release>
94+
<compilerArgs>
95+
<arg>-proc:none</arg>
96+
</compilerArgs>
97+
</configuration>
98+
</plugin>
99+
<plugin>
100+
<groupId>org.springframework.boot</groupId>
101+
<artifactId>spring-boot-maven-plugin</artifactId>
102+
<version>${org.springframework.boot.version}</version>
103+
<configuration>
104+
<mainClass>${mainClass}</mainClass>
105+
<jvmArguments>
106+
--add-opens java.base/java.util=ALL-UNNAMED
107+
--add-opens java.base/java.time=ALL-UNNAMED
108+
</jvmArguments>
109+
</configuration>
110+
</plugin>
111+
</plugins>
112+
</build>
113+
<profiles>
114+
<profile>
115+
<id>checkstyle</id>
116+
<build>
117+
<plugins>
118+
<plugin>
119+
<groupId>org.apache.maven.plugins</groupId>
120+
<artifactId>maven-checkstyle-plugin</artifactId>
121+
<version>3.3.1</version>
122+
<dependencies>
123+
<dependency>
124+
<groupId>com.puppycrawl.tools</groupId>
125+
<artifactId>checkstyle</artifactId>
126+
<version>10.12.7</version>
127+
</dependency>
128+
</dependencies>
129+
<configuration>
130+
<configLocation>../.config/checkstyle/checkstyle.xml</configLocation>
131+
</configuration>
132+
<executions>
133+
<execution>
134+
<goals>
135+
<goal>check</goal>
136+
</goals>
137+
</execution>
138+
</executions>
139+
</plugin>
140+
</plugins>
141+
</build>
142+
</profile>
143+
</profiles>
144+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package software.xdev.spring.data.eclipse.store.jpa;
2+
3+
import jakarta.persistence.Id;
4+
5+
6+
public class CustomerInEclipseStore
7+
{
8+
@Id
9+
private String id;
10+
11+
private String firstName;
12+
private String lastName;
13+
14+
public CustomerInEclipseStore(final String id, final String firstName, final String lastName)
15+
{
16+
this.id = id;
17+
this.firstName = firstName;
18+
this.lastName = lastName;
19+
}
20+
21+
public CustomerInEclipseStore()
22+
{
23+
24+
}
25+
26+
@Override
27+
public String toString()
28+
{
29+
return String.format(
30+
"Customer[id=%s, firstName='%s', lastName='%s']",
31+
this.id, this.firstName, this.lastName);
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package software.xdev.spring.data.eclipse.store.jpa;
2+
3+
import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreCrudRepository;
4+
5+
6+
/**
7+
* To be able to properly coexist with JPA in one project, the repositories must be declared as specific JPA- or
8+
* EclipseStore-Repositories.
9+
*/
10+
public interface CustomerInEclipseStoreRepository extends EclipseStoreCrudRepository<CustomerInEclipseStore, String>
11+
{
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package software.xdev.spring.data.eclipse.store.jpa;
2+
3+
import jakarta.persistence.Entity;
4+
import jakarta.persistence.Id;
5+
6+
7+
@Entity
8+
public class CustomerInJpa
9+
{
10+
@Id
11+
private String id;
12+
13+
private String firstName;
14+
private String lastName;
15+
16+
public CustomerInJpa(final String id, final String firstName, final String lastName)
17+
{
18+
this.id = id;
19+
this.firstName = firstName;
20+
this.lastName = lastName;
21+
}
22+
23+
public CustomerInJpa()
24+
{
25+
26+
}
27+
28+
@Override
29+
public String toString()
30+
{
31+
return String.format(
32+
"Customer[id=%s, firstName='%s', lastName='%s']",
33+
this.id, this.firstName, this.lastName);
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package software.xdev.spring.data.eclipse.store.jpa;
2+
3+
import org.springframework.data.jpa.repository.JpaRepository;
4+
5+
6+
/**
7+
* To be able to properly coexist with JPA in one project, the repositories must be declared as specific JPA- or
8+
* EclipseStore-Repositories.
9+
*/
10+
public interface CustomerInJpaRepository extends JpaRepository<CustomerInJpa, String>
11+
{
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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.jpa;
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+
import org.springframework.context.ConfigurableApplicationContext;
25+
26+
import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories;
27+
28+
29+
/**
30+
* In this example we want to coexist with Spring data JPA. This is possible by using
31+
* {@link software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreRepository}s instead of the generic
32+
* {@link org.springframework.data.repository.Repository}s of the Spring framework.
33+
*/
34+
@SpringBootApplication
35+
@EnableEclipseStoreRepositories
36+
public class JpaDemoApplication implements CommandLineRunner
37+
{
38+
private static final Logger LOG = LoggerFactory.getLogger(JpaDemoApplication.class);
39+
private final CustomerInEclipseStoreRepository eclipseStoreRepository;
40+
private final CustomerInJpaRepository jpaRepository;
41+
42+
public JpaDemoApplication(
43+
final CustomerInEclipseStoreRepository eclipseStoreRepository,
44+
final CustomerInJpaRepository jpaRepository
45+
)
46+
{
47+
this.eclipseStoreRepository = eclipseStoreRepository;
48+
this.jpaRepository = jpaRepository;
49+
}
50+
51+
public static void main(final String[] args)
52+
{
53+
final ConfigurableApplicationContext run = SpringApplication.run(JpaDemoApplication.class, args);
54+
run.close();
55+
}
56+
57+
@Override
58+
public void run(final String... args)
59+
{
60+
this.saveEntityInEclipseStoreRepository();
61+
this.saveEntityInJpaRepository();
62+
}
63+
64+
private void saveEntityInEclipseStoreRepository()
65+
{
66+
LOG.info("-------- EclipseStore-Actions --------");
67+
this.eclipseStoreRepository.deleteAll();
68+
69+
// save a couple of customers
70+
this.eclipseStoreRepository.save(new CustomerInEclipseStore("1", "Stevie", "Nicks"));
71+
this.eclipseStoreRepository.save(new CustomerInEclipseStore("2", "Mick", "Fleetwood"));
72+
73+
// fetch all customers
74+
LOG.info("Customers found with findAll() in EclipseStore:");
75+
this.eclipseStoreRepository.findAll().forEach(c -> LOG.info(c.toString()));
76+
}
77+
78+
private void saveEntityInJpaRepository()
79+
{
80+
LOG.info("-------- JPA-Actions --------");
81+
this.jpaRepository.deleteAll();
82+
83+
// save a couple of customers
84+
this.jpaRepository.save(new CustomerInJpa("1", "Stevie", "Nicks"));
85+
this.jpaRepository.save(new CustomerInJpa("2", "Mick", "Fleetwood"));
86+
87+
// fetch all customers
88+
LOG.info("Customers found with findAll() in JPA:");
89+
this.jpaRepository.findAll().forEach(c -> LOG.info(c.toString()));
90+
}
91+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.eclipse.store.storage-directory=./storage-jpa

0 commit comments

Comments
 (0)