Skip to content

Commit

Permalink
Add conversion capabilities to the entity instantiator.
Browse files Browse the repository at this point in the history
Closes #1646
  • Loading branch information
schauder committed Oct 17, 2023
1 parent 778d368 commit 6736d83
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,16 @@ void multipleCollectionsWithEmptyList() {
assertThat(reloaded.mapElements.get("delta")).isEqualTo(new MapElement("four"));
}

@Test // GH-1646
void recordOfSet() {

Author tolkien = template.save(new Author(null, Set.of(new Book("Lord of the Rings"))));

Iterable<Author> authors = template.findAll(Author.class);

assertThat(authors).containsExactly(tolkien);
}

private <T extends Number> void saveAndUpdateAggregateWithVersion(VersionedAggregate aggregate,
Function<Number, T> toConcreteNumber) {
saveAndUpdateAggregateWithVersion(aggregate, toConcreteNumber, 0);
Expand Down Expand Up @@ -2079,6 +2089,13 @@ record SetElement(String name) {
record MapElement(String name) {
}

record Author(@Id Long id, Set<Book> books) {
}

record Book(String name) {

}

@Configuration
@Import(TestConfiguration.class)
static class Config {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ DROP TABLE MAP_ELEMENT;
DROP TABLE LIST_ELEMENT;
DROP TABLE SET_ELEMENT;

DROP TABLE BOOK;
DROP TABLE AUTHOR;

CREATE TABLE LEGO_SET
(
"id1" BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY,
Expand Down Expand Up @@ -405,3 +408,14 @@ CREATE TABLE MAP_ELEMENT
MULTIPLE_COLLECTIONS_KEY VARCHAR(10),
NAME VARCHAR(100)
);

CREATE TABLE AUTHOR
(
ID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY
);

CREATE TABLE BOOK
(
AUTHOR BIGINT,
NAME VARCHAR(100)
);
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,14 @@ CREATE TABLE MAP_ELEMENT
MULTIPLE_COLLECTIONS_KEY VARCHAR(10),
NAME VARCHAR(100)
);

CREATE TABLE AUTHOR
(
ID SERIAL PRIMARY KEY
);

CREATE TABLE BOOK
(
AUTHOR BIGINT,
NAME VARCHAR(100)
);
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,14 @@ CREATE TABLE MAP_ELEMENT
MULTIPLE_COLLECTIONS_KEY VARCHAR(10),
NAME VARCHAR(100)
);

CREATE TABLE AUTHOR
(
ID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY
);

CREATE TABLE BOOK
(
AUTHOR BIGINT,
NAME VARCHAR(100)
);
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,14 @@ CREATE TABLE MAP_ELEMENT
MULTIPLE_COLLECTIONS_KEY VARCHAR(10),
NAME VARCHAR(100)
);

CREATE TABLE AUTHOR
(
ID BIGINT AUTO_INCREMENT PRIMARY KEY
);

CREATE TABLE BOOK
(
AUTHOR BIGINT,
NAME VARCHAR(100)
);
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,17 @@ CREATE TABLE MAP_ELEMENT
MULTIPLE_COLLECTIONS_KEY VARCHAR(10),
NAME VARCHAR(100)
);

DROP TABLE BOOK;
DROP TABLE AUTHOR;

CREATE TABLE AUTHOR
(
ID BIGINT IDENTITY PRIMARY KEY
);

CREATE TABLE BOOK
(
AUTHOR BIGINT,
NAME VARCHAR(100)
);
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,14 @@ CREATE TABLE MAP_ELEMENT
MULTIPLE_COLLECTIONS_KEY VARCHAR(10),
NAME VARCHAR(100)
);

CREATE TABLE AUTHOR
(
ID BIGINT AUTO_INCREMENT PRIMARY KEY
);

CREATE TABLE BOOK
(
AUTHOR BIGINT,
NAME VARCHAR(100)
);
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ DROP TABLE MAP_ELEMENT CASCADE CONSTRAINTS PURGE;
DROP TABLE LIST_ELEMENT CASCADE CONSTRAINTS PURGE;
DROP TABLE SET_ELEMENT CASCADE CONSTRAINTS PURGE;

DROP TABLE BOOK CASCADE CONSTRAINTS PURGE;
DROP TABLE AUTHOR CASCADE CONSTRAINTS PURGE;

CREATE TABLE LEGO_SET
(
"id1" NUMBER GENERATED by default on null as IDENTITY PRIMARY KEY,
Expand Down Expand Up @@ -386,3 +389,14 @@ CREATE TABLE MAP_ELEMENT
MULTIPLE_COLLECTIONS_KEY VARCHAR(10),
NAME VARCHAR(100)
);

CREATE TABLE AUTHOR
(
ID NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY PRIMARY KEY
);

CREATE TABLE BOOK
(
AUTHOR NUMBER,
NAME VARCHAR(100)
);
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ DROP TABLE MAP_ELEMENT;
DROP TABLE LIST_ELEMENT;
DROP TABLE SET_ELEMENT;

DROP TABLE BOOK;
DROP TABLE AUTHOR;

CREATE TABLE LEGO_SET
(
"id1" SERIAL PRIMARY KEY,
Expand Down Expand Up @@ -408,3 +411,14 @@ CREATE TABLE MAP_ELEMENT
MULTIPLE_COLLECTIONS_KEY VARCHAR(10),
NAME VARCHAR(100)
);

CREATE TABLE AUTHOR
(
ID SERIAL PRIMARY KEY
);

CREATE TABLE BOOK
(
AUTHOR BIGINT,
NAME VARCHAR(100)
);
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ public RelationalPropertyValueProvider withContext(ConversionContext context) {
entity, contextualizing, context.getPath().getCurrentObject());

return new ConverterAwareSpELExpressionParameterValueProvider(context, evaluator, getConversionService(),
parameterProvider);
new ConvertingParameterValueProvider<>( parameterProvider::getParameterValue));
}

private <S> S populateProperties(ConversionContext context, RelationalPersistentEntity<S> entity,
Expand Down

0 comments on commit 6736d83

Please sign in to comment.