Remove lombok annotations.

Closes #1557
This commit is contained in:
Jens Schauder
2023-07-07 13:09:51 +02:00
parent 56ec491724
commit cf126d2d42
72 changed files with 4934 additions and 1370 deletions

View File

@@ -15,15 +15,22 @@
*/
package org.springframework.data.jdbc.core;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.SoftAssertions.*;
import static org.mockito.Mockito.*;
import lombok.AllArgsConstructor;
import lombok.Value;
import lombok.With;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.mapping.PersistentPropertyPaths;
import org.springframework.data.relational.core.conversion.DbAction;
import org.springframework.data.relational.core.conversion.IdValueSource;
import org.springframework.data.relational.core.conversion.MutableAggregateChange;
import org.springframework.data.relational.core.conversion.RootAggregateChange;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Embedded;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.lang.Nullable;
import java.util.HashMap;
import java.util.List;
@@ -32,22 +39,11 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.mapping.PersistentPropertyPaths;
import org.springframework.data.relational.core.conversion.RootAggregateChange;
import org.springframework.data.relational.core.conversion.DbAction;
import org.springframework.data.relational.core.conversion.IdValueSource;
import org.springframework.data.relational.core.conversion.MutableAggregateChange;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Embedded;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.lang.Nullable;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.SoftAssertions.*;
import static org.mockito.Mockito.*;
/**
* Unit tests for the {@link MutableAggregateChange} testing the setting of generated ids in aggregates consisting of
@@ -220,7 +216,7 @@ public class AggregateChangeIdGenerationImmutableUnitTests {
.extracting(c -> c.id) //
.containsExactly(2); //
softly.assertThat(entity.contentSet.stream() //
.flatMap(c -> c.tagSet.stream())) //
.flatMap(c -> c.tagSet.stream())) //
.extracting(t -> t.id) //
.containsExactlyInAnyOrder(3, 4); //
});
@@ -288,8 +284,8 @@ public class AggregateChangeIdGenerationImmutableUnitTests {
.extracting(c -> c.id) //
.containsExactly(2, 3); //
softly.assertThat(entity.contentList.stream() //
.flatMap(c -> c.tagList.stream()) //
).extracting(t -> t.id) //
.flatMap(c -> c.tagList.stream()) //
).extracting(t -> t.id) //
.containsExactly(4, 5, 6); //
});
}
@@ -324,13 +320,13 @@ public class AggregateChangeIdGenerationImmutableUnitTests {
.extracting(Map.Entry::getKey, e -> e.getValue().id) //
.containsExactly(tuple("one", 2), tuple("two", 3)); //
softly.assertThat(entity.contentMap.values().stream() //
.flatMap(c -> c.tagMap.entrySet().stream())) //
.flatMap(c -> c.tagMap.entrySet().stream())) //
.extracting(Map.Entry::getKey, e -> e.getValue().id) //
.containsExactly( //
tuple("111", 4), //
tuple("222", 5), //
tuple("333", 6) //
); //
); //
});
}
@@ -412,7 +408,7 @@ public class AggregateChangeIdGenerationImmutableUnitTests {
}
DbAction.Insert<?> createDeepInsert(String propertyName, Object value, Object key,
@Nullable DbAction.Insert<?> parentInsert) {
@Nullable DbAction.Insert<?> parentInsert) {
PersistentPropertyPath<RelationalPersistentProperty> propertyPath = toPath(
parentInsert.getPropertyPath().toDotPath() + "." + propertyName);
@@ -430,18 +426,19 @@ public class AggregateChangeIdGenerationImmutableUnitTests {
.orElseThrow(() -> new IllegalArgumentException("No matching path found"));
}
@Value
@With
@AllArgsConstructor
private static class DummyEntity {
private static final class DummyEntity {
@Id Integer rootId;
Content single;
Set<Content> contentSet;
List<Content> contentList;
Map<String, Content> contentMap;
List<ContentNoId> contentNoIdList;
@Embedded(onEmpty = Embedded.OnEmpty.USE_NULL, prefix = "fooBar") ContentNoId embedded;
@Id
private final
Integer rootId;
private final Content single;
private final Set<Content> contentSet;
private final List<Content> contentList;
private final Map<String, Content> contentMap;
private final List<ContentNoId> contentNoIdList;
@Embedded(onEmpty = Embedded.OnEmpty.USE_NULL, prefix = "fooBar")
private final
ContentNoId embedded;
DummyEntity() {
@@ -453,18 +450,139 @@ public class AggregateChangeIdGenerationImmutableUnitTests {
contentNoIdList = emptyList();
embedded = new ContentNoId();
}
public DummyEntity(Integer rootId, Content single, Set<Content> contentSet, List<Content> contentList, Map<String, Content> contentMap, List<ContentNoId> contentNoIdList, ContentNoId embedded) {
this.rootId = rootId;
this.single = single;
this.contentSet = contentSet;
this.contentList = contentList;
this.contentMap = contentMap;
this.contentNoIdList = contentNoIdList;
this.embedded = embedded;
}
public Integer getRootId() {
return this.rootId;
}
public Content getSingle() {
return this.single;
}
public Set<Content> getContentSet() {
return this.contentSet;
}
public List<Content> getContentList() {
return this.contentList;
}
public Map<String, Content> getContentMap() {
return this.contentMap;
}
public List<ContentNoId> getContentNoIdList() {
return this.contentNoIdList;
}
public ContentNoId getEmbedded() {
return this.embedded;
}
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof DummyEntity)) return false;
final DummyEntity other = (DummyEntity) o;
final Object this$rootId = this.getRootId();
final Object other$rootId = other.getRootId();
if (this$rootId == null ? other$rootId != null : !this$rootId.equals(other$rootId)) return false;
final Object this$single = this.getSingle();
final Object other$single = other.getSingle();
if (this$single == null ? other$single != null : !this$single.equals(other$single)) return false;
final Object this$contentSet = this.getContentSet();
final Object other$contentSet = other.getContentSet();
if (this$contentSet == null ? other$contentSet != null : !this$contentSet.equals(other$contentSet))
return false;
final Object this$contentList = this.getContentList();
final Object other$contentList = other.getContentList();
if (this$contentList == null ? other$contentList != null : !this$contentList.equals(other$contentList))
return false;
final Object this$contentMap = this.getContentMap();
final Object other$contentMap = other.getContentMap();
if (this$contentMap == null ? other$contentMap != null : !this$contentMap.equals(other$contentMap))
return false;
final Object this$contentNoIdList = this.getContentNoIdList();
final Object other$contentNoIdList = other.getContentNoIdList();
if (this$contentNoIdList == null ? other$contentNoIdList != null : !this$contentNoIdList.equals(other$contentNoIdList))
return false;
final Object this$embedded = this.getEmbedded();
final Object other$embedded = other.getEmbedded();
if (this$embedded == null ? other$embedded != null : !this$embedded.equals(other$embedded)) return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $rootId = this.getRootId();
result = result * PRIME + ($rootId == null ? 43 : $rootId.hashCode());
final Object $single = this.getSingle();
result = result * PRIME + ($single == null ? 43 : $single.hashCode());
final Object $contentSet = this.getContentSet();
result = result * PRIME + ($contentSet == null ? 43 : $contentSet.hashCode());
final Object $contentList = this.getContentList();
result = result * PRIME + ($contentList == null ? 43 : $contentList.hashCode());
final Object $contentMap = this.getContentMap();
result = result * PRIME + ($contentMap == null ? 43 : $contentMap.hashCode());
final Object $contentNoIdList = this.getContentNoIdList();
result = result * PRIME + ($contentNoIdList == null ? 43 : $contentNoIdList.hashCode());
final Object $embedded = this.getEmbedded();
result = result * PRIME + ($embedded == null ? 43 : $embedded.hashCode());
return result;
}
public String toString() {
return "AggregateChangeIdGenerationImmutableUnitTests.DummyEntity(rootId=" + this.getRootId() + ", single=" + this.getSingle() + ", contentSet=" + this.getContentSet() + ", contentList=" + this.getContentList() + ", contentMap=" + this.getContentMap() + ", contentNoIdList=" + this.getContentNoIdList() + ", embedded=" + this.getEmbedded() + ")";
}
public DummyEntity withRootId(Integer rootId) {
return this.rootId == rootId ? this : new DummyEntity(rootId, this.single, this.contentSet, this.contentList, this.contentMap, this.contentNoIdList, this.embedded);
}
public DummyEntity withSingle(Content single) {
return this.single == single ? this : new DummyEntity(this.rootId, single, this.contentSet, this.contentList, this.contentMap, this.contentNoIdList, this.embedded);
}
public DummyEntity withContentSet(Set<Content> contentSet) {
return this.contentSet == contentSet ? this : new DummyEntity(this.rootId, this.single, contentSet, this.contentList, this.contentMap, this.contentNoIdList, this.embedded);
}
public DummyEntity withContentList(List<Content> contentList) {
return this.contentList == contentList ? this : new DummyEntity(this.rootId, this.single, this.contentSet, contentList, this.contentMap, this.contentNoIdList, this.embedded);
}
public DummyEntity withContentMap(Map<String, Content> contentMap) {
return this.contentMap == contentMap ? this : new DummyEntity(this.rootId, this.single, this.contentSet, this.contentList, contentMap, this.contentNoIdList, this.embedded);
}
public DummyEntity withContentNoIdList(List<ContentNoId> contentNoIdList) {
return this.contentNoIdList == contentNoIdList ? this : new DummyEntity(this.rootId, this.single, this.contentSet, this.contentList, this.contentMap, contentNoIdList, this.embedded);
}
public DummyEntity withEmbedded(ContentNoId embedded) {
return this.embedded == embedded ? this : new DummyEntity(this.rootId, this.single, this.contentSet, this.contentList, this.contentMap, this.contentNoIdList, embedded);
}
}
@Value
@With
@AllArgsConstructor
private static class Content {
private static final class Content {
@Id Integer id;
Tag single;
Set<Tag> tagSet;
List<Tag> tagList;
Map<String, Tag> tagMap;
@Id
private final
Integer id;
private final Tag single;
private final Set<Tag> tagSet;
private final List<Tag> tagList;
private final Map<String, Tag> tagMap;
Content() {
@@ -474,16 +592,105 @@ public class AggregateChangeIdGenerationImmutableUnitTests {
tagList = emptyList();
tagMap = emptyMap();
}
public Content(Integer id, Tag single, Set<Tag> tagSet, List<Tag> tagList, Map<String, Tag> tagMap) {
this.id = id;
this.single = single;
this.tagSet = tagSet;
this.tagList = tagList;
this.tagMap = tagMap;
}
public Integer getId() {
return this.id;
}
public Tag getSingle() {
return this.single;
}
public Set<Tag> getTagSet() {
return this.tagSet;
}
public List<Tag> getTagList() {
return this.tagList;
}
public Map<String, Tag> getTagMap() {
return this.tagMap;
}
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof Content)) return false;
final Content other = (Content) o;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false;
final Object this$single = this.getSingle();
final Object other$single = other.getSingle();
if (this$single == null ? other$single != null : !this$single.equals(other$single)) return false;
final Object this$tagSet = this.getTagSet();
final Object other$tagSet = other.getTagSet();
if (this$tagSet == null ? other$tagSet != null : !this$tagSet.equals(other$tagSet)) return false;
final Object this$tagList = this.getTagList();
final Object other$tagList = other.getTagList();
if (this$tagList == null ? other$tagList != null : !this$tagList.equals(other$tagList)) return false;
final Object this$tagMap = this.getTagMap();
final Object other$tagMap = other.getTagMap();
if (this$tagMap == null ? other$tagMap != null : !this$tagMap.equals(other$tagMap)) return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
final Object $single = this.getSingle();
result = result * PRIME + ($single == null ? 43 : $single.hashCode());
final Object $tagSet = this.getTagSet();
result = result * PRIME + ($tagSet == null ? 43 : $tagSet.hashCode());
final Object $tagList = this.getTagList();
result = result * PRIME + ($tagList == null ? 43 : $tagList.hashCode());
final Object $tagMap = this.getTagMap();
result = result * PRIME + ($tagMap == null ? 43 : $tagMap.hashCode());
return result;
}
public String toString() {
return "AggregateChangeIdGenerationImmutableUnitTests.Content(id=" + this.getId() + ", single=" + this.getSingle() + ", tagSet=" + this.getTagSet() + ", tagList=" + this.getTagList() + ", tagMap=" + this.getTagMap() + ")";
}
public Content withId(Integer id) {
return this.id == id ? this : new Content(id, this.single, this.tagSet, this.tagList, this.tagMap);
}
public Content withSingle(Tag single) {
return this.single == single ? this : new Content(this.id, single, this.tagSet, this.tagList, this.tagMap);
}
public Content withTagSet(Set<Tag> tagSet) {
return this.tagSet == tagSet ? this : new Content(this.id, this.single, tagSet, this.tagList, this.tagMap);
}
public Content withTagList(List<Tag> tagList) {
return this.tagList == tagList ? this : new Content(this.id, this.single, this.tagSet, tagList, this.tagMap);
}
public Content withTagMap(Map<String, Tag> tagMap) {
return this.tagMap == tagMap ? this : new Content(this.id, this.single, this.tagSet, this.tagList, tagMap);
}
}
@Value
@With
@AllArgsConstructor
private static class ContentNoId {
@Column("single") Tag single;
Set<Tag> tagSet;
List<Tag> tagList;
Map<String, Tag> tagMap;
private static final class ContentNoId {
@Column("single")
private final
Tag single;
private final Set<Tag> tagSet;
private final List<Tag> tagList;
private final Map<String, Tag> tagMap;
ContentNoId() {
@@ -492,20 +699,143 @@ public class AggregateChangeIdGenerationImmutableUnitTests {
tagList = emptyList();
tagMap = emptyMap();
}
public ContentNoId(Tag single, Set<Tag> tagSet, List<Tag> tagList, Map<String, Tag> tagMap) {
this.single = single;
this.tagSet = tagSet;
this.tagList = tagList;
this.tagMap = tagMap;
}
public Tag getSingle() {
return this.single;
}
public Set<Tag> getTagSet() {
return this.tagSet;
}
public List<Tag> getTagList() {
return this.tagList;
}
public Map<String, Tag> getTagMap() {
return this.tagMap;
}
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof ContentNoId)) return false;
final ContentNoId other = (ContentNoId) o;
final Object this$single = this.getSingle();
final Object other$single = other.getSingle();
if (this$single == null ? other$single != null : !this$single.equals(other$single)) return false;
final Object this$tagSet = this.getTagSet();
final Object other$tagSet = other.getTagSet();
if (this$tagSet == null ? other$tagSet != null : !this$tagSet.equals(other$tagSet)) return false;
final Object this$tagList = this.getTagList();
final Object other$tagList = other.getTagList();
if (this$tagList == null ? other$tagList != null : !this$tagList.equals(other$tagList)) return false;
final Object this$tagMap = this.getTagMap();
final Object other$tagMap = other.getTagMap();
if (this$tagMap == null ? other$tagMap != null : !this$tagMap.equals(other$tagMap)) return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $single = this.getSingle();
result = result * PRIME + ($single == null ? 43 : $single.hashCode());
final Object $tagSet = this.getTagSet();
result = result * PRIME + ($tagSet == null ? 43 : $tagSet.hashCode());
final Object $tagList = this.getTagList();
result = result * PRIME + ($tagList == null ? 43 : $tagList.hashCode());
final Object $tagMap = this.getTagMap();
result = result * PRIME + ($tagMap == null ? 43 : $tagMap.hashCode());
return result;
}
public String toString() {
return "AggregateChangeIdGenerationImmutableUnitTests.ContentNoId(single=" + this.getSingle() + ", tagSet=" + this.getTagSet() + ", tagList=" + this.getTagList() + ", tagMap=" + this.getTagMap() + ")";
}
public ContentNoId withSingle(Tag single) {
return this.single == single ? this : new ContentNoId(single, this.tagSet, this.tagList, this.tagMap);
}
public ContentNoId withTagSet(Set<Tag> tagSet) {
return this.tagSet == tagSet ? this : new ContentNoId(this.single, tagSet, this.tagList, this.tagMap);
}
public ContentNoId withTagList(List<Tag> tagList) {
return this.tagList == tagList ? this : new ContentNoId(this.single, this.tagSet, tagList, this.tagMap);
}
public ContentNoId withTagMap(Map<String, Tag> tagMap) {
return this.tagMap == tagMap ? this : new ContentNoId(this.single, this.tagSet, this.tagList, tagMap);
}
}
@Value
@With
@AllArgsConstructor
private static class Tag {
private static final class Tag {
@Id Integer id;
@Id
private final
Integer id;
String name;
private final String name;
Tag(String name) {
id = null;
this.name = name;
}
public Tag(Integer id, String name) {
this.id = id;
this.name = name;
}
public Integer getId() {
return this.id;
}
public String getName() {
return this.name;
}
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof Tag)) return false;
final Tag other = (Tag) o;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false;
final Object this$name = this.getName();
final Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
final Object $name = this.getName();
result = result * PRIME + ($name == null ? 43 : $name.hashCode());
return result;
}
public String toString() {
return "AggregateChangeIdGenerationImmutableUnitTests.Tag(id=" + this.getId() + ", name=" + this.getName() + ")";
}
public Tag withId(Integer id) {
return this.id == id ? this : new Tag(id, this.name);
}
public Tag withName(String name) {
return this.name == name ? this : new Tag(this.id, name);
}
}
}

View File

@@ -18,11 +18,6 @@ package org.springframework.data.jdbc.core;
import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Value;
import lombok.With;
import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -300,45 +295,307 @@ public class ImmutableAggregateTemplateHsqlIntegrationTests {
"Accelerates to 99% of light speed. Destroys almost everything. See https://what-if.xkcd.com/1/");
}
@Value
@With
static class LegoSet {
static final class LegoSet {
@Id Long id;
String name;
Manual manual;
Author author;
@Id private final Long id;
private final String name;
private final Manual manual;
private final Author author;
public LegoSet(Long id, String name, Manual manual, Author author) {
this.id = id;
this.name = name;
this.manual = manual;
this.author = author;
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public Manual getManual() {
return this.manual;
}
public Author getAuthor() {
return this.author;
}
public boolean equals(final Object o) {
if (o == this)
return true;
if (!(o instanceof LegoSet))
return false;
final LegoSet other = (LegoSet) o;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id))
return false;
final Object this$name = this.getName();
final Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name))
return false;
final Object this$manual = this.getManual();
final Object other$manual = other.getManual();
if (this$manual == null ? other$manual != null : !this$manual.equals(other$manual))
return false;
final Object this$author = this.getAuthor();
final Object other$author = other.getAuthor();
if (this$author == null ? other$author != null : !this$author.equals(other$author))
return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
final Object $name = this.getName();
result = result * PRIME + ($name == null ? 43 : $name.hashCode());
final Object $manual = this.getManual();
result = result * PRIME + ($manual == null ? 43 : $manual.hashCode());
final Object $author = this.getAuthor();
result = result * PRIME + ($author == null ? 43 : $author.hashCode());
return result;
}
public String toString() {
return "ImmutableAggregateTemplateHsqlIntegrationTests.LegoSet(id=" + this.getId() + ", name=" + this.getName()
+ ", manual=" + this.getManual() + ", author=" + this.getAuthor() + ")";
}
public LegoSet withId(Long id) {
return this.id == id ? this : new LegoSet(id, this.name, this.manual, this.author);
}
public LegoSet withName(String name) {
return this.name == name ? this : new LegoSet(this.id, name, this.manual, this.author);
}
public LegoSet withManual(Manual manual) {
return this.manual == manual ? this : new LegoSet(this.id, this.name, manual, this.author);
}
public LegoSet withAuthor(Author author) {
return this.author == author ? this : new LegoSet(this.id, this.name, this.manual, author);
}
}
@Value
@With
static class Manual {
static final class Manual {
@Id Long id;
String content;
@Id private final Long id;
private final String content;
public Manual(Long id, String content) {
this.id = id;
this.content = content;
}
public Long getId() {
return this.id;
}
public String getContent() {
return this.content;
}
public boolean equals(final Object o) {
if (o == this)
return true;
if (!(o instanceof Manual))
return false;
final Manual other = (Manual) o;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id))
return false;
final Object this$content = this.getContent();
final Object other$content = other.getContent();
if (this$content == null ? other$content != null : !this$content.equals(other$content))
return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
final Object $content = this.getContent();
result = result * PRIME + ($content == null ? 43 : $content.hashCode());
return result;
}
public String toString() {
return "ImmutableAggregateTemplateHsqlIntegrationTests.Manual(id=" + this.getId() + ", content="
+ this.getContent() + ")";
}
public Manual withId(Long id) {
return this.id == id ? this : new Manual(id, this.content);
}
public Manual withContent(String content) {
return this.content == content ? this : new Manual(this.id, content);
}
}
@Value
@With
static class Author {
static final class Author {
@Id Long id;
String name;
@Id private final Long id;
private final String name;
public Author(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public boolean equals(final Object o) {
if (o == this)
return true;
if (!(o instanceof Author))
return false;
final Author other = (Author) o;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id))
return false;
final Object this$name = this.getName();
final Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name))
return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
final Object $name = this.getName();
result = result * PRIME + ($name == null ? 43 : $name.hashCode());
return result;
}
public String toString() {
return "ImmutableAggregateTemplateHsqlIntegrationTests.Author(id=" + this.getId() + ", name=" + this.getName()
+ ")";
}
public Author withId(Long id) {
return this.id == id ? this : new Author(id, this.name);
}
public Author withName(String name) {
return this.name == name ? this : new Author(this.id, name);
}
}
@Data
@AllArgsConstructor
static class Root {
@Id private Long id;
private String name;
private NonRoot reference;
public Root(Long id, String name, NonRoot reference) {
this.id = id;
this.name = name;
this.reference = reference;
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public NonRoot getReference() {
return this.reference;
}
public void setId(Long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setReference(NonRoot reference) {
this.reference = reference;
}
}
@Value
@With
static class NonRoot {
@Id Long id;
String name;
static final class NonRoot {
@Id private final Long id;
private final String name;
public NonRoot(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public boolean equals(final Object o) {
if (o == this)
return true;
if (!(o instanceof NonRoot))
return false;
final NonRoot other = (NonRoot) o;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id))
return false;
final Object this$name = this.getName();
final Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name))
return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
final Object $name = this.getName();
result = result * PRIME + ($name == null ? 43 : $name.hashCode());
return result;
}
public String toString() {
return "ImmutableAggregateTemplateHsqlIntegrationTests.NonRoot(id=" + this.getId() + ", name=" + this.getName()
+ ")";
}
public NonRoot withId(Long id) {
return this.id == id ? this : new NonRoot(id, this.name);
}
public NonRoot withName(String name) {
return this.name == name ? this : new NonRoot(this.id, name);
}
}
static class WithCopyConstructor {

View File

@@ -15,16 +15,6 @@
*/
package org.springframework.data.jdbc.core;
import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import lombok.AllArgsConstructor;
import lombok.Value;
import lombok.With;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
@@ -42,6 +32,12 @@ import org.springframework.data.relational.core.mapping.RelationalMappingContext
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.lang.Nullable;
import java.util.List;
import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
/**
* Test for the {@link JdbcAggregateChangeExecutionContext} when operating on immutable classes.
*
@@ -181,17 +177,16 @@ public class JdbcAggregateChangeExecutorContextImmutableUnitTests {
.orElseThrow(() -> new IllegalArgumentException("No matching path found"));
}
@Value
@AllArgsConstructor
@With
private static class DummyEntity {
private static final class DummyEntity {
@Id Long id;
@Version long version;
@Id
private final Long id;
@Version
private final long version;
Content content;
private final Content content;
List<Content> list;
private final List<Content> list;
DummyEntity() {
@@ -200,17 +195,123 @@ public class JdbcAggregateChangeExecutorContextImmutableUnitTests {
content = null;
list = null;
}
public DummyEntity(Long id, long version, Content content, List<Content> list) {
this.id = id;
this.version = version;
this.content = content;
this.list = list;
}
public Long getId() {
return this.id;
}
public long getVersion() {
return this.version;
}
public Content getContent() {
return this.content;
}
public List<Content> getList() {
return this.list;
}
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof DummyEntity)) return false;
final DummyEntity other = (DummyEntity) o;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false;
if (this.getVersion() != other.getVersion()) return false;
final Object this$content = this.getContent();
final Object other$content = other.getContent();
if (this$content == null ? other$content != null : !this$content.equals(other$content)) return false;
final Object this$list = this.getList();
final Object other$list = other.getList();
if (this$list == null ? other$list != null : !this$list.equals(other$list)) return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
final long $version = this.getVersion();
result = result * PRIME + (int) ($version >>> 32 ^ $version);
final Object $content = this.getContent();
result = result * PRIME + ($content == null ? 43 : $content.hashCode());
final Object $list = this.getList();
result = result * PRIME + ($list == null ? 43 : $list.hashCode());
return result;
}
public String toString() {
return "JdbcAggregateChangeExecutorContextImmutableUnitTests.DummyEntity(id=" + this.getId() + ", version=" + this.getVersion() + ", content=" + this.getContent() + ", list=" + this.getList() + ")";
}
public DummyEntity withId(Long id) {
return this.id == id ? this : new DummyEntity(id, this.version, this.content, this.list);
}
public DummyEntity withVersion(long version) {
return this.version == version ? this : new DummyEntity(this.id, version, this.content, this.list);
}
public DummyEntity withContent(Content content) {
return this.content == content ? this : new DummyEntity(this.id, this.version, content, this.list);
}
public DummyEntity withList(List<Content> list) {
return this.list == list ? this : new DummyEntity(this.id, this.version, this.content, list);
}
}
@Value
@AllArgsConstructor
@With
private static class Content {
@Id Long id;
private static final class Content {
@Id
private final Long id;
Content() {
id = null;
}
public Content(Long id) {
this.id = id;
}
public Long getId() {
return this.id;
}
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof Content)) return false;
final Content other = (Content) o;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
return result;
}
public String toString() {
return "JdbcAggregateChangeExecutorContextImmutableUnitTests.Content(id=" + this.getId() + ")";
}
public Content withId(Long id) {
return this.id == id ? this : new Content(id);
}
}
}

View File

@@ -20,8 +20,6 @@ import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.jdbc.core.convert.JdbcIdentifierBuilder.*;
import lombok.Value;
import java.util.ArrayList;
import java.util.List;
@@ -287,9 +285,7 @@ public class JdbcAggregateChangeExecutorContextUnitTests {
@Id Long id;
}
@Value
private static class ContentImmutableId {
@Id Long id;
record ContentImmutableId(@Id Long id) {
}
}

View File

@@ -22,11 +22,6 @@ import static org.assertj.core.api.SoftAssertions.*;
import static org.springframework.data.jdbc.testing.TestDatabaseFeatures.Feature.*;
import static org.springframework.test.context.TestExecutionListeners.MergeMode.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Value;
import lombok.With;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
@@ -35,6 +30,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.IntStream;
@@ -188,11 +184,11 @@ class JdbcAggregateTemplateIntegrationTests {
private static LegoSet createLegoSet(String name) {
LegoSet entity = new LegoSet();
entity.setName(name);
entity.name = (name);
Manual manual = new Manual();
manual.setContent("Accelerates to 99% of light speed; Destroys almost everything. See https://what-if.xkcd.com/1/");
entity.setManual(manual);
manual.content = ("Accelerates to 99% of light speed; Destroys almost everything. See https://what-if.xkcd.com/1/");
entity.manual = (manual);
return entity;
}
@@ -205,15 +201,15 @@ class JdbcAggregateTemplateIntegrationTests {
assertThat(legoSet.manual.id).describedAs("id of stored manual").isNotNull();
LegoSet reloadedLegoSet = template.findById(legoSet.getId(), LegoSet.class);
LegoSet reloadedLegoSet = template.findById(legoSet.id, LegoSet.class);
assertThat(reloadedLegoSet.manual).isNotNull();
assertSoftly(softly -> {
softly.assertThat(reloadedLegoSet.manual.getId()) //
.isEqualTo(legoSet.getManual().getId()) //
softly.assertThat(reloadedLegoSet.manual.id) //
.isEqualTo(legoSet.manual.id) //
.isNotNull();
softly.assertThat(reloadedLegoSet.manual.getContent()).isEqualTo(legoSet.getManual().getContent());
softly.assertThat(reloadedLegoSet.manual.content).isEqualTo(legoSet.manual.content);
});
}
@@ -228,7 +224,7 @@ class JdbcAggregateTemplateIntegrationTests {
assertThat(reloadedLegoSets) //
.extracting("id", "manual.id", "manual.content") //
.containsExactly(tuple(legoSet.getId(), legoSet.getManual().getId(), legoSet.getManual().getContent()));
.containsExactly(tuple(legoSet.id, legoSet.manual.id, legoSet.manual.content));
}
@Test // DATAJDBC-101
@@ -277,38 +273,36 @@ class JdbcAggregateTemplateIntegrationTests {
.containsExactly("Frozen", "Star", null);
}
@Test //
@EnabledOnFeature({ SUPPORTS_QUOTED_IDS})
@EnabledOnFeature({ SUPPORTS_QUOTED_IDS })
void findByNonPropertySortFails() {
assertThatThrownBy(() -> template.findAll(LegoSet.class,
Sort.by("somethingNotExistant"))).isInstanceOf(InvalidPersistentPropertyPath.class);
assertThatThrownBy(() -> template.findAll(LegoSet.class, Sort.by("somethingNotExistant")))
.isInstanceOf(InvalidPersistentPropertyPath.class);
}
@Test // DATAJDBC-112
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void saveAndLoadManyEntitiesByIdWithReferencedEntity() {
template.save(legoSet);
Iterable<LegoSet> reloadedLegoSets = template.findAllById(singletonList(legoSet.getId()), LegoSet.class);
Iterable<LegoSet> reloadedLegoSets = template.findAllById(singletonList(legoSet.id), LegoSet.class);
assertThat(reloadedLegoSets).hasSize(1).extracting("id", "manual.id", "manual.content")
.contains(tuple(legoSet.getId(), legoSet.getManual().getId(), legoSet.getManual().getContent()));
.contains(tuple(legoSet.id, legoSet.manual.id, legoSet.manual.content));
}
@Test // DATAJDBC-112
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void saveAndLoadAnEntityWithReferencedNullEntity() {
legoSet.setManual(null);
legoSet.manual = (null);
template.save(legoSet);
LegoSet reloadedLegoSet = template.findById(legoSet.getId(), LegoSet.class);
LegoSet reloadedLegoSet = template.findById(legoSet.id, LegoSet.class);
assertThat(reloadedLegoSet.manual).isNull();
}
@@ -378,7 +372,8 @@ class JdbcAggregateTemplateIntegrationTests {
});
}
@Test // GH-537
@Test
// GH-537
void saveAndDeleteAllByAggregateRootsWithVersion() {
AggregateWithImmutableVersion aggregate1 = new AggregateWithImmutableVersion(null, null);
@@ -397,7 +392,8 @@ class JdbcAggregateTemplateIntegrationTests {
assertThat(template.count(AggregateWithImmutableVersion.class)).isEqualTo(0);
}
@Test // GH-1395
@Test
// GH-1395
void insertAndUpdateAllByAggregateRootsWithVersion() {
AggregateWithImmutableVersion aggregate1 = new AggregateWithImmutableVersion(null, null);
@@ -412,8 +408,8 @@ class JdbcAggregateTemplateIntegrationTests {
AggregateWithImmutableVersion twiceSavedAggregate2 = template.save(savedAggregatesIterator.next());
AggregateWithImmutableVersion twiceSavedAggregate3 = template.save(savedAggregatesIterator.next());
savedAggregatesIterator = template.updateAll(
List.of(savedAggregate1, twiceSavedAggregate2, twiceSavedAggregate3)).iterator();
savedAggregatesIterator = template.updateAll(List.of(savedAggregate1, twiceSavedAggregate2, twiceSavedAggregate3))
.iterator();
assertThat(savedAggregatesIterator.next().version).isEqualTo(1);
assertThat(savedAggregatesIterator.next().version).isEqualTo(2);
@@ -426,17 +422,17 @@ class JdbcAggregateTemplateIntegrationTests {
@EnabledOnFeature({ SUPPORTS_QUOTED_IDS, SUPPORTS_GENERATED_IDS_IN_REFERENCED_ENTITIES })
void updateReferencedEntityFromNull() {
legoSet.setManual(null);
legoSet.manual = (null);
template.save(legoSet);
Manual manual = new Manual();
manual.setId(23L);
manual.setContent("Some content");
legoSet.setManual(manual);
manual.id = (23L);
manual.content = ("Some content");
legoSet.manual = (manual);
template.save(legoSet);
LegoSet reloadedLegoSet = template.findById(legoSet.getId(), LegoSet.class);
LegoSet reloadedLegoSet = template.findById(legoSet.id, LegoSet.class);
assertThat(reloadedLegoSet.manual.content).isEqualTo("Some content");
}
@@ -447,11 +443,11 @@ class JdbcAggregateTemplateIntegrationTests {
template.save(legoSet);
legoSet.setManual(null);
legoSet.manual = (null);
template.save(legoSet);
LegoSet reloadedLegoSet = template.findById(legoSet.getId(), LegoSet.class);
LegoSet reloadedLegoSet = template.findById(legoSet.id, LegoSet.class);
SoftAssertions softly = new SoftAssertions();
@@ -461,11 +457,12 @@ class JdbcAggregateTemplateIntegrationTests {
softly.assertAll();
}
@Test // DATAJDBC-438
@Test
// DATAJDBC-438
void updateFailedRootDoesNotExist() {
LegoSet entity = new LegoSet();
entity.setId(100L); // does not exist in the database
entity.id = (100L); // does not exist in the database
assertThatExceptionOfType(DbActionExecutionException.class) //
.isThrownBy(() -> template.save(entity)) //
@@ -479,12 +476,12 @@ class JdbcAggregateTemplateIntegrationTests {
template.save(legoSet);
Manual manual = new Manual();
manual.setContent("other content");
legoSet.setManual(manual);
manual.content = ("other content");
legoSet.manual = (manual);
template.save(legoSet);
LegoSet reloadedLegoSet = template.findById(legoSet.getId(), LegoSet.class);
LegoSet reloadedLegoSet = template.findById(legoSet.id, LegoSet.class);
assertSoftly(softly -> {
@@ -499,11 +496,11 @@ class JdbcAggregateTemplateIntegrationTests {
template.save(legoSet);
legoSet.manual.setContent("new content");
legoSet.manual.content = ("new content");
template.save(legoSet);
LegoSet reloadedLegoSet = template.findById(legoSet.getId(), LegoSet.class);
LegoSet reloadedLegoSet = template.findById(legoSet.id, LegoSet.class);
assertThat(reloadedLegoSet.manual.content).isEqualTo("new content");
}
@@ -565,7 +562,7 @@ class JdbcAggregateTemplateIntegrationTests {
assertThat(legoSet.manual.id).describedAs("id of stored manual").isNotNull();
LegoSet reloadedLegoSet = template.findById(legoSet.getId(), LegoSet.class);
LegoSet reloadedLegoSet = template.findById(legoSet.id, LegoSet.class);
assertThat(reloadedLegoSet.alternativeInstructions).isNull();
}
@@ -580,7 +577,7 @@ class JdbcAggregateTemplateIntegrationTests {
assertThat(legoSet.manual.id).describedAs("id of stored manual").isNotNull();
LegoSet reloadedLegoSet = template.findById(legoSet.getId(), LegoSet.class);
LegoSet reloadedLegoSet = template.findById(legoSet.id, LegoSet.class);
assertSoftly(softly -> {
@@ -736,7 +733,8 @@ class JdbcAggregateTemplateIntegrationTests {
assertThat(reloaded.digits).isEqualTo(new HashSet<>(asList("one", "two", "three")));
}
@Test // DATAJDBC-327
@Test
// DATAJDBC-327
void saveAndLoadAnEntityWithByteArray() {
ByteArrayOwner owner = new ByteArrayOwner();
@@ -811,7 +809,8 @@ class JdbcAggregateTemplateIntegrationTests {
assertThat(count("CHAIN0")).isEqualTo(0);
}
@Test // DATAJDBC-223
@Test
// DATAJDBC-223
void saveAndLoadLongChainOfListsWithoutIds() {
NoIdListChain4 saved = template.save(createNoIdTree());
@@ -822,7 +821,8 @@ class JdbcAggregateTemplateIntegrationTests {
assertThat(reloaded).isEqualTo(saved);
}
@Test // DATAJDBC-223
@Test
// DATAJDBC-223
void shouldDeleteChainOfListsWithoutIds() {
NoIdListChain4 saved = template.save(createNoIdTree());
@@ -838,7 +838,8 @@ class JdbcAggregateTemplateIntegrationTests {
});
}
@Test // DATAJDBC-223
@Test
// DATAJDBC-223
void saveAndLoadLongChainOfMapsWithoutIds() {
NoIdMapChain4 saved = template.save(createNoIdMapTree());
@@ -849,7 +850,8 @@ class JdbcAggregateTemplateIntegrationTests {
assertThat(reloaded).isEqualTo(saved);
}
@Test // DATAJDBC-223
@Test
// DATAJDBC-223
void shouldDeleteChainOfMapsWithoutIds() {
NoIdMapChain4 saved = template.save(createNoIdMapTree());
@@ -880,14 +882,15 @@ class JdbcAggregateTemplateIntegrationTests {
.isEqualTo("from-db");
}
@Test // DATAJDBC-219 Test that immutable version attribute works as expected.
@Test
// DATAJDBC-219 Test that immutable version attribute works as expected.
void saveAndUpdateAggregateWithImmutableVersion() {
AggregateWithImmutableVersion aggregate = new AggregateWithImmutableVersion(null, null);
aggregate = template.save(aggregate);
assertThat(aggregate.version).isEqualTo(0L);
Long id = aggregate.getId();
Long id = aggregate.id;
AggregateWithImmutableVersion reloadedAggregate = template.findById(id, aggregate.getClass());
assertThat(reloadedAggregate.getVersion()).describedAs("version field should initially have the value 0")
@@ -911,7 +914,8 @@ class JdbcAggregateTemplateIntegrationTests {
.isInstanceOf(OptimisticLockingFailureException.class);
}
@Test // GH-1137
@Test
// GH-1137
void testUpdateEntityWithVersionDoesNotTriggerAnewConstructorInvocation() {
AggregateWithImmutableVersion aggregateWithImmutableVersion = new AggregateWithImmutableVersion(null, null);
@@ -939,7 +943,8 @@ class JdbcAggregateTemplateIntegrationTests {
.containsOnly(new ConstructorInvocation(savedRoot.id, updatedRoot.version));
}
@Test // DATAJDBC-219 Test that a delete with a version attribute works as expected.
@Test
// DATAJDBC-219 Test that a delete with a version attribute works as expected.
void deleteAggregateWithVersion() {
AggregateWithImmutableVersion aggregate = new AggregateWithImmutableVersion(null, null);
@@ -948,17 +953,15 @@ class JdbcAggregateTemplateIntegrationTests {
aggregate = template.save(aggregate);
// Should have an ID and a version of 1.
final Long id = aggregate.getId();
final Long id = aggregate.id;
assertThatThrownBy(
() -> template.delete(new AggregateWithImmutableVersion(id, 0L)))
.describedAs("deleting an aggregate with an outdated version should raise an exception")
.isInstanceOf(OptimisticLockingFailureException.class);
assertThatThrownBy(() -> template.delete(new AggregateWithImmutableVersion(id, 0L)))
.describedAs("deleting an aggregate with an outdated version should raise an exception")
.isInstanceOf(OptimisticLockingFailureException.class);
assertThatThrownBy(
() -> template.delete(new AggregateWithImmutableVersion(id, 2L)))
.describedAs("deleting an aggregate with a future version should raise an exception")
.isInstanceOf(OptimisticLockingFailureException.class);
assertThatThrownBy(() -> template.delete(new AggregateWithImmutableVersion(id, 2L)))
.describedAs("deleting an aggregate with a future version should raise an exception")
.isInstanceOf(OptimisticLockingFailureException.class);
// This should succeed
template.delete(aggregate);
@@ -967,41 +970,48 @@ class JdbcAggregateTemplateIntegrationTests {
aggregate = template.save(aggregate);
// This should succeed, as version will not be used.
template.deleteById(aggregate.getId(), AggregateWithImmutableVersion.class);
template.deleteById(aggregate.id, AggregateWithImmutableVersion.class);
}
@Test // DATAJDBC-219
@Test
// DATAJDBC-219
void saveAndUpdateAggregateWithLongVersion() {
saveAndUpdateAggregateWithVersion(new AggregateWithLongVersion(), Number::longValue);
}
@Test // DATAJDBC-219
@Test
// DATAJDBC-219
void saveAndUpdateAggregateWithPrimitiveLongVersion() {
saveAndUpdateAggregateWithPrimitiveVersion(new AggregateWithPrimitiveLongVersion(), Number::longValue);
}
@Test // DATAJDBC-219
@Test
// DATAJDBC-219
void saveAndUpdateAggregateWithIntegerVersion() {
saveAndUpdateAggregateWithVersion(new AggregateWithIntegerVersion(), Number::intValue);
}
@Test // DATAJDBC-219
@Test
// DATAJDBC-219
void saveAndUpdateAggregateWithPrimitiveIntegerVersion() {
saveAndUpdateAggregateWithPrimitiveVersion(new AggregateWithPrimitiveIntegerVersion(), Number::intValue);
}
@Test // DATAJDBC-219
@Test
// DATAJDBC-219
void saveAndUpdateAggregateWithShortVersion() {
saveAndUpdateAggregateWithVersion(new AggregateWithShortVersion(), Number::shortValue);
}
@Test // DATAJDBC-219
@Test
// DATAJDBC-219
void saveAndUpdateAggregateWithPrimitiveShortVersion() {
saveAndUpdateAggregateWithPrimitiveVersion(new AggregateWithPrimitiveShortVersion(), Number::shortValue);
}
@Test // GH-1254
@Test
// GH-1254
void saveAndUpdateAggregateWithIdAndNullVersion() {
PersistableVersionedAggregate aggregate = new PersistableVersionedAggregate();
@@ -1037,7 +1047,8 @@ class JdbcAggregateTemplateIntegrationTests {
assertThat(loaded.testTime).isEqualTo(entity.testTime);
}
@Test // DATAJDBC-637
@Test
// DATAJDBC-637
void saveAndLoadDateTimeWithMicrosecondPrecision() {
WithLocalDateTime entity = new WithLocalDateTime();
@@ -1051,7 +1062,8 @@ class JdbcAggregateTemplateIntegrationTests {
assertThat(loaded.testTime).isEqualTo(entity.testTime);
}
@Test // GH-777
@Test
// GH-777
void insertWithIdOnly() {
WithIdOnly entity = new WithIdOnly();
@@ -1059,7 +1071,8 @@ class JdbcAggregateTemplateIntegrationTests {
assertThat(template.save(entity).id).isNotNull();
}
@Test // GH-1309
@Test
// GH-1309
void updateIdOnlyAggregate() {
WithIdOnly entity = new WithIdOnly();
@@ -1069,7 +1082,8 @@ class JdbcAggregateTemplateIntegrationTests {
template.save(entity);
}
@Test // GH-637
@Test
// GH-637
void insertOnlyPropertyDoesNotGetUpdated() {
WithInsertOnly entity = new WithInsertOnly();
@@ -1088,11 +1102,11 @@ class JdbcAggregateTemplateIntegrationTests {
void readEnumArray() {
EnumArrayOwner entity = new EnumArrayOwner();
entity.digits = new Color[]{Color.BLUE};
entity.digits = new Color[] { Color.BLUE };
template.save(entity);
assertThat(template.findById(entity.id, EnumArrayOwner.class).digits).isEqualTo(new Color[]{Color.BLUE});
assertThat(template.findById(entity.id, EnumArrayOwner.class).digits).isEqualTo(new Color[] { Color.BLUE });
}
private <T extends Number> void saveAndUpdateAggregateWithVersion(VersionedAggregate aggregate,
@@ -1110,13 +1124,13 @@ class JdbcAggregateTemplateIntegrationTests {
template.save(aggregate);
VersionedAggregate reloadedAggregate = template.findById(aggregate.getId(), aggregate.getClass());
VersionedAggregate reloadedAggregate = template.findById(aggregate.id, aggregate.getClass());
assertThat(reloadedAggregate.getVersion()) //
.withFailMessage("version field should initially have the value 0")
.isEqualTo(toConcreteNumber.apply(initialId));
template.save(reloadedAggregate);
VersionedAggregate updatedAggregate = template.findById(aggregate.getId(), aggregate.getClass());
VersionedAggregate updatedAggregate = template.findById(aggregate.id, aggregate.getClass());
assertThat(updatedAggregate.getVersion()) //
.withFailMessage("version field should increment by one with each save")
.isEqualTo(toConcreteNumber.apply(initialId + 1));
@@ -1189,10 +1203,10 @@ class JdbcAggregateTemplateIntegrationTests {
List<Float> digits = new ArrayList<>();
}
@Data
static class LegoSet {
@Column("id1") @Id private Long id;
@Column("id1")
@Id private Long id;
private String name;
@@ -1200,10 +1214,10 @@ class JdbcAggregateTemplateIntegrationTests {
@Column("alternative") private Manual alternativeInstructions;
}
@Data
static class Manual {
@Column("id2") @Id private Long id;
@Column("id2")
@Id private Long id;
private String content;
}
@@ -1211,7 +1225,8 @@ class JdbcAggregateTemplateIntegrationTests {
@SuppressWarnings("unused")
static class OneToOneParent {
@Column("id3") @Id private Long id;
@Column("id3")
@Id private Long id;
private String content;
private ChildNoId child;
@@ -1225,7 +1240,8 @@ class JdbcAggregateTemplateIntegrationTests {
@SuppressWarnings("unused")
static class ListParent {
@Column("id4") @Id private Long id;
@Column("id4")
@Id private Long id;
String name;
@MappedCollection(idColumn = "LIST_PARENT") List<ElementNoId> content = new ArrayList<>();
}
@@ -1233,7 +1249,8 @@ class JdbcAggregateTemplateIntegrationTests {
@Table("LIST_PARENT")
static class ListParentAllArgs {
@Column("id4") @Id private final Long id;
@Column("id4")
@Id private final Long id;
private final String name;
@MappedCollection(idColumn = "LIST_PARENT") private final List<ElementNoId> content = new ArrayList<>();
@@ -1321,67 +1338,209 @@ class JdbcAggregateTemplateIntegrationTests {
/**
* One may think of ChainN as a chain with N further elements
*/
@EqualsAndHashCode
static class NoIdListChain0 {
String zeroValue;
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
NoIdListChain0 that = (NoIdListChain0) o;
return Objects.equals(zeroValue, that.zeroValue);
}
@Override
public int hashCode() {
return Objects.hash(zeroValue);
}
}
@EqualsAndHashCode
static class NoIdListChain1 {
String oneValue;
List<NoIdListChain0> chain0 = new ArrayList<>();
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
NoIdListChain1 that = (NoIdListChain1) o;
return Objects.equals(oneValue, that.oneValue) && Objects.equals(chain0, that.chain0);
}
@Override
public int hashCode() {
return Objects.hash(oneValue, chain0);
}
}
@EqualsAndHashCode
static class NoIdListChain2 {
String twoValue;
List<NoIdListChain1> chain1 = new ArrayList<>();
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
NoIdListChain2 that = (NoIdListChain2) o;
return Objects.equals(twoValue, that.twoValue) && Objects.equals(chain1, that.chain1);
}
@Override
public int hashCode() {
return Objects.hash(twoValue, chain1);
}
}
@EqualsAndHashCode
static class NoIdListChain3 {
String threeValue;
List<NoIdListChain2> chain2 = new ArrayList<>();
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
NoIdListChain3 that = (NoIdListChain3) o;
return Objects.equals(threeValue, that.threeValue) && Objects.equals(chain2, that.chain2);
}
@Override
public int hashCode() {
return Objects.hash(threeValue, chain2);
}
}
@EqualsAndHashCode
static class NoIdListChain4 {
@Id Long four;
String fourValue;
List<NoIdListChain3> chain3 = new ArrayList<>();
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
NoIdListChain4 that = (NoIdListChain4) o;
return Objects.equals(four, that.four) && Objects.equals(fourValue, that.fourValue)
&& Objects.equals(chain3, that.chain3);
}
@Override
public int hashCode() {
return Objects.hash(four, fourValue, chain3);
}
}
/**
* One may think of ChainN as a chain with N further elements
*/
@EqualsAndHashCode
static class NoIdMapChain0 {
String zeroValue;
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
NoIdMapChain0 that = (NoIdMapChain0) o;
return Objects.equals(zeroValue, that.zeroValue);
}
@Override
public int hashCode() {
return Objects.hash(zeroValue);
}
}
@EqualsAndHashCode
static class NoIdMapChain1 {
String oneValue;
Map<String, NoIdMapChain0> chain0 = new HashMap<>();
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
NoIdMapChain1 that = (NoIdMapChain1) o;
return Objects.equals(oneValue, that.oneValue) && Objects.equals(chain0, that.chain0);
}
@Override
public int hashCode() {
return Objects.hash(oneValue, chain0);
}
}
@EqualsAndHashCode
static class NoIdMapChain2 {
String twoValue;
Map<String, NoIdMapChain1> chain1 = new HashMap<>();
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
NoIdMapChain2 that = (NoIdMapChain2) o;
return Objects.equals(twoValue, that.twoValue) && Objects.equals(chain1, that.chain1);
}
@Override
public int hashCode() {
return Objects.hash(twoValue, chain1);
}
}
@EqualsAndHashCode
static class NoIdMapChain3 {
String threeValue;
Map<String, NoIdMapChain2> chain2 = new HashMap<>();
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
NoIdMapChain3 that = (NoIdMapChain3) o;
return Objects.equals(threeValue, that.threeValue) && Objects.equals(chain2, that.chain2);
}
@Override
public int hashCode() {
return Objects.hash(threeValue, chain2);
}
}
@EqualsAndHashCode
static class NoIdMapChain4 {
@Id Long four;
String fourValue;
Map<String, NoIdMapChain3> chain3 = new HashMap<>();
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
NoIdMapChain4 that = (NoIdMapChain4) o;
return Objects.equals(four, that.four) && Objects.equals(fourValue, that.fourValue)
&& Objects.equals(chain3, that.chain3);
}
@Override
public int hashCode() {
return Objects.hash(four, fourValue, chain3);
}
}
@SuppressWarnings("unused")
@@ -1391,7 +1550,6 @@ class JdbcAggregateTemplateIntegrationTests {
@ReadOnlyProperty String readOnly;
}
@Data
static abstract class VersionedAggregate {
@Id private Long id;
@@ -1401,7 +1559,6 @@ class JdbcAggregateTemplateIntegrationTests {
abstract void setVersion(Number newVersion);
}
@Data
@Table("VERSIONED_AGGREGATE")
static class PersistableVersionedAggregate implements Persistable<Long> {
@@ -1413,15 +1570,29 @@ class JdbcAggregateTemplateIntegrationTests {
public boolean isNew() {
return getId() == null;
}
public Long getId() {
return this.id;
}
public Long getVersion() {
return this.version;
}
public void setId(Long id) {
this.id = id;
}
public void setVersion(Long version) {
this.version = version;
}
}
@Value
@With
@Table("VERSIONED_AGGREGATE")
static class AggregateWithImmutableVersion {
static final class AggregateWithImmutableVersion {
@Id Long id;
@Version Long version;
@Id private final Long id;
@Version private final Long version;
private final static List<ConstructorInvocation> constructorInvocations = new ArrayList<>();
@@ -1435,17 +1606,107 @@ class JdbcAggregateTemplateIntegrationTests {
this.id = id;
this.version = version;
}
public Long getId() {
return this.id;
}
public Long getVersion() {
return this.version;
}
public boolean equals(final Object o) {
if (o == this)
return true;
if (!(o instanceof AggregateWithImmutableVersion))
return false;
final AggregateWithImmutableVersion other = (AggregateWithImmutableVersion) o;
final Object this$id = this.id;
final Object other$id = other.id;
if (this$id == null ? other$id != null : !this$id.equals(other$id))
return false;
final Object this$version = this.getVersion();
final Object other$version = other.getVersion();
if (this$version == null ? other$version != null : !this$version.equals(other$version))
return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.id;
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
final Object $version = this.getVersion();
result = result * PRIME + ($version == null ? 43 : $version.hashCode());
return result;
}
public String toString() {
return "JdbcAggregateTemplateIntegrationTests.AggregateWithImmutableVersion(id=" + this.id + ", version="
+ this.getVersion() + ")";
}
public AggregateWithImmutableVersion withId(Long id) {
return this.id == id ? this : new AggregateWithImmutableVersion(id, this.version);
}
public AggregateWithImmutableVersion withVersion(Long version) {
return this.version == version ? this : new AggregateWithImmutableVersion(this.id, version);
}
}
@Value
@EqualsAndHashCode
private static class ConstructorInvocation {
private static final class ConstructorInvocation {
Long id;
Long version;
private final Long id;
private final Long version;
public ConstructorInvocation(Long id, Long version) {
this.id = id;
this.version = version;
}
public Long getId() {
return this.id;
}
public Long getVersion() {
return this.version;
}
public String toString() {
return "JdbcAggregateTemplateIntegrationTests.ConstructorInvocation(id=" + this.id + ", version="
+ this.getVersion() + ")";
}
public boolean equals(final Object o) {
if (o == this)
return true;
if (!(o instanceof ConstructorInvocation))
return false;
final ConstructorInvocation other = (ConstructorInvocation) o;
final Object this$id = this.id;
final Object other$id = other.id;
if (this$id == null ? other$id != null : !this$id.equals(other$id))
return false;
final Object this$version = this.getVersion();
final Object other$version = other.getVersion();
if (this$version == null ? other$version != null : !this$version.equals(other$version))
return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.id;
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
final Object $version = this.getVersion();
result = result * PRIME + ($version == null ? 43 : $version.hashCode());
return result;
}
}
@Data
@Table("VERSIONED_AGGREGATE")
static class AggregateWithLongVersion extends VersionedAggregate {
@@ -1455,6 +1716,10 @@ class JdbcAggregateTemplateIntegrationTests {
void setVersion(Number newVersion) {
this.version = (Long) newVersion;
}
public Long getVersion() {
return this.version;
}
}
@Table("VERSIONED_AGGREGATE")
@@ -1473,7 +1738,6 @@ class JdbcAggregateTemplateIntegrationTests {
}
}
@Data
@Table("VERSIONED_AGGREGATE")
static class AggregateWithIntegerVersion extends VersionedAggregate {
@@ -1483,6 +1747,10 @@ class JdbcAggregateTemplateIntegrationTests {
void setVersion(Number newVersion) {
this.version = (Integer) newVersion;
}
public Integer getVersion() {
return this.version;
}
}
@Table("VERSIONED_AGGREGATE")
@@ -1501,7 +1769,6 @@ class JdbcAggregateTemplateIntegrationTests {
}
}
@Data
@Table("VERSIONED_AGGREGATE")
static class AggregateWithShortVersion extends VersionedAggregate {
@@ -1511,6 +1778,10 @@ class JdbcAggregateTemplateIntegrationTests {
void setVersion(Number newVersion) {
this.version = (Short) newVersion;
}
public Short getVersion() {
return this.version;
}
}
@Table("VERSIONED_AGGREGATE")
@@ -1544,8 +1815,7 @@ class JdbcAggregateTemplateIntegrationTests {
@Table
static class WithInsertOnly {
@Id Long id;
@InsertOnlyProperty
String insertOnly;
@InsertOnlyProperty String insertOnly;
}
@Configuration

View File

@@ -15,15 +15,6 @@
*/
package org.springframework.data.jdbc.core;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -50,6 +41,11 @@ import org.springframework.data.relational.core.mapping.event.BeforeConvertCallb
import org.springframework.data.relational.core.mapping.event.BeforeDeleteCallback;
import org.springframework.data.relational.core.mapping.event.BeforeSaveCallback;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
/**
* Unit tests for {@link JdbcAggregateTemplate}.
*
@@ -63,10 +59,14 @@ public class JdbcAggregateTemplateUnitTests {
JdbcAggregateTemplate template;
@Mock DataAccessStrategy dataAccessStrategy;
@Mock ApplicationEventPublisher eventPublisher;
@Mock RelationResolver relationResolver;
@Mock EntityCallbacks callbacks;
@Mock
DataAccessStrategy dataAccessStrategy;
@Mock
ApplicationEventPublisher eventPublisher;
@Mock
RelationResolver relationResolver;
@Mock
EntityCallbacks callbacks;
@BeforeEach
public void setUp() {
@@ -129,7 +129,8 @@ public class JdbcAggregateTemplateUnitTests {
verifyNoInteractions(eventPublisher);
}
@Test // GH-1137
@Test
// GH-1137
void savePreparesInstanceWithInitialVersion_onInsert() {
EntityWithVersion entity = new EntityWithVersion(1L);
@@ -144,7 +145,8 @@ public class JdbcAggregateTemplateUnitTests {
assertThat(afterConvert.getVersion()).isEqualTo(0L);
}
@Test // GH-1137
@Test
// GH-1137
void savePreparesInstanceWithInitialVersion_onInsert_whenVersionPropertyIsImmutable() {
EntityWithImmutableVersion entity = new EntityWithImmutableVersion(1L, null);
@@ -159,7 +161,8 @@ public class JdbcAggregateTemplateUnitTests {
assertThat(afterConvert.getVersion()).isEqualTo(0L);
}
@Test // GH-1137
@Test
// GH-1137
void savePreparesInstanceWithInitialVersion_onInsert_whenVersionPropertyIsPrimitiveType() {
EntityWithPrimitiveVersion entity = new EntityWithPrimitiveVersion(1L);
@@ -174,7 +177,8 @@ public class JdbcAggregateTemplateUnitTests {
assertThat(afterConvert.getVersion()).isEqualTo(1L);
}
@Test // GH-1137
@Test
// GH-1137
void savePreparesInstanceWithInitialVersion_onInsert__whenVersionPropertyIsImmutableAndPrimitiveType() {
EntityWithImmutablePrimitiveVersion entity = new EntityWithImmutablePrimitiveVersion(1L, 0L);
@@ -190,7 +194,8 @@ public class JdbcAggregateTemplateUnitTests {
assertThat(afterConvert.getVersion()).isEqualTo(1L);
}
@Test // GH-1137
@Test
// GH-1137
void savePreparesChangeWithPreviousVersion_onUpdate() {
when(dataAccessStrategy.updateWithVersion(any(), any(), any())).thenReturn(true);
@@ -207,7 +212,8 @@ public class JdbcAggregateTemplateUnitTests {
assertThat(aggregateChange.getPreviousVersion()).isEqualTo(1L);
}
@Test // GH-1137
@Test
// GH-1137
void savePreparesInstanceWithNextVersion_onUpdate() {
when(dataAccessStrategy.updateWithVersion(any(), any(), any())).thenReturn(true);
@@ -224,7 +230,8 @@ public class JdbcAggregateTemplateUnitTests {
assertThat(afterConvert.getVersion()).isEqualTo(2L);
}
@Test // GH-1137
@Test
// GH-1137
void savePreparesInstanceWithNextVersion_onUpdate_whenVersionPropertyIsImmutable() {
when(dataAccessStrategy.updateWithVersion(any(), any(), any())).thenReturn(true);
@@ -239,7 +246,8 @@ public class JdbcAggregateTemplateUnitTests {
assertThat(afterConvert.getVersion()).isEqualTo(2L);
}
@Test // GH-1137
@Test
// GH-1137
void deletePreparesChangeWithPreviousVersion_onDeleteByInstance() {
EntityWithImmutableVersion entity = new EntityWithImmutableVersion(1L, 1L);
@@ -337,48 +345,131 @@ public class JdbcAggregateTemplateUnitTests {
template.deleteAllById(emptyList(), SampleEntity.class);
}
@Data
@AllArgsConstructor
private static class SampleEntity {
@Column("id1") @Id private Long id;
@Column("id1")
@Id
private Long id;
private String name;
public SampleEntity(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public void setId(Long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
}
@Data
@RequiredArgsConstructor
private static class EntityWithVersion {
@Column("id1") @Id private final Long id;
@Column("id1")
@Id
private final Long id;
@Version private Long version;
@Version
private Long version;
public EntityWithVersion(Long id) {
this.id = id;
}
public Long getId() {
return this.id;
}
public Long getVersion() {
return this.version;
}
public void setVersion(Long version) {
this.version = version;
}
}
@Data
@RequiredArgsConstructor
private static class EntityWithImmutableVersion {
@Column("id1") @Id private final Long id;
@Column("id1")
@Id
private final Long id;
@Version private final Long version;
@Version
private final Long version;
public EntityWithImmutableVersion(Long id, Long version) {
this.id = id;
this.version = version;
}
public Long getId() {
return this.id;
}
public Long getVersion() {
return this.version;
}
}
@Data
@RequiredArgsConstructor
private static class EntityWithPrimitiveVersion {
@Column("id1") @Id private final Long id;
@Column("id1")
@Id
private final Long id;
@Version private long version;
@Version
private long version;
public EntityWithPrimitiveVersion(Long id) {
this.id = id;
}
public Long getId() {
return this.id;
}
public long getVersion() {
return this.version;
}
public void setVersion(long version) {
this.version = version;
}
}
@Data
@RequiredArgsConstructor
private static class EntityWithImmutablePrimitiveVersion {
@Column("id1") @Id private final Long id;
@Column("id1")
@Id
private final Long id;
@Version private final long version;
@Version
private final long version;
public EntityWithImmutablePrimitiveVersion(Long id, long version) {
this.id = id;
this.version = version;
}
public Long getId() {
return this.id;
}
public long getVersion() {
return this.version;
}
}
}

View File

@@ -16,8 +16,6 @@ package org.springframework.data.jdbc.core;
* limitations under the License.
*/
import lombok.experimental.UtilityClass;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.mapping.PersistentPropertyPaths;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
@@ -28,8 +26,11 @@ import org.springframework.data.relational.core.mapping.RelationalPersistentProp
*
* @author Jens Schauder
*/
@UtilityClass
public class PropertyPathTestingUtils {
public final class PropertyPathTestingUtils {
private PropertyPathTestingUtils() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}
public static PersistentPropertyPath<RelationalPersistentProperty> toPath(String path, Class source,
RelationalMappingContext context) {

View File

@@ -19,8 +19,6 @@ import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.SoftAssertions.*;
import static org.mockito.Mockito.*;
import lombok.Data;
import java.sql.Array;
import java.sql.Timestamp;
import java.time.Instant;
@@ -161,7 +159,6 @@ public class BasicJdbcConverterUnitTests {
softly.assertThat(converter.getColumnType(property)).describedAs(propertyName).isEqualTo(expected);
}
@Data
@SuppressWarnings("unused")
private static class DummyEntity {
@@ -184,6 +181,91 @@ public class BasicJdbcConverterUnitTests {
private final List<OtherEntity> listOfEntity;
private final OtherEntity[] arrayOfEntity;
private DummyEntity(Long id, SomeEnum someEnum, LocalDateTime localDateTime, LocalDate localDate,
LocalTime localTime, ZonedDateTime zonedDateTime, OffsetDateTime offsetDateTime, Instant instant, Date date,
Timestamp timestamp, AggregateReference<DummyEntity, Long> reference, UUID uuid, List<String> listOfString,
String[] arrayOfString, List<OtherEntity> listOfEntity, OtherEntity[] arrayOfEntity) {
this.id = id;
this.someEnum = someEnum;
this.localDateTime = localDateTime;
this.localDate = localDate;
this.localTime = localTime;
this.zonedDateTime = zonedDateTime;
this.offsetDateTime = offsetDateTime;
this.instant = instant;
this.date = date;
this.timestamp = timestamp;
this.reference = reference;
this.uuid = uuid;
this.listOfString = listOfString;
this.arrayOfString = arrayOfString;
this.listOfEntity = listOfEntity;
this.arrayOfEntity = arrayOfEntity;
}
public Long getId() {
return this.id;
}
public SomeEnum getSomeEnum() {
return this.someEnum;
}
public LocalDateTime getLocalDateTime() {
return this.localDateTime;
}
public LocalDate getLocalDate() {
return this.localDate;
}
public LocalTime getLocalTime() {
return this.localTime;
}
public ZonedDateTime getZonedDateTime() {
return this.zonedDateTime;
}
public OffsetDateTime getOffsetDateTime() {
return this.offsetDateTime;
}
public Instant getInstant() {
return this.instant;
}
public Date getDate() {
return this.date;
}
public Timestamp getTimestamp() {
return this.timestamp;
}
public AggregateReference<DummyEntity, Long> getReference() {
return this.reference;
}
public UUID getUuid() {
return this.uuid;
}
public List<String> getListOfString() {
return this.listOfString;
}
public String[] getArrayOfString() {
return this.arrayOfString;
}
public List<OtherEntity> getListOfEntity() {
return this.listOfEntity;
}
public OtherEntity[] getArrayOfEntity() {
return this.arrayOfEntity;
}
}
@SuppressWarnings("unused")

View File

@@ -19,8 +19,6 @@ import static java.util.Collections.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import lombok.RequiredArgsConstructor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.data.annotation.Id;
@@ -114,15 +112,21 @@ class DefaultDataAccessStrategyUnitTests {
verify(insertStrategyFactory).batchInsertStrategy(IdValueSource.GENERATED, null);
}
@RequiredArgsConstructor
private static class DummyEntity {
@Id private final Long id;
public DummyEntity(Long id) {
this.id = id;
}
}
@RequiredArgsConstructor
private static class DummyEntityWithoutIdAnnotation {
private final Long id;
public DummyEntityWithoutIdAnnotation(Long id) {
this.id = id;
}
}
}

View File

@@ -15,35 +15,6 @@
*/
package org.springframework.data.jdbc.core.convert;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.SoftAssertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import lombok.With;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.naming.OperationNotSupportedException;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.invocation.InvocationOnMock;
@@ -66,6 +37,26 @@ import org.springframework.data.repository.query.Param;
import org.springframework.util.Assert;
import org.springframework.util.LinkedCaseInsensitiveMap;
import javax.naming.OperationNotSupportedException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.SoftAssertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
/**
* Tests the extraction of entities from a {@link ResultSet} by the {@link EntityRowMapper}.
*
@@ -82,12 +73,7 @@ public class EntityRowMapperUnitTests {
static final long ID_FOR_ENTITY_REFERENCING_MAP = 42L;
static final long ID_FOR_ENTITY_REFERENCING_LIST = 4711L;
static final long ID_FOR_ENTITY_NOT_REFERENCING_MAP = 23L;
static final NamingStrategy X_APPENDING_NAMINGSTRATEGY = new NamingStrategy() {
@Override
public String getColumnName(RelationalPersistentProperty property) {
return NamingStrategy.super.getColumnName(property).concat("x");
}
};
static final NamingStrategy X_APPENDING_NAMINGSTRATEGY=new NamingStrategy(){@Override public String getColumnName(RelationalPersistentProperty property){return NamingStrategy.super.getColumnName(property).concat("x");}};
@Test // DATAJDBC-113
void simpleEntitiesGetProperlyExtracted() throws SQLException {
@@ -647,55 +633,235 @@ public class EntityRowMapperUnitTests {
// Model classes to be used in tests
@With
@RequiredArgsConstructor
static class TrivialImmutable {
@Id private final Long id;
@Id
private final Long id;
private final String name;
public TrivialImmutable(Long id, String name) {
this.id = id;
this.name = name;
}
public TrivialImmutable withId(Long id) {
return this.id == id ? this : new TrivialImmutable(id, this.name);
}
public TrivialImmutable withName(String name) {
return this.name == name ? this : new TrivialImmutable(this.id, name);
}
}
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
@Getter
static class Trivial {
@Id Long id;
@Id
Long id;
String name;
public Trivial(Long id, String name) {
this.id = id;
this.name = name;
}
public Trivial() {
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof Trivial)) return false;
final Trivial other = (Trivial) o;
if (!other.canEqual((Object) this)) return false;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false;
final Object this$name = this.getName();
final Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
return true;
}
protected boolean canEqual(final Object other) {
return other instanceof Trivial;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
final Object $name = this.getName();
result = result * PRIME + ($name == null ? 43 : $name.hashCode());
return result;
}
}
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
@Getter
static class TrivialMapPropertiesToNullIfNotNeeded {
@Id Long id;
@Id
Long id;
int age;
String phone;
Boolean isSupreme;
long referenceToCustomer;
public TrivialMapPropertiesToNullIfNotNeeded(Long id, int age, String phone, Boolean isSupreme, long referenceToCustomer) {
this.id = id;
this.age = age;
this.phone = phone;
this.isSupreme = isSupreme;
this.referenceToCustomer = referenceToCustomer;
}
public TrivialMapPropertiesToNullIfNotNeeded() {
}
public Long getId() {
return this.id;
}
public int getAge() {
return this.age;
}
public String getPhone() {
return this.phone;
}
public Boolean getIsSupreme() {
return this.isSupreme;
}
public long getReferenceToCustomer() {
return this.referenceToCustomer;
}
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof TrivialMapPropertiesToNullIfNotNeeded)) return false;
final TrivialMapPropertiesToNullIfNotNeeded other = (TrivialMapPropertiesToNullIfNotNeeded) o;
if (!other.canEqual((Object) this)) return false;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false;
if (this.getAge() != other.getAge()) return false;
final Object this$phone = this.getPhone();
final Object other$phone = other.getPhone();
if (this$phone == null ? other$phone != null : !this$phone.equals(other$phone)) return false;
final Object this$isSupreme = this.getIsSupreme();
final Object other$isSupreme = other.getIsSupreme();
if (this$isSupreme == null ? other$isSupreme != null : !this$isSupreme.equals(other$isSupreme))
return false;
if (this.getReferenceToCustomer() != other.getReferenceToCustomer()) return false;
return true;
}
protected boolean canEqual(final Object other) {
return other instanceof TrivialMapPropertiesToNullIfNotNeeded;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
result = result * PRIME + this.getAge();
final Object $phone = this.getPhone();
result = result * PRIME + ($phone == null ? 43 : $phone.hashCode());
final Object $isSupreme = this.getIsSupreme();
result = result * PRIME + ($isSupreme == null ? 43 : $isSupreme.hashCode());
final long $referenceToCustomer = this.getReferenceToCustomer();
result = result * PRIME + (int) ($referenceToCustomer >>> 32 ^ $referenceToCustomer);
return result;
}
}
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
@Getter
static class WithReference {
@Id Long id;
@Id
Long id;
String name;
AggregateReference<Trivial, Long> trivialId;
public WithReference(Long id, String name, AggregateReference<Trivial, Long> trivialId) {
this.id = id;
this.name = name;
this.trivialId = trivialId;
}
public WithReference() {
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public AggregateReference<Trivial, Long> getTrivialId() {
return this.trivialId;
}
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof WithReference)) return false;
final WithReference other = (WithReference) o;
if (!other.canEqual((Object) this)) return false;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false;
final Object this$name = this.getName();
final Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
final Object this$trivialId = this.getTrivialId();
final Object other$trivialId = other.getTrivialId();
if (this$trivialId == null ? other$trivialId != null : !this$trivialId.equals(other$trivialId))
return false;
return true;
}
protected boolean canEqual(final Object other) {
return other instanceof WithReference;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
final Object $name = this.getName();
result = result * PRIME + ($name == null ? 43 : $name.hashCode());
final Object $trivialId = this.getTrivialId();
result = result * PRIME + ($trivialId == null ? 43 : $trivialId.hashCode());
return result;
}
}
@With
@RequiredArgsConstructor
static class WithReferenceImmutable {
record WithReferenceImmutable(
@Id Long id, String name,
AggregateReference<TrivialImmutable, Long> trivialId){
@Id private final Long id;
private final String name;
private final AggregateReference<TrivialImmutable, Long> trivialId;
public WithReferenceImmutable withId(Long id) {
return this.id == id ? this : new WithReferenceImmutable(id, this.name, this.trivialId);
}
public WithReferenceImmutable withName(String name) {
return this.name == name ? this : new WithReferenceImmutable(this.id, name, this.trivialId);
}
public WithReferenceImmutable withTrivialId(AggregateReference<TrivialImmutable, Long> trivialId) {
return this.trivialId == trivialId ? this : new WithReferenceImmutable(this.id, this.name, trivialId);
}
}
static class OneToOne {
@@ -705,13 +871,25 @@ public class EntityRowMapperUnitTests {
Trivial child;
}
@With
@RequiredArgsConstructor
static class OneToOneImmutable {
record OneToOneImmutable(
private final @Id Long id;
private final String name;
private final TrivialImmutable child;
@Id Long id, String name, TrivialImmutable child) {
OneToOneImmutable() {
this(null, null, null);
}
public OneToOneImmutable withId(Long id) {
return this.id == id ? this : new OneToOneImmutable(id, name, child);
}
public OneToOneImmutable withName(String name) {
return this.name == name ? this : new OneToOneImmutable(id, name, child);
}
public OneToOneImmutable withChild(TrivialImmutable child) {
return this.child == child ? this : new OneToOneImmutable(id, name, child);
}
}
static class OneToSet {
@@ -817,15 +995,10 @@ public class EntityRowMapperUnitTests {
@Embedded.Nullable ImmutablePrimitiveValue embeddedImmutablePrimitiveValue;
}
@Value
static class ImmutableValue {
Object value;
String name;
record ImmutableValue(Object value, String name) {
}
@Value
static class ImmutablePrimitiveValue {
int value;
record ImmutablePrimitiveValue(int value) {
}
static class WithDeepNestedEmbeddable {
@@ -1190,12 +1363,16 @@ public class EntityRowMapperUnitTests {
}
}
@AllArgsConstructor
private static class Fixture<T> {
final ResultSet resultSet;
final List<Expectation<T>> expectations;
public Fixture(ResultSet resultSet, List<Expectation<T>> expectations) {
this.resultSet = resultSet;
this.expectations = expectations;
}
public void assertOn(T result) {
assertSoftly(softly -> {
@@ -1209,15 +1386,19 @@ public class EntityRowMapperUnitTests {
}
}
@AllArgsConstructor
private static class Expectation<T> {
final Function<T, Object> extractor;
final Object expectedValue;
final String sourceColumn;
public Expectation(Function<T, Object> extractor, Object expectedValue, String sourceColumn) {
this.extractor = extractor;
this.expectedValue = expectedValue;
this.sourceColumn = sourceColumn;
}
}
@Getter
private static class WithAtValue {
@Id private final Long id;
@@ -1228,5 +1409,13 @@ public class EntityRowMapperUnitTests {
this.id = id;
this.computed = computed;
}
public Long getId() {
return this.id;
}
public String getComputed() {
return this.computed;
}
}
}

View File

@@ -21,11 +21,6 @@ import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategyUnitTests.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -91,7 +86,8 @@ class SqlParametersFactoryTest {
assertThat(sqlParameterSource.getValue("DUMMYENTITYROOT")).isEqualTo(rawId);
}
@Test // DATAJDBC-146
@Test
// DATAJDBC-146
void identifiersGetAddedAsParameters() {
long id = 4711L;
@@ -105,7 +101,8 @@ class SqlParametersFactoryTest {
assertThat(sqlParameterSource.getValue("reference")).isEqualTo(reference);
}
@Test // DATAJDBC-146
@Test
// DATAJDBC-146
void additionalIdentifierForIdDoesNotLeadToDuplicateParameters() {
long id = 4711L;
@@ -117,7 +114,8 @@ class SqlParametersFactoryTest {
assertThat(sqlParameterSource.getValue("id")).isEqualTo(id);
}
@Test // DATAJDBC-235
@Test
// DATAJDBC-235
void considersConfiguredWriteConverter() {
SqlParametersFactory sqlParametersFactory = createSqlParametersFactoryWithConverters(
@@ -131,7 +129,8 @@ class SqlParametersFactoryTest {
assertThat(sqlParameterSource.getValue("flag")).isEqualTo("T");
}
@Test // DATAJDBC-412
@Test
// DATAJDBC-412
void considersConfiguredWriteConverterForIdValueObjects_onWrite() {
SqlParametersFactory sqlParametersFactory = createSqlParametersFactoryWithConverters(
@@ -148,7 +147,8 @@ class SqlParametersFactoryTest {
assertThat(sqlParameterSource.getValue("value")).isEqualTo(value);
}
@Test // GH-1405
@Test
// GH-1405
void parameterNamesGetSanitized() {
WithIllegalCharacters entity = new WithIllegalCharacters(23L, "aValue");
@@ -174,16 +174,63 @@ class SqlParametersFactoryTest {
}
}
@Data
private static class WithValueObjectId {
@Id private final IdValue id;
String value;
private WithValueObjectId(IdValue id) {
this.id = id;
}
public IdValue getId() {
return this.id;
}
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value = value;
}
}
@Value
private static class IdValue {
String id;
private static final class IdValue {
private final String id;
public IdValue(String id) {
this.id = id;
}
public String getId() {
return this.id;
}
public boolean equals(final Object o) {
if (o == this)
return true;
if (!(o instanceof IdValue))
return false;
final IdValue other = (IdValue) o;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id))
return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
return result;
}
public String toString() {
return "SqlParametersFactoryTest.IdValue(id=" + this.getId() + ")";
}
}
@WritingConverter
@@ -208,33 +255,48 @@ class SqlParametersFactoryTest {
}
}
@AllArgsConstructor
private static class EntityWithBoolean {
@Id Long id;
boolean flag;
public EntityWithBoolean(Long id, boolean flag) {
this.id = id;
this.flag = flag;
}
}
@RequiredArgsConstructor // DATAJDBC-349
// DATAJDBC-349
private static class DummyEntityRoot {
@Id private final IdValue id;
List<DummyEntity> dummyEntities = new ArrayList<>();
public DummyEntityRoot(IdValue id) {
this.id = id;
}
}
@RequiredArgsConstructor
private static class DummyEntity {
@Id private final Long id;
public DummyEntity(Long id) {
this.id = id;
}
}
@AllArgsConstructor
private static class WithIllegalCharacters {
@Column("i.d")
@Id Long id;
@Column("val&ue") String value;
public WithIllegalCharacters(Long id, String value) {
this.id = id;
this.value = value;
}
}
private SqlParametersFactory createSqlParametersFactoryWithConverters(List<?> converters) {

View File

@@ -2,11 +2,6 @@ package org.springframework.data.jdbc.core.dialect;
import static org.assertj.core.api.Assertions.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Value;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -17,7 +12,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.api.extension.ExtendWith;
import org.postgresql.util.PGobject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@@ -133,21 +127,98 @@ public class PostgresDialectIntegrationTests {
}
}
@Value
@Table("customers")
public static class Customer {
public static final class Customer {
@Id Long id;
String name;
JsonHolder personData;
PGobject sessionData;
@Id private final Long id;
private final String name;
private final JsonHolder personData;
private final PGobject sessionData;
public Customer(Long id, String name, JsonHolder personData, PGobject sessionData) {
this.id = id;
this.name = name;
this.personData = personData;
this.sessionData = sessionData;
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public JsonHolder getPersonData() {
return this.personData;
}
public PGobject getSessionData() {
return this.sessionData;
}
public boolean equals(final Object o) {
if (o == this)
return true;
if (!(o instanceof Customer))
return false;
final Customer other = (Customer) o;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id))
return false;
final Object this$name = this.getName();
final Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name))
return false;
final Object this$personData = this.getPersonData();
final Object other$personData = other.getPersonData();
if (this$personData == null ? other$personData != null : !this$personData.equals(other$personData))
return false;
final Object this$sessionData = this.getSessionData();
final Object other$sessionData = other.getSessionData();
if (this$sessionData == null ? other$sessionData != null : !this$sessionData.equals(other$sessionData))
return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
final Object $name = this.getName();
result = result * PRIME + ($name == null ? 43 : $name.hashCode());
final Object $personData = this.getPersonData();
result = result * PRIME + ($personData == null ? 43 : $personData.hashCode());
final Object $sessionData = this.getSessionData();
result = result * PRIME + ($sessionData == null ? 43 : $sessionData.hashCode());
return result;
}
public String toString() {
return "PostgresDialectIntegrationTests.Customer(id=" + this.getId() + ", name=" + this.getName()
+ ", personData=" + this.getPersonData() + ", sessionData=" + this.getSessionData() + ")";
}
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class JsonHolder {
String content;
public JsonHolder(String content) {
this.content = content;
}
public JsonHolder() {}
public String getContent() {
return this.content;
}
public void setContent(String content) {
this.content = content;
}
}
interface CustomerRepository extends CrudRepository<Customer, Long> {}

View File

@@ -15,19 +15,7 @@
*/
package org.springframework.data.jdbc.core.mapping;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.SoftAssertions.*;
import static org.springframework.data.relational.core.sql.SqlIdentifier.*;
import junit.framework.AssertionFailedError;
import lombok.Data;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.mapping.PersistentPropertyPath;
@@ -39,6 +27,16 @@ import org.springframework.data.relational.core.mapping.RelationalMappingContext
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.SoftAssertions.*;
import static org.springframework.data.relational.core.sql.SqlIdentifier.*;
/**
* Unit tests for the {@link BasicRelationalPersistentProperty}.
*
@@ -141,11 +139,11 @@ public class BasicJdbcPersistentPropertyUnitTests {
ALPHA
}
@Data
@SuppressWarnings("unused")
private static class DummyEntity {
@Id private final Long id;
@Id
private final Long id;
private final SomeEnum someEnum;
private final LocalDateTime localDateTime;
private final ZonedDateTime zonedDateTime;
@@ -154,11 +152,22 @@ public class BasicJdbcPersistentPropertyUnitTests {
private final UUID uuid;
@MappedCollection(idColumn = "dummy_column_name",
keyColumn = "dummy_key_column_name") private List<Integer> someList;
keyColumn = "dummy_key_column_name")
private List<Integer> someList;
// DATACMNS-106
private @Column("dummy_name") String name;
private DummyEntity(Long id, SomeEnum someEnum, LocalDateTime localDateTime, ZonedDateTime zonedDateTime, AggregateReference<DummyEntity, Long> reference, List<String> listField, UUID uuid) {
this.id = id;
this.someEnum = someEnum;
this.localDateTime = localDateTime;
this.zonedDateTime = zonedDateTime;
this.reference = reference;
this.listField = listField;
this.uuid = uuid;
}
@Column("dummy_last_updated_at")
public LocalDateTime getLocalDateTime() {
return localDateTime;
@@ -171,15 +180,71 @@ public class BasicJdbcPersistentPropertyUnitTests {
public List<Date> getListGetter() {
return null;
}
public Long getId() {
return this.id;
}
public SomeEnum getSomeEnum() {
return this.someEnum;
}
public ZonedDateTime getZonedDateTime() {
return this.zonedDateTime;
}
public AggregateReference<DummyEntity, Long> getReference() {
return this.reference;
}
public List<String> getListField() {
return this.listField;
}
public UUID getUuid() {
return this.uuid;
}
public List<Integer> getSomeList() {
return this.someList;
}
public String getName() {
return this.name;
}
public void setSomeList(List<Integer> someList) {
this.someList = someList;
}
public void setName(String name) {
this.name = name;
}
}
@Data
private static class WithCollections {
@Column(value = "some_value") List<Integer> someList;
@Column(value = "some_value")
List<Integer> someList;
@Column(value = "some_value") //
@MappedCollection(idColumn = "override_id", keyColumn = "override_key") //
List<Integer> overrideList;
public List<Integer> getSomeList() {
return this.someList;
}
public List<Integer> getOverrideList() {
return this.overrideList;
}
public void setSomeList(List<Integer> someList) {
this.someList = someList;
}
public void setOverrideList(List<Integer> overrideList) {
this.overrideList = overrideList;
}
}
}

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.jdbc.core.mapping;
import lombok.experimental.UtilityClass;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
@@ -24,11 +22,14 @@ import org.springframework.data.relational.core.mapping.RelationalPersistentProp
/**
* @author Jens Schauder
*/
@UtilityClass
public class PersistentPropertyPathTestUtils {
public final class PersistentPropertyPathTestUtils {
private PersistentPropertyPathTestUtils() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}
public static PersistentPropertyPath<RelationalPersistentProperty> getPath(RelationalMappingContext context,
String path, Class<?> baseType) {
String path, Class<?> baseType) {
return context.findPersistentPropertyPaths(baseType, p -> p.isEntity()) //
.filter(p -> p.toDotPath().equals(path)) //

View File

@@ -15,21 +15,18 @@
*/
package org.springframework.data.jdbc.mapping.model;
import static org.assertj.core.api.Assertions.*;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.relational.core.mapping.DefaultNamingStrategy;
import org.springframework.data.relational.core.mapping.NamingStrategy;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import java.time.LocalDateTime;
import java.util.List;
import static org.assertj.core.api.Assertions.*;
/**
* Unit tests for the default {@link NamingStrategy}.
*
@@ -78,19 +75,59 @@ public class DefaultNamingStrategyUnitTests {
assertThat(target.getSchema()).isEqualTo("");
}
@Data
private static class DummyEntity {
@Id private int id;
@Id
private int id;
private LocalDateTime createdAt;
private List<DummySubEntity> dummySubEntities;
public int getId() {
return this.id;
}
public LocalDateTime getCreatedAt() {
return this.createdAt;
}
public List<DummySubEntity> getDummySubEntities() {
return this.dummySubEntities;
}
public void setId(int id) {
this.id = id;
}
public void setCreatedAt(LocalDateTime createdAt) {
this.createdAt = createdAt;
}
public void setDummySubEntities(List<DummySubEntity> dummySubEntities) {
this.dummySubEntities = dummySubEntities;
}
}
@Data
private static class DummySubEntity {
@Id private int id;
@Id
private int id;
private LocalDateTime createdAt;
public int getId() {
return this.id;
}
public LocalDateTime getCreatedAt() {
return this.createdAt;
}
public void setId(int id) {
this.id = id;
}
public void setCreatedAt(LocalDateTime createdAt) {
this.createdAt = createdAt;
}
}
}

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.jdbc.mybatis;
import lombok.With;
import org.apache.ibatis.type.Alias;
import org.springframework.data.annotation.Id;
@@ -26,11 +24,16 @@ import org.springframework.data.annotation.Id;
@Alias("DummyEntity")
class DummyEntity {
@With @Id final Long id;
@Id
final Long id;
final String name;
public DummyEntity(Long id, String name) {
this.id = id;
this.name = name;
}
public DummyEntity withId(Long id) {
return this.id == id ? this : new DummyEntity(id, this.name);
}
}

View File

@@ -15,15 +15,6 @@
*/
package org.springframework.data.jdbc.repository;
import static org.assertj.core.api.Assertions.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Value;
import lombok.With;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -43,6 +34,10 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.util.List;
import static org.assertj.core.api.Assertions.*;
/**
* Integration tests for the {@link BeforeSaveCallback}.
*
@@ -57,7 +52,8 @@ public class JdbcRepositoryBeforeSaveHsqlIntegrationTests {
@Import(TestConfiguration.class)
static class Config {
@Autowired JdbcRepositoryFactory factory;
@Autowired
JdbcRepositoryFactory factory;
@Bean
Class<?> testClass() {
@@ -65,11 +61,16 @@ public class JdbcRepositoryBeforeSaveHsqlIntegrationTests {
}
}
@Autowired NamedParameterJdbcTemplate template;
@Autowired ImmutableEntityRepository immutableWithManualIdEntityRepository;
@Autowired MutableEntityRepository mutableEntityRepository;
@Autowired MutableWithImmutableIdEntityRepository mutableWithImmutableIdEntityRepository;
@Autowired ImmutableWithMutableIdEntityRepository immutableWithMutableIdEntityRepository;
@Autowired
NamedParameterJdbcTemplate template;
@Autowired
ImmutableEntityRepository immutableWithManualIdEntityRepository;
@Autowired
MutableEntityRepository mutableEntityRepository;
@Autowired
MutableWithImmutableIdEntityRepository mutableWithImmutableIdEntityRepository;
@Autowired
ImmutableWithMutableIdEntityRepository immutableWithMutableIdEntityRepository;
@Test // GH-1199
public void immutableEntity() {
@@ -135,42 +136,150 @@ public class JdbcRepositoryBeforeSaveHsqlIntegrationTests {
assertThat(reloaded.getName()).isEqualTo("fromBeforeSaveCallback");
}
private interface ImmutableEntityRepository extends ListCrudRepository<ImmutableEntity, Long> {}
@Value
@With
static class ImmutableEntity {
@Id Long id;
String name;
private interface ImmutableEntityRepository extends ListCrudRepository<ImmutableEntity, Long> {
}
private interface MutableEntityRepository extends ListCrudRepository<MutableEntity, Long> {}
static final class ImmutableEntity {
@Id
private final
Long id;
private final String name;
public ImmutableEntity(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof ImmutableEntity)) return false;
final ImmutableEntity other = (ImmutableEntity) o;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false;
final Object this$name = this.getName();
final Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
final Object $name = this.getName();
result = result * PRIME + ($name == null ? 43 : $name.hashCode());
return result;
}
public String toString() {
return "JdbcRepositoryBeforeSaveHsqlIntegrationTests.ImmutableEntity(id=" + this.getId() + ", name=" + this.getName() + ")";
}
public ImmutableEntity withId(Long id) {
return this.id == id ? this : new ImmutableEntity(id, this.name);
}
public ImmutableEntity withName(String name) {
return this.name == name ? this : new ImmutableEntity(this.id, name);
}
}
private interface MutableEntityRepository extends ListCrudRepository<MutableEntity, Long> {
}
@Data
@AllArgsConstructor
static class MutableEntity {
@Id private Long id;
@Id
private Long id;
private String name;
public MutableEntity(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public void setId(Long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
}
private interface MutableWithImmutableIdEntityRepository
extends ListCrudRepository<MutableWithImmutableIdEntity, Long> {}
extends ListCrudRepository<MutableWithImmutableIdEntity, Long> {
}
@Data
@AllArgsConstructor
static class MutableWithImmutableIdEntity {
@Id private final Long id;
@Id
private final Long id;
private String name;
public MutableWithImmutableIdEntity(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
private interface ImmutableWithMutableIdEntityRepository
extends ListCrudRepository<ImmutableWithMutableIdEntity, Long> {}
extends ListCrudRepository<ImmutableWithMutableIdEntity, Long> {
}
@Data
@AllArgsConstructor
static class ImmutableWithMutableIdEntity {
@Id private Long id;
@With private final String name;
@Id
private Long id;
private final String name;
public ImmutableWithMutableIdEntity(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public void setId(Long id) {
this.id = id;
}
public ImmutableWithMutableIdEntity withName(String name) {
return this.name == name ? this : new ImmutableWithMutableIdEntity(this.id, name);
}
}
@Configuration

View File

@@ -15,28 +15,13 @@
*/
package org.springframework.data.jdbc.repository;
import static org.assertj.core.api.Assertions.*;
import junit.framework.AssertionFailedError;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.With;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringJoiner;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.function.UnaryOperator;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.commons.util.ExceptionUtils;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -48,10 +33,19 @@ import org.springframework.data.jdbc.testing.TestConfiguration;
import org.springframework.data.repository.CrudRepository;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringJoiner;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.function.UnaryOperator;
import static org.assertj.core.api.Assertions.*;
/**
* Tests that highly concurrent update operations of an entity don't cause deadlocks.
*
@@ -65,7 +59,8 @@ public class JdbcRepositoryConcurrencyIntegrationTests {
@Import(TestConfiguration.class)
static class Config {
@Autowired JdbcRepositoryFactory factory;
@Autowired
JdbcRepositoryFactory factory;
@Bean
Class<?> testClass() {
@@ -78,9 +73,12 @@ public class JdbcRepositoryConcurrencyIntegrationTests {
}
}
@Autowired NamedParameterJdbcTemplate template;
@Autowired DummyEntityRepository repository;
@Autowired PlatformTransactionManager transactionManager;
@Autowired
NamedParameterJdbcTemplate template;
@Autowired
DummyEntityRepository repository;
@Autowired
PlatformTransactionManager transactionManager;
List<DummyEntity> concurrencyEntities;
DummyEntity entity;
@@ -155,7 +153,7 @@ public class JdbcRepositoryConcurrencyIntegrationTests {
CountDownLatch startLatch = new CountDownLatch(concurrencyEntities.size() + 1); // latch for all threads to wait on.
CountDownLatch doneLatch = new CountDownLatch(concurrencyEntities.size() + 1); // latch for main thread to wait on
// until all threads are done.
// until all threads are done.
UnaryOperator<DummyEntity> updateAction = e -> {
try {
return repository.save(e);
@@ -188,7 +186,7 @@ public class JdbcRepositoryConcurrencyIntegrationTests {
CountDownLatch startLatch = new CountDownLatch(concurrencyEntities.size() + 1); // latch for all threads to wait on.
CountDownLatch doneLatch = new CountDownLatch(concurrencyEntities.size() + 1); // latch for main thread to wait on
// until all threads are done.
// until all threads are done.
UnaryOperator<DummyEntity> updateAction = e -> {
try {
@@ -218,7 +216,7 @@ public class JdbcRepositoryConcurrencyIntegrationTests {
}
private void executeInParallel(CountDownLatch startLatch, CountDownLatch doneLatch,
UnaryOperator<DummyEntity> deleteAction, DummyEntity entity) {
UnaryOperator<DummyEntity> deleteAction, DummyEntity entity) {
// delete
new Thread(() -> {
try {
@@ -255,22 +253,56 @@ public class JdbcRepositoryConcurrencyIntegrationTests {
return new DummyEntity(null, "Entity Name", new ArrayList<>());
}
interface DummyEntityRepository extends CrudRepository<DummyEntity, Long> {}
interface DummyEntityRepository extends CrudRepository<DummyEntity, Long> {
}
@Getter
@AllArgsConstructor
static class DummyEntity {
@Id private Long id;
@With String name;
@With final List<Element> content;
@Id
private Long id;
String name;
final List<Element> content;
public DummyEntity(Long id, String name, List<Element> content) {
this.id = id;
this.name = name;
this.content = content;
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public List<Element> getContent() {
return this.content;
}
public DummyEntity withName(String name) {
return this.name == name ? this : new DummyEntity(this.id, name, this.content);
}
public DummyEntity withContent(List<Element> content) {
return this.content == content ? this : new DummyEntity(this.id, this.name, content);
}
}
@AllArgsConstructor
static class Element {
@Id private Long id;
@With final Long content;
@Id
private Long id;
final Long content;
public Element(Long id, Long content) {
this.id = id;
this.content = content;
}
public Element withContent(Long content) {
return this.content == content ? this : new Element(this.id, content);
}
}
}

View File

@@ -15,11 +15,6 @@
*/
package org.springframework.data.jdbc.repository;
import static org.assertj.core.api.Assertions.*;
import lombok.Value;
import lombok.With;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -37,6 +32,8 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.transaction.annotation.Transactional;
import static org.assertj.core.api.Assertions.*;
/**
* Very simple use cases for creation and usage of JdbcRepositories with {@link Embedded} annotation in Entities.
*
@@ -86,20 +83,115 @@ public class JdbcRepositoryEmbeddedImmutableIntegrationTests {
interface DummyEntityRepository extends CrudRepository<DummyEntity, Long> {}
@Value
@With
static class DummyEntity {
static final class DummyEntity {
@Id Long id;
@Id
private final Long id;
@Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "PREFIX_") Embeddable prefixedEmbeddable;
@Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "PREFIX_")
private final Embeddable prefixedEmbeddable;
public DummyEntity(Long id, Embeddable prefixedEmbeddable) {
this.id = id;
this.prefixedEmbeddable = prefixedEmbeddable;
}
public Long getId() {
return this.id;
}
public Embeddable getPrefixedEmbeddable() {
return this.prefixedEmbeddable;
}
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof DummyEntity)) return false;
final DummyEntity other = (DummyEntity) o;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false;
final Object this$prefixedEmbeddable = this.getPrefixedEmbeddable();
final Object other$prefixedEmbeddable = other.getPrefixedEmbeddable();
if (this$prefixedEmbeddable == null ? other$prefixedEmbeddable != null : !this$prefixedEmbeddable.equals(other$prefixedEmbeddable))
return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
final Object $prefixedEmbeddable = this.getPrefixedEmbeddable();
result = result * PRIME + ($prefixedEmbeddable == null ? 43 : $prefixedEmbeddable.hashCode());
return result;
}
public String toString() {
return "JdbcRepositoryEmbeddedImmutableIntegrationTests.DummyEntity(id=" + this.getId() + ", prefixedEmbeddable=" + this.getPrefixedEmbeddable() + ")";
}
public DummyEntity withId(Long id) {
return this.id == id ? this : new DummyEntity(id, this.prefixedEmbeddable);
}
public DummyEntity withPrefixedEmbeddable(Embeddable prefixedEmbeddable) {
return this.prefixedEmbeddable == prefixedEmbeddable ? this : new DummyEntity(this.id, prefixedEmbeddable);
}
}
@Value
@With
private static class Embeddable {
private static final class Embeddable {
Long attr1;
String attr2;
private final Long attr1;
private final String attr2;
public Embeddable(Long attr1, String attr2) {
this.attr1 = attr1;
this.attr2 = attr2;
}
public Long getAttr1() {
return this.attr1;
}
public String getAttr2() {
return this.attr2;
}
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof Embeddable)) return false;
final Embeddable other = (Embeddable) o;
final Object this$attr1 = this.getAttr1();
final Object other$attr1 = other.getAttr1();
if (this$attr1 == null ? other$attr1 != null : !this$attr1.equals(other$attr1)) return false;
final Object this$attr2 = this.getAttr2();
final Object other$attr2 = other.getAttr2();
if (this$attr2 == null ? other$attr2 != null : !this$attr2.equals(other$attr2)) return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $attr1 = this.getAttr1();
result = result * PRIME + ($attr1 == null ? 43 : $attr1.hashCode());
final Object $attr2 = this.getAttr2();
result = result * PRIME + ($attr2 == null ? 43 : $attr2.hashCode());
return result;
}
public String toString() {
return "JdbcRepositoryEmbeddedImmutableIntegrationTests.Embeddable(attr1=" + this.getAttr1() + ", attr2=" + this.getAttr2() + ")";
}
public Embeddable withAttr1(Long attr1) {
return this.attr1 == attr1 ? this : new Embeddable(attr1, this.attr2);
}
public Embeddable withAttr2(String attr2) {
return this.attr2 == attr2 ? this : new Embeddable(this.attr1, attr2);
}
}
}

View File

@@ -18,12 +18,9 @@ package org.springframework.data.jdbc.repository;
import static java.util.Arrays.*;
import static org.assertj.core.api.Assertions.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.List;
import lombok.NoArgsConstructor;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -33,9 +30,7 @@ import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.domain.Sort;
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
import org.springframework.data.jdbc.testing.EnabledOnFeature;
import org.springframework.data.jdbc.testing.TestConfiguration;
import org.springframework.data.jdbc.testing.TestDatabaseFeatures;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Embedded;
import org.springframework.data.relational.core.mapping.Embedded.OnEmpty;
@@ -49,8 +44,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.jdbc.JdbcTestUtils;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* Very simple use cases for creation and usage of JdbcRepositories with test {@link Embedded} annotation in Entities.
*
@@ -85,7 +78,9 @@ public class JdbcRepositoryEmbeddedIntegrationTests {
}
@Bean
WithDotColumnRepo withDotColumnRepo() { return factory.getRepository(WithDotColumnRepo.class);}
WithDotColumnRepo withDotColumnRepo() {
return factory.getRepository(WithDotColumnRepo.class);
}
}
@@ -250,11 +245,12 @@ public class JdbcRepositoryEmbeddedIntegrationTests {
Person second = new Person(null, "Alex", "LA", new PersonContacts("aaa@example.com", "+2 222 2222 22 22"));
Person third = new Person(null, "Sarah", "NY", new PersonContacts("ggg@example.com", "+3 333 3333 33 33"));
personRepository.saveAll(List.of(first, second, third));
List<Person> people = (List)personRepository.saveAll(List.of(first, second, third));
Iterable<Person> fetchedPersons = personRepository.findAll(Sort.by(new Sort.Order(Sort.Direction.ASC, "personContacts.email")));
Iterable<Person> fetchedPersons = personRepository
.findAll(Sort.by(new Sort.Order(Sort.Direction.ASC, "personContacts.email")));
Assertions.assertThat(fetchedPersons).containsExactly(second, first, third);
Assertions.assertThat(fetchedPersons).containsExactly(people.get(1), people.get(0), people.get(2));
}
@Test // GH-1286
@@ -264,11 +260,12 @@ public class JdbcRepositoryEmbeddedIntegrationTests {
WithDotColumn second = new WithDotColumn(null, "Istanbul");
WithDotColumn third = new WithDotColumn(null, "Tokyo");
withDotColumnRepo.saveAll(List.of(first, second, third));
List<WithDotColumn> saved = (List) withDotColumnRepo.saveAll(List.of(first, second, third));
Iterable<WithDotColumn> fetchedPersons = withDotColumnRepo.findAll(Sort.by(new Sort.Order(Sort.Direction.ASC, "address")));
Iterable<WithDotColumn> fetchedPersons = withDotColumnRepo
.findAll(Sort.by(new Sort.Order(Sort.Direction.ASC, "address")));
Assertions.assertThat(fetchedPersons).containsExactly(second, first, third);
Assertions.assertThat(fetchedPersons).containsExactly(saved.get(1), saved.get(0), saved.get(2));
}
private static DummyEntity createDummyEntity() {
@@ -299,42 +296,20 @@ public class JdbcRepositoryEmbeddedIntegrationTests {
interface PersonRepository extends PagingAndSortingRepository<Person, Long>, CrudRepository<Person, Long> {}
interface WithDotColumnRepo extends PagingAndSortingRepository<WithDotColumn, Integer>, CrudRepository<WithDotColumn, Integer> {}
interface WithDotColumnRepo
extends PagingAndSortingRepository<WithDotColumn, Integer>, CrudRepository<WithDotColumn, Integer> {}
@Data
@AllArgsConstructor
@NoArgsConstructor
static class WithDotColumn {
@Id
private Integer id;
@Column("address.city")
private String address;
record WithDotColumn(@Id Integer id, @Column("address.city") String address) {
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@Table("SORT_EMBEDDED_ENTITY")
static class Person {
@Id
private Long id;
private String firstName;
private String address;
@Embedded.Nullable
private PersonContacts personContacts;
record Person(@Id Long id, String firstName, String address, @Embedded.Nullable PersonContacts personContacts) {
}
@Data
@AllArgsConstructor
@NoArgsConstructor
static class PersonContacts {
private String email;
private String phoneNumber;
}
record PersonContacts(String email, String phoneNumber) {
}
@Data
static class DummyEntity {
@Id Long id;
@@ -342,17 +317,63 @@ public class JdbcRepositoryEmbeddedIntegrationTests {
@Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "PREFIX_") CascadedEmbeddable prefixedEmbeddable;
@Embedded(onEmpty = OnEmpty.USE_NULL) CascadedEmbeddable embeddable;
public Long getId() {
return this.id;
}
public CascadedEmbeddable getPrefixedEmbeddable() {
return this.prefixedEmbeddable;
}
public CascadedEmbeddable getEmbeddable() {
return this.embeddable;
}
public void setId(Long id) {
this.id = id;
}
public void setPrefixedEmbeddable(CascadedEmbeddable prefixedEmbeddable) {
this.prefixedEmbeddable = prefixedEmbeddable;
}
public void setEmbeddable(CascadedEmbeddable embeddable) {
this.embeddable = embeddable;
}
}
@Data
static class CascadedEmbeddable {
String test;
@Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "PREFIX2_") Embeddable embeddable;
public String getTest() {
return this.test;
}
public Embeddable getEmbeddable() {
return this.embeddable;
}
public void setTest(String test) {
this.test = test;
}
public void setEmbeddable(Embeddable embeddable) {
this.embeddable = embeddable;
}
}
@Data
static class Embeddable {
Long attr;
public Long getAttr() {
return this.attr;
}
public void setAttr(Long attr) {
this.attr = attr;
}
}
}

View File

@@ -15,14 +15,6 @@
*/
package org.springframework.data.jdbc.repository;
import static java.util.Arrays.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.test.context.TestExecutionListeners.MergeMode.*;
import lombok.Data;
import java.sql.SQLException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -47,6 +39,12 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.jdbc.JdbcTestUtils;
import org.springframework.transaction.annotation.Transactional;
import java.sql.SQLException;
import static java.util.Arrays.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.test.context.TestExecutionListeners.MergeMode.*;
/**
* Very simple use cases for creation and usage of JdbcRepositories with test {@link Embedded} annotation in Entities.
*
@@ -245,26 +243,85 @@ public class JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests {
}
@Data
static class DummyEntity {
@Column("ID") @Id Long id;
@Column("ID")
@Id
Long id;
String test;
@Column("ID") DummyEntity2 dummyEntity2;
@Column("ID")
DummyEntity2 dummyEntity2;
public Long getId() {
return this.id;
}
public String getTest() {
return this.test;
}
public DummyEntity2 getDummyEntity2() {
return this.dummyEntity2;
}
public void setId(Long id) {
this.id = id;
}
public void setTest(String test) {
this.test = test;
}
public void setDummyEntity2(DummyEntity2 dummyEntity2) {
this.dummyEntity2 = dummyEntity2;
}
}
@Data
static class DummyEntity2 {
@Column("ID") @Id Long id;
@Column("ID")
@Id
Long id;
String test;
@Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "prefix_") Embeddable embeddable;
@Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "prefix_")
Embeddable embeddable;
public Long getId() {
return this.id;
}
public String getTest() {
return this.test;
}
public Embeddable getEmbeddable() {
return this.embeddable;
}
public void setId(Long id) {
this.id = id;
}
public void setTest(String test) {
this.test = test;
}
public void setEmbeddable(Embeddable embeddable) {
this.embeddable = embeddable;
}
}
@Data
static class Embeddable {
Long attr;
public Long getAttr() {
return this.attr;
}
public void setAttr(Long attr) {
this.attr = attr;
}
}
}

View File

@@ -18,8 +18,6 @@ package org.springframework.data.jdbc.repository;
import static java.util.Arrays.*;
import static org.assertj.core.api.Assertions.*;
import lombok.Data;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@@ -36,8 +34,8 @@ import org.springframework.data.jdbc.testing.TestConfiguration;
import org.springframework.data.relational.core.dialect.Dialect;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Embedded;
import org.springframework.data.relational.core.mapping.MappedCollection;
import org.springframework.data.relational.core.mapping.Embedded.OnEmpty;
import org.springframework.data.relational.core.mapping.MappedCollection;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.data.repository.CrudRepository;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -254,24 +252,70 @@ public class JdbcRepositoryEmbeddedWithCollectionIntegrationTests {
interface DummyEntityRepository extends CrudRepository<DummyEntity, Long> {}
@Data
private static class DummyEntity {
@Column("ID") @Id Long id;
@Column("ID")
@Id Long id;
String test;
@Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "PREFIX_") Embeddable embeddable;
public Long getId() {
return this.id;
}
public String getTest() {
return this.test;
}
public Embeddable getEmbeddable() {
return this.embeddable;
}
public void setId(Long id) {
this.id = id;
}
public void setTest(String test) {
this.test = test;
}
public void setEmbeddable(Embeddable embeddable) {
this.embeddable = embeddable;
}
}
@Data
private static class Embeddable {
@MappedCollection(idColumn = "ID", keyColumn = "ORDER_KEY") List<DummyEntity2> list = new ArrayList<>();
String test;
public List<DummyEntity2> getList() {
return this.list;
}
public String getTest() {
return this.test;
}
public void setList(List<DummyEntity2> list) {
this.list = list;
}
public void setTest(String test) {
this.test = test;
}
}
@Data
private static class DummyEntity2 {
String test;
public String getTest() {
return this.test;
}
public void setTest(String test) {
this.test = test;
}
}
}

View File

@@ -19,8 +19,6 @@ import static java.util.Arrays.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.test.context.TestExecutionListeners.MergeMode.*;
import lombok.Data;
import java.util.List;
import org.junit.jupiter.api.Test;
@@ -269,37 +267,107 @@ public class JdbcRepositoryEmbeddedWithReferenceIntegrationTests {
}
@Data
private static class DummyEntity {
@Column("ID") @Id Long id;
@Column("ID")
@Id Long id;
String test;
@Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "PREFIX_") Embeddable embeddable;
@Embedded(onEmpty = OnEmpty.USE_NULL) Embeddable2 embeddable2;
public Long getId() {
return this.id;
}
public String getTest() {
return this.test;
}
public Embeddable getEmbeddable() {
return this.embeddable;
}
public Embeddable2 getEmbeddable2() {
return this.embeddable2;
}
public void setId(Long id) {
this.id = id;
}
public void setTest(String test) {
this.test = test;
}
public void setEmbeddable(Embeddable embeddable) {
this.embeddable = embeddable;
}
public void setEmbeddable2(Embeddable2 embeddable2) {
this.embeddable2 = embeddable2;
}
}
@Data
private static class Embeddable {
@Column("ID") DummyEntity2 dummyEntity2;
String test;
public DummyEntity2 getDummyEntity2() {
return this.dummyEntity2;
}
public String getTest() {
return this.test;
}
public void setDummyEntity2(DummyEntity2 dummyEntity2) {
this.dummyEntity2 = dummyEntity2;
}
public void setTest(String test) {
this.test = test;
}
}
@Data
private static class Embeddable2 {
@Column("ID") DummyEntity2 dummyEntity2;
public DummyEntity2 getDummyEntity2() {
return this.dummyEntity2;
}
public void setDummyEntity2(DummyEntity2 dummyEntity2) {
this.dummyEntity2 = dummyEntity2;
}
}
@Data
private static class DummyEntity2 {
@Column("ID") @Id Long id;
@Column("ID")
@Id Long id;
String test;
public Long getId() {
return this.id;
}
public String getTest() {
return this.test;
}
public void setId(Long id) {
this.id = id;
}
public void setTest(String test) {
this.test = test;
}
}
}

View File

@@ -15,18 +15,8 @@
*/
package org.springframework.data.jdbc.repository;
import static org.assertj.core.api.Assertions.*;
import lombok.Data;
import lombok.Value;
import lombok.With;
import lombok.experimental.FieldDefaults;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@@ -44,6 +34,10 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.util.concurrent.atomic.AtomicLong;
import static org.assertj.core.api.Assertions.*;
/**
* Testing special cases for id generation with {@link SimpleJdbcRepository}.
*
@@ -119,26 +113,128 @@ public class JdbcRepositoryIdGenerationIntegrationTests {
private interface ImmutableWithManualIdEntityRepository extends CrudRepository<ImmutableWithManualIdEntity, Long> {}
@Value
@FieldDefaults(makeFinal = false)
static class ReadOnlyIdEntity {
static final class ReadOnlyIdEntity {
@Id Long id;
String name;
@Id
private final Long id;
private final String name;
public ReadOnlyIdEntity(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof ReadOnlyIdEntity)) return false;
final ReadOnlyIdEntity other = (ReadOnlyIdEntity) o;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false;
final Object this$name = this.getName();
final Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
final Object $name = this.getName();
result = result * PRIME + ($name == null ? 43 : $name.hashCode());
return result;
}
public String toString() {
return "JdbcRepositoryIdGenerationIntegrationTests.ReadOnlyIdEntity(id=" + this.getId() + ", name=" + this.getName() + ")";
}
}
@Data
static class PrimitiveIdEntity {
@Id private long id;
@Id
private long id;
String name;
public long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public void setId(long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
}
@Value
@With
static class ImmutableWithManualIdEntity {
@Id Long id;
String name;
static final class ImmutableWithManualIdEntity {
@Id
private final Long id;
private final String name;
public ImmutableWithManualIdEntity(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof ImmutableWithManualIdEntity)) return false;
final ImmutableWithManualIdEntity other = (ImmutableWithManualIdEntity) o;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false;
final Object this$name = this.getName();
final Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
final Object $name = this.getName();
result = result * PRIME + ($name == null ? 43 : $name.hashCode());
return result;
}
public String toString() {
return "JdbcRepositoryIdGenerationIntegrationTests.ImmutableWithManualIdEntity(id=" + this.getId() + ", name=" + this.getName() + ")";
}
public ImmutableWithManualIdEntity withId(Long id) {
return this.id == id ? this : new ImmutableWithManualIdEntity(id, this.name);
}
public ImmutableWithManualIdEntity withName(String name) {
return this.name == name ? this : new ImmutableWithManualIdEntity(this.id, name);
}
}
@Configuration

View File

@@ -21,10 +21,6 @@ import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.SoftAssertions.*;
import static org.springframework.test.context.TestExecutionListeners.MergeMode.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Value;
import java.io.IOException;
import java.sql.ResultSet;
import java.time.Instant;
@@ -36,6 +32,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;
@@ -83,8 +80,8 @@ import org.springframework.data.repository.core.support.PropertiesBasedNamedQuer
import org.springframework.data.repository.query.ExtensionAwareQueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.FluentQuery;
import org.springframework.data.repository.query.Param;
import org.springframework.data.spel.spi.EvaluationContextExtension;
import org.springframework.data.repository.query.QueryByExampleExecutor;
import org.springframework.data.spel.spi.EvaluationContextExtension;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
@@ -94,8 +91,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.jdbc.JdbcTestUtils;
import org.springframework.transaction.annotation.Transactional;
import lombok.Data;
/**
* Very simple use cases for creation and usage of JdbcRepositories.
*
@@ -1387,13 +1382,12 @@ public class JdbcRepositoryIntegrationTests {
List<Root> findAllByOrderByIdAsc();
}
interface WithDelimitedColumnRepository extends CrudRepository<WithDelimitedColumn, Long> { }
interface WithDelimitedColumnRepository extends CrudRepository<WithDelimitedColumn, Long> {}
@Configuration
@Import(TestConfiguration.class)
static class Config {
@Autowired JdbcRepositoryFactory factory;
@Bean
@@ -1412,7 +1406,9 @@ public class JdbcRepositoryIntegrationTests {
}
@Bean
WithDelimitedColumnRepository withDelimitedColumnRepository() { return factory.getRepository(WithDelimitedColumnRepository.class); }
WithDelimitedColumnRepository withDelimitedColumnRepository() {
return factory.getRepository(WithDelimitedColumnRepository.class);
}
@Bean
NamedQueries namedQueries() throws IOException {
@@ -1430,12 +1426,14 @@ public class JdbcRepositoryIntegrationTests {
@Bean
public ExtensionAwareQueryMethodEvaluationContextProvider extensionAware(List<EvaluationContextExtension> exts) {
ExtensionAwareQueryMethodEvaluationContextProvider extensionAwareQueryMethodEvaluationContextProvider = new ExtensionAwareQueryMethodEvaluationContextProvider(exts);
ExtensionAwareQueryMethodEvaluationContextProvider extensionAwareQueryMethodEvaluationContextProvider = new ExtensionAwareQueryMethodEvaluationContextProvider(
exts);
factory.setEvaluationContextProvider(extensionAwareQueryMethodEvaluationContextProvider);
return extensionAwareQueryMethodEvaluationContextProvider;
}
@Bean
public EvaluationContextExtension evaluationContextExtension() {
return new MyIdContextProvider();
@@ -1443,37 +1441,235 @@ public class JdbcRepositoryIntegrationTests {
}
@Value
static class Root {
static final class Root {
@Id Long id;
String name;
Intermediate intermediate;
@MappedCollection(idColumn = "ROOT_ID", keyColumn = "ROOT_KEY") List<Intermediate> intermediates;
@Id private final Long id;
private final String name;
private final Intermediate intermediate;
@MappedCollection(idColumn = "ROOT_ID", keyColumn = "ROOT_KEY") private final List<Intermediate> intermediates;
public Root(Long id, String name, Intermediate intermediate, List<Intermediate> intermediates) {
this.id = id;
this.name = name;
this.intermediate = intermediate;
this.intermediates = intermediates;
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public Intermediate getIntermediate() {
return this.intermediate;
}
public List<Intermediate> getIntermediates() {
return this.intermediates;
}
public boolean equals(final Object o) {
if (o == this)
return true;
if (!(o instanceof Root))
return false;
final Root other = (Root) o;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id))
return false;
final Object this$name = this.getName();
final Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name))
return false;
final Object this$intermediate = this.getIntermediate();
final Object other$intermediate = other.getIntermediate();
if (this$intermediate == null ? other$intermediate != null : !this$intermediate.equals(other$intermediate))
return false;
final Object this$intermediates = this.getIntermediates();
final Object other$intermediates = other.getIntermediates();
if (this$intermediates == null ? other$intermediates != null : !this$intermediates.equals(other$intermediates))
return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
final Object $name = this.getName();
result = result * PRIME + ($name == null ? 43 : $name.hashCode());
final Object $intermediate = this.getIntermediate();
result = result * PRIME + ($intermediate == null ? 43 : $intermediate.hashCode());
final Object $intermediates = this.getIntermediates();
result = result * PRIME + ($intermediates == null ? 43 : $intermediates.hashCode());
return result;
}
public String toString() {
return "JdbcRepositoryIntegrationTests.Root(id=" + this.getId() + ", name=" + this.getName() + ", intermediate="
+ this.getIntermediate() + ", intermediates=" + this.getIntermediates() + ")";
}
}
@Data
@Table("WITH_DELIMITED_COLUMN")
static class WithDelimitedColumn {
@Id Long id;
@Column("ORG.XTUNIT.IDENTIFIER") String identifier;
@Column ("STYPE") String type;
@Column("STYPE") String type;
public Long getId() {
return this.id;
}
public String getIdentifier() {
return this.identifier;
}
public String getType() {
return this.type;
}
public void setId(Long id) {
this.id = id;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public void setType(String type) {
this.type = type;
}
}
@Value
static class Intermediate {
static final class Intermediate {
@Id Long id;
String name;
Leaf leaf;
@MappedCollection(idColumn = "INTERMEDIATE_ID", keyColumn = "INTERMEDIATE_KEY") List<Leaf> leaves;
@Id private final Long id;
private final String name;
private final Leaf leaf;
@MappedCollection(idColumn = "INTERMEDIATE_ID", keyColumn = "INTERMEDIATE_KEY") private final List<Leaf> leaves;
public Intermediate(Long id, String name, Leaf leaf, List<Leaf> leaves) {
this.id = id;
this.name = name;
this.leaf = leaf;
this.leaves = leaves;
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public Leaf getLeaf() {
return this.leaf;
}
public List<Leaf> getLeaves() {
return this.leaves;
}
public boolean equals(final Object o) {
if (o == this)
return true;
if (!(o instanceof Intermediate))
return false;
final Intermediate other = (Intermediate) o;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id))
return false;
final Object this$name = this.getName();
final Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name))
return false;
final Object this$leaf = this.getLeaf();
final Object other$leaf = other.getLeaf();
if (this$leaf == null ? other$leaf != null : !this$leaf.equals(other$leaf))
return false;
final Object this$leaves = this.getLeaves();
final Object other$leaves = other.getLeaves();
if (this$leaves == null ? other$leaves != null : !this$leaves.equals(other$leaves))
return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
final Object $name = this.getName();
result = result * PRIME + ($name == null ? 43 : $name.hashCode());
final Object $leaf = this.getLeaf();
result = result * PRIME + ($leaf == null ? 43 : $leaf.hashCode());
final Object $leaves = this.getLeaves();
result = result * PRIME + ($leaves == null ? 43 : $leaves.hashCode());
return result;
}
public String toString() {
return "JdbcRepositoryIntegrationTests.Intermediate(id=" + this.getId() + ", name=" + this.getName() + ", leaf="
+ this.getLeaf() + ", leaves=" + this.getLeaves() + ")";
}
}
@Value
static class Leaf {
static final class Leaf {
@Id Long id;
String name;
@Id private final Long id;
private final String name;
public Leaf(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public boolean equals(final Object o) {
if (o == this)
return true;
if (!(o instanceof Leaf))
return false;
final Leaf other = (Leaf) o;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id))
return false;
final Object this$name = this.getName();
final Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name))
return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
final Object $name = this.getName();
result = result * PRIME + ($name == null ? 43 : $name.hashCode());
return result;
}
public String toString() {
return "JdbcRepositoryIntegrationTests.Leaf(id=" + this.getId() + ", name=" + this.getName() + ")";
}
}
static class MyEventListener implements ApplicationListener<AbstractRelationalEvent<?>> {
@@ -1507,8 +1703,6 @@ public class JdbcRepositoryIntegrationTests {
}
}
@Data
@NoArgsConstructor
static class DummyEntity {
String name;
@@ -1522,6 +1716,77 @@ public class JdbcRepositoryIntegrationTests {
public DummyEntity(String name) {
this.name = name;
}
public DummyEntity() {}
public String getName() {
return this.name;
}
public Instant getPointInTime() {
return this.pointInTime;
}
public OffsetDateTime getOffsetDateTime() {
return this.offsetDateTime;
}
public Long getIdProp() {
return this.idProp;
}
public boolean isFlag() {
return this.flag;
}
public AggregateReference<DummyEntity, Long> getRef() {
return this.ref;
}
public Direction getDirection() {
return this.direction;
}
public void setName(String name) {
this.name = name;
}
public void setPointInTime(Instant pointInTime) {
this.pointInTime = pointInTime;
}
public void setOffsetDateTime(OffsetDateTime offsetDateTime) {
this.offsetDateTime = offsetDateTime;
}
public void setIdProp(Long idProp) {
this.idProp = idProp;
}
public void setFlag(boolean flag) {
this.flag = flag;
}
public void setRef(AggregateReference<DummyEntity, Long> ref) {
this.ref = ref;
}
public void setDirection(Direction direction) {
this.direction = direction;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DummyEntity that = (DummyEntity) o;
return flag == that.flag && Objects.equals(name, that.name) && Objects.equals(pointInTime, that.pointInTime) && Objects.equals(offsetDateTime, that.offsetDateTime) && Objects.equals(idProp, that.idProp) && Objects.equals(ref, that.ref) && direction == that.direction;
}
@Override
public int hashCode() {
return Objects.hash(name, pointInTime, offsetDateTime, idProp, flag, ref, direction);
}
}
enum Direction {
@@ -1532,9 +1797,41 @@ public class JdbcRepositoryIntegrationTests {
String getName();
}
@Value
static class DtoProjection {
String name;
static final class DtoProjection {
private final String name;
public DtoProjection(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public boolean equals(final Object o) {
if (o == this)
return true;
if (!(o instanceof DtoProjection))
return false;
final DtoProjection other = (DtoProjection) o;
final Object this$name = this.getName();
final Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name))
return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $name = this.getName();
result = result * PRIME + ($name == null ? 43 : $name.hashCode());
return result;
}
public String toString() {
return "JdbcRepositoryIntegrationTests.DtoProjection(name=" + this.getName() + ")";
}
}
static class CustomRowMapper implements RowMapper<DummyEntity> {

View File

@@ -20,8 +20,6 @@ import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.jdbc.testing.TestDatabaseFeatures.Feature.*;
import static org.springframework.test.context.TestExecutionListeners.MergeMode.*;
import lombok.Data;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.SimpleDateFormat;
@@ -188,7 +186,6 @@ public class JdbcRepositoryPropertyConversionIntegrationTests {
}
}
@Data
static class EntityWithColumnsRequiringConversions {
boolean bool;
@@ -201,11 +198,82 @@ public class JdbcRepositoryPropertyConversionIntegrationTests {
@Id private LocalDateTime idTimestamp;
@MappedCollection(idColumn = "ID_TIMESTAMP") Set<EntityWithColumnsRequiringConversionsRelation> relation;
public boolean isBool() {
return this.bool;
}
public SomeEnum getSomeEnum() {
return this.someEnum;
}
public BigDecimal getBigDecimal() {
return this.bigDecimal;
}
public BigInteger getBigInteger() {
return this.bigInteger;
}
public Date getDate() {
return this.date;
}
public LocalDateTime getLocalDateTime() {
return this.localDateTime;
}
public LocalDateTime getIdTimestamp() {
return this.idTimestamp;
}
public Set<EntityWithColumnsRequiringConversionsRelation> getRelation() {
return this.relation;
}
public void setBool(boolean bool) {
this.bool = bool;
}
public void setSomeEnum(SomeEnum someEnum) {
this.someEnum = someEnum;
}
public void setBigDecimal(BigDecimal bigDecimal) {
this.bigDecimal = bigDecimal;
}
public void setBigInteger(BigInteger bigInteger) {
this.bigInteger = bigInteger;
}
public void setDate(Date date) {
this.date = date;
}
public void setLocalDateTime(LocalDateTime localDateTime) {
this.localDateTime = localDateTime;
}
public void setIdTimestamp(LocalDateTime idTimestamp) {
this.idTimestamp = idTimestamp;
}
public void setRelation(Set<EntityWithColumnsRequiringConversionsRelation> relation) {
this.relation = relation;
}
}
// DATAJDBC-349
@Data
static class EntityWithColumnsRequiringConversionsRelation {
String data;
public String getData() {
return this.data;
}
public void setData(String data) {
this.data = data;
}
}
}

View File

@@ -15,19 +15,6 @@
*/
package org.springframework.data.jdbc.repository;
import static org.assertj.core.api.Assertions.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -46,10 +33,18 @@ import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.junit4.rules.SpringClassRule;
import org.springframework.test.context.junit4.rules.SpringMethodRule;
import org.springframework.transaction.annotation.Transactional;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.*;
/**
* Very simple use cases for creation and usage of {@link ResultSetExtractor}s in JdbcRepository.
*
@@ -138,21 +133,70 @@ public class JdbcRepositoryResultSetExtractorIntegrationTests {
List<Person> findAllPeopleWithAddresses();
}
@Data
@AllArgsConstructor
static class Person {
@Id private Long id;
@Id
private Long id;
private String name;
private List<Address> addresses;
public Person(Long id, String name, List<Address> addresses) {
this.id = id;
this.name = name;
this.addresses = addresses;
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public List<Address> getAddresses() {
return this.addresses;
}
public void setId(Long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setAddresses(List<Address> addresses) {
this.addresses = addresses;
}
}
@Data
@AllArgsConstructor
static class Address {
@Id private Long id;
@Id
private Long id;
private String street;
public Address(Long id, String street) {
this.id = id;
this.street = street;
}
public Long getId() {
return this.id;
}
public String getStreet() {
return this.street;
}
public void setId(Long id) {
this.id = id;
}
public void setStreet(String street) {
this.street = street;
}
}
static class PersonResultSetExtractor implements ResultSetExtractor<List<Person>> {

View File

@@ -15,17 +15,7 @@
*/
package org.springframework.data.jdbc.repository;
import static org.assertj.core.api.Assertions.*;
import junit.framework.AssertionFailedError;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -44,6 +34,13 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import static org.assertj.core.api.Assertions.*;
/**
* Very simple use cases for creation and usage of JdbcRepositories.
*
@@ -229,20 +226,46 @@ public class JdbcRepositoryWithCollectionsAndManuallyAssignedIdHsqlIntegrationTe
interface DummyEntityRepository extends CrudRepository<DummyEntity, Long> {}
@Data
static class DummyEntity {
@Id private Long id;
@Id
private Long id;
String name;
Set<Element> content = new HashSet<>();
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public Set<Element> getContent() {
return this.content;
}
public void setId(Long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setContent(Set<Element> content) {
this.content = content;
}
}
@RequiredArgsConstructor
static class Element {
@Id private Long id;
@Id
private Long id;
String content;
public Element() {
}
}
}

View File

@@ -20,8 +20,6 @@ import static org.springframework.data.jdbc.testing.TestDatabaseFeatures.Feature
import static org.springframework.test.context.TestExecutionListeners.MergeMode.*;
import junit.framework.AssertionFailedError;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import java.util.HashMap;
import java.util.HashSet;
@@ -210,16 +208,37 @@ public class JdbcRepositoryWithCollectionsIntegrationTests {
}
}
@Data
static class DummyEntity {
String name;
Set<Element> content = new HashSet<>();
@Id private Long id;
public String getName() {
return this.name;
}
public Set<Element> getContent() {
return this.content;
}
public Long getId() {
return this.id;
}
public void setName(String name) {
this.name = name;
}
public void setContent(Set<Element> content) {
this.content = content;
}
public void setId(Long id) {
this.id = id;
}
}
@RequiredArgsConstructor
static class Element {
String content;

View File

@@ -21,9 +21,6 @@ import static org.springframework.data.jdbc.testing.TestDatabaseFeatures.Feature
import static org.springframework.test.context.TestExecutionListeners.MergeMode.*;
import junit.framework.AssertionFailedError;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import java.util.ArrayList;
import java.util.HashMap;
@@ -247,36 +244,121 @@ public class JdbcRepositoryWithListsIntegrationTests {
}
}
@Data
static class DummyEntity {
String name;
List<Element> content = new ArrayList<>();
@Id private Long id;
public String getName() {
return this.name;
}
public List<Element> getContent() {
return this.content;
}
public Long getId() {
return this.id;
}
public void setName(String name) {
this.name = name;
}
public void setContent(List<Element> content) {
this.content = content;
}
public void setId(Long id) {
this.id = id;
}
}
@RequiredArgsConstructor
static class Element {
String content;
@Id private Long id;
public Element() {}
}
@Data
static class Root {
@Id private Long id;
List<Intermediate> intermediates = new ArrayList<>();
public Long getId() {
return this.id;
}
public List<Intermediate> getIntermediates() {
return this.intermediates;
}
public void setId(Long id) {
this.id = id;
}
public void setIntermediates(List<Intermediate> intermediates) {
this.intermediates = intermediates;
}
}
@Data
static class Intermediate {
@Id private Long id;
List<Leaf> leaves = new ArrayList<>();
public Long getId() {
return this.id;
}
public List<Leaf> getLeaves() {
return this.leaves;
}
public void setId(Long id) {
this.id = id;
}
public void setLeaves(List<Leaf> leaves) {
this.leaves = leaves;
}
}
@Value
static class Leaf {
String name;
static final class Leaf {
private final String name;
public Leaf(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public boolean equals(final Object o) {
if (o == this)
return true;
if (!(o instanceof Leaf))
return false;
final Leaf other = (Leaf) o;
final Object this$name = this.getName();
final Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name))
return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $name = this.getName();
result = result * PRIME + ($name == null ? 43 : $name.hashCode());
return result;
}
public String toString() {
return "JdbcRepositoryWithListsIntegrationTests.Leaf(name=" + this.getName() + ")";
}
}
}

View File

@@ -20,8 +20,6 @@ import static org.springframework.data.jdbc.testing.TestDatabaseFeatures.Feature
import static org.springframework.test.context.TestExecutionListeners.MergeMode.*;
import junit.framework.AssertionFailedError;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import java.util.HashMap;
import java.util.Map;
@@ -213,20 +211,43 @@ public class JdbcRepositoryWithMapsIntegrationTests {
interface DummyEntityRepository extends CrudRepository<DummyEntity, Long> {}
@Data
static class DummyEntity {
@Id private Long id;
String name;
Map<String, Element> content = new HashMap<>();
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public Map<String, Element> getContent() {
return this.content;
}
public void setId(Long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setContent(Map<String, Element> content) {
this.content = content;
}
}
@RequiredArgsConstructor
static class Element {
@Id private Long id;
String content;
public Element() {}
}
}

View File

@@ -15,20 +15,6 @@
*/
package org.springframework.data.jdbc.repository;
import static java.util.Arrays.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.groups.Tuple.tuple;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import lombok.With;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.stubbing.Answer;
@@ -62,6 +48,16 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.lang.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import static java.util.Arrays.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.groups.Tuple.tuple;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
/**
* Unit tests for application events via {@link SimpleJdbcRepository}.
*
@@ -302,11 +298,43 @@ class SimpleJdbcRepositoryEventsUnitTests {
interface DummyEntityRepository
extends CrudRepository<DummyEntity, Long>, PagingAndSortingRepository<DummyEntity, Long> {}
@Value
@With
@RequiredArgsConstructor
static class DummyEntity {
@Id Long id;
static final class DummyEntity {
@Id
private final Long id;
public DummyEntity(Long id) {
this.id = id;
}
public Long getId() {
return this.id;
}
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof DummyEntity)) return false;
final DummyEntity other = (DummyEntity) o;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
return result;
}
public String toString() {
return "SimpleJdbcRepositoryEventsUnitTests.DummyEntity(id=" + this.getId() + ")";
}
public DummyEntity withId(Long id) {
return this.id == id ? this : new DummyEntity(id);
}
}
static class CollectingEventPublisher implements ApplicationEventPublisher {

View File

@@ -18,9 +18,6 @@ package org.springframework.data.jdbc.repository;
import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
@@ -28,7 +25,6 @@ import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@@ -122,12 +118,31 @@ public class StringBasedJdbcQueryMappingConfigurationIntegrationTests {
}
}
@Data
@AllArgsConstructor
public static class Car {
@Id private Long id;
private String model;
public Car(Long id, String model) {
this.id = id;
this.model = model;
}
public Long getId() {
return this.id;
}
public String getModel() {
return this.model;
}
public void setId(Long id) {
this.id = id;
}
public void setModel(String model) {
this.model = model;
}
}
static class CarResultSetExtractor implements ResultSetExtractor<List<Car>> {
@@ -163,7 +178,6 @@ public class StringBasedJdbcQueryMappingConfigurationIntegrationTests {
@Query(value = "select model from car", rowMapperRef = "CustomRowMapperBean")
List<String> findByNameWithRowMapperBean();
@Query(value = "select * from car", resultSetExtractorClass = RowMapperResultSetExtractor.class)
RowMapper customFindAllWithRowMapper();

View File

@@ -17,10 +17,9 @@ package org.springframework.data.jdbc.repository.config;
import static org.assertj.core.api.Assertions.*;
import lombok.Data;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
@@ -236,7 +235,6 @@ public class EnableJdbcAuditingHsqlIntegrationTests {
interface AuditingAnnotatedDummyEntityRepository extends CrudRepository<AuditingAnnotatedDummyEntity, Long> {}
@Data
static class AuditingAnnotatedDummyEntity {
@Id long id;
@@ -244,16 +242,84 @@ public class EnableJdbcAuditingHsqlIntegrationTests {
@CreatedDate LocalDateTime createdDate;
@LastModifiedBy String lastModifiedBy;
@LastModifiedDate LocalDateTime lastModifiedDate;
public long getId() {
return this.id;
}
public String getCreatedBy() {
return this.createdBy;
}
public LocalDateTime getCreatedDate() {
return this.createdDate;
}
public String getLastModifiedBy() {
return this.lastModifiedBy;
}
public LocalDateTime getLastModifiedDate() {
return this.lastModifiedDate;
}
public void setId(long id) {
this.id = id;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public void setCreatedDate(LocalDateTime createdDate) {
this.createdDate = createdDate;
}
public void setLastModifiedBy(String lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
public void setLastModifiedDate(LocalDateTime lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
}
interface DummyEntityRepository extends CrudRepository<DummyEntity, Long> {}
@Data
static class DummyEntity {
@Id private Long id;
// not actually used, exists just to avoid empty value list during insert.
String name;
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public void setId(Long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DummyEntity that = (DummyEntity) o;
return Objects.equals(id, that.id) && Objects.equals(name, that.name);
}
@Override
public int hashCode() {
return Objects.hash(id, name);
}
}
@ComponentScan("org.springframework.data.jdbc.testing")

View File

@@ -17,8 +17,6 @@ package org.springframework.data.jdbc.repository.config;
import static org.assertj.core.api.Assertions.*;
import lombok.Data;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -52,9 +50,16 @@ public class EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests {
}
@Data
static class DummyEntity {
@Id private Long id;
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
}
@ComponentScan("org.springframework.data.jdbc.testing")

View File

@@ -18,8 +18,6 @@ package org.springframework.data.jdbc.repository.config;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import lombok.Data;
import java.lang.reflect.Field;
import java.util.Optional;
@@ -133,9 +131,16 @@ public class EnableJdbcRepositoriesIntegrationTests {
}
@Data
static class DummyEntity {
@Id private Long id;
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
}
@ComponentScan("org.springframework.data.jdbc.testing")

View File

@@ -19,8 +19,6 @@ import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.SoftAssertions.*;
import static org.mockito.Mockito.*;
import lombok.AllArgsConstructor;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
@@ -795,15 +793,10 @@ public class PartTreeJdbcQueryUnitTests {
AggregateReference<Hobby, String> hobbyReference;
}
@AllArgsConstructor
static class Address {
String street;
String city;
record Address(String street, String city) {
}
@AllArgsConstructor
static class AnotherEmbedded {
@MappedCollection(idColumn = "ID", keyColumn = "ORDER_KEY") List<Hobby> list;
record AnotherEmbedded(@MappedCollection(idColumn = "ID", keyColumn = "ORDER_KEY") List<Hobby> list) {
}
static class Hobby {

View File

@@ -18,8 +18,6 @@ package org.springframework.data.jdbc.repository.query;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.SoftAssertions.*;
import lombok.Value;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
@@ -347,11 +345,7 @@ public class QueryAnnotationHsqlIntegrationTests {
@Query("SELECT 'one' one, 'two' two, 3 three FROM (VALUES (0)) as tableName")
ImmutableTuple immutableTuple();
@Value
class ImmutableTuple {
String one;
String two;
int three;
record ImmutableTuple(String one, String two, int three) {
}
}
}