Polishing.
Reformat code. Simplify annotation setup. See #603 Original pull request: #604.
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>spring-data-jpa-examples</artifactId>
|
||||
<groupId>org.springframework.data.examples</groupId>
|
||||
<version>2.0.0.BUILD-gh-603-SNAPSHOT</version>
|
||||
</parent>
|
||||
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.springframework.data.examples</groupId>
|
||||
<artifactId>spring-data-jpa-examples</artifactId>
|
||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>spring-data-jpa-envers</artifactId>
|
||||
<name>Spring Data Envers</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -17,4 +18,5 @@
|
||||
<artifactId>spring-data-envers</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -22,8 +22,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
/**
|
||||
* Configuration for the Envers Demo.
|
||||
* <p>
|
||||
* Note that a special {@literal repositoryFactoryBeanClass} is configured for Spring
|
||||
* Data Envers support.
|
||||
* Note that a special {@literal repositoryFactoryBeanClass} is configured for Spring Data Envers support.
|
||||
*
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package example.springdata.jpa.envers;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
/**
|
||||
* An entity with a single non-technical attribute
|
||||
*
|
||||
|
||||
@@ -23,5 +23,4 @@ import org.springframework.data.repository.history.RevisionRepository;
|
||||
*
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
public interface PersonRepository extends CrudRepository<Person, Long>, RevisionRepository<Person, Long, Long> {
|
||||
}
|
||||
public interface PersonRepository extends CrudRepository<Person, Long>, RevisionRepository<Person, Long, Long> {}
|
||||
|
||||
@@ -17,24 +17,22 @@ package example.springdata.jpa.envers;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.history.Revision;
|
||||
import org.springframework.data.history.RevisionMetadata.RevisionType;
|
||||
import org.springframework.data.history.Revisions;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Demonstrating the usage of Spring Data Envers
|
||||
*
|
||||
*
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest
|
||||
public class EnversIntegrationTests {
|
||||
|
||||
@@ -48,7 +46,6 @@ public class EnversIntegrationTests {
|
||||
|
||||
Revisions<Long, Person> revisions = repository.findRevisions(updated.id);
|
||||
|
||||
|
||||
Iterator<Revision<Long, Person>> revisionIterator = revisions.iterator();
|
||||
|
||||
checkNextRevision(revisionIterator, "John", RevisionType.INSERT);
|
||||
@@ -58,7 +55,8 @@ public class EnversIntegrationTests {
|
||||
|
||||
}
|
||||
|
||||
private void checkNextRevision(Iterator<Revision<Long, Person>> revisionIterator, String name, RevisionType revisionType) {
|
||||
private void checkNextRevision(Iterator<Revision<Long, Person>> revisionIterator, String name,
|
||||
RevisionType revisionType) {
|
||||
|
||||
assertThat(revisionIterator.hasNext()).isTrue();
|
||||
Revision<Long, Person> revision = revisionIterator.next();
|
||||
@@ -71,7 +69,7 @@ public class EnversIntegrationTests {
|
||||
Person john = new Person();
|
||||
john.setName("John");
|
||||
|
||||
//create
|
||||
// create
|
||||
Person saved = tx.execute(__ -> repository.save(john));
|
||||
assertThat(saved).isNotNull();
|
||||
|
||||
@@ -82,7 +80,7 @@ public class EnversIntegrationTests {
|
||||
assertThat(updated).isNotNull();
|
||||
|
||||
// delete
|
||||
tx.executeWithoutResult(__->repository.delete(updated));
|
||||
tx.executeWithoutResult(__ -> repository.delete(updated));
|
||||
return updated;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user