-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refine JPA integration via ByteBuddy.
Significant rework in the JPA integration via a ByteBuddy plugin. All features supported now can be found in the readme of the jmolecules-integration/jmolecules-jpa module. Separated ByteBuddy plugin from JPA integration code needed at runtime. Related discussions: #44
- Loading branch information
Showing
17 changed files
with
860 additions
and
149 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
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
47 changes: 47 additions & 0 deletions
47
...ecules-spring-data-jpa/src/main/java/org/jmolecules/examples/jpa/customer/SomeEntity.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,47 @@ | ||
/* | ||
* Copyright 2021 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 org.jmolecules.examples.jpa.customer; | ||
|
||
import java.time.LocalDate; | ||
|
||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
|
||
import org.jmolecules.ddd.types.Entity; | ||
|
||
/** | ||
* @author Oliver Drotbohm | ||
*/ | ||
public class SomeEntity implements Entity<Customer, Long> { | ||
|
||
private @Id @GeneratedValue Long id; | ||
private final LocalDate date; | ||
private String firstname; | ||
|
||
public SomeEntity(String foo) { | ||
this.firstname = foo; | ||
this.date = null; | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.jmolecules.ddd.types.Identifiable#getId() | ||
*/ | ||
@Override | ||
public Long getId() { | ||
return id; | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
...amples/jmolecules-spring-data-jpa/src/test/java/org/jmolecules/examples/jpa/JpaTests.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,55 @@ | ||
/* | ||
* Copyright 2021 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 org.jmolecules.examples.jpa; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import javax.persistence.EntityManager; | ||
|
||
import org.jmolecules.examples.jpa.customer.SomeEntity; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.TestConstructor; | ||
import org.springframework.test.context.TestConstructor.AutowireMode; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
/** | ||
* @author Oliver Drotbohm | ||
*/ | ||
@Transactional | ||
@SpringBootTest | ||
@TestConstructor(autowireMode = AutowireMode.ALL) | ||
@RequiredArgsConstructor | ||
class JpaTests { | ||
|
||
private final EntityManager em; | ||
|
||
@Test | ||
void testName() throws Exception { | ||
|
||
SomeEntity entity = new SomeEntity("Test"); | ||
|
||
em.persist(entity); | ||
em.flush(); | ||
em.clear(); | ||
|
||
SomeEntity result = em.find(SomeEntity.class, entity.getId()); | ||
|
||
assertThat(result).isNotNull(); | ||
} | ||
} |
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,73 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.jmolecules</groupId> | ||
<artifactId>jmolecules-integration</artifactId> | ||
<version>1.1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<name>jMolecules - JPA ByteBuddy plugin</name> | ||
<artifactId>jmolecules-jpa-plugin</artifactId> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>jmolecules-ddd</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>jmolecules-jpa</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.data</groupId> | ||
<artifactId>spring-data-commons</artifactId> | ||
<version>2.4.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>net.bytebuddy</groupId> | ||
<artifactId>byte-buddy</artifactId> | ||
<version>${bytebuddy.version}</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>net.bytebuddy</groupId> | ||
<artifactId>byte-buddy-maven-plugin</artifactId> | ||
<version>${bytebuddy.version}</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>transform-test</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>${project.artifactId}</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
<configuration> | ||
<transformations> | ||
<transformation> | ||
<plugin>org.jmolecules.jpa.plugin.JMoleculesJpaPlugin</plugin> | ||
</transformation> | ||
</transformations> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Oops, something went wrong.