diff --git a/examples/spring-data-spqr/pom.xml b/examples/spring-data-spqr/pom.xml index c1a57f4581..1872149626 100644 --- a/examples/spring-data-spqr/pom.xml +++ b/examples/spring-data-spqr/pom.xml @@ -198,6 +198,12 @@ jakarta.annotation-api ${version.annotation} + + ${project.groupId} + blaze-persistence-entity-view-processor + ${project.version} + provided + @@ -221,6 +227,72 @@ + + org.bsc.maven + maven-processor-plugin + + + process + + process + + generate-sources + + + ${project.build.directory}/metamodel + + com.blazebit.persistence.view.processor.EntityViewAnnotationProcessor + + + + + + + + ${project.groupId} + blaze-persistence-entity-view-processor + ${project.version} + + + jakarta.xml.bind + jakarta.xml.bind-api + ${version.jaxb-api} + + + com.sun.xml.bind + jaxb-impl + ${version.jaxb} + + + jakarta.transaction + jakarta.transaction-api + ${version.jta} + + + jakarta.activation + jakarta.activation-api + ${version.activation} + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + add-source-metamodel + generate-sources + + add-source + + + + ${project.build.directory}/metamodel + + + + + diff --git a/examples/spring-data-spqr/src/main/java/com/blazebit/persistence/examples/spring/data/spqr/config/BlazePersistenceConfiguration.java b/examples/spring-data-spqr/src/main/java/com/blazebit/persistence/examples/spring/data/spqr/config/BlazePersistenceConfiguration.java index 1264b2eda9..b05f16a939 100644 --- a/examples/spring-data-spqr/src/main/java/com/blazebit/persistence/examples/spring/data/spqr/config/BlazePersistenceConfiguration.java +++ b/examples/spring-data-spqr/src/main/java/com/blazebit/persistence/examples/spring/data/spqr/config/BlazePersistenceConfiguration.java @@ -57,6 +57,7 @@ public CriteriaBuilderFactory createCriteriaBuilderFactory() { @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) @Lazy(false) public EntityViewManager createEntityViewManager(CriteriaBuilderFactory cbf, EntityViewConfiguration entityViewConfiguration) { +// entityViewConfiguration.getProperties().setProperty("com.blazebit.persistence.view.static_implementation_scanning_disabled", "true"); return entityViewConfiguration.createEntityViewManager(cbf); } } \ No newline at end of file diff --git a/examples/spring-data-spqr/src/main/java/com/blazebit/persistence/examples/spring/data/spqr/resource/CatGraphQLApi.java b/examples/spring-data-spqr/src/main/java/com/blazebit/persistence/examples/spring/data/spqr/resource/CatGraphQLApi.java index c7f162582e..b95fa0ce55 100644 --- a/examples/spring-data-spqr/src/main/java/com/blazebit/persistence/examples/spring/data/spqr/resource/CatGraphQLApi.java +++ b/examples/spring-data-spqr/src/main/java/com/blazebit/persistence/examples/spring/data/spqr/resource/CatGraphQLApi.java @@ -19,6 +19,9 @@ import com.blazebit.persistence.examples.spring.data.spqr.repository.CatViewRepository; import com.blazebit.persistence.examples.spring.data.spqr.view.CatCreateView; import com.blazebit.persistence.examples.spring.data.spqr.view.CatWithOwnerView; +import com.blazebit.persistence.examples.spring.data.spqr.view.ChildInput; +import com.blazebit.persistence.examples.spring.data.spqr.view.ChildView; +import com.blazebit.persistence.examples.spring.data.spqr.view.PersonSimpleView; import com.blazebit.persistence.integration.graphql.GraphQLEntityViewSupport; import com.blazebit.persistence.view.EntityViewManager; import com.blazebit.persistence.view.EntityViewSetting; @@ -76,4 +79,13 @@ public Long createCat(@GraphQLArgument(name = "cat") CatCreateView cat) { repository.save(cat); return cat.getId(); } + + @GraphQLMutation + public Long addPersonChild(@GraphQLArgument(name = "child") ChildInput childInput, @GraphQLArgument(name = "personId") Long personId) { + PersonSimpleView person = repository.findById(EntityViewSetting.create(PersonSimpleView.class), personId); + ChildView child = (childInput.getBoy() != null) ? childInput.getBoy() : childInput.getGirl(); + person.getChildren().add(child); + repository.save(person); + return child.getId(); + } } diff --git a/examples/spring-data-spqr/src/main/java/com/blazebit/persistence/examples/spring/data/spqr/view/ChildInput.java b/examples/spring-data-spqr/src/main/java/com/blazebit/persistence/examples/spring/data/spqr/view/ChildInput.java new file mode 100644 index 0000000000..6c0399ad18 --- /dev/null +++ b/examples/spring-data-spqr/src/main/java/com/blazebit/persistence/examples/spring/data/spqr/view/ChildInput.java @@ -0,0 +1,45 @@ +/* + * Copyright 2014 - 2023 Blazebit. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.blazebit.persistence.examples.spring.data.spqr.view; + +import io.leangen.graphql.annotations.types.GraphQLType; + +/** + * @author Christian Beikov + * @since 1.6.4 + */ +@GraphQLType(name = "ChildInput") +public class ChildInput { + BoyView boy; + GirlView girl; + + public BoyView getBoy() { + return boy; + } + + public void setBoy(BoyView boy) { + this.boy = boy; + } + + public GirlView getGirl() { + return girl; + } + + public void setGirl(GirlView girl) { + this.girl = girl; + } +} diff --git a/examples/spring-data-spqr/src/main/java/com/blazebit/persistence/examples/spring/data/spqr/view/ChildView.java b/examples/spring-data-spqr/src/main/java/com/blazebit/persistence/examples/spring/data/spqr/view/ChildView.java index eac5c4f5b9..03fd6fe438 100644 --- a/examples/spring-data-spqr/src/main/java/com/blazebit/persistence/examples/spring/data/spqr/view/ChildView.java +++ b/examples/spring-data-spqr/src/main/java/com/blazebit/persistence/examples/spring/data/spqr/view/ChildView.java @@ -17,6 +17,7 @@ package com.blazebit.persistence.examples.spring.data.spqr.view; import com.blazebit.persistence.examples.spring.data.spqr.model.Child; +import com.blazebit.persistence.view.CreatableEntityView; import com.blazebit.persistence.view.EntityView; import com.blazebit.persistence.view.EntityViewInheritance; import com.blazebit.persistence.view.IdMapping; @@ -26,7 +27,9 @@ * @author Christian Beikov * @since 1.6.4 */ -@GraphQLUnion(name = "Child", possibleTypeAutoDiscovery = true) +// Can't use possibleTypeAutoDiscovery=true because of the generated EV implementations +@GraphQLUnion(name = "Child", possibleTypes = {BoyView.class, GirlView.class}) +@CreatableEntityView @EntityView(Child.class) @EntityViewInheritance public interface ChildView { @@ -35,4 +38,6 @@ public interface ChildView { Long getId(); String getName(); + + void setName(String name); } diff --git a/examples/spring-data-spqr/src/main/java/com/blazebit/persistence/examples/spring/data/spqr/view/PersonSimpleView.java b/examples/spring-data-spqr/src/main/java/com/blazebit/persistence/examples/spring/data/spqr/view/PersonSimpleView.java index 216cf294ac..5dc2966f77 100644 --- a/examples/spring-data-spqr/src/main/java/com/blazebit/persistence/examples/spring/data/spqr/view/PersonSimpleView.java +++ b/examples/spring-data-spqr/src/main/java/com/blazebit/persistence/examples/spring/data/spqr/view/PersonSimpleView.java @@ -18,6 +18,7 @@ import com.blazebit.persistence.examples.spring.data.spqr.model.Person; import com.blazebit.persistence.view.EntityView; +import com.blazebit.persistence.view.UpdatableEntityView; import java.util.Set; @@ -25,6 +26,7 @@ * @author Christian Beikov * @since 1.6.4 */ +@UpdatableEntityView @EntityView(Person.class) public interface PersonSimpleView extends PersonIdView { diff --git a/examples/spring-data-spqr/src/test/java/com/blazebit/persistence/examples/spring/data/spqr/repository/SampleTest.java b/examples/spring-data-spqr/src/test/java/com/blazebit/persistence/examples/spring/data/spqr/repository/SampleTest.java index b916ceb32a..5181848fab 100644 --- a/examples/spring-data-spqr/src/test/java/com/blazebit/persistence/examples/spring/data/spqr/repository/SampleTest.java +++ b/examples/spring-data-spqr/src/test/java/com/blazebit/persistence/examples/spring/data/spqr/repository/SampleTest.java @@ -31,6 +31,7 @@ import java.util.List; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; /** * @author Christian Beikov @@ -106,6 +107,22 @@ public void testCreate() { assertEquals("PersonSimpleView", response.getBody().get("data").get("catById").get("owner").get("__typename").asText()); } + @Test + public void testCreateInheritance() { + String requestGraphQL = "mutation {\n" + + " addPersonChild(\n" + + " child: {\n" + + " boy: { name: \"Test\" }\n" + + " },\n" + + " personId: 3\n" + + " )\n" + + "}"; + HttpHeaders headers = new HttpHeaders(); + headers.add("content-type", "application/graphql"); + ResponseEntity response = this.restTemplate.postForEntity("/graphql", new HttpEntity<>(requestGraphQL, headers), JsonNode.class); + assertNull(response.getBody().get("errors")); + } + static String request(int first, String after) { String other = ""; if (after != null) {