From e625ec7a83f33c651883b5a1731a9fda0f9fc6cf Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Wed, 15 Mar 2017 08:36:08 +0100 Subject: [PATCH] #366 - Implemented simple correlations, reworked metamodel building, updated how general correlations work --- CHANGELOG.md | 4 + .../com/blazebit/persistence/FromBuilder.java | 9 + .../impl/AbstractCommonQueryBuilder.java | 11 +- .../persistence/impl/ExpressionUtils.java | 1 - .../impl}/AliasReplacementVisitor.java | 2 +- ...xingAndAliasReplacementQueryGenerator.java | 74 ++++ .../impl/expression/MacroConfiguration.java | 4 + .../persistence/testsuite/GroupByTest.java | 3 +- .../persistence/testsuite/SelectTest.java | 4 - .../entity-view/manual/en_US/04_mappings.adoc | 84 ++-- .../manual/en_US/05_fetch_strategies.adoc | 35 +- .../persistence/view/CorrelationBuilder.java | 19 +- .../persistence/view/MappingCorrelated.java | 6 +- .../view/MappingCorrelatedSimple.java | 75 ++++ .../view/spi/ViewRootJpqlMacro.java | 40 ++ .../view/impl/CorrelationProviderHelper.java | 9 + .../impl/CorrelationProviderProxyBase.java | 73 ++++ .../impl/EntityViewConfigurationImpl.java | 4 +- .../view/impl/EntityViewManagerImpl.java | 99 ++--- ...calarTargetResolvingExpressionVisitor.java | 1 + .../CorrelatedSubqueryViewRootJpqlMacro.java | 14 +- ...cro.java => DefaultViewRootJpqlMacro.java} | 20 +- .../impl/metamodel/AbstractAttribute.java | 368 +++++++++++++----- .../metamodel/AbstractMethodAttribute.java | 27 +- .../AbstractMethodPluralAttribute.java | 9 +- .../AbstractMethodSingularAttribute.java | 5 +- .../metamodel/AbstractParameterAttribute.java | 23 +- .../AbstractParameterPluralAttribute.java | 7 +- .../AbstractParameterSingularAttribute.java | 5 +- .../metamodel/EmbeddableViewTypeImpl.java | 20 +- .../impl/metamodel/ManagedViewTypeImpl.java | 87 ++--- .../metamodel/MappingConstructorImpl.java | 94 +++-- .../metamodel/MetamodelBuildingContext.java | 45 +++ .../MetamodelBuildingContextImpl.java | 97 +++++ .../impl/metamodel/ViewMetamodelImpl.java | 45 +-- .../view/impl/metamodel/ViewTypeImpl.java | 45 +-- .../AbstractMethodCollectionAttribute.java | 6 +- .../AbstractMethodListAttribute.java | 10 +- .../attribute/AbstractMethodMapAttribute.java | 12 +- .../attribute/AbstractMethodSetAttribute.java | 5 +- .../AbstractParameterCollectionAttribute.java | 6 +- .../AbstractParameterListAttribute.java | 10 +- .../AbstractParameterMapAttribute.java | 10 +- .../AbstractParameterSetAttribute.java | 5 +- .../CorrelatedMethodCollectionAttribute.java | 6 +- .../CorrelatedMethodListAttribute.java | 8 +- ...relatedMethodMappingSingularAttribute.java | 6 +- .../CorrelatedMethodSetAttribute.java | 5 +- ...orrelatedParameterCollectionAttribute.java | 6 +- .../CorrelatedParameterListAttribute.java | 8 +- ...atedParameterMappingSingularAttribute.java | 6 +- .../CorrelatedParameterSetAttribute.java | 5 +- .../MappingMethodCollectionAttribute.java | 6 +- .../attribute/MappingMethodListAttribute.java | 8 +- .../attribute/MappingMethodMapAttribute.java | 6 +- .../attribute/MappingMethodSetAttribute.java | 5 +- .../MappingMethodSingularAttribute.java | 12 +- .../MappingParameterCollectionAttribute.java | 6 +- .../MappingParameterListAttribute.java | 8 +- .../MappingParameterMapAttribute.java | 6 +- ...pingParameterMappingSingularAttribute.java | 10 +- .../MappingParameterSetAttribute.java | 5 +- .../SubqueryMethodSingularAttribute.java | 12 +- .../SubqueryParameterSingularAttribute.java | 10 +- .../ViewTypeObjectBuilderTemplate.java | 49 +-- ...sionCorrelationJoinTupleElementMapper.java | 6 +- ...sionCorrelationJoinTupleElementMapper.java | 6 +- ...ctCorrelatedBatchTupleListTransformer.java | 4 +- ...llectionSubselectTupleListTransformer.java | 4 +- ...rrelatedSubselectTupleListTransformer.java | 6 +- ...dSubselectTupleListTransformerFactory.java | 4 +- ...bstractCorrelatedTupleListTransformer.java | 4 +- ...atedListSubselectTupleListTransformer.java | 4 +- ...tSubselectTupleListTransformerFactory.java | 6 +- ...deredSetSubselectTupleListTransformer.java | 4 +- ...tSubselectTupleListTransformerFactory.java | 6 +- ...latedSetSubselectTupleListTransformer.java | 4 +- ...tSubselectTupleListTransformerFactory.java | 6 +- ...SingularSubselectTupleListTransformer.java | 4 +- ...rSubselectTupleListTransformerFactory.java | 6 +- ...ortedSetSubselectTupleListTransformer.java | 4 +- ...tSubselectTupleListTransformerFactory.java | 7 +- ...tedSubviewJoinTupleTransformerFactory.java | 6 +- .../correlation/JoinCorrelationBuilder.java | 25 +- .../SubqueryCorrelationBuilder.java | 29 +- .../view/impl/proxy/ProxyFactory.java | 61 +++ .../basic/AbstractClassViewTest.java | 4 +- .../testsuite/basic/CovariantViewTest.java | 3 +- .../basic/EmbeddableTestEntityViewTest.java | 3 +- .../basic/EntityViewSettingTest.java | 13 +- .../testsuite/basic/InterfaceViewTest.java | 2 +- .../view/testsuite/basic/JoinOrderTest.java | 2 +- .../view/testsuite/basic/PolymorphicTest.java | 3 +- .../testsuite/basic/PrimitiveViewTest.java | 3 +- .../view/testsuite/basic/ValidationTest.java | 6 +- .../testsuite/basic/ViewConstructorTest.java | 2 +- .../testsuite/basic/ViewMetamodelTest.java | 16 +- .../basic/BasicCollectionsTest.java | 3 +- .../ExtendedEmbeddableCollectionsTest.java | 2 +- .../simple/EmbeddableCollectionsTest.java | 3 +- .../ordered/ViewSetAsListTest.java | 2 +- .../subview/EntityMapKeySubviewTest.java | 2 +- .../subview/NestedCollectionsTest.java | 3 +- .../subview/NestedEmptyCollectionsTest.java | 3 +- .../subview/SimpleCollectionsTest.java | 2 +- .../subview/SubviewClassCollectionsTest.java | 3 +- .../general/GeneralCorrelationTest.java} | 17 +- .../model/DocumentCorrelationView.java | 3 +- .../model/DocumentCorrelationViewJoinId.java | 11 +- .../DocumentCorrelationViewJoinNormal.java | 11 +- .../DocumentCorrelationViewSubquery.java | 11 +- .../DocumentCorrelationViewSubselect.java | 33 +- ...nerOnlyRelatedCorrelationIdProviderId.java | 7 +- ...nlyRelatedCorrelationIdProviderNormal.java | 7 +- ...OwnerOnlyRelatedCorrelationProviderId.java | 7 +- ...rOnlyRelatedCorrelationProviderNormal.java | 7 +- .../OwnerRelatedCorrelationIdProviderId.java | 9 +- ...nerRelatedCorrelationIdProviderNormal.java | 9 +- .../OwnerRelatedCorrelationProviderId.java | 9 +- ...OwnerRelatedCorrelationProviderNormal.java | 9 +- .../simple/SimpleCorrelationTest.java | 265 +++++++++++++ .../model/DocumentSimpleCorrelationView.java | 44 +++ .../DocumentSimpleCorrelationViewJoinId.java | 51 +++ ...cumentSimpleCorrelationViewJoinNormal.java | 47 +++ ...DocumentSimpleCorrelationViewSubquery.java | 51 +++ ...ocumentSimpleCorrelationViewSubselect.java | 51 +++ .../testsuite/filter/AttributeFilterTest.java | 14 +- .../pagination/BasicViewPaginationTest.java | 3 +- .../testsuite/proxy/ProxyFactoryTest.java | 2 +- .../subquery/MappingSubqueryTest.java | 13 +- .../testsuite/subview/NullSubviewTest.java | 2 +- .../subview/SubviewEntityViewSettingTest.java | 5 +- .../view/testsuite/subview/SubviewTest.java | 3 +- .../update/EntityViewUpdateTest.java | 2 +- .../EntityViewUpdateWithCollectionsTest.java | 2 +- .../producer/BlazePersistenceProducer.java | 2 +- .../config/BlazePersistenceConfiguration.java | 2 +- .../config/BlazePersistenceConfiguration.java | 2 +- parent/pom.xml | 12 +- 139 files changed, 1981 insertions(+), 753 deletions(-) rename core/{impl/src/main/java/com/blazebit/persistence/impl/transform => parser/src/main/java/com/blazebit/persistence/impl}/AliasReplacementVisitor.java (97%) create mode 100644 core/parser/src/main/java/com/blazebit/persistence/impl/PrefixingAndAliasReplacementQueryGenerator.java create mode 100644 entity-view/api/src/main/java/com/blazebit/persistence/view/MappingCorrelatedSimple.java create mode 100644 entity-view/api/src/main/java/com/blazebit/persistence/view/spi/ViewRootJpqlMacro.java create mode 100644 entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/CorrelationProviderProxyBase.java rename entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/macro/{ViewRootJpqlMacro.java => DefaultViewRootJpqlMacro.java} (74%) create mode 100644 entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/MetamodelBuildingContext.java create mode 100644 entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/MetamodelBuildingContextImpl.java rename entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/{subview/CorrelationProviderTest.java => correlation/general/GeneralCorrelationTest.java} (94%) rename entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/{subview => correlation/general}/model/DocumentCorrelationView.java (87%) rename entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/{subview => correlation/general}/model/DocumentCorrelationViewJoinId.java (70%) rename entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/{subview => correlation/general}/model/DocumentCorrelationViewJoinNormal.java (66%) rename entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/{subview => correlation/general}/model/DocumentCorrelationViewSubquery.java (68%) rename entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/{subview => correlation/general}/model/DocumentCorrelationViewSubselect.java (55%) rename entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/{subview => correlation/general}/model/OwnerOnlyRelatedCorrelationIdProviderId.java (78%) rename entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/{subview => correlation/general}/model/OwnerOnlyRelatedCorrelationIdProviderNormal.java (78%) rename entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/{subview => correlation/general}/model/OwnerOnlyRelatedCorrelationProviderId.java (78%) rename entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/{subview => correlation/general}/model/OwnerOnlyRelatedCorrelationProviderNormal.java (78%) rename entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/{subview => correlation/general}/model/OwnerRelatedCorrelationIdProviderId.java (74%) rename entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/{subview => correlation/general}/model/OwnerRelatedCorrelationIdProviderNormal.java (74%) rename entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/{subview => correlation/general}/model/OwnerRelatedCorrelationProviderId.java (74%) rename entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/{subview => correlation/general}/model/OwnerRelatedCorrelationProviderNormal.java (74%) create mode 100644 entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/SimpleCorrelationTest.java create mode 100644 entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationView.java create mode 100644 entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationViewJoinId.java create mode 100644 entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationViewJoinNormal.java create mode 100644 entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationViewSubquery.java create mode 100644 entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationViewSubselect.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ba322ac58..0d660c8ab4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ Not yet released * Entity View Spring integration now allows the use of `includeFilters` and `excludeFilters` on `@EnableEntityViews` * Extended `SubqueryInitiator` by most of the `from()` variants * Support enum and entity type literal like the JPA spec says +* Introduction of `@MappingCorrelatedSimple` for simple correlations +* Allow empty correlation result with `JOIN` fetch strategy ### Bug fixes @@ -46,6 +48,8 @@ Not yet released * Renamed showcase project artifacts to be consistent * Removed special qualified literals for enums and entity types * Removed the `QueryTransformer` SPI as it is not required anymore +* Changed the default correlation fetch strategy from `JOIN` to `SELECT` +* Changed `CorrelationProvider` and `CorrelationBuilder` to disallow specifying a custom alias ## 1.2.0-Alpha2 diff --git a/core/api/src/main/java/com/blazebit/persistence/FromBuilder.java b/core/api/src/main/java/com/blazebit/persistence/FromBuilder.java index f2120d5676..46f8c8cfb8 100644 --- a/core/api/src/main/java/com/blazebit/persistence/FromBuilder.java +++ b/core/api/src/main/java/com/blazebit/persistence/FromBuilder.java @@ -45,6 +45,15 @@ public interface FromBuilder> { */ public From getFrom(String alias); + /** + * Returns the from element for the given path, creating it if necessary. + * + * @param path The path to the from element + * @return The from element of this query + * @since 1.2.0 + */ + public From getFromByPath(String path); + /** * Like {@link FromBuilder#from(Class, String)} with the * alias equivalent to the camel cased result of what {@link Class#getSimpleName()} of the entity class returns. diff --git a/core/impl/src/main/java/com/blazebit/persistence/impl/AbstractCommonQueryBuilder.java b/core/impl/src/main/java/com/blazebit/persistence/impl/AbstractCommonQueryBuilder.java index 16c1a76f1c..949c94c7d5 100644 --- a/core/impl/src/main/java/com/blazebit/persistence/impl/AbstractCommonQueryBuilder.java +++ b/core/impl/src/main/java/com/blazebit/persistence/impl/AbstractCommonQueryBuilder.java @@ -38,6 +38,7 @@ import com.blazebit.persistence.WhereOrBuilder; import com.blazebit.persistence.impl.expression.Expression; import com.blazebit.persistence.impl.expression.ExpressionFactory; +import com.blazebit.persistence.impl.expression.PathExpression; import com.blazebit.persistence.impl.expression.SubqueryExpressionFactory; import com.blazebit.persistence.impl.expression.VisitorAdapter; import com.blazebit.persistence.impl.function.entity.ValuesEntity; @@ -657,11 +658,11 @@ public Set getRoots() { return new LinkedHashSet(joinManager.getRoots()); } - public From getRoot() { + public JoinNode getRoot() { return joinManager.getRootNodeOrFail("This should never happen. Please report this error!"); } - public From getFrom(String alias) { + public JoinNode getFrom(String alias) { AliasInfo info = aliasManager.getAliasInfo(alias); if (info == null || !(info instanceof JoinAliasInfo)) { return null; @@ -670,6 +671,12 @@ public From getFrom(String alias) { return ((JoinAliasInfo) info).getJoinNode(); } + public JoinNode getFromByPath(String path) { + PathExpression pathExpression = expressionFactory.createPathExpression(path); + joinManager.implicitJoin(pathExpression, true, null, null, false, false, true); + return (JoinNode) pathExpression.getBaseNode(); + } + public boolean isEmpty() { return joinManager.getRoots().isEmpty() || ( diff --git a/core/impl/src/main/java/com/blazebit/persistence/impl/ExpressionUtils.java b/core/impl/src/main/java/com/blazebit/persistence/impl/ExpressionUtils.java index 840e767817..a2a08c0d69 100644 --- a/core/impl/src/main/java/com/blazebit/persistence/impl/ExpressionUtils.java +++ b/core/impl/src/main/java/com/blazebit/persistence/impl/ExpressionUtils.java @@ -38,7 +38,6 @@ import com.blazebit.persistence.impl.expression.TemporalLiteral; import com.blazebit.persistence.impl.expression.WhenClauseExpression; import com.blazebit.persistence.impl.predicate.BooleanLiteral; -import com.blazebit.persistence.impl.transform.AliasReplacementVisitor; import javax.persistence.Basic; import javax.persistence.ElementCollection; diff --git a/core/impl/src/main/java/com/blazebit/persistence/impl/transform/AliasReplacementVisitor.java b/core/parser/src/main/java/com/blazebit/persistence/impl/AliasReplacementVisitor.java similarity index 97% rename from core/impl/src/main/java/com/blazebit/persistence/impl/transform/AliasReplacementVisitor.java rename to core/parser/src/main/java/com/blazebit/persistence/impl/AliasReplacementVisitor.java index ca55a533eb..2834bcc423 100644 --- a/core/impl/src/main/java/com/blazebit/persistence/impl/transform/AliasReplacementVisitor.java +++ b/core/parser/src/main/java/com/blazebit/persistence/impl/AliasReplacementVisitor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.blazebit.persistence.impl.transform; +package com.blazebit.persistence.impl; import com.blazebit.persistence.impl.expression.Expression; import com.blazebit.persistence.impl.expression.InplaceModificationResultVisitorAdapter; diff --git a/core/parser/src/main/java/com/blazebit/persistence/impl/PrefixingAndAliasReplacementQueryGenerator.java b/core/parser/src/main/java/com/blazebit/persistence/impl/PrefixingAndAliasReplacementQueryGenerator.java new file mode 100644 index 0000000000..0330995471 --- /dev/null +++ b/core/parser/src/main/java/com/blazebit/persistence/impl/PrefixingAndAliasReplacementQueryGenerator.java @@ -0,0 +1,74 @@ +/* + * Copyright 2014 - 2017 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.impl; + +import com.blazebit.persistence.impl.expression.PathElementExpression; +import com.blazebit.persistence.impl.expression.PathExpression; +import com.blazebit.persistence.impl.expression.PropertyExpression; + +import java.util.List; + +/** + * + * @author Christian Beikov + * @since 1.2.0 + */ +public class PrefixingAndAliasReplacementQueryGenerator extends SimpleQueryGenerator { + + private final String prefix; + private final String substitute; + private final String alias; + private final String aliasToSkip; + + public PrefixingAndAliasReplacementQueryGenerator(String prefix, String substitute, String alias) { + this(prefix, substitute, alias, null); + } + + public PrefixingAndAliasReplacementQueryGenerator(String prefix, String substitute, String alias, String aliasToSkip) { + this.prefix = prefix; + this.substitute = substitute; + this.alias = alias; + this.aliasToSkip = aliasToSkip; + } + + @Override + public void visit(PathExpression expression) { + List expressions = expression.getExpressions(); + int size = expressions.size(); + + if (size == 1) { + PathElementExpression elementExpression = expressions.get(0); + if (elementExpression instanceof PropertyExpression) { + if (alias.equals(((PropertyExpression) elementExpression).getProperty())) { + sb.append(substitute); + return; + } + } + } else if (aliasToSkip != null) { + PathElementExpression elementExpression = expressions.get(0); + if (elementExpression instanceof PropertyExpression) { + if (aliasToSkip.equals(((PropertyExpression) elementExpression).getProperty())) { + super.visit(expression); + return; + } + } + } + sb.append(prefix); + super.visit(expression); + } + +} diff --git a/core/parser/src/main/java/com/blazebit/persistence/impl/expression/MacroConfiguration.java b/core/parser/src/main/java/com/blazebit/persistence/impl/expression/MacroConfiguration.java index 614f7b2d60..acb078d76f 100644 --- a/core/parser/src/main/java/com/blazebit/persistence/impl/expression/MacroConfiguration.java +++ b/core/parser/src/main/java/com/blazebit/persistence/impl/expression/MacroConfiguration.java @@ -39,6 +39,10 @@ public static MacroConfiguration of(Map macros) { return new MacroConfiguration(map); } + public MacroFunction get(String name) { + return macros.get(name); + } + public MacroConfiguration with(Map newMacros) { NavigableMap map = new TreeMap(this.macros); for (Map.Entry entry : newMacros.entrySet()) { diff --git a/core/testsuite/src/test/java/com/blazebit/persistence/testsuite/GroupByTest.java b/core/testsuite/src/test/java/com/blazebit/persistence/testsuite/GroupByTest.java index a8c0e8a920..a76a57a092 100644 --- a/core/testsuite/src/test/java/com/blazebit/persistence/testsuite/GroupByTest.java +++ b/core/testsuite/src/test/java/com/blazebit/persistence/testsuite/GroupByTest.java @@ -45,8 +45,7 @@ */ public class GroupByTest extends AbstractCoreTest { - // NOTE: SQL Server complains that the properties of "owner_1" are not in the group by but datanucleus puts them there - // Remove when the issue is fixed: https://github.com/datanucleus/datanucleus-rdbms/issues/155 + // Datanucleus does not support grouping by a byte[] as it seems @Test @Category({ NoDatanucleus.class }) public void testGroupByEntitySelect() { diff --git a/core/testsuite/src/test/java/com/blazebit/persistence/testsuite/SelectTest.java b/core/testsuite/src/test/java/com/blazebit/persistence/testsuite/SelectTest.java index 2492e37a8b..daa6e7c9e7 100644 --- a/core/testsuite/src/test/java/com/blazebit/persistence/testsuite/SelectTest.java +++ b/core/testsuite/src/test/java/com/blazebit/persistence/testsuite/SelectTest.java @@ -27,10 +27,8 @@ import javax.persistence.EntityManager; import javax.persistence.Tuple; -import com.blazebit.persistence.testsuite.base.category.NoDatanucleus; import com.blazebit.persistence.testsuite.tx.TxVoidWork; import org.junit.Test; -import org.junit.experimental.categories.Category; import com.blazebit.persistence.CriteriaBuilder; import com.blazebit.persistence.JoinType; @@ -516,8 +514,6 @@ public void testSelectSuperExpressionSubquery(){ } @Test - // NOTE: Datanucleus JPQL parser has a bug: https://github.com/datanucleus/datanucleus-core/issues/175 - @Category({ NoDatanucleus.class }) public void testSelectMinimalTrimFunction(){ CriteriaBuilder cb = cbf.create(em, String.class) .from(Document.class) diff --git a/documentation/src/main/asciidoc/entity-view/manual/en_US/04_mappings.adoc b/documentation/src/main/asciidoc/entity-view/manual/en_US/04_mappings.adoc index 39b6cbe31c..ababfd2151 100644 --- a/documentation/src/main/asciidoc/entity-view/manual/en_US/04_mappings.adoc +++ b/documentation/src/main/asciidoc/entity-view/manual/en_US/04_mappings.adoc @@ -744,16 +744,17 @@ Apart from unmapped relations, there is sometimes the need to _correlate_ entiti For these cases {projectname} entity views introduces the concept of _correlated mappings_. These mappings can be used to connect entities through a custom criteria instead of through mapped entity relations. Correlated mappings can be used for any attribute type(basic, entity, subview, collection) although singular basic attributes can also be implemented as <>. -A correlation mapping is declared by annotating the desired attribute with `@MappingCorrelated`. -// and also with @MappingCorrelatedSimple -// ==== General correlated mappings +A correlation mapping is declared by annotating the desired attribute with `@MappingCorrelated` or `@MappingCorrelatedSimple`. + +==== General correlated mappings + In order to map the correlation you need to specify some values * `correlationBasis` - An expression that maps to the so called _correlation key_ * `correlator` - The `CorrelationProvider` to use for the correlation that introduces a so called _correlated entity_ -* `correlationResult` - An expression that refers to the alias of the _correlated entity_ or an attribute of that entity -There is also the possibility to specify a <> that should be used for the correlation. By default, the `JOIN` strategy is used. +By default, the correlated entity type is _projected into_ the view. To map a specific property of the entity type, use the `correlationResult` attribute. +There is also the possibility to specify a <> that should be used for the correlation. By default, the `SELECT` strategy is used. [source,java] ---- @@ -766,7 +767,7 @@ public interface CatView { @MappingCorrelated( correlationBasis = "age", correlator = PersonAgeCorrelationProvider.class, - correlationResult = "pers" + fetch = FetchStrategy.JOIN ) Set getSameAgedPersons(); @@ -774,16 +775,17 @@ public interface CatView { @Override public void applyCorrelation(CorrelationBuilder builder, String correlationExpression) { - builder.correlate(Person.class, "pers") # <1> - .on("pers.age").inExpressions(correlationExpression) # <2> + final String alias = builder.getCorrelationAlias(); # <1> + builder.correlate(Person.class) + .on(alias + ".age").inExpressions(correlationExpression) # <2> .end(); } } } ---- -<1> Currently the alias _leaks_ into the main query builder when using the `JOIN` strategy so try to use a unique name -<2> Represents the `correlationBasis`. We generally recommend to use the `IN` predicate through `inExpressions()` to be able to easily switch the fetch strategy +<1> `getCorrelationAlias()` defines the alias for the correlated entity +<2> `correlationExpression` represents the `correlationBasis`. We generally recommend to use the `IN` predicate through `inExpressions()` to be able to easily switch the fetch strategy Depending on the fetch strategy multiple other queries might be executed. Check out the different <> for further information. In this case, the `JOIN` strategy was used, so the following query is generated. @@ -792,10 +794,10 @@ In this case, the `JOIN` strategy was used, so the following query is generated. ---- SELECT cat.id, pers FROM Cat cat -LEFT JOIN Person pers # <1> - ON cat.age = pers.age # <2> +LEFT JOIN Person correlated_SameAgedPersons # <1> + ON cat.age = correlated_SameAgedPersons.age # <2> ---- -<1> This is makes use of the so called link:{core_doc}#anchor-entity-joins[`entity join` feature] which is only available in newer JPA provider versions +<1> This makes use of the so called link:{core_doc}#anchor-entity-joins[`entity join` feature] which is only available in newer JPA provider versions <2> Note that the `IN` predicate which was used in the correlation provider was rewritten to a equality predicate Since entity joins are required for using the `JOIN` fetch strategy with correlation mappings you have to make sure your JPA provider supports them. @@ -803,12 +805,50 @@ If your JPA provider does not support entity joins, you have to use a different NOTE: Entity joins are only supported in newer versions of JPA providers(Hibernate 5.1+, EclipseLink 2.4+, DataNucleus 5+) -WARNING: Until https://github.com/Blazebit/blaze-persistence/issues/341[#341] is fixed, you should make sure that if you use relations as correlation keys, if it wouldn't be better to use the relations id instead or vice versa. -For some providers it might even be necessary to use the plain relation `relation` instead of it's id `relation.id` or the other way round because of possible cyclic join dependencies. +WARNING: Until https://github.com/Blazebit/blaze-persistence/issues/341[#341] is fixed, you should make sure that when using relations as correlation keys, if it wouldn't be better to use the relations id instead or vice versa. +For some providers it might even be *necessary* to use the plain relation `relation` instead of it's id `relation.id` or the other way round because of possible cyclic join dependencies. The possible cyclic joins might happen for a JPA provider because it might generate a join for an expression like `relation.id` whereas other JPA providers might not. -// ==== Simple correlated mappings -// TODO: mention this can be done simple with `@MappingCorrelatedSimple` +==== Simple correlated mappings + +Since correlation providers are mostly static, {projectname} also offers a way to define simple correlations in a declarative manner. +The `@MappingCorrelatedSimple` annotation only requires a few values + +* `correlationBasis` - An expression that maps to the so called _correlation key_ +* `correlated` - The _correlated entity_ type +* `correlationExpression` - The expression to use for correlating the _correlated entity_ type to the view + +[source,java] +---- +@EntityView(Person.class) +public interface PersonView { + + @IdMapping("id") + Long getId(); + + String getName(); +} + +@EntityView(Cat.class) +public interface CatView { + + @IdMapping("id") + Long getId(); + + @MappingCorrelated( + correlationBasis = "age", + correlated = Person.class, + correlationExpression = "age IN correlationKey" # <1> + fetch = FetchStrategy.JOIN + ) + Set getSameAgedPersons(); # <2> +} +---- +<1> The expression uses the default name for the correlation key but could use a different name by specifying the attribute `correlationKeyAlias` +<2> As you see here, it is obviously also possible to map subviews for correlated entity types + +Just like the general correlation, by default, the correlated entity type is _projected into_ the view. To map a specific property of the entity type, use the `correlationResult` attribute. +There is also the possibility to specify a <> that should be used for the correlation. By default, the `SELECT` strategy is used. === Mapping expression extensions @@ -914,8 +954,7 @@ public interface CatView { @MappingCorrelated( correlationBasis = "age", - correlator = CatAgeCorrelationProvider.class, - correlationResult = "correlatedCat" + correlator = CatAgeCorrelationProvider.class ) Set getSameAgedCats(); @@ -923,9 +962,10 @@ public interface CatView { @Override public void applyCorrelation(CorrelationBuilder builder, String correlationExpression) { - builder.correlate(Cat.class, "correlatedCat") - .on("correlatedCat.age").inExpressions(correlationExpression) - .on("correlatedCat.id").notInExpressions("VIEW_ROOT(id)") # <1> + final String correlatedCat = builder.getCorrelationAlias(); + builder.correlate(Cat.class) + .on(correlatedCat + ".age").inExpressions(correlationExpression) + .on(correlatedCat + ".id").notInExpressions("VIEW_ROOT(id)") # <1> .end(); } diff --git a/documentation/src/main/asciidoc/entity-view/manual/en_US/05_fetch_strategies.adoc b/documentation/src/main/asciidoc/entity-view/manual/en_US/05_fetch_strategies.adoc index e1be07c4d6..eccb4b9a64 100644 --- a/documentation/src/main/asciidoc/entity-view/manual/en_US/05_fetch_strategies.adoc +++ b/documentation/src/main/asciidoc/entity-view/manual/en_US/05_fetch_strategies.adoc @@ -4,7 +4,7 @@ There are multiple different fetch strategies available for fetching. Right now, a fetch strategy can only be applied on a correlated mapping, but soon will also be able to be specified for any other mapping. Also see https://github.com/Blazebit/blaze-persistence/issues/323[#323] for further information. -NOTE: `@MappingSubquery` is the only mapping that doesn't support overriding the fetch strategy. It will always use the `JOIN` strategy +NOTE: `@MappingSubquery` is the only mapping that doesn't support overriding the fetch strategy. It will always use the `JOIN` strategy, i.e. it will put the subquery into the main query. // Any attribute in an entity view can be fetched separately(that's the idea, but only implemented for correlation right now) @@ -14,7 +14,7 @@ and only change the strategy on a case by case basis. === Join fetch strategy -The `JOIN` strategy is not only the default, but also the one that makes mostly sense. +If your JPA provider supports entity joins, the `JOIN` strategy usually makes sense most of the time. In case of correlated mappings it will result in a `LEFT JOIN` link:{core_doc}#anchor-entity-joins[entity join] of the correlated entity type. The correlation expression created by the `CorrelationProvider` will be used in the `ON` condition. @@ -42,7 +42,6 @@ public interface CatView { @MappingCorrelated( correlationBasis = "age", correlator = PersonAgeCorrelationProvider.class, - correlationResult = "pers", fetch = FetchStrategy.SELECT ) Set getSameAgedPersons(); @@ -51,8 +50,9 @@ public interface CatView { @Override public void applyCorrelation(CorrelationBuilder builder, String correlationExpression) { - builder.correlate(Person.class, "pers") - .on("pers.age").inExpressions(correlationExpression) + final String pers = builder.getCorrelationAlias(); + builder.correlate(Person.class) + .on(pers + ".age").inExpressions(correlationExpression) .end(); } @@ -77,10 +77,10 @@ The main query will fetch the `correlationBasis` and all the other attributes. ---- SELECT TREAT_LONG(correlationParams.value), - pers -FROM Person pers, + correlated_SameAgedPersons +FROM Person correlated_SameAgedPersons, VALUES ((?), (?), ...) correlationParams # <1> -WHERE pers.age = TREAT_LONG(correlationParams.value) +WHERE correlated_SameAgedPersons.age = TREAT_LONG(correlationParams.value) ---- <1> Actually there will be 20 question marks here because of the defined batch size of 20 @@ -144,7 +144,6 @@ public interface KittenCatView { @MappingCorrelated( correlationBasis = "age", correlator = CatAgeCorrelationProvider.class, - correlationResult = "correlatedCat", fetch = FetchStrategy.SELECT ) Set getSameAgedCats(); @@ -153,9 +152,10 @@ public interface KittenCatView { @Override public void applyCorrelation(CorrelationBuilder builder, String correlationExpression) { - builder.correlate(Cat.class, "correlatedCat") - .on("correlatedCat.age").inExpressions(correlationExpression) - .on("correlatedCat.id").notInExpressions("VIEW_ROOT(id)") + final String correlatedCat = builder.getCorrelationAlias(); + builder.correlate(Cat.class) + .on(correlatedCat + ".age").inExpressions(correlationExpression) + .on(correlatedCat + ".id").notInExpressions("VIEW_ROOT(id)") .end(); } @@ -212,8 +212,9 @@ public interface CatView { @Override public void applyCorrelation(CorrelationBuilder builder, String correlationExpression) { - builder.correlate(Person.class, "pers") - .on("pers.age").inExpressions(correlationExpression) + final String pers = builder.getCorrelationAlias(); + builder.correlate(Person.class) + .on(pers + ".age").inExpressions(correlationExpression) .end(); } @@ -237,10 +238,10 @@ The main query will fetch the `correlationBasis` and all the other attributes. ---- SELECT cat.age, - pers + correlated_SameAgedPersons FROM Cat cat, - Person pers -WHERE pers.age = cat.age + Person correlated_SameAgedPersons +WHERE correlated_SameAgedPersons.age = cat.age ---- The correlation query looks very similar since it's based on the main query, but has a custom select clause. diff --git a/entity-view/api/src/main/java/com/blazebit/persistence/view/CorrelationBuilder.java b/entity-view/api/src/main/java/com/blazebit/persistence/view/CorrelationBuilder.java index 1fa2c22df9..a460a56511 100644 --- a/entity-view/api/src/main/java/com/blazebit/persistence/view/CorrelationBuilder.java +++ b/entity-view/api/src/main/java/com/blazebit/persistence/view/CorrelationBuilder.java @@ -27,12 +27,27 @@ */ public interface CorrelationBuilder { + /** + * Returns the service or null if none is available. + * + * @param serviceClass The type of the service + * @param The service type + * @return The service or null + */ + public T getService(Class serviceClass); + + /** + * Generates a meaningful alias that can be used for the correlation. + * + * @return The generated alias + */ + public String getCorrelationAlias(); + /** * Correlates a basis with the given entity class. * * @param entityClass The entity class which should be correlated - * @param alias The alias of the entity class * @return The restriction builder for the correlation predicate */ - public JoinOnBuilder> correlate(Class entityClass, String alias); + public JoinOnBuilder> correlate(Class entityClass); } diff --git a/entity-view/api/src/main/java/com/blazebit/persistence/view/MappingCorrelated.java b/entity-view/api/src/main/java/com/blazebit/persistence/view/MappingCorrelated.java index 92fdfa6dbe..5218ae8e39 100644 --- a/entity-view/api/src/main/java/com/blazebit/persistence/view/MappingCorrelated.java +++ b/entity-view/api/src/main/java/com/blazebit/persistence/view/MappingCorrelated.java @@ -39,11 +39,11 @@ String correlationBasis(); /** - * The absolute expression result mapping of the correlation. + * The expression for the result mapping of the correlation relative to the correlated alias. * * @return The expression */ - String correlationResult(); + String correlationResult() default ""; /** * The class which provides the correlation provider. @@ -57,5 +57,5 @@ * * @return The correlation fetch strategy */ - FetchStrategy fetch() default FetchStrategy.JOIN; + FetchStrategy fetch() default FetchStrategy.SELECT; } diff --git a/entity-view/api/src/main/java/com/blazebit/persistence/view/MappingCorrelatedSimple.java b/entity-view/api/src/main/java/com/blazebit/persistence/view/MappingCorrelatedSimple.java new file mode 100644 index 0000000000..8188c19e9c --- /dev/null +++ b/entity-view/api/src/main/java/com/blazebit/persistence/view/MappingCorrelatedSimple.java @@ -0,0 +1,75 @@ +/* + * Copyright 2014 - 2017 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.view; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Maps the annotated attribute as correlation attribute with a simple declarative mapping of the correlation. + * + * @author Christian Beikov + * @since 1.2.0 + */ +@Target({ ElementType.METHOD, ElementType.PARAMETER }) +@Retention(RetentionPolicy.RUNTIME) +public @interface MappingCorrelatedSimple { + + /** + * The entity class which is correlated. + * + * @return The correlated entity class + */ + Class correlated(); + + /** + * The expression which is the basis for correlation. + * + * @return The expression + */ + String correlationBasis(); + + /** + * The alias to use for the correlation key in the correlation expression. + * + * @return The expression + */ + String correlationKeyAlias() default "correlationKey"; + + /** + * The expression to use for correlating the entity type to the correlation basis. + * + * @return The expression + */ + String correlationExpression(); + + /** + * The expression for the result mapping of the correlated entity type. + * + * @return The expression + */ + String correlationResult() default ""; + + /** + * The fetch strategy to use for correlation. + * + * @return The correlation fetch strategy + */ + FetchStrategy fetch() default FetchStrategy.SELECT; +} diff --git a/entity-view/api/src/main/java/com/blazebit/persistence/view/spi/ViewRootJpqlMacro.java b/entity-view/api/src/main/java/com/blazebit/persistence/view/spi/ViewRootJpqlMacro.java new file mode 100644 index 0000000000..a84b9a6a64 --- /dev/null +++ b/entity-view/api/src/main/java/com/blazebit/persistence/view/spi/ViewRootJpqlMacro.java @@ -0,0 +1,40 @@ +/* + * Copyright 2014 - 2017 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.view.spi; + +import com.blazebit.persistence.spi.JpqlMacro; + +/** + * Interface implemented by the entity view provider. + * + * Represents a view root macro that gives access to the view root. + * + * @author Christian Beikov + * @since 1.2.0 + */ +public interface ViewRootJpqlMacro extends JpqlMacro { + + /** + * Returns the view root alias or null if not an alias. + * + * When using batched fetching, it can happen that a view root is represented as parameter. In that case null is returned. + * + * @return The view root or null + */ + public String getViewRoot(); + +} diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/CorrelationProviderHelper.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/CorrelationProviderHelper.java index c1c0fddb4b..6baa1ba7a8 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/CorrelationProviderHelper.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/CorrelationProviderHelper.java @@ -18,6 +18,7 @@ import com.blazebit.persistence.view.CorrelationProvider; import com.blazebit.persistence.view.MappingParameter; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import java.lang.annotation.Annotation; import java.lang.reflect.Constructor; @@ -27,6 +28,14 @@ public class CorrelationProviderHelper { private CorrelationProviderHelper() { } + public static Class createCorrelationProvider(Class correlated, String correlationKeyAlias, String correlationExpression, MetamodelBuildingContext context) { + return context.getProxyFactory().getCorrelationProviderProxy(correlated, correlationKeyAlias, correlationExpression); + } + + public static String getDefaultCorrelationAlias(String attributePath) { + return "correlated_" + attributePath.replaceAll("\\.", "_"); + } + @SuppressWarnings("unchecked") public static CorrelationProviderFactory getFactory(Class clazz) { Constructor[] constructors = (Constructor[]) clazz.getConstructors(); diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/CorrelationProviderProxyBase.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/CorrelationProviderProxyBase.java new file mode 100644 index 0000000000..8638fb1b37 --- /dev/null +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/CorrelationProviderProxyBase.java @@ -0,0 +1,73 @@ +/* + * Copyright 2014 - 2017 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.view.impl; + +import com.blazebit.persistence.impl.PrefixingAndAliasReplacementQueryGenerator; +import com.blazebit.persistence.impl.expression.Expression; +import com.blazebit.persistence.impl.expression.ExpressionFactory; +import com.blazebit.persistence.impl.expression.MacroFunction; +import com.blazebit.persistence.view.CorrelationBuilder; +import com.blazebit.persistence.view.CorrelationProvider; +import com.blazebit.persistence.view.spi.ViewRootJpqlMacro; + +/** + * This serves as base implementation for correlation providers that is copied at runtime for simple correlation mappings. + * + * WARNING: When doing changes here, check if it doesn't violate assumtions in {@link com.blazebit.persistence.view.impl.proxy.ProxyFactory#getCorrelationProviderProxy(Class, String, String)}. + * + * One of the assumptions is that two constructors exist, the default one and the parameterized one. + * The order of the parameters is also important. + * + * @author Christian Beikov + * @since 1.2.0 + */ +public class CorrelationProviderProxyBase implements CorrelationProvider { + + private final Class correlated; + private final String correlationKeyAlias; + private final int approximateExpressionSize; + private final String correlationExpression; + + private CorrelationProviderProxyBase(Class correlated, String correlationKeyAlias, String correlationExpression) { + this.correlated = correlated; + this.correlationKeyAlias = correlationKeyAlias; + this.approximateExpressionSize = correlationExpression.length() * 2; + this.correlationExpression = correlationExpression; + } + + // NOTE: Careful, you can't debug into this method as it is copied + @Override + public void applyCorrelation(CorrelationBuilder correlationBuilder, String correlationExpression) { + String alias = correlationBuilder.getCorrelationAlias(); + String prefix = alias + "."; + + // Find out the view root alias + ExpressionFactory expressionFactory = correlationBuilder.getService(ExpressionFactory.class); + MacroFunction viewRootFunction = expressionFactory.getDefaultMacroConfiguration().get("VIEW_ROOT"); + ViewRootJpqlMacro viewRootMacro = (ViewRootJpqlMacro) viewRootFunction.getState()[0]; + + // Prefix all paths except view root alias based ones and substitute the key alias with the correlation expression + PrefixingAndAliasReplacementQueryGenerator generator = new PrefixingAndAliasReplacementQueryGenerator(prefix, correlationExpression, correlationKeyAlias, viewRootMacro.getViewRoot()); + StringBuilder buffer = new StringBuilder(approximateExpressionSize); + generator.setQueryBuffer(buffer); + Expression expression = expressionFactory.createBooleanExpression(this.correlationExpression, false); + expression.accept(generator); + + correlationBuilder.correlate(correlated) + .onExpression(buffer.toString()); + } +} diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/EntityViewConfigurationImpl.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/EntityViewConfigurationImpl.java index 62a946a25a..8db229a49c 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/EntityViewConfigurationImpl.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/EntityViewConfigurationImpl.java @@ -21,12 +21,12 @@ import java.util.Properties; import java.util.Set; -import javax.persistence.EntityManagerFactory; - import com.blazebit.persistence.CriteriaBuilderFactory; import com.blazebit.persistence.view.EntityViewManager; import com.blazebit.persistence.view.spi.EntityViewConfiguration; +import javax.persistence.EntityManagerFactory; + /** * * @author Christian Beikov diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/EntityViewManagerImpl.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/EntityViewManagerImpl.java index 7a5e85e91e..413278190e 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/EntityViewManagerImpl.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/EntityViewManagerImpl.java @@ -23,17 +23,14 @@ import javax.persistence.EntityManager; +import com.blazebit.lang.StringUtils; import com.blazebit.persistence.CriteriaBuilder; import com.blazebit.persistence.CriteriaBuilderFactory; import com.blazebit.persistence.From; import com.blazebit.persistence.FullQueryBuilder; import com.blazebit.persistence.ObjectBuilder; import com.blazebit.persistence.impl.EntityMetamodel; -import com.blazebit.persistence.impl.PathTargetResolvingExpressionVisitor; -import com.blazebit.persistence.impl.expression.AbstractCachingExpressionFactory; import com.blazebit.persistence.impl.expression.ExpressionFactory; -import com.blazebit.persistence.impl.expression.MacroConfiguration; -import com.blazebit.persistence.impl.expression.MacroFunction; import com.blazebit.persistence.view.AttributeFilterProvider; import com.blazebit.persistence.view.EntityViewManager; import com.blazebit.persistence.view.EntityViewSetting; @@ -62,7 +59,9 @@ import com.blazebit.persistence.view.impl.filter.NullFilterImpl; import com.blazebit.persistence.view.impl.filter.StartsWithFilterImpl; import com.blazebit.persistence.view.impl.filter.StartsWithIgnoreCaseFilterImpl; -import com.blazebit.persistence.view.impl.macro.ViewRootJpqlMacro; +import com.blazebit.persistence.view.impl.macro.DefaultViewRootJpqlMacro; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContextImpl; import com.blazebit.persistence.view.impl.metamodel.ViewMetamodelImpl; import com.blazebit.persistence.view.impl.objectbuilder.ViewTypeObjectBuilderTemplate; import com.blazebit.persistence.view.impl.proxy.ProxyFactory; @@ -92,8 +91,27 @@ public class EntityViewManagerImpl implements EntityViewManager { private final boolean unsafeDisabled; public EntityViewManagerImpl(EntityViewConfigurationImpl config, CriteriaBuilderFactory cbf) { - this.metamodel = new ViewMetamodelImpl(config.getEntityViews(), !Boolean.valueOf(String.valueOf(config.getProperty(ConfigurationProperties.EXPRESSION_VALIDATION_DISABLED))), cbf.getService(ExpressionFactory.class), cbf.getService(EntityMetamodel.class)); this.proxyFactory = new ProxyFactory(); + + boolean validateExpressions = !Boolean.valueOf(String.valueOf(config.getProperty(ConfigurationProperties.EXPRESSION_VALIDATION_DISABLED))); + Set> entityViews = config.getEntityViews(); + + Set errors = new HashSet(); + MetamodelBuildingContext context = new MetamodelBuildingContextImpl(cbf.getService(EntityMetamodel.class), cbf.getService(ExpressionFactory.class), proxyFactory, entityViews, errors); + this.metamodel = new ViewMetamodelImpl(entityViews, cbf, context, validateExpressions); + + if (!errors.isEmpty()) { + StringBuilder sb = new StringBuilder(); + sb.append("There are error(s) in entity views!"); + + for (String error : errors) { + sb.append('\n'); + sb.append(error); + } + + throw new IllegalArgumentException(sb.toString()); + } + this.properties = copyProperties(config.getProperties()); this.objectBuilderCache = new ConcurrentHashMap>(); this.partialEntityViewUpdaterCache = new ConcurrentHashMap, PartialEntityViewUpdater>(); @@ -104,12 +122,10 @@ public EntityViewManagerImpl(EntityViewConfigurationImpl config, CriteriaBuilder this.unsafeDisabled = !Boolean.valueOf(String.valueOf(properties.get(ConfigurationProperties.PROXY_UNSAFE_ALLOWED))); if (Boolean.valueOf(String.valueOf(properties.get(ConfigurationProperties.TEMPLATE_EAGER_LOADING)))) { - MacroConfiguration originalMacroConfiguration = cbf.getService(MacroConfiguration.class); - ExpressionFactory cachingExpressionFactory = cbf.getService(ExpressionFactory.class).unwrap(AbstractCachingExpressionFactory.class); for (ViewType view : metamodel.getViews()) { - MacroFunction macro = new JpqlMacroAdapter(new ViewRootJpqlMacro(null), cachingExpressionFactory); - MacroConfiguration macroConfiguration = originalMacroConfiguration.with(Collections.singletonMap("view_root", macro)); - ExpressionFactory expressionFactory = new MacroConfigurationExpressionFactory(cachingExpressionFactory, macroConfiguration); + // TODO: Might be a good idea to let the view root be overridden or specified via the annotation + String probableViewRoot = StringUtils.firstToLower(view.getEntityClass().getSimpleName()); + ExpressionFactory expressionFactory = context.createMacroAwareExpressionFactory(probableViewRoot); getTemplate(expressionFactory, view, null, null); for (MappingConstructor constructor : view.getConstructors()) { @@ -267,80 +283,33 @@ public void applyObjectBuilder(ViewType viewType, MappingConstructor mappi } public ObjectBuilder createObjectBuilder(ViewType viewType, MappingConstructor mappingConstructor, String viewName, String entityViewRoot, FullQueryBuilder criteriaBuilder, EntityViewConfiguration configuration, int offset, boolean registerMacro) { - Class entityClazz; - Map.Entry rootEntry = findRoot(criteriaBuilder, entityViewRoot); - From root = rootEntry.getKey(); - entityViewRoot = rootEntry.getValue(); + From root = getFromByViewRoot(criteriaBuilder, entityViewRoot); + Class entityClazz = root.getType(); + entityViewRoot = root.getAlias(); ExpressionFactory ef = criteriaBuilder.getService(ExpressionFactory.class); - if (entityViewRoot != null) { - if (root.getAlias().equals(entityViewRoot)) { - entityClazz = root.getType(); - } else { - PathTargetResolvingExpressionVisitor visitor = new PathTargetResolvingExpressionVisitor(metamodel.getEntityMetamodel(), root.getType(), root.getAlias()); - ef.createPathExpression(entityViewRoot).accept(visitor); - Collection> possibleTypes = visitor.getPossibleTargets().values(); - if (possibleTypes.size() > 1) { - throw new IllegalArgumentException("The expression '" + entityViewRoot + "' is ambiguous in the context of the type '" + root.getType() + "'!"); - } - // It must have one, otherwise a parse error would have been thrown already - entityClazz = possibleTypes.iterator().next(); - - if (entityClazz == null) { - throw new IllegalArgumentException("Could not resolve the expression '" + entityViewRoot + "' in the context of the type '" + root.getType() + "'!"); - } - } - } else { - entityClazz = root.getType(); - entityViewRoot = root.getAlias(); - } if (!viewType.getEntityClass().isAssignableFrom(entityClazz)) { throw new IllegalArgumentException("The given view type with the entity type '" + viewType.getEntityClass().getName() + "' can not be applied to the query builder with result type '" + criteriaBuilder.getResultType().getName() + "'"); } if (registerMacro) { - criteriaBuilder.registerMacro("view_root", new ViewRootJpqlMacro(entityViewRoot)); + criteriaBuilder.registerMacro("view_root", new DefaultViewRootJpqlMacro(entityViewRoot)); } return getTemplate(ef, viewType, mappingConstructor, viewName, entityViewRoot, offset) .createObjectBuilder(criteriaBuilder, configuration.getOptionalParameters(), configuration); } - private static Map.Entry findRoot(FullQueryBuilder queryBuilder, String entityViewRoot) { + private static From getFromByViewRoot(FullQueryBuilder queryBuilder, String entityViewRoot) { if (entityViewRoot == null || entityViewRoot.isEmpty()) { Set roots = queryBuilder.getRoots(); if (roots.size() > 1) { throw new IllegalArgumentException("Can not apply entity view to given criteria builder because it has multiple query roots! Please specify the entity view root when applying the entity-view setting!"); } - return new AbstractMap.SimpleEntry(roots.iterator().next(), null); - } - - From candidate = queryBuilder.getFrom(entityViewRoot); - - if (candidate != null) { - return new AbstractMap.SimpleEntry(candidate, null); - } - - Set roots = queryBuilder.getRoots(); - - if (roots.size() == 1) { - From r = roots.iterator().next(); - String alias = r.getAlias(); - if (entityViewRoot.startsWith(alias) && (entityViewRoot.length() == alias.length() || entityViewRoot.charAt(alias.length()) == '.')) { - return new AbstractMap.SimpleEntry(r, entityViewRoot); - } else { - return new AbstractMap.SimpleEntry(r, alias + '.' + entityViewRoot); - } - } - - for (From r : roots) { - String alias = r.getAlias(); - if (entityViewRoot.startsWith(alias) && (entityViewRoot.length() == alias.length() || entityViewRoot.charAt(alias.length()) == '.')) { - return new AbstractMap.SimpleEntry(r, entityViewRoot); - } + return roots.iterator().next(); } - throw new IllegalArgumentException("Entity view root '" + entityViewRoot + "' must be an absolute path when multiple criteria builder roots are possible!"); + return queryBuilder.getFromByPath(entityViewRoot); } @SuppressWarnings("unchecked") diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/ScalarTargetResolvingExpressionVisitor.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/ScalarTargetResolvingExpressionVisitor.java index dd0eca27ba..67452598c8 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/ScalarTargetResolvingExpressionVisitor.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/ScalarTargetResolvingExpressionVisitor.java @@ -102,6 +102,7 @@ Class getCurrentClass() { void setCurrentClass(Class currentClass) { this.currentClass = currentClass; this.valueClass = null; + this.hasCollectionJoin = false; } Method getMethod() { diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/macro/CorrelatedSubqueryViewRootJpqlMacro.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/macro/CorrelatedSubqueryViewRootJpqlMacro.java index 426312a695..1e5a676940 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/macro/CorrelatedSubqueryViewRootJpqlMacro.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/macro/CorrelatedSubqueryViewRootJpqlMacro.java @@ -18,7 +18,7 @@ import com.blazebit.persistence.FullQueryBuilder; import com.blazebit.persistence.spi.FunctionRenderContext; -import com.blazebit.persistence.spi.JpqlMacro; +import com.blazebit.persistence.view.spi.ViewRootJpqlMacro; import javax.persistence.EntityManager; import javax.persistence.Query; @@ -32,7 +32,7 @@ * @author Christian Beikov * @since 1.2.0 */ -public class CorrelatedSubqueryViewRootJpqlMacro implements JpqlMacro { +public class CorrelatedSubqueryViewRootJpqlMacro implements ViewRootJpqlMacro { private static final String CORRELATION_VIEW_ROOT_PARAM_PREFIX = "correlationViewRootParam_"; private static final String CORRELATION_VIEW_ROOT_ID_PARAM_PREFIX = "correlationViewRootIdParam_"; @@ -84,6 +84,16 @@ public void setParameters(Query query, Object viewRootId) { } } + @Override + public String getViewRoot() { + // Might be null when the viewRootParamName should be used + // If this is a parameter, we return null + if (viewRootExpression == null || viewRootExpression.charAt(0) == ':') { + return null; + } + return viewRootExpression; + } + public boolean usesViewRootEntityParameter() { return viewRootExpression != null; } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/macro/ViewRootJpqlMacro.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/macro/DefaultViewRootJpqlMacro.java similarity index 74% rename from entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/macro/ViewRootJpqlMacro.java rename to entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/macro/DefaultViewRootJpqlMacro.java index cc7ce49896..4192c9a8a1 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/macro/ViewRootJpqlMacro.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/macro/DefaultViewRootJpqlMacro.java @@ -17,24 +17,33 @@ package com.blazebit.persistence.view.impl.macro; import com.blazebit.persistence.spi.FunctionRenderContext; -import com.blazebit.persistence.spi.JpqlMacro; +import com.blazebit.persistence.view.spi.ViewRootJpqlMacro; /** * * @author Christian Beikov * @since 1.2.0 */ -public class ViewRootJpqlMacro implements JpqlMacro { +public class DefaultViewRootJpqlMacro implements ViewRootJpqlMacro { private final String viewRoot; - public ViewRootJpqlMacro(String viewRoot) { + public DefaultViewRootJpqlMacro(String viewRoot) { if (viewRoot == null || viewRoot.isEmpty()) { throw new IllegalArgumentException("An empty view root is not allowed!"); } + if (viewRoot.contains(".")) { + // This is required for @MappingCorrelatedSimple to work + throw new IllegalArgumentException("A view root must always be a simple alias!"); + } this.viewRoot = viewRoot; } + @Override + public String getViewRoot() { + return viewRoot; + } + @Override public void render(FunctionRenderContext context) { if (context.getArgumentsSize() > 1) { @@ -53,14 +62,13 @@ public boolean equals(Object o) { if (this == o) { return true; } - if (!(o instanceof ViewRootJpqlMacro)) { + if (!(o instanceof DefaultViewRootJpqlMacro)) { return false; } - ViewRootJpqlMacro that = (ViewRootJpqlMacro) o; + DefaultViewRootJpqlMacro that = (DefaultViewRootJpqlMacro) o; return viewRoot != null ? viewRoot.equals(that.viewRoot) : that.viewRoot == null; - } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractAttribute.java index 5fe67d0212..cad15e6bfe 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractAttribute.java @@ -22,10 +22,7 @@ import java.util.*; import javax.persistence.metamodel.ManagedType; -import javax.persistence.metamodel.Metamodel; -import com.blazebit.persistence.impl.EntityMetamodel; -import com.blazebit.persistence.impl.expression.ExpressionFactory; import com.blazebit.persistence.impl.expression.SyntaxErrorException; import com.blazebit.persistence.view.BatchFetch; import com.blazebit.persistence.view.CorrelationProvider; @@ -33,10 +30,12 @@ import com.blazebit.persistence.view.IdMapping; import com.blazebit.persistence.view.Mapping; import com.blazebit.persistence.view.MappingCorrelated; +import com.blazebit.persistence.view.MappingCorrelatedSimple; import com.blazebit.persistence.view.MappingParameter; import com.blazebit.persistence.view.MappingSubquery; import com.blazebit.persistence.view.SubqueryProvider; import com.blazebit.persistence.view.impl.CollectionJoinMappingGathererExpressionVisitor; +import com.blazebit.persistence.view.impl.CorrelationProviderHelper; import com.blazebit.persistence.view.impl.ScalarTargetResolvingExpressionVisitor; import com.blazebit.persistence.view.impl.UpdatableExpressionVisitor; import com.blazebit.persistence.view.impl.ScalarTargetResolvingExpressionVisitor.TargetType; @@ -64,20 +63,23 @@ public abstract class AbstractAttribute implements Attribute { protected final Class correlationProvider; protected final String correlationBasis; protected final String correlationResult; + protected final Class correlated; + protected final String correlationKeyAlias; + protected final String correlationExpression; protected final boolean queryParameter; protected final boolean id; protected final boolean subview; - public AbstractAttribute(ManagedViewType declaringType, Class javaType, Annotation mapping, Set> entityViews, BatchFetch batchFetch, String errorLocation, Set errors) { + public AbstractAttribute(ManagedViewType declaringType, Class javaType, Annotation mapping, BatchFetch batchFetch, String errorLocation, MetamodelBuildingContext context) { if (javaType == null) { - errors.add("The attribute type is not resolvable " + errorLocation); + context.addError("The attribute type is not resolvable " + errorLocation); } int batchSize; if (batchFetch == null || batchFetch.size() == -1) { batchSize = -1; } else if (batchFetch.size() < 1) { - errors.add("Illegal batch fetch size defined at '" + errorLocation + "'! Use a value greater than 0!"); + context.addError("Illegal batch fetch size defined at '" + errorLocation + "'! Use a value greater than 0!"); batchSize = Integer.MIN_VALUE; } else { batchSize = batchFetch.size(); @@ -85,7 +87,7 @@ public AbstractAttribute(ManagedViewType declaringType, Class javaType, An this.declaringType = declaringType; this.javaType = javaType; - this.subview = entityViews.contains(javaType); + this.subview = context.isEntityView(javaType); if (mapping instanceof IdMapping) { this.mapping = ((IdMapping) mapping).value(); @@ -99,6 +101,9 @@ public AbstractAttribute(ManagedViewType declaringType, Class javaType, An this.correlationBasis = null; this.correlationResult = null; this.correlationProvider = null; + this.correlated = null; + this.correlationKeyAlias = null; + this.correlationExpression = null; } else if (mapping instanceof Mapping) { Mapping m = (Mapping) mapping; this.mapping = m.value(); @@ -112,6 +117,9 @@ public AbstractAttribute(ManagedViewType declaringType, Class javaType, An this.correlationBasis = null; this.correlationResult = null; this.correlationProvider = null; + this.correlated = null; + this.correlationKeyAlias = null; + this.correlationExpression = null; } else if (mapping instanceof MappingParameter) { this.mapping = ((MappingParameter) mapping).value(); this.fetchStrategy = FetchStrategy.JOIN; @@ -124,6 +132,9 @@ public AbstractAttribute(ManagedViewType declaringType, Class javaType, An this.correlationBasis = null; this.correlationResult = null; this.correlationProvider = null; + this.correlated = null; + this.correlationKeyAlias = null; + this.correlationExpression = null; } else if (mapping instanceof MappingSubquery) { MappingSubquery mappingSubquery = (MappingSubquery) mapping; this.mapping = null; @@ -137,12 +148,15 @@ public AbstractAttribute(ManagedViewType declaringType, Class javaType, An this.correlationBasis = null; this.correlationResult = null; this.correlationProvider = null; + this.correlated = null; + this.correlationKeyAlias = null; + this.correlationExpression = null; if (!subqueryExpression.isEmpty() && subqueryAlias.isEmpty()) { - errors.add("The subquery alias is empty although the subquery expression is not " + errorLocation); + context.addError("The subquery alias is empty although the subquery expression is not " + errorLocation); } if (subqueryProvider.getEnclosingClass() != null && !Modifier.isStatic(subqueryProvider.getModifiers())) { - errors.add("The subquery provider is defined as non-static inner class. Make it static, otherwise it can't be instantiated: " + errorLocation); + context.addError("The subquery provider is defined as non-static inner class. Make it static, otherwise it can't be instantiated: " + errorLocation); } } else if (mapping instanceof MappingCorrelated) { MappingCorrelated mappingCorrelated = (MappingCorrelated) mapping; @@ -163,12 +177,37 @@ public AbstractAttribute(ManagedViewType declaringType, Class javaType, An this.correlationBasis = mappingCorrelated.correlationBasis(); this.correlationResult = mappingCorrelated.correlationResult(); this.correlationProvider = mappingCorrelated.correlator(); + this.correlated = null; + this.correlationKeyAlias = null; + this.correlationExpression = null; if (correlationProvider.getEnclosingClass() != null && !Modifier.isStatic(correlationProvider.getModifiers())) { - errors.add("The correlation provider is defined as non-static inner class. Make it static, otherwise it can't be instantiated: " + errorLocation); + context.addError("The correlation provider is defined as non-static inner class. Make it static, otherwise it can't be instantiated: " + errorLocation); } + } else if (mapping instanceof MappingCorrelatedSimple) { + MappingCorrelatedSimple mappingCorrelated = (MappingCorrelatedSimple) mapping; + this.mapping = null; + this.fetchStrategy = mappingCorrelated.fetch(); + + if (fetchStrategy == FetchStrategy.SELECT) { + this.batchSize = batchSize; + } else { + this.batchSize = -1; + } + + this.subqueryProvider = null; + this.id = false; + this.queryParameter = false; + this.subqueryExpression = null; + this.subqueryAlias = null; + this.correlationProvider = CorrelationProviderHelper.createCorrelationProvider(mappingCorrelated.correlated(), mappingCorrelated.correlationKeyAlias(), mappingCorrelated.correlationExpression(), context); + this.correlationBasis = mappingCorrelated.correlationBasis(); + this.correlationResult = mappingCorrelated.correlationResult(); + this.correlated = mappingCorrelated.correlated(); + this.correlationKeyAlias = mappingCorrelated.correlationKeyAlias(); + this.correlationExpression = mappingCorrelated.correlationExpression(); } else { - errors.add("No mapping annotation could be found " + errorLocation); + context.addError("No mapping annotation could be found " + errorLocation); this.mapping = null; this.fetchStrategy = null; this.batchSize = Integer.MIN_VALUE; @@ -180,17 +219,20 @@ public AbstractAttribute(ManagedViewType declaringType, Class javaType, An this.correlationBasis = null; this.correlationResult = null; this.correlationProvider = null; + this.correlated = null; + this.correlationKeyAlias = null; + this.correlationExpression = null; } } - public Set getCollectionJoinMappings(ManagedType managedType, Metamodel metamodel, ExpressionFactory expressionFactory) { + public Set getCollectionJoinMappings(ManagedType managedType, MetamodelBuildingContext context) { if (mapping == null || queryParameter) { // Subqueries and parameters can't be checked return Collections.emptySet(); } - CollectionJoinMappingGathererExpressionVisitor visitor = new CollectionJoinMappingGathererExpressionVisitor(managedType, metamodel); - expressionFactory.createSimpleExpression(mapping, false).accept(visitor); + CollectionJoinMappingGathererExpressionVisitor visitor = new CollectionJoinMappingGathererExpressionVisitor(managedType, context.getEntityMetamodel()); + context.getExpressionFactory().createSimpleExpression(mapping, false).accept(visitor); Set mappings = new HashSet(); for (String s : visitor.getPaths()) { @@ -200,13 +242,7 @@ public Set getCollectionJoinMappings(ManagedType managedType, Metamod return mappings; } - public void checkAttributeCorrelationUsage(Collection errors, Map, String> seenCorrelationProviders, Map, ManagedViewTypeImpl> managedViews, Set> seenViewTypes, Set> seenConstructors) { - if (correlationProvider != null) { - String usageLocation = seenCorrelationProviders.put(correlationProvider, getLocation()); - if (usageLocation != null) { - errors.add("Illegal multiple usages of correlation provider '" + correlationProvider.getName() + "' in the following locations:\n\t" + getLocation() + "\n\t" + usageLocation); - } - } + public void checkAttributeCorrelationUsage(Map, ManagedViewTypeImpl> managedViews, Set> seenViewTypes, Set> seenConstructors, MetamodelBuildingContext context) { if (isSubview()) { ManagedViewTypeImpl subviewType; @@ -215,113 +251,146 @@ public void checkAttributeCorrelationUsage(Collection errors, Map checkAttribute(ManagedType managedType, Map, ManagedViewTypeImpl> managedViews, ExpressionFactory expressionFactory, EntityMetamodel metamodel) { - List errors = new ArrayList(); - if (mapping == null || queryParameter) { - if (correlationProvider != null) { - if (correlationBasis.isEmpty()) { - errors.add("Illegal empty correlation basis in the " + getLocation()); + private static enum ExpressionLocation { + MAPPING("mapping expression"), + CORRELATION_BASIS("correlation basis"), + CORRELATION_RESULT("correlation result"), + CORRELATION_EXPRESSION("correlation expression"); + + private final String location; + + ExpressionLocation(String location) { + this.location = location; + } + + @Override + public String toString() { + return location; + } + } + + private static boolean isCompatible(TargetType t, Class targetType, Class targetElementType, boolean subtypesAllowed) { + if (t.hasCollectionJoin()) { + return isCompatible(t.getLeafBaseClass(), t.getLeafBaseValueClass(), targetType, targetElementType, subtypesAllowed); + } else { + return isCompatible(t.getLeafBaseClass(), null, targetType, targetElementType, subtypesAllowed); + } + } + + /** + * Checks if possibleTargetType with an optional element type possibleTargetElementType + * can be mapped to targetType with the optional element type targetElementType and the given subtypesAllowed config. + * + * A possibleTargetType of NULL represents the any type which makes it always compatible i.e. returning true. + * A type is compatible if the source types given by possibleTargetType/possibleTargetElementType + * are subtypes of the target types targetType/targetElementType. + * + * A source collection type it is also compatible with non-collection targets if the source element type is a subtype of the target type. + * A source non-collection type is also compatible with a collection target if the source type is a subtype of the target element type. + * + * @param possibleTargetType The source type + * @param possibleTargetElementType The optional source element type + * @param targetType The target type + * @param targetElementType The optional target element type + * @param subtypesAllowed Whether a more specific source type is allowed to map to a general target type + * @return True if mapping from possibleTargetType/possibleTargetElementType to targetType/targetElementType is possible + */ + private static boolean isCompatible(Class possibleTargetType, Class possibleTargetElementType, Class targetType, Class targetElementType, boolean subtypesAllowed) { + // Null is the marker for ANY TYPE + if (possibleTargetType == null) { + return true; + } + + if (subtypesAllowed) { + if (possibleTargetElementType != null) { + if (targetElementType != null) { + // Mapping a plural entity attribute to a plural view attribute + return targetType.isAssignableFrom(possibleTargetType) + && targetElementType.isAssignableFrom(possibleTargetElementType); + } else { + // Mapping a plural entity attribute to a singular view attribute + return targetType.isAssignableFrom(possibleTargetElementType); } - if (correlationResult.isEmpty()) { - errors.add("Illegal empty correlation result in the " + getLocation()); + } else { + if (targetElementType != null) { + // Mapping a singular entity attribute to a plural view attribute + return targetElementType.isAssignableFrom(possibleTargetType); + } else { + // Mapping a singular entity attribute to a singular view attribute + return targetType.isAssignableFrom(possibleTargetType); } } - // Subqueries and parameters can't be checked - return errors; - } - - if (isUpdatable()) { - UpdatableExpressionVisitor visitor = new UpdatableExpressionVisitor(managedType.getJavaType()); - try { - expressionFactory.createPathExpression(mapping).accept(visitor); - Map[]> possibleTargets = visitor.getPossibleTargets(); - - if (possibleTargets.size() > 1) { - errors.add("Multiple possible target type for the mapping in the " + getLocation() + ": " + possibleTargets); + } else { + if (possibleTargetElementType != null) { + if (targetElementType != null) { + // Mapping a plural entity attribute to a plural view attribute + return targetType == possibleTargetType + && targetElementType == possibleTargetElementType; + } else { + // Mapping a plural entity attribute to a singular view attribute + return targetType == possibleTargetElementType; + } + } else { + if (targetElementType != null) { + // Mapping a singular entity attribute to a plural view attribute + return targetElementType == possibleTargetType; } else { - // TODO: further type checks like - // * collection type is same - // * collection value type is compatible + // Mapping a singular entity attribute to a singular view attribute + return targetType == possibleTargetType; } - } catch (SyntaxErrorException ex) { - errors.add("Syntax error in mapping expression '" + mapping + "' of the " + getLocation() + ": " + ex.getMessage()); - } catch (IllegalArgumentException ex) { - errors.add("There is an error for the " + getLocation() + ": " + ex.getMessage()); } } - - Class expressionType = getJavaType(); - Class elementType = null; - - if (isCollection()) { - elementType = getElementType(); - } - - // TODO: check if collection value types are compatible => subview is view for entity class, or class is super type of entity class - - // Updatable collection attributes must have the same collection type - if (!isUpdatable() && isCollection() && !isIndexed() && Collection.class.isAssignableFrom(expressionType)) { - // We can assign e.g. a Set to a List, so let's use the common supertype - expressionType = Collection.class; - } else if (!isCollection() && isSubview()) { - ManagedViewType subviewType = managedViews.get(expressionType); - - if (subviewType == null) { - throw new IllegalStateException("Expected subview '" + expressionType.getName() + "' to exist but couldn't find it!"); + } + + private static void validateTypesCompatible(ManagedType managedType, String expression, Class targetType, Class targetElementType, boolean subtypesAllowed, MetamodelBuildingContext context, ExpressionLocation expressionLocation, String location) { + final Class expressionType = targetType; + if (expression.isEmpty()) { + if (isCompatible(managedType.getJavaType(), null, targetType, targetElementType, subtypesAllowed)) { + return; } - - expressionType = subviewType.getEntityClass(); + StringBuilder sb = new StringBuilder(); + sb.append('['); + sb.append(managedType.getJavaType().getName()); + sb.append(']'); + context.addError("The resolved possible types " + sb.toString() + " are not assignable to the given expression type '" + expressionType.getName() + "' of the " + expressionLocation + " declared by the " + location + "!"); + return; } - ScalarTargetResolvingExpressionVisitor visitor = new ScalarTargetResolvingExpressionVisitor(managedType, metamodel); - + ScalarTargetResolvingExpressionVisitor visitor = new ScalarTargetResolvingExpressionVisitor(managedType, context.getEntityMetamodel()); + try { - expressionFactory.createSimpleExpression(mapping, false).accept(visitor); + context.getExpressionFactory().createSimpleExpression(expression, false).accept(visitor); } catch (SyntaxErrorException ex) { - errors.add("Syntax error in mapping expression '" + mapping + "' of the " + getLocation() + ": " + ex.getMessage()); + context.addError("Syntax error in " + expressionLocation + " '" + expression + "' of the " + location + ": " + ex.getMessage()); } catch (IllegalArgumentException ex) { - errors.add("An error occurred while trying to resolve " + getLocation() + ": " + ex.getMessage()); + context.addError("An error occurred while trying to resolve the " + expressionLocation + " of the " + location + ": " + ex.getMessage()); } - + List possibleTargets = visitor.getPossibleTargets(); - + if (!possibleTargets.isEmpty()) { boolean error = true; for (TargetType t : possibleTargets) { - Class possibleTargetType = t.getLeafBaseClass(); - - // Null is the marker for ANY TYPE - if (possibleTargetType == null || expressionType.isAssignableFrom(possibleTargetType) - || Map.class.isAssignableFrom(possibleTargetType) && expressionType.isAssignableFrom(t.getLeafBaseValueClass())) { - error = false; - break; - } else if (t.hasCollectionJoin() && elementType != null && elementType.isAssignableFrom(t.getLeafBaseValueClass())) { + if (isCompatible(t, targetType, targetElementType, subtypesAllowed)) { error = false; break; } } if (error) { - if (expressionType.isPrimitive()) { - expressionType = ReflectionUtils.getObjectClassOfPrimitve(expressionType); + if (targetType.isPrimitive()) { + targetType = ReflectionUtils.getObjectClassOfPrimitve(targetType); } else { - expressionType = ReflectionUtils.getPrimitiveClassOfWrapper(expressionType); + targetType = ReflectionUtils.getPrimitiveClassOfWrapper(targetType); } - if (expressionType != null) { + if (targetType != null) { for (TargetType t : possibleTargets) { - Class possibleTargetType = t.getLeafBaseClass(); - - // Null is the marker for ANY TYPE - if (possibleTargetType == null || expressionType.isAssignableFrom(possibleTargetType) - || Map.class.isAssignableFrom(possibleTargetType) && expressionType.isAssignableFrom(t.getLeafBaseValueClass())) { - error = false; - break; - } else if (t.hasCollectionJoin() && elementType != null && elementType.isAssignableFrom(t.getLeafBaseValueClass())) { + if (isCompatible(t, targetType, targetElementType, subtypesAllowed)) { error = false; break; } @@ -336,15 +405,114 @@ public List checkAttribute(ManagedType managedType, Map, Man sb.append(t.getLeafBaseClass().getName()); sb.append(", "); } - + sb.setLength(sb.length() - 2); sb.append(']'); - errors.add("The resolved possible types " + sb.toString() + " are not assignable to the given expression type '" + getJavaType().getName() + "' of the expression declared by the " + getLocation() + "!"); + context.addError("The resolved possible types " + sb.toString() + " are not assignable to the given expression type '" + expressionType.getName() + "' of the " + expressionLocation + " declared by the " + location + "!"); + } + } + } + + public void checkAttribute(ManagedType managedType, Map, ManagedViewTypeImpl> managedViews, MetamodelBuildingContext context) { + Class expressionType = getJavaType(); + Class elementType = null; + + if (isCollection()) { + elementType = getElementType(); + + if (isUpdatable()) { + // Updatable collection attributes currently must have the same collection type + } else { + if (isIndexed()) { + if (getCollectionType() == PluralAttribute.CollectionType.MAP) { + // All map types can be sourced from a map + expressionType = Map.class; + } else { + // An indexed list can only be sourced from an indexed list + expressionType = List.class; + } + } else { + // We can assign e.g. a Set to a List, so let's use the common supertype + expressionType = Collection.class; + } } } - return errors; + if (isSubview()) { + if (isCollection()) { + ManagedViewType subviewType = managedViews.get(elementType); + + if (subviewType == null) { + throw new IllegalStateException("Expected subview '" + elementType.getName() + "' to exist but couldn't find it!"); + } + elementType = subviewType.getEntityClass(); + } else { + ManagedViewType subviewType = managedViews.get(expressionType); + + if (subviewType == null) { + throw new IllegalStateException("Expected subview '" + expressionType.getName() + "' to exist but couldn't find it!"); + } + expressionType = subviewType.getEntityClass(); + } + } + + if (isCorrelated()) { + if (correlationBasis.isEmpty()) { + context.addError("Illegal empty correlation basis in the " + getLocation()); + } + if (isUpdatable()) { + context.addError("Illegal updatable correlated attribute " + getLocation()); + } + // Validate that resolving "correlationBasis" on "managedType" is valid + validateTypesCompatible(managedType, correlationBasis, Object.class, null, true, context, ExpressionLocation.CORRELATION_BASIS, getLocation()); + + if (correlated != null) { + // Validate that resolving "correlationResult" on "correlated" is compatible with "expressionType" and "elementType" + validateTypesCompatible(context.getEntityMetamodel().managedType(correlated), correlationResult, expressionType, elementType, true, context, ExpressionLocation.CORRELATION_RESULT, getLocation()); + + // TODO: Validate the "correlationExpression" when https://github.com/Blazebit/blaze-persistence/issues/212 is implemented + try { + // Validate the expression parses + context.createMacroAwareExpressionFactory().createBooleanExpression(correlationExpression, false); + } catch (SyntaxErrorException ex) { + context.addError("Syntax error in " + ExpressionLocation.CORRELATION_EXPRESSION + " '" + correlationExpression + "' of the " + getLocation() + ": " + ex.getMessage()); + } catch (IllegalArgumentException ex) { + context.addError("An error occurred while trying to resolve the " + ExpressionLocation.CORRELATION_EXPRESSION + " of the " + getLocation() + ": " + ex.getMessage()); + } + } + } else if (isSubquery() || isQueryParameter()) { + // Subqueries and parameters can't be checked + } else { + boolean subtypesAllowed = !isUpdatable(); + + // Forcing singular via @MappingSingular + if (!isCollection() && Collection.class.isAssignableFrom(expressionType)) { + Class[] typeArguments = getTypeArguments(); + elementType = typeArguments[typeArguments.length - 1]; + } + + // Validate that resolving "mapping" on "managedType" is compatible with "expressionType" and "elementType" + validateTypesCompatible(managedType, mapping, expressionType, elementType, subtypesAllowed, context, ExpressionLocation.MAPPING, getLocation()); + + if (isUpdatable()) { + UpdatableExpressionVisitor visitor = new UpdatableExpressionVisitor(managedType.getJavaType()); + try { + context.getExpressionFactory().createPathExpression(mapping).accept(visitor); + Map[]> possibleTargets = visitor.getPossibleTargets(); + + if (possibleTargets.size() > 1) { + context.addError("Multiple possible target type for the mapping in the " + getLocation() + ": " + possibleTargets); + } + } catch (SyntaxErrorException ex) { + context.addError("Syntax error in mapping expression '" + mapping + "' of the " + getLocation() + ": " + ex.getMessage()); + } catch (IllegalArgumentException ex) { + context.addError("There is an error for the " + getLocation() + ": " + ex.getMessage()); + } + } + } } + + protected abstract Class[] getTypeArguments(); public boolean isUpdatable() { return false; diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractMethodAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractMethodAttribute.java index 8edee8d50b..5bfed22f35 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractMethodAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractMethodAttribute.java @@ -30,6 +30,7 @@ import com.blazebit.persistence.view.IdMapping; import com.blazebit.persistence.view.Mapping; import com.blazebit.persistence.view.MappingCorrelated; +import com.blazebit.persistence.view.MappingCorrelatedSimple; import com.blazebit.persistence.view.MappingParameter; import com.blazebit.persistence.view.MappingSubquery; import com.blazebit.persistence.view.UpdatableMapping; @@ -51,14 +52,13 @@ public abstract class AbstractMethodAttribute extends AbstractAttribute filterMappings; @SuppressWarnings("unchecked") - protected AbstractMethodAttribute(ManagedViewType viewType, Method method, Annotation mapping, Set> entityViews, Set errors) { + protected AbstractMethodAttribute(ManagedViewType viewType, Method method, Annotation mapping, MetamodelBuildingContext context) { super(viewType, (Class) ReflectionUtils.getResolvedMethodReturnType(viewType.getJavaType(), method), mapping, - entityViews, AnnotationUtils.findAnnotation(method, BatchFetch.class), "for the attribute '" + getAttributeName(method) + "' of the class '" + viewType.getJavaType().getName() + "'!", - errors); + context); this.name = getAttributeName(method); UpdatableMapping updatableMapping = AnnotationUtils.findAnnotation(method, UpdatableMapping.class); @@ -82,19 +82,24 @@ protected AbstractMethodAttribute(ManagedViewType viewType, Method method, An if (filterMapping != null) { if (filtersMapping != null) { - errors.add("Illegal occurrences of @Filter and @Filters on the attribute '" + name + "' of the class '" + viewType.getJavaType().getName() + "'!"); + context.addError("Illegal occurrences of @Filter and @Filters on the attribute '" + name + "' of the class '" + viewType.getJavaType().getName() + "'!"); } else { - addFilterMapping(filterMapping, filterMappings, errors); + addFilterMapping(filterMapping, filterMappings, context); } } else if (filtersMapping != null) { for (AttributeFilter f : filtersMapping.value()) { - addFilterMapping(f, filterMappings, errors); + addFilterMapping(f, filterMappings, context); } } this.filterMappings = Collections.unmodifiableMap(filterMappings); } + @Override + protected Class[] getTypeArguments() { + return ReflectionUtils.getResolvedMethodReturnTypeArguments(getDeclaringType().getJavaType(), getJavaMethod()); + } + protected static String getAttributeName(Method getterOrSetter) { String name = getterOrSetter.getName(); StringBuilder sb = new StringBuilder(name.length()); @@ -105,13 +110,13 @@ protected static String getAttributeName(Method getterOrSetter) { .toString(); } - private void addFilterMapping(AttributeFilter filterMapping, Map filterMappings, Set errors) { + private void addFilterMapping(AttributeFilter filterMapping, Map filterMappings, MetamodelBuildingContext context) { String filterName = filterMapping.name(); boolean errorOccurred = false; if (filterMappings.containsKey(filterName)) { errorOccurred = true; - errors.add("Illegal duplicate filter name mapping '" + filterName + "' at attribute '" + name + "' of the class '" + getDeclaringType().getJavaType().getName() + "'!"); + context.addError("Illegal duplicate filter name mapping '" + filterName + "' at attribute '" + name + "' of the class '" + getDeclaringType().getJavaType().getName() + "'!"); } if (!errorOccurred) { @@ -230,6 +235,12 @@ public static Annotation getMapping(ManagedViewType viewType, Method m) { return mappingCorrelated; } + MappingCorrelatedSimple mappingCorrelatedSimple = AnnotationUtils.findAnnotation(m, MappingCorrelatedSimple.class); + + if (mappingCorrelatedSimple != null) { + return mappingCorrelatedSimple; + } + // Implicit mapping mapping = new MappingLiteral(getAttributeName(m)); } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractMethodPluralAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractMethodPluralAttribute.java index 32dab0da2d..60a45fe6f7 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractMethodPluralAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractMethodPluralAttribute.java @@ -19,7 +19,6 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Comparator; -import java.util.Set; import com.blazebit.persistence.view.CollectionMapping; import com.blazebit.persistence.view.SubqueryProvider; @@ -43,15 +42,15 @@ public abstract class AbstractMethodPluralAttribute extends AbstractMet private final Comparator comparator; @SuppressWarnings("unchecked") - public AbstractMethodPluralAttribute(ManagedViewType viewType, Method method, Annotation mapping, Set> entityViews, boolean sorted, Set errors) { - super(viewType, method, mapping, entityViews, errors); + public AbstractMethodPluralAttribute(ManagedViewType viewType, Method method, Annotation mapping, boolean sorted, MetamodelBuildingContext context) { + super(viewType, method, mapping, context); Class[] typeArguments = ReflectionUtils.getResolvedMethodReturnTypeArguments(viewType.getJavaType(), method); this.elementType = (Class) typeArguments[typeArguments.length - 1]; if (elementType == null) { - errors.add("The element type is not resolvable " + "for the attribute '" + getAttributeName(method) + "' of the class '" + viewType.getJavaType().getName() + "'!"); + context.addError("The element type is not resolvable " + "for the attribute '" + getAttributeName(method) + "' of the class '" + viewType.getJavaType().getName() + "'!"); } - this.subview = entityViews.contains(elementType); + this.subview = context.isEntityView(elementType); this.sorted = sorted; CollectionMapping collectionMapping = MetamodelUtils.getCollectionMapping(method); diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractMethodSingularAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractMethodSingularAttribute.java index d0bf6afb94..01b9663b24 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractMethodSingularAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractMethodSingularAttribute.java @@ -18,7 +18,6 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; -import java.util.Set; import com.blazebit.persistence.view.metamodel.ManagedViewType; import com.blazebit.persistence.view.metamodel.SingularAttribute; @@ -30,8 +29,8 @@ */ public abstract class AbstractMethodSingularAttribute extends AbstractMethodAttribute implements SingularAttribute { - public AbstractMethodSingularAttribute(ManagedViewType viewType, Method method, Annotation mapping, Set> entityViews, Set errors) { - super(viewType, method, mapping, entityViews, errors); + public AbstractMethodSingularAttribute(ManagedViewType viewType, Method method, Annotation mapping, MetamodelBuildingContext context) { + super(viewType, method, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractParameterAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractParameterAttribute.java index 7b7d8a3271..bb3f07131e 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractParameterAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractParameterAttribute.java @@ -17,7 +17,8 @@ package com.blazebit.persistence.view.impl.metamodel; import java.lang.annotation.Annotation; -import java.util.Set; +import java.lang.reflect.Constructor; +import java.lang.reflect.Type; import com.blazebit.persistence.view.BatchFetch; import com.blazebit.persistence.view.IdMapping; @@ -40,23 +41,31 @@ public abstract class AbstractParameterAttribute extends AbstractAttribute private final MappingConstructor declaringConstructor; @SuppressWarnings("unchecked") - public AbstractParameterAttribute(MappingConstructor constructor, int index, Annotation mapping, Set> entityViews, Set errors) { + public AbstractParameterAttribute(MappingConstructor constructor, int index, Annotation mapping, MetamodelBuildingContext context) { super(constructor.getDeclaringType(), (Class) constructor.getJavaConstructor().getParameterTypes()[index], mapping, - entityViews, findAnnotation(constructor.getJavaConstructor().getParameterAnnotations()[index], BatchFetch.class), "for the parameter of the constructor '" + constructor.getJavaConstructor().toString() + "' at the index '" + index + "'!", - errors); + context); this.index = index; this.declaringConstructor = constructor; if (this.mapping != null && this.mapping.isEmpty()) { - errors.add("Illegal empty mapping for the parameter of the constructor '" + declaringConstructor.getJavaConstructor().toString() + context.addError("Illegal empty mapping for the parameter of the constructor '" + declaringConstructor.getJavaConstructor().toString() + "' at the index '" + index + "'!"); } } + @Override + protected Class[] getTypeArguments() { + Class clazz = getDeclaringType().getJavaType(); + Constructor constructor = getDeclaringConstructor().getJavaConstructor(); + Type[] genericParameterTypes = constructor.getGenericParameterTypes(); + + return ReflectionUtils.resolveTypeArguments(clazz, genericParameterTypes[getIndex()]); + } + private static T findAnnotation(Annotation[] parameterAnnotations, Class annotationClass) { for (Annotation a : parameterAnnotations) { if (a.annotationType() == annotationClass) { @@ -67,7 +76,7 @@ private static T findAnnotation(Annotation[] parameterAnn return null; } - public static void validate(MappingConstructor constructor, int index, Set errors) { + public static void validate(MappingConstructor constructor, int index, MetamodelBuildingContext context) { Annotation[] annotations = constructor.getJavaConstructor().getParameterAnnotations()[index]; boolean foundAnnotation = false; @@ -82,7 +91,7 @@ public static void validate(MappingConstructor constructor, int index, Set extends Abstract private final Comparator comparator; @SuppressWarnings("unchecked") - public AbstractParameterPluralAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, Set> entityViews, boolean sorted, Set errors) { - super(mappingConstructor, index, mapping, entityViews, errors); + public AbstractParameterPluralAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping,boolean sorted, MetamodelBuildingContext context) { + super(mappingConstructor, index, mapping, context); Type parameterType = mappingConstructor.getJavaConstructor().getGenericParameterTypes()[index]; Class[] typeArguments = ReflectionUtils.resolveTypeArguments(mappingConstructor.getDeclaringType().getJavaType(), parameterType); this.elementType = (Class) typeArguments[typeArguments.length - 1]; - this.subview = entityViews.contains(elementType); + this.subview = context.isEntityView(elementType); this.sorted = sorted; CollectionMapping collectionMapping = MetamodelUtils.getCollectionMapping(mappingConstructor, index); diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractParameterSingularAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractParameterSingularAttribute.java index 36cd580886..6685afd4ab 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractParameterSingularAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractParameterSingularAttribute.java @@ -17,7 +17,6 @@ package com.blazebit.persistence.view.impl.metamodel; import java.lang.annotation.Annotation; -import java.util.Set; import com.blazebit.persistence.view.metamodel.MappingConstructor; import com.blazebit.persistence.view.metamodel.SingularAttribute; @@ -29,8 +28,8 @@ */ public abstract class AbstractParameterSingularAttribute extends AbstractParameterAttribute implements SingularAttribute { - public AbstractParameterSingularAttribute(MappingConstructor constructor, int index, Annotation mapping, Set> entityViews, Set errors) { - super(constructor, index, mapping, entityViews, errors); + public AbstractParameterSingularAttribute(MappingConstructor constructor, int index, Annotation mapping, MetamodelBuildingContext context) { + super(constructor, index, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/EmbeddableViewTypeImpl.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/EmbeddableViewTypeImpl.java index 40817e1c01..679c34fe72 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/EmbeddableViewTypeImpl.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/EmbeddableViewTypeImpl.java @@ -16,16 +16,12 @@ package com.blazebit.persistence.view.impl.metamodel; -import java.util.Set; - -import javax.persistence.metamodel.EmbeddableType; - import com.blazebit.annotation.AnnotationUtils; -import com.blazebit.persistence.impl.EntityMetamodel; -import com.blazebit.persistence.impl.expression.ExpressionFactory; import com.blazebit.persistence.view.EmbeddableEntityView; import com.blazebit.persistence.view.metamodel.EmbeddableViewType; +import javax.persistence.metamodel.EmbeddableType; + /** * * @author Christian Beikov @@ -34,22 +30,22 @@ public class EmbeddableViewTypeImpl extends ManagedViewTypeImpl implements EmbeddableViewType { - public EmbeddableViewTypeImpl(Class clazz, Set> entityViews, EntityMetamodel metamodel, ExpressionFactory expressionFactory, Set errors) { - super(clazz, getEntityClass(clazz, metamodel, errors), entityViews, metamodel, expressionFactory, errors); + public EmbeddableViewTypeImpl(Class clazz, MetamodelBuildingContext context) { + super(clazz, getEntityClass(clazz, context), context); } - private static Class getEntityClass(Class clazz, EntityMetamodel metamodel, Set errors) { + private static Class getEntityClass(Class clazz, MetamodelBuildingContext context) { EmbeddableEntityView entityViewAnnot = AnnotationUtils.findAnnotation(clazz, EmbeddableEntityView.class); if (entityViewAnnot == null) { - errors.add("Could not find any EmbeddableEntityView annotation for the class '" + clazz.getName() + "'"); + context.addError("Could not find any EmbeddableEntityView annotation for the class '" + clazz.getName() + "'"); return null; } Class entityClass = entityViewAnnot.value(); - if (!(metamodel.getManagedType(entityClass) instanceof EmbeddableType)) { - errors.add("The class which is referenced by the EmbeddableEntityView annotation of the class '" + clazz.getName() + "' is not an embeddable!"); + if (!(context.getEntityMetamodel().getManagedType(entityClass) instanceof EmbeddableType)) { + context.addError("The class which is referenced by the EmbeddableEntityView annotation of the class '" + clazz.getName() + "' is not an embeddable!"); return null; } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/ManagedViewTypeImpl.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/ManagedViewTypeImpl.java index 4c27696ecb..ee8982a0ac 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/ManagedViewTypeImpl.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/ManagedViewTypeImpl.java @@ -38,10 +38,9 @@ import javax.persistence.metamodel.ManagedType; import com.blazebit.annotation.AnnotationUtils; -import com.blazebit.persistence.impl.EntityMetamodel; -import com.blazebit.persistence.impl.expression.ExpressionFactory; import com.blazebit.persistence.view.BatchFetch; import com.blazebit.persistence.view.MappingCorrelated; +import com.blazebit.persistence.view.MappingCorrelatedSimple; import com.blazebit.persistence.view.MappingParameter; import com.blazebit.persistence.view.MappingSingular; import com.blazebit.persistence.view.MappingSubquery; @@ -76,19 +75,19 @@ public abstract class ManagedViewTypeImpl implements ManagedViewType { protected final Map> constructorIndex; @SuppressWarnings("unchecked") - public ManagedViewTypeImpl(Class clazz, Class entityClass, Set> entityViews, EntityMetamodel metamodel, ExpressionFactory expressionFactory, Set errors) { + public ManagedViewTypeImpl(Class clazz, Class entityClass, MetamodelBuildingContext context) { this.javaType = (Class) clazz; this.entityClass = entityClass; if (!clazz.isInterface() && !Modifier.isAbstract(clazz.getModifiers())) { - errors.add("Only interfaces or abstract classes are allowed as entity views. '" + clazz.getName() + "' is neither of those."); + context.addError("Only interfaces or abstract classes are allowed as entity views. '" + clazz.getName() + "' is neither of those."); } BatchFetch batchFetch = AnnotationUtils.findAnnotation(clazz, BatchFetch.class); if (batchFetch == null || batchFetch.size() == -1) { this.defaultBatchSize = -1; } else if (batchFetch.size() < 1) { - errors.add("Illegal batch fetch size defined at '" + clazz.getName() + "'! Use a value greater than 0 or -1!"); + context.addError("Illegal batch fetch size defined at '" + clazz.getName() + "'! Use a value greater than 0 or -1!"); this.defaultBatchSize = Integer.MIN_VALUE; } else { this.defaultBatchSize = batchFetch.size(); @@ -113,7 +112,7 @@ public ManagedViewTypeImpl(Class clazz, Class entityClass, Set clazz, Class entityClass, Set newAttribute = createMethodAttribute(this, method, entityViews, metamodel, expressionFactory, errors); + AbstractMethodAttribute newAttribute = createMethodAttribute(this, method, context); attributes.put(newAttribute.getName(), newAttribute); continue; } - errors.add("Conflicting attribute mapping for attribute '" + attributeName + "' at the methods [" + methodReference(method) + ", " + methodReference(attribute.getJavaMethod()) + "] for managed view type '" + javaType.getName() + "'"); + context.addError("Conflicting attribute mapping for attribute '" + attributeName + "' at the methods [" + methodReference(method) + ", " + methodReference(attribute.getJavaMethod()) + "] for managed view type '" + javaType.getName() + "'"); } } } @@ -162,7 +161,7 @@ public ManagedViewTypeImpl(Class clazz, Class entityClass, Set mappingConstructor = new MappingConstructorImpl(this, constructorName, (Constructor) constructor, entityViews, metamodel, expressionFactory, errors); + MappingConstructorImpl mappingConstructor = new MappingConstructorImpl(this, constructorName, (Constructor) constructor, context); constructors.put(new ParametersKey(constructor.getParameterTypes()), mappingConstructor); constructorIndex.put(constructorName, mappingConstructor); } @@ -175,47 +174,46 @@ private static String methodReference(Method method) { return method.getDeclaringClass().getName() + "." + method.getName(); } - private void handleMethod(Method method, Set> entityViews, Map> attributes, EntityMetamodel metamodel, ExpressionFactory expressionFactory, Set errors) { + private void handleMethod(Method method, Map> attributes, MetamodelBuildingContext context) { String attributeName = AbstractMethodAttribute.extractAttributeName(javaType, method); if (attributeName != null && !attributes.containsKey(attributeName)) { - AbstractMethodAttribute attribute = createMethodAttribute(this, method, entityViews, metamodel, expressionFactory, errors); + AbstractMethodAttribute attribute = createMethodAttribute(this, method, context); if (attribute != null) { attributes.put(attribute.getName(), attribute); } } } - public void checkAttributesCorrelationUsage(Collection errors, Map, String> seenCorrelationProviders, Map, ManagedViewTypeImpl> managedViews, Set> seenViewTypes, Set> seenConstructors) { + public void checkAttributesCorrelationUsage(Map, ManagedViewTypeImpl> managedViews, Set> seenViewTypes, Set> seenConstructors, MetamodelBuildingContext context) { if (seenViewTypes.contains(this)) { return; } seenViewTypes.add(this); for (AbstractMethodAttribute attribute : attributes.values()) { - attribute.checkAttributeCorrelationUsage(errors, seenCorrelationProviders, managedViews, seenViewTypes, seenConstructors); + attribute.checkAttributeCorrelationUsage(managedViews, seenViewTypes, seenConstructors, context); } if (!constructors.isEmpty()) { for (MappingConstructorImpl constructor : constructors.values()) { - constructor.checkParameterCorrelationUsage(errors, new HashMap, String>(seenCorrelationProviders), managedViews, new HashSet>(seenViewTypes), new HashSet>(seenConstructors)); + constructor.checkParameterCorrelationUsage(managedViews, new HashSet>(seenViewTypes), new HashSet>(seenConstructors), context); } } } - public void checkAttributes(Map, ManagedViewTypeImpl> managedViews, ExpressionFactory expressionFactory, EntityMetamodel metamodel, Set errors) { - ManagedType managedType = metamodel.managedType(entityClass); + public void checkAttributes(Map, ManagedViewTypeImpl> managedViews, MetamodelBuildingContext context) { + ManagedType managedType = context.getEntityMetamodel().managedType(entityClass); Map> collectionMappings = new HashMap>(); - Map, String> seenCorrelationProviders = new HashMap, String>(); Set> seenViewTypes = new HashSet>(); Set> seenConstructors = new HashSet>(); seenViewTypes.add(this); for (AbstractMethodAttribute attribute : attributes.values()) { - errors.addAll(attribute.checkAttribute(managedType, managedViews, expressionFactory, metamodel)); - attribute.checkAttributeCorrelationUsage(errors, seenCorrelationProviders, managedViews, seenViewTypes, seenConstructors); + attribute.checkAttribute(managedType, managedViews, context); + attribute.checkAttributeCorrelationUsage(managedViews, seenViewTypes, seenConstructors, context); - for (String mapping : attribute.getCollectionJoinMappings(managedType, metamodel, expressionFactory)) { + for (String mapping : attribute.getCollectionJoinMappings(managedType, context)) { List locations = collectionMappings.get(mapping); if (locations == null) { locations = new ArrayList(2); @@ -234,8 +232,8 @@ public void checkAttributes(Map, ManagedViewTypeImpl> managedViews, constructorCollectionMappings.put(entry.getKey(), new ArrayList(entry.getValue())); } - constructor.checkParameters(managedType, managedViews, expressionFactory, metamodel, constructorCollectionMappings, errors); - constructor.checkParameterCorrelationUsage(errors, new HashMap, String>(seenCorrelationProviders), managedViews, new HashSet>(seenViewTypes), new HashSet>(seenConstructors)); + constructor.checkParameters(managedType, managedViews, constructorCollectionMappings, context); + constructor.checkParameterCorrelationUsage(managedViews, new HashSet>(seenViewTypes), new HashSet>(seenConstructors), context); StringBuilder sb = new StringBuilder(); for (Map.Entry> locationsEntry : constructorCollectionMappings.entrySet()) { @@ -248,7 +246,7 @@ public void checkAttributes(Map, ManagedViewTypeImpl> managedViews, sb.append("\n - "); sb.append(location); } - errors.add(sb.toString()); + context.addError(sb.toString()); } } } @@ -264,7 +262,7 @@ public void checkAttributes(Map, ManagedViewTypeImpl> managedViews, sb.append("\n - "); sb.append(location); } - errors.add(sb.toString()); + context.addError(sb.toString()); } } } @@ -287,54 +285,55 @@ private void addAttributeFilters(AbstractMethodAttribute attribute } // If you change something here don't forget to also update MappingConstructorImpl#createMethodAttribute - private static AbstractMethodAttribute createMethodAttribute(ManagedViewType viewType, Method method, Set> entityViews, EntityMetamodel metamodel, ExpressionFactory expressionFactory, Set errors) { + private static AbstractMethodAttribute createMethodAttribute(ManagedViewType viewType, Method method, MetamodelBuildingContext context) { Annotation mapping = AbstractMethodAttribute.getMapping(viewType, method); if (mapping == null) { return null; } Class attributeType = ReflectionUtils.getResolvedMethodReturnType(viewType.getJavaType(), method); + boolean correlated = mapping instanceof MappingCorrelated || mapping instanceof MappingCorrelatedSimple; // Force singular mapping if (AnnotationUtils.findAnnotation(method, MappingSingular.class) != null || mapping instanceof MappingParameter) { - if (mapping instanceof MappingCorrelated) { - return new CorrelatedMethodMappingSingularAttribute(viewType, method, mapping, entityViews, errors); + if (correlated) { + return new CorrelatedMethodMappingSingularAttribute(viewType, method, mapping, context); } else { - return new MappingMethodSingularAttribute(viewType, method, mapping, entityViews, errors); + return new MappingMethodSingularAttribute(viewType, method, mapping, context); } } if (Collection.class == attributeType) { - if (mapping instanceof MappingCorrelated) { - return new CorrelatedMethodCollectionAttribute(viewType, method, mapping, entityViews, errors); + if (correlated) { + return new CorrelatedMethodCollectionAttribute(viewType, method, mapping, context); } else { - return new MappingMethodCollectionAttribute(viewType, method, mapping, entityViews, errors); + return new MappingMethodCollectionAttribute(viewType, method, mapping, context); } } else if (List.class == attributeType) { - if (mapping instanceof MappingCorrelated) { - return new CorrelatedMethodListAttribute(viewType, method, mapping, entityViews, metamodel, expressionFactory, errors); + if (correlated) { + return new CorrelatedMethodListAttribute(viewType, method, mapping, context); } else { - return new MappingMethodListAttribute(viewType, method, mapping, entityViews, metamodel, expressionFactory, errors); + return new MappingMethodListAttribute(viewType, method, mapping, context); } } else if (Set.class == attributeType || SortedSet.class == attributeType || NavigableSet.class == attributeType) { - if (mapping instanceof MappingCorrelated) { - return new CorrelatedMethodSetAttribute(viewType, method, mapping, entityViews, errors); + if (correlated) { + return new CorrelatedMethodSetAttribute(viewType, method, mapping, context); } else { - return new MappingMethodSetAttribute(viewType, method, mapping, entityViews, errors); + return new MappingMethodSetAttribute(viewType, method, mapping, context); } } else if (Map.class == attributeType || SortedMap.class == attributeType || NavigableMap.class == attributeType) { - if (mapping instanceof MappingCorrelated) { - errors.add("The mapping defined on method '" + viewType.getJavaType().getName() + "." + method.getName() + "' uses a Map type with a correlated mapping which is unsupported!"); + if (correlated) { + context.addError("The mapping defined on method '" + viewType.getJavaType().getName() + "." + method.getName() + "' uses a Map type with a correlated mapping which is unsupported!"); return null; } else { - return new MappingMethodMapAttribute(viewType, method, mapping, entityViews, errors); + return new MappingMethodMapAttribute(viewType, method, mapping, context); } } else if (mapping instanceof MappingSubquery) { - return new SubqueryMethodSingularAttribute(viewType, method, mapping, entityViews, errors); - } else if (mapping instanceof MappingCorrelated) { - return new CorrelatedMethodMappingSingularAttribute(viewType, method, mapping, entityViews, errors); + return new SubqueryMethodSingularAttribute(viewType, method, mapping, context); + } else if (correlated) { + return new CorrelatedMethodMappingSingularAttribute(viewType, method, mapping, context); } else { - return new MappingMethodSingularAttribute(viewType, method, mapping, entityViews, errors); + return new MappingMethodSingularAttribute(viewType, method, mapping, context); } } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/MappingConstructorImpl.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/MappingConstructorImpl.java index 459e6402c1..0b4587131a 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/MappingConstructorImpl.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/MappingConstructorImpl.java @@ -16,36 +16,44 @@ package com.blazebit.persistence.view.impl.metamodel; -import java.lang.annotation.Annotation; -import java.lang.reflect.Constructor; -import java.lang.reflect.Type; -import java.lang.reflect.TypeVariable; -import java.util.*; - -import javax.persistence.metamodel.ManagedType; - -import com.blazebit.persistence.impl.EntityMetamodel; -import com.blazebit.persistence.impl.expression.ExpressionFactory; import com.blazebit.persistence.view.MappingCorrelated; +import com.blazebit.persistence.view.MappingCorrelatedSimple; import com.blazebit.persistence.view.MappingParameter; import com.blazebit.persistence.view.MappingSingular; import com.blazebit.persistence.view.MappingSubquery; import com.blazebit.persistence.view.ViewConstructor; import com.blazebit.persistence.view.impl.metamodel.attribute.CorrelatedParameterCollectionAttribute; import com.blazebit.persistence.view.impl.metamodel.attribute.CorrelatedParameterListAttribute; -import com.blazebit.persistence.view.impl.metamodel.attribute.CorrelatedParameterSetAttribute; import com.blazebit.persistence.view.impl.metamodel.attribute.CorrelatedParameterMappingSingularAttribute; +import com.blazebit.persistence.view.impl.metamodel.attribute.CorrelatedParameterSetAttribute; import com.blazebit.persistence.view.impl.metamodel.attribute.MappingParameterCollectionAttribute; import com.blazebit.persistence.view.impl.metamodel.attribute.MappingParameterListAttribute; import com.blazebit.persistence.view.impl.metamodel.attribute.MappingParameterMapAttribute; -import com.blazebit.persistence.view.impl.metamodel.attribute.MappingParameterSetAttribute; import com.blazebit.persistence.view.impl.metamodel.attribute.MappingParameterMappingSingularAttribute; +import com.blazebit.persistence.view.impl.metamodel.attribute.MappingParameterSetAttribute; import com.blazebit.persistence.view.impl.metamodel.attribute.SubqueryParameterSingularAttribute; import com.blazebit.persistence.view.metamodel.ManagedViewType; import com.blazebit.persistence.view.metamodel.MappingConstructor; import com.blazebit.persistence.view.metamodel.ParameterAttribute; import com.blazebit.reflection.ReflectionUtils; +import javax.persistence.metamodel.ManagedType; +import java.lang.annotation.Annotation; +import java.lang.reflect.Constructor; +import java.lang.reflect.Type; +import java.lang.reflect.TypeVariable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.NavigableMap; +import java.util.NavigableSet; +import java.util.Set; +import java.util.SortedMap; +import java.util.SortedSet; + /** * * @author Christian Beikov @@ -58,21 +66,21 @@ public class MappingConstructorImpl implements MappingConstructor { private final Constructor javaConstructor; private final List> parameters; - public MappingConstructorImpl(ManagedViewType viewType, String name, Constructor constructor, Set> entityViews, EntityMetamodel metamodel, ExpressionFactory expressionFactory, Set errors) { + public MappingConstructorImpl(ManagedViewType viewType, String name, Constructor constructor, MetamodelBuildingContext context) { this.name = name; this.declaringType = viewType; this.javaConstructor = constructor; if (constructor.getExceptionTypes().length != 0) { - errors.add("The constructor '" + constructor.toString() + "' of the class '" + constructor.getDeclaringClass().getName() + context.addError("The constructor '" + constructor.toString() + "' of the class '" + constructor.getDeclaringClass().getName() + "' may not throw an exception!"); } int parameterCount = constructor.getParameterTypes().length; List> parameters = new ArrayList>(parameterCount); for (int i = 0; i < parameterCount; i++) { - AbstractParameterAttribute.validate(this, i, errors); - AbstractParameterAttribute parameter = createParameterAttribute(this, i, entityViews, metamodel, expressionFactory, errors); + AbstractParameterAttribute.validate(this, i, context); + AbstractParameterAttribute parameter = createParameterAttribute(this, i, context); if (parameter != null) { parameters.add(parameter); } @@ -81,22 +89,22 @@ public MappingConstructorImpl(ManagedViewType viewType, String name, Construc this.parameters = Collections.unmodifiableList(parameters); } - public void checkParameterCorrelationUsage(Collection errors, HashMap, String> seenCorrelationProviders, Map, ManagedViewTypeImpl> managedViews, HashSet> seenViewTypes, HashSet> seenConstructors) { + public void checkParameterCorrelationUsage(Map, ManagedViewTypeImpl> managedViews, HashSet> seenViewTypes, HashSet> seenConstructors, MetamodelBuildingContext context) { if (seenConstructors.contains(this)) { return; } seenConstructors.add(this); for (AbstractParameterAttribute parameter : parameters) { - parameter.checkAttributeCorrelationUsage(errors, seenCorrelationProviders, managedViews, seenViewTypes, seenConstructors); + parameter.checkAttributeCorrelationUsage(managedViews, seenViewTypes, seenConstructors, context); } } - public void checkParameters(ManagedType managedType, Map, ManagedViewTypeImpl> managedViews, ExpressionFactory expressionFactory, EntityMetamodel metamodel, Map> collectionMappings, Set errors) { + public void checkParameters(ManagedType managedType, Map, ManagedViewTypeImpl> managedViews, Map> collectionMappings, MetamodelBuildingContext context) { for (AbstractParameterAttribute parameter : parameters) { - errors.addAll(parameter.checkAttribute(managedType, managedViews, expressionFactory, metamodel)); + parameter.checkAttribute(managedType, managedViews, context); - for (String mapping : parameter.getCollectionJoinMappings(managedType, metamodel, expressionFactory)) { + for (String mapping : parameter.getCollectionJoinMappings(managedType, context)) { List locations = collectionMappings.get(mapping); if (locations == null) { locations = new ArrayList(2); @@ -119,7 +127,7 @@ public static String extractConstructorName(ManagedViewType viewType, Constru } // If you change something here don't forget to also update ViewTypeImpl#createMethodAttribute - private static AbstractParameterAttribute createParameterAttribute(MappingConstructor constructor, int index, Set> entityViews, EntityMetamodel metamodel, ExpressionFactory expressionFactory, Set errors) { + private static AbstractParameterAttribute createParameterAttribute(MappingConstructor constructor, int index, MetamodelBuildingContext context) { Annotation mapping = AbstractParameterAttribute.getMapping(constructor, index); if (mapping == null) { return null; @@ -133,9 +141,11 @@ public static String extractConstructorName(ManagedViewType viewType, Constru } else { attributeType = constructor.getJavaConstructor().getParameterTypes()[index]; } + + boolean correlated = mapping instanceof MappingCorrelated || mapping instanceof MappingCorrelatedSimple; if (mapping instanceof MappingParameter) { - return new MappingParameterMappingSingularAttribute(constructor, index, mapping, entityViews, errors); + return new MappingParameterMappingSingularAttribute(constructor, index, mapping, context); } Annotation[] annotations = constructor.getJavaConstructor().getParameterAnnotations()[index]; @@ -143,46 +153,46 @@ public static String extractConstructorName(ManagedViewType viewType, Constru for (Annotation a : annotations) { // Force singular mapping if (MappingSingular.class == a.annotationType()) { - if (mapping instanceof MappingCorrelated) { - return new CorrelatedParameterMappingSingularAttribute(constructor, index, mapping, entityViews, errors); + if (correlated) { + return new CorrelatedParameterMappingSingularAttribute(constructor, index, mapping, context); } else { - return new MappingParameterMappingSingularAttribute(constructor, index, mapping, entityViews, errors); + return new MappingParameterMappingSingularAttribute(constructor, index, mapping, context); } } } if (Collection.class == attributeType) { - if (mapping instanceof MappingCorrelated) { - return new CorrelatedParameterCollectionAttribute(constructor, index, mapping, entityViews, errors); + if (correlated) { + return new CorrelatedParameterCollectionAttribute(constructor, index, mapping, context); } else { - return new MappingParameterCollectionAttribute(constructor, index, mapping, entityViews, errors); + return new MappingParameterCollectionAttribute(constructor, index, mapping, context); } } else if (List.class == attributeType) { - if (mapping instanceof MappingCorrelated) { - return new CorrelatedParameterListAttribute(constructor, index, mapping, entityViews, metamodel, expressionFactory, errors); + if (correlated) { + return new CorrelatedParameterListAttribute(constructor, index, mapping, context); } else { - return new MappingParameterListAttribute(constructor, index, mapping, entityViews, metamodel, expressionFactory, errors); + return new MappingParameterListAttribute(constructor, index, mapping, context); } } else if (Set.class == attributeType || SortedSet.class == attributeType || NavigableSet.class == attributeType) { - if (mapping instanceof MappingCorrelated) { - return new CorrelatedParameterSetAttribute(constructor, index, mapping, entityViews, errors); + if (correlated) { + return new CorrelatedParameterSetAttribute(constructor, index, mapping, context); } else { - return new MappingParameterSetAttribute(constructor, index, mapping, entityViews, errors); + return new MappingParameterSetAttribute(constructor, index, mapping, context); } } else if (Map.class == attributeType || SortedMap.class == attributeType || NavigableMap.class == attributeType) { - if (mapping instanceof MappingCorrelated) { - errors.add("Parameter with the index '" + index + "' of the constructor '" + constructor.getJavaConstructor() + "' uses a Map type with a correlated mapping which is unsupported!"); + if (correlated) { + context.addError("Parameter with the index '" + index + "' of the constructor '" + constructor.getJavaConstructor() + "' uses a Map type with a correlated mapping which is unsupported!"); return null; } else { - return new MappingParameterMapAttribute(constructor, index, mapping, entityViews, errors); + return new MappingParameterMapAttribute(constructor, index, mapping, context); } } else if (mapping instanceof MappingSubquery) { - return new SubqueryParameterSingularAttribute(constructor, index, mapping, entityViews, errors); + return new SubqueryParameterSingularAttribute(constructor, index, mapping, context); } else { - if (mapping instanceof MappingCorrelated) { - return new CorrelatedParameterMappingSingularAttribute(constructor, index, mapping, entityViews, errors); + if (correlated) { + return new CorrelatedParameterMappingSingularAttribute(constructor, index, mapping, context); } else { - return new MappingParameterMappingSingularAttribute(constructor, index, mapping, entityViews, errors); + return new MappingParameterMappingSingularAttribute(constructor, index, mapping, context); } } } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/MetamodelBuildingContext.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/MetamodelBuildingContext.java new file mode 100644 index 0000000000..5a9ab92741 --- /dev/null +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/MetamodelBuildingContext.java @@ -0,0 +1,45 @@ +/* + * Copyright 2014 - 2017 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.view.impl.metamodel; + +import com.blazebit.persistence.impl.EntityMetamodel; +import com.blazebit.persistence.impl.expression.ExpressionFactory; +import com.blazebit.persistence.view.impl.proxy.ProxyFactory; + +/** + * + * @author Christian Beikov + * @since 1.2.0 + */ +public interface MetamodelBuildingContext { + + public EntityMetamodel getEntityMetamodel(); + + public ExpressionFactory getExpressionFactory(); + + public ExpressionFactory createMacroAwareExpressionFactory(); + + public ExpressionFactory createMacroAwareExpressionFactory(String viewRoot); + + public ProxyFactory getProxyFactory(); + + public void addError(String error); + + public boolean hasErrors(); + + public boolean isEntityView(Class clazz); +} diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/MetamodelBuildingContextImpl.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/MetamodelBuildingContextImpl.java new file mode 100644 index 0000000000..b1b9885b1d --- /dev/null +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/MetamodelBuildingContextImpl.java @@ -0,0 +1,97 @@ +/* + * Copyright 2014 - 2017 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.view.impl.metamodel; + +import com.blazebit.persistence.impl.EntityMetamodel; +import com.blazebit.persistence.impl.expression.AbstractCachingExpressionFactory; +import com.blazebit.persistence.impl.expression.ExpressionFactory; +import com.blazebit.persistence.impl.expression.MacroConfiguration; +import com.blazebit.persistence.impl.expression.MacroFunction; +import com.blazebit.persistence.view.impl.JpqlMacroAdapter; +import com.blazebit.persistence.view.impl.MacroConfigurationExpressionFactory; +import com.blazebit.persistence.view.impl.macro.DefaultViewRootJpqlMacro; +import com.blazebit.persistence.view.impl.proxy.ProxyFactory; + +import java.util.Collections; +import java.util.Set; + +/** + * + * @author Christian Beikov + * @since 1.2.0 + */ +public class MetamodelBuildingContextImpl implements MetamodelBuildingContext { + + private final EntityMetamodel entityMetamodel; + private final ExpressionFactory expressionFactory; + private final ProxyFactory proxyFactory; + private final Set> entityViewClasses; + private final Set errors; + + public MetamodelBuildingContextImpl(EntityMetamodel entityMetamodel, ExpressionFactory expressionFactory, ProxyFactory proxyFactory, Set> entityViewClasses, Set errors) { + this.entityMetamodel = entityMetamodel; + this.expressionFactory = expressionFactory; + this.proxyFactory = proxyFactory; + this.entityViewClasses = entityViewClasses; + this.errors = errors; + } + + @Override + public EntityMetamodel getEntityMetamodel() { + return entityMetamodel; + } + + @Override + public ExpressionFactory getExpressionFactory() { + return expressionFactory; + } + + @Override + public ExpressionFactory createMacroAwareExpressionFactory() { + return createMacroAwareExpressionFactory("syntax_checking_placeholder"); + } + + @Override + public ExpressionFactory createMacroAwareExpressionFactory(String viewRoot) { + MacroConfiguration originalMacroConfiguration = expressionFactory.getDefaultMacroConfiguration(); + ExpressionFactory cachingExpressionFactory = expressionFactory.unwrap(AbstractCachingExpressionFactory.class); + MacroFunction macro = new JpqlMacroAdapter(new DefaultViewRootJpqlMacro(viewRoot), cachingExpressionFactory); + MacroConfiguration macroConfiguration = originalMacroConfiguration.with(Collections.singletonMap("view_root", macro)); + return new MacroConfigurationExpressionFactory(cachingExpressionFactory, macroConfiguration); + } + + @Override + public ProxyFactory getProxyFactory() { + return proxyFactory; + } + + @Override + public void addError(String error) { + errors.add(error); + } + + @Override + public boolean hasErrors() { + return !errors.isEmpty(); + } + + @Override + public boolean isEntityView(Class clazz) { + return entityViewClasses.contains(clazz); + } + +} diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/ViewMetamodelImpl.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/ViewMetamodelImpl.java index ae467fad25..07012b1686 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/ViewMetamodelImpl.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/ViewMetamodelImpl.java @@ -25,7 +25,7 @@ import com.blazebit.annotation.AnnotationUtils; import com.blazebit.persistence.impl.EntityMetamodel; -import com.blazebit.persistence.impl.expression.ExpressionFactory; +import com.blazebit.persistence.spi.ServiceProvider; import com.blazebit.persistence.view.EmbeddableEntityView; import com.blazebit.persistence.view.metamodel.EmbeddableViewType; import com.blazebit.persistence.view.metamodel.ManagedViewType; @@ -46,23 +46,22 @@ public class ViewMetamodelImpl implements ViewMetamodel { private final Map, EmbeddableViewType> embeddableViews; private final Map, ManagedViewTypeImpl> managedViews; - public ViewMetamodelImpl(Set> entityViews, boolean validateExpressions, ExpressionFactory expressionFactory, EntityMetamodel metamodel) { - this.metamodel = metamodel; + public ViewMetamodelImpl(Set> entityViews, ServiceProvider serviceProvider, MetamodelBuildingContext context, boolean validateExpressions) { + this.metamodel = serviceProvider.getService(EntityMetamodel.class); + Map, ViewType> views = new HashMap, ViewType>(entityViews.size()); Map, EmbeddableViewType> embeddableViews = new HashMap, EmbeddableViewType>(entityViews.size()); Map, ManagedViewTypeImpl> managedViews = new HashMap, ManagedViewTypeImpl>(entityViews.size()); - - Set errors = new HashSet(); for (Class entityViewClass : entityViews) { ManagedViewTypeImpl managedView; if (!isEmbeddableViewType(entityViewClass)) { - ViewTypeImpl viewType = getViewType(entityViewClass, entityViews, this.metamodel, expressionFactory, errors); + ViewTypeImpl viewType = getViewType(entityViewClass, context); views.put(entityViewClass, viewType); managedView = viewType; } else { - EmbeddableViewTypeImpl embeddableViewType = getEmbeddableViewType(entityViewClass, entityViews, this.metamodel, expressionFactory, errors); + EmbeddableViewTypeImpl embeddableViewType = getEmbeddableViewType(entityViewClass, context); embeddableViews.put(entityViewClass, embeddableViewType); managedView = embeddableViewType; } @@ -74,10 +73,10 @@ public ViewMetamodelImpl(Set> entityViews, boolean validateExpressions, this.embeddableViews = Collections.unmodifiableMap(embeddableViews); this.managedViews = Collections.unmodifiableMap(managedViews); - if (errors.isEmpty()) { + if (!context.hasErrors()) { if (validateExpressions) { for (ManagedViewTypeImpl t : managedViews.values()) { - t.checkAttributes(this.managedViews, expressionFactory, this.metamodel, errors); + t.checkAttributes(this.managedViews, context); } } @@ -85,24 +84,12 @@ public ViewMetamodelImpl(Set> entityViews, boolean validateExpressions, for (ViewType viewType : views.values()) { Set> dependencies = new HashSet>(); dependencies.add(viewType); - checkCircularDependencies(viewType, dependencies, errors); + checkCircularDependencies(viewType, dependencies, context); } } - - if (!errors.isEmpty()) { - StringBuilder sb = new StringBuilder(); - sb.append("There are error(s) in entity views!"); - - for (String error : errors) { - sb.append('\n'); - sb.append(error); - } - - throw new IllegalArgumentException(sb.toString()); - } } - private void checkCircularDependencies(ManagedViewType viewType, Set> dependencies, Set errors) { + private void checkCircularDependencies(ManagedViewType viewType, Set> dependencies, MetamodelBuildingContext context) { for (MethodAttribute attr : viewType.getAttributes()) { if (attr.isSubview()) { ManagedViewType subviewType; @@ -112,14 +99,14 @@ private void checkCircularDependencies(ManagedViewType viewType, Set> subviewDependencies = new HashSet>(dependencies); subviewDependencies.add(subviewType); - checkCircularDependencies(subviewType, subviewDependencies, errors); + checkCircularDependencies(subviewType, subviewDependencies, context); } } } @@ -165,12 +152,12 @@ private boolean isEmbeddableViewType(Class entityViewClass) { return AnnotationUtils.findAnnotation(entityViewClass, EmbeddableEntityView.class) != null; } - private ViewTypeImpl getViewType(Class entityViewClass, Set> entityViews, EntityMetamodel metamodel, ExpressionFactory expressionFactory, Set errors) { - return new ViewTypeImpl(entityViewClass, entityViews, metamodel, expressionFactory, errors); + private ViewTypeImpl getViewType(Class entityViewClass, MetamodelBuildingContext context) { + return new ViewTypeImpl(entityViewClass, context); } - private EmbeddableViewTypeImpl getEmbeddableViewType(Class entityViewClass, Set> entityViews, EntityMetamodel metamodel, ExpressionFactory expressionFactory, Set errors) { - return new EmbeddableViewTypeImpl(entityViewClass, entityViews, metamodel, expressionFactory, errors); + private EmbeddableViewTypeImpl getEmbeddableViewType(Class entityViewClass, MetamodelBuildingContext context) { + return new EmbeddableViewTypeImpl(entityViewClass, context); } } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/ViewTypeImpl.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/ViewTypeImpl.java index 662f4a2de4..c4282abbf8 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/ViewTypeImpl.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/ViewTypeImpl.java @@ -16,16 +16,7 @@ package com.blazebit.persistence.view.impl.metamodel; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import javax.persistence.metamodel.IdentifiableType; - import com.blazebit.annotation.AnnotationUtils; -import com.blazebit.persistence.impl.EntityMetamodel; -import com.blazebit.persistence.impl.expression.ExpressionFactory; import com.blazebit.persistence.view.EntityView; import com.blazebit.persistence.view.UpdatableEntityView; import com.blazebit.persistence.view.ViewFilter; @@ -34,6 +25,12 @@ import com.blazebit.persistence.view.metamodel.ViewFilterMapping; import com.blazebit.persistence.view.metamodel.ViewType; +import javax.persistence.metamodel.IdentifiableType; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + /** * * @author Christian Beikov @@ -47,8 +44,8 @@ public class ViewTypeImpl extends ManagedViewTypeImpl implements ViewType< private final MethodAttribute idAttribute; private final Map viewFilters; - public ViewTypeImpl(Class clazz, Set> entityViews, EntityMetamodel metamodel, ExpressionFactory expressionFactory, Set errors) { - super(clazz, getEntityClass(clazz, metamodel, errors), entityViews, metamodel, expressionFactory, errors); + public ViewTypeImpl(Class clazz, MetamodelBuildingContext context) { + super(clazz, getEntityClass(clazz, context), context); EntityView entityViewAnnot = AnnotationUtils.findAnnotation(clazz, EntityView.class); @@ -74,13 +71,13 @@ public ViewTypeImpl(Class clazz, Set> entityViews, EntityM if (filterMapping != null) { if (filtersMapping != null) { - errors.add("Illegal occurrences of @ViewFilter and @ViewFilters on the class '" + javaType.getName() + "'!"); + context.addError("Illegal occurrences of @ViewFilter and @ViewFilters on the class '" + javaType.getName() + "'!"); } else { - addFilterMapping(filterMapping, viewFilters, errors); + addFilterMapping(filterMapping, viewFilters, context); } } else if (filtersMapping != null) { for (ViewFilter f : filtersMapping.value()) { - addFilterMapping(f, viewFilters, errors); + addFilterMapping(f, viewFilters, context); } } @@ -91,7 +88,7 @@ public ViewTypeImpl(Class clazz, Set> entityViews, EntityM for (AbstractMethodAttribute attribute : attributes.values()) { if (attribute.isId()) { if (foundIdAttribute != null) { - errors.add("Illegal occurrence of multiple id attributes ['" + foundIdAttribute.getName() + "', '" + attribute.getName() + "'] in entity view '" + javaType.getName() + "'!"); + context.addError("Illegal occurrence of multiple id attributes ['" + foundIdAttribute.getName() + "', '" + attribute.getName() + "'] in entity view '" + javaType.getName() + "'!"); } else { foundIdAttribute = attribute; } @@ -99,37 +96,37 @@ public ViewTypeImpl(Class clazz, Set> entityViews, EntityM } if (foundIdAttribute == null) { - errors.add("No id attribute was defined for entity view '" + javaType.getName() + "' although it is needed!"); + context.addError("No id attribute was defined for entity view '" + javaType.getName() + "' although it is needed!"); } if (updatable) { if (foundIdAttribute.isUpdatable()) { - errors.add("Id attribute in entity view '" + javaType.getName() + "' is updatable which is not allowed!"); + context.addError("Id attribute in entity view '" + javaType.getName() + "' is updatable which is not allowed!"); } } this.idAttribute = foundIdAttribute; } - private static Class getEntityClass(Class clazz, EntityMetamodel metamodel, Set errors) { + private static Class getEntityClass(Class clazz, MetamodelBuildingContext context) { EntityView entityViewAnnot = AnnotationUtils.findAnnotation(clazz, EntityView.class); if (entityViewAnnot == null) { - errors.add("Could not find any EntityView annotation for the class '" + clazz.getName() + "'"); + context.addError("Could not find any EntityView annotation for the class '" + clazz.getName() + "'"); return null; } Class entityClass = entityViewAnnot.value(); - if (!(metamodel.getManagedType(entityClass) instanceof IdentifiableType)) { - errors.add("The class which is referenced by the EntityView annotation of the class '" + clazz.getName() + "' is not an identifiable type!"); + if (!(context.getEntityMetamodel().getManagedType(entityClass) instanceof IdentifiableType)) { + context.addError("The class which is referenced by the EntityView annotation of the class '" + clazz.getName() + "' is not an identifiable type!"); return null; } return entityClass; } - private void addFilterMapping(ViewFilter filterMapping,Map viewFilters, Set errors) { + private void addFilterMapping(ViewFilter filterMapping, Map viewFilters, MetamodelBuildingContext context) { String filterName = filterMapping.name(); boolean errorOccurred = false; @@ -138,12 +135,12 @@ private void addFilterMapping(ViewFilter filterMapping,Map extends AbstractMethodPluralAttribute, Y> implements CollectionAttribute { - public AbstractMethodCollectionAttribute(ManagedViewType viewType, Method method, Annotation mapping, Set> entityViews, Set errors) { - super(viewType, method, mapping, entityViews, false, errors); + public AbstractMethodCollectionAttribute(ManagedViewType viewType, Method method, Annotation mapping, MetamodelBuildingContext context) { + super(viewType, method, mapping, false, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractMethodListAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractMethodListAttribute.java index 0b24a62359..9e26b95b58 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractMethodListAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractMethodListAttribute.java @@ -16,9 +16,8 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; -import com.blazebit.persistence.impl.EntityMetamodel; -import com.blazebit.persistence.impl.expression.ExpressionFactory; import com.blazebit.persistence.view.impl.metamodel.AbstractMethodPluralAttribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.impl.metamodel.MetamodelUtils; import com.blazebit.persistence.view.metamodel.ListAttribute; import com.blazebit.persistence.view.metamodel.ManagedViewType; @@ -26,7 +25,6 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.List; -import java.util.Set; /** * @@ -37,13 +35,13 @@ public abstract class AbstractMethodListAttribute extends AbstractMethodPl private final boolean isIndexed; - public AbstractMethodListAttribute(ManagedViewType viewType, Method method, Annotation mapping, Set> entityViews, EntityMetamodel metamodel, ExpressionFactory expressionFactory, Set errors) { - super(viewType, method, mapping, entityViews, false, errors); + public AbstractMethodListAttribute(ManagedViewType viewType, Method method, Annotation mapping, MetamodelBuildingContext context) { + super(viewType, method, mapping, false, context); if (isIgnoreIndex()) { this.isIndexed = false; } else { - this.isIndexed = MetamodelUtils.isIndexedList(metamodel, expressionFactory, viewType.getEntityClass(), mapping); + this.isIndexed = MetamodelUtils.isIndexedList(context.getEntityMetamodel(), context.getExpressionFactory(), viewType.getEntityClass(), mapping); } } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractMethodMapAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractMethodMapAttribute.java index 08e28b222e..a19284ef79 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractMethodMapAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractMethodMapAttribute.java @@ -17,6 +17,7 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; import com.blazebit.persistence.view.impl.metamodel.AbstractMethodPluralAttribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.impl.metamodel.MetamodelUtils; import com.blazebit.persistence.view.metamodel.ManagedViewType; import com.blazebit.persistence.view.metamodel.MapAttribute; @@ -25,7 +26,6 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Map; -import java.util.Set; /** * @@ -38,16 +38,16 @@ public abstract class AbstractMethodMapAttribute extends AbstractMethod private final boolean keySubview; @SuppressWarnings("unchecked") - public AbstractMethodMapAttribute(ManagedViewType viewType, Method method, Annotation mapping, Set> entityViews, Set errors) { - super(viewType, method, mapping, entityViews, MetamodelUtils.isSorted(viewType.getJavaType(), method), errors); + public AbstractMethodMapAttribute(ManagedViewType viewType, Method method, Annotation mapping, MetamodelBuildingContext context) { + super(viewType, method, mapping, MetamodelUtils.isSorted(viewType.getJavaType(), method), context); Class[] typeArguments = ReflectionUtils.getResolvedMethodReturnTypeArguments(viewType.getJavaType(), method); this.keyType = (Class) typeArguments[0]; if (keyType == null) { - errors.add("The key type is not resolvable " + "for the attribute '" + getName() + "' of the class '" + viewType.getJavaType().getName() + "'!"); + context.addError("The key type is not resolvable " + "for the attribute '" + getName() + "' of the class '" + viewType.getJavaType().getName() + "'!"); } - this.keySubview = entityViews.contains(keyType); + this.keySubview = context.isEntityView(keyType); if (isIgnoreIndex()) { - errors.add("Illegal ignoreIndex mapping for the attribute '" + getName() + "' of the class '" + viewType.getJavaType().getName() + "'!"); + context.addError("Illegal ignoreIndex mapping for the attribute '" + getName() + "' of the class '" + viewType.getJavaType().getName() + "'!"); } } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractMethodSetAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractMethodSetAttribute.java index 59e02b59d7..d7f765690d 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractMethodSetAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractMethodSetAttribute.java @@ -17,6 +17,7 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; import com.blazebit.persistence.view.impl.metamodel.AbstractMethodPluralAttribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.impl.metamodel.MetamodelUtils; import com.blazebit.persistence.view.metamodel.ManagedViewType; import com.blazebit.persistence.view.metamodel.SetAttribute; @@ -32,8 +33,8 @@ */ public abstract class AbstractMethodSetAttribute extends AbstractMethodPluralAttribute, Y> implements SetAttribute { - public AbstractMethodSetAttribute(ManagedViewType viewType, Method method, Annotation mapping, Set> entityViews, Set errors) { - super(viewType, method, mapping, entityViews, MetamodelUtils.isSorted(viewType.getJavaType(), method), errors); + public AbstractMethodSetAttribute(ManagedViewType viewType, Method method, Annotation mapping, MetamodelBuildingContext context) { + super(viewType, method, mapping, MetamodelUtils.isSorted(viewType.getJavaType(), method), context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractParameterCollectionAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractParameterCollectionAttribute.java index 19c862c34b..7b8f0dbfca 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractParameterCollectionAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractParameterCollectionAttribute.java @@ -17,12 +17,12 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; import com.blazebit.persistence.view.impl.metamodel.AbstractParameterPluralAttribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.CollectionAttribute; import com.blazebit.persistence.view.metamodel.MappingConstructor; import java.lang.annotation.Annotation; import java.util.Collection; -import java.util.Set; /** * @@ -31,8 +31,8 @@ */ public abstract class AbstractParameterCollectionAttribute extends AbstractParameterPluralAttribute, Y> implements CollectionAttribute { - public AbstractParameterCollectionAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, Set> entityViews, Set errors) { - super(mappingConstructor, index, mapping, entityViews, false, errors); + public AbstractParameterCollectionAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, MetamodelBuildingContext context) { + super(mappingConstructor, index, mapping, false, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractParameterListAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractParameterListAttribute.java index 1e09531ea6..9293c62624 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractParameterListAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractParameterListAttribute.java @@ -16,16 +16,14 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; -import com.blazebit.persistence.impl.EntityMetamodel; -import com.blazebit.persistence.impl.expression.ExpressionFactory; import com.blazebit.persistence.view.impl.metamodel.AbstractParameterPluralAttribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.impl.metamodel.MetamodelUtils; import com.blazebit.persistence.view.metamodel.ListAttribute; import com.blazebit.persistence.view.metamodel.MappingConstructor; import java.lang.annotation.Annotation; import java.util.List; -import java.util.Set; /** * @@ -36,13 +34,13 @@ public abstract class AbstractParameterListAttribute extends AbstractParam private final boolean isIndexed; - public AbstractParameterListAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, Set> entityViews, EntityMetamodel metamodel, ExpressionFactory expressionFactory, Set errors) { - super(mappingConstructor, index, mapping, entityViews, false, errors); + public AbstractParameterListAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, MetamodelBuildingContext context) { + super(mappingConstructor, index, mapping, false, context); if (isIgnoreIndex()) { this.isIndexed = false; } else { - this.isIndexed = MetamodelUtils.isIndexedList(metamodel, expressionFactory, mappingConstructor.getDeclaringType().getEntityClass(), mapping); + this.isIndexed = MetamodelUtils.isIndexedList(context.getEntityMetamodel(), context.getExpressionFactory(), mappingConstructor.getDeclaringType().getEntityClass(), mapping); } } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractParameterMapAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractParameterMapAttribute.java index c5c461b947..430f031cfb 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractParameterMapAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractParameterMapAttribute.java @@ -17,6 +17,7 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; import com.blazebit.persistence.view.impl.metamodel.AbstractParameterPluralAttribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.impl.metamodel.MetamodelUtils; import com.blazebit.persistence.view.metamodel.MapAttribute; import com.blazebit.persistence.view.metamodel.MappingConstructor; @@ -25,7 +26,6 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Type; import java.util.Map; -import java.util.Set; /** * @@ -38,14 +38,14 @@ public abstract class AbstractParameterMapAttribute extends AbstractPar private final boolean keySubview; @SuppressWarnings("unchecked") - public AbstractParameterMapAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, Set> entityViews, Set errors) { - super(mappingConstructor, index, mapping, entityViews, MetamodelUtils.isSorted(mappingConstructor, index), errors); + public AbstractParameterMapAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, MetamodelBuildingContext context) { + super(mappingConstructor, index, mapping, MetamodelUtils.isSorted(mappingConstructor, index), context); Type parameterType = mappingConstructor.getJavaConstructor().getGenericParameterTypes()[index]; Class[] typeArguments = ReflectionUtils.resolveTypeArguments(mappingConstructor.getDeclaringType().getJavaType(), parameterType); this.keyType = (Class) typeArguments[0]; - this.keySubview = entityViews.contains(keyType); + this.keySubview = context.isEntityView(keyType); if (isIgnoreIndex()) { - errors.add("Illegal ignoreIndex mapping for the parameter of the constructor '" + mappingConstructor.getJavaConstructor().toString() + context.addError("Illegal ignoreIndex mapping for the parameter of the constructor '" + mappingConstructor.getJavaConstructor().toString() + "' at the index '" + index + "'!"); } } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractParameterSetAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractParameterSetAttribute.java index 1784cf35c3..282c26a964 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractParameterSetAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/AbstractParameterSetAttribute.java @@ -17,6 +17,7 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; import com.blazebit.persistence.view.impl.metamodel.AbstractParameterPluralAttribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.impl.metamodel.MetamodelUtils; import com.blazebit.persistence.view.metamodel.MappingConstructor; import com.blazebit.persistence.view.metamodel.SetAttribute; @@ -31,8 +32,8 @@ */ public abstract class AbstractParameterSetAttribute extends AbstractParameterPluralAttribute, Y> implements SetAttribute { - public AbstractParameterSetAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, Set> entityViews, Set errors) { - super(mappingConstructor, index, mapping, entityViews, MetamodelUtils.isSorted(mappingConstructor, index), errors); + public AbstractParameterSetAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, MetamodelBuildingContext context) { + super(mappingConstructor, index, mapping, MetamodelUtils.isSorted(mappingConstructor, index), context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedMethodCollectionAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedMethodCollectionAttribute.java index b2274d75d2..57d02583ba 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedMethodCollectionAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedMethodCollectionAttribute.java @@ -16,13 +16,13 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.CorrelatedAttribute; import com.blazebit.persistence.view.metamodel.ManagedViewType; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Collection; -import java.util.Set; /** * @@ -31,8 +31,8 @@ */ public class CorrelatedMethodCollectionAttribute extends AbstractMethodCollectionAttribute implements CorrelatedAttribute> { - public CorrelatedMethodCollectionAttribute(ManagedViewType viewType, Method method, Annotation mapping, Set> entityViews, Set errors) { - super(viewType, method, mapping, entityViews, errors); + public CorrelatedMethodCollectionAttribute(ManagedViewType viewType, Method method, Annotation mapping, MetamodelBuildingContext context) { + super(viewType, method, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedMethodListAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedMethodListAttribute.java index ecf9203202..b8d9ce3015 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedMethodListAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedMethodListAttribute.java @@ -16,15 +16,13 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; -import com.blazebit.persistence.impl.EntityMetamodel; -import com.blazebit.persistence.impl.expression.ExpressionFactory; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.CorrelatedAttribute; import com.blazebit.persistence.view.metamodel.ManagedViewType; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.List; -import java.util.Set; /** * @@ -33,8 +31,8 @@ */ public class CorrelatedMethodListAttribute extends AbstractMethodListAttribute implements CorrelatedAttribute> { - public CorrelatedMethodListAttribute(ManagedViewType viewType, Method method, Annotation mapping, Set> entityViews, EntityMetamodel metamodel, ExpressionFactory expressionFactory, Set errors) { - super(viewType, method, mapping, entityViews, metamodel, expressionFactory, errors); + public CorrelatedMethodListAttribute(ManagedViewType viewType, Method method, Annotation mapping, MetamodelBuildingContext context) { + super(viewType, method, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedMethodMappingSingularAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedMethodMappingSingularAttribute.java index 2a504d64fe..4f95eb74e9 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedMethodMappingSingularAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedMethodMappingSingularAttribute.java @@ -17,12 +17,12 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; import com.blazebit.persistence.view.impl.metamodel.AbstractMethodSingularAttribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.CorrelatedAttribute; import com.blazebit.persistence.view.metamodel.ManagedViewType; import java.lang.annotation.Annotation; import java.lang.reflect.Method; -import java.util.Set; /** * @@ -31,8 +31,8 @@ */ public class CorrelatedMethodMappingSingularAttribute extends AbstractMethodSingularAttribute implements CorrelatedAttribute { - public CorrelatedMethodMappingSingularAttribute(ManagedViewType viewType, Method method, Annotation mapping, Set> entityViews, Set errors) { - super(viewType, method, mapping, entityViews, errors); + public CorrelatedMethodMappingSingularAttribute(ManagedViewType viewType, Method method, Annotation mapping, MetamodelBuildingContext context) { + super(viewType, method, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedMethodSetAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedMethodSetAttribute.java index ac13c645dd..faca2a3a6f 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedMethodSetAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedMethodSetAttribute.java @@ -16,6 +16,7 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.CorrelatedAttribute; import com.blazebit.persistence.view.metamodel.ManagedViewType; @@ -30,8 +31,8 @@ */ public class CorrelatedMethodSetAttribute extends AbstractMethodSetAttribute implements CorrelatedAttribute> { - public CorrelatedMethodSetAttribute(ManagedViewType viewType, Method method, Annotation mapping, Set> entityViews, Set errors) { - super(viewType, method, mapping, entityViews, errors); + public CorrelatedMethodSetAttribute(ManagedViewType viewType, Method method, Annotation mapping, MetamodelBuildingContext context) { + super(viewType, method, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedParameterCollectionAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedParameterCollectionAttribute.java index 9f585dc4f5..a1029813dd 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedParameterCollectionAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedParameterCollectionAttribute.java @@ -16,12 +16,12 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.CorrelatedAttribute; import com.blazebit.persistence.view.metamodel.MappingConstructor; import java.lang.annotation.Annotation; import java.util.Collection; -import java.util.Set; /** * @@ -30,8 +30,8 @@ */ public class CorrelatedParameterCollectionAttribute extends AbstractParameterCollectionAttribute implements CorrelatedAttribute> { - public CorrelatedParameterCollectionAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, Set> entityViews, Set errors) { - super(mappingConstructor, index, mapping, entityViews, errors); + public CorrelatedParameterCollectionAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, MetamodelBuildingContext context) { + super(mappingConstructor, index, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedParameterListAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedParameterListAttribute.java index 6095a5efa6..38c4febfeb 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedParameterListAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedParameterListAttribute.java @@ -16,14 +16,12 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; -import com.blazebit.persistence.impl.EntityMetamodel; -import com.blazebit.persistence.impl.expression.ExpressionFactory; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.CorrelatedAttribute; import com.blazebit.persistence.view.metamodel.MappingConstructor; import java.lang.annotation.Annotation; import java.util.List; -import java.util.Set; /** * @@ -32,8 +30,8 @@ */ public class CorrelatedParameterListAttribute extends AbstractParameterListAttribute implements CorrelatedAttribute> { - public CorrelatedParameterListAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, Set> entityViews, EntityMetamodel metamodel, ExpressionFactory expressionFactory, Set errors) { - super(mappingConstructor, index, mapping, entityViews, metamodel, expressionFactory, errors); + public CorrelatedParameterListAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, MetamodelBuildingContext context) { + super(mappingConstructor, index, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedParameterMappingSingularAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedParameterMappingSingularAttribute.java index 0d73767961..d40b3c0b5f 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedParameterMappingSingularAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedParameterMappingSingularAttribute.java @@ -17,11 +17,11 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; import com.blazebit.persistence.view.impl.metamodel.AbstractParameterSingularAttribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.CorrelatedAttribute; import com.blazebit.persistence.view.metamodel.MappingConstructor; import java.lang.annotation.Annotation; -import java.util.Set; /** * @@ -30,8 +30,8 @@ */ public class CorrelatedParameterMappingSingularAttribute extends AbstractParameterSingularAttribute implements CorrelatedAttribute { - public CorrelatedParameterMappingSingularAttribute(MappingConstructor constructor, int index, Annotation mapping, Set> entityViews, Set errors) { - super(constructor, index, mapping, entityViews, errors); + public CorrelatedParameterMappingSingularAttribute(MappingConstructor constructor, int index, Annotation mapping, MetamodelBuildingContext context) { + super(constructor, index, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedParameterSetAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedParameterSetAttribute.java index 636b9181b4..d7fe2ec37b 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedParameterSetAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/CorrelatedParameterSetAttribute.java @@ -16,6 +16,7 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.CorrelatedAttribute; import com.blazebit.persistence.view.metamodel.MappingConstructor; @@ -29,8 +30,8 @@ */ public class CorrelatedParameterSetAttribute extends AbstractParameterSetAttribute implements CorrelatedAttribute> { - public CorrelatedParameterSetAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, Set> entityViews, Set errors) { - super(mappingConstructor, index, mapping, entityViews, errors); + public CorrelatedParameterSetAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, MetamodelBuildingContext context) { + super(mappingConstructor, index, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodCollectionAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodCollectionAttribute.java index c6bcd2ae15..337489a6b0 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodCollectionAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodCollectionAttribute.java @@ -16,13 +16,13 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.ManagedViewType; import com.blazebit.persistence.view.metamodel.MappingAttribute; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Collection; -import java.util.Set; /** * @@ -31,8 +31,8 @@ */ public class MappingMethodCollectionAttribute extends AbstractMethodCollectionAttribute implements MappingAttribute> { - public MappingMethodCollectionAttribute(ManagedViewType viewType, Method method, Annotation mapping, Set> entityViews, Set errors) { - super(viewType, method, mapping, entityViews, errors); + public MappingMethodCollectionAttribute(ManagedViewType viewType, Method method, Annotation mapping, MetamodelBuildingContext context) { + super(viewType, method, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodListAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodListAttribute.java index a7246949ed..95546fc392 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodListAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodListAttribute.java @@ -16,15 +16,13 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; -import com.blazebit.persistence.impl.EntityMetamodel; -import com.blazebit.persistence.impl.expression.ExpressionFactory; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.ManagedViewType; import com.blazebit.persistence.view.metamodel.MappingAttribute; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.List; -import java.util.Set; /** * @@ -34,8 +32,8 @@ public class MappingMethodListAttribute extends AbstractMethodListAttribute implements MappingAttribute> { - public MappingMethodListAttribute(ManagedViewType viewType, Method method, Annotation mapping, Set> entityViews, EntityMetamodel metamodel, ExpressionFactory expressionFactory, Set errors) { - super(viewType, method, mapping, entityViews, metamodel, expressionFactory, errors); + public MappingMethodListAttribute(ManagedViewType viewType, Method method, Annotation mapping, MetamodelBuildingContext context) { + super(viewType, method, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodMapAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodMapAttribute.java index f8ce34f707..53db267b07 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodMapAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodMapAttribute.java @@ -16,13 +16,13 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.ManagedViewType; import com.blazebit.persistence.view.metamodel.MappingAttribute; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Map; -import java.util.Set; /** * @@ -32,8 +32,8 @@ public class MappingMethodMapAttribute extends AbstractMethodMapAttribute implements MappingAttribute> { @SuppressWarnings("unchecked") - public MappingMethodMapAttribute(ManagedViewType viewType, Method method, Annotation mapping, Set> entityViews, Set errors) { - super(viewType, method, mapping, entityViews, errors); + public MappingMethodMapAttribute(ManagedViewType viewType, Method method, Annotation mapping, MetamodelBuildingContext context) { + super(viewType, method, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodSetAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodSetAttribute.java index c55e52d1df..440d66b646 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodSetAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodSetAttribute.java @@ -16,6 +16,7 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.ManagedViewType; import com.blazebit.persistence.view.metamodel.MappingAttribute; @@ -30,8 +31,8 @@ */ public class MappingMethodSetAttribute extends AbstractMethodSetAttribute implements MappingAttribute> { - public MappingMethodSetAttribute(ManagedViewType viewType, Method method, Annotation mapping, Set> entityViews, Set errors) { - super(viewType, method, mapping, entityViews, errors); + public MappingMethodSetAttribute(ManagedViewType viewType, Method method, Annotation mapping, MetamodelBuildingContext context) { + super(viewType, method, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodSingularAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodSingularAttribute.java index 7bb2280d89..e0abc4c44f 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodSingularAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingMethodSingularAttribute.java @@ -16,14 +16,14 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.util.Set; - import com.blazebit.persistence.view.impl.metamodel.AbstractMethodSingularAttribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.ManagedViewType; import com.blazebit.persistence.view.metamodel.MappingAttribute; +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; + /** * * @author Christian Beikov @@ -31,8 +31,8 @@ */ public class MappingMethodSingularAttribute extends AbstractMethodSingularAttribute implements MappingAttribute { - public MappingMethodSingularAttribute(ManagedViewType viewType, Method method, Annotation mapping, Set> entityViews, Set errors) { - super(viewType, method, mapping, entityViews, errors); + public MappingMethodSingularAttribute(ManagedViewType viewType, Method method, Annotation mapping, MetamodelBuildingContext context) { + super(viewType, method, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterCollectionAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterCollectionAttribute.java index 45cf29c89d..ee78564b4e 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterCollectionAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterCollectionAttribute.java @@ -16,12 +16,12 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.MappingAttribute; import com.blazebit.persistence.view.metamodel.MappingConstructor; import java.lang.annotation.Annotation; import java.util.Collection; -import java.util.Set; /** * @@ -30,8 +30,8 @@ */ public class MappingParameterCollectionAttribute extends AbstractParameterCollectionAttribute implements MappingAttribute> { - public MappingParameterCollectionAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, Set> entityViews, Set errors) { - super(mappingConstructor, index, mapping, entityViews, errors); + public MappingParameterCollectionAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, MetamodelBuildingContext context) { + super(mappingConstructor, index, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterListAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterListAttribute.java index 2d998ab1f5..456ee60bbe 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterListAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterListAttribute.java @@ -16,14 +16,12 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; -import com.blazebit.persistence.impl.EntityMetamodel; -import com.blazebit.persistence.impl.expression.ExpressionFactory; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.MappingAttribute; import com.blazebit.persistence.view.metamodel.MappingConstructor; import java.lang.annotation.Annotation; import java.util.List; -import java.util.Set; /** * @@ -32,8 +30,8 @@ */ public class MappingParameterListAttribute extends AbstractParameterListAttribute implements MappingAttribute> { - public MappingParameterListAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, Set> entityViews, EntityMetamodel metamodel, ExpressionFactory expressionFactory, Set errors) { - super(mappingConstructor, index, mapping, entityViews, metamodel, expressionFactory, errors); + public MappingParameterListAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, MetamodelBuildingContext context) { + super(mappingConstructor, index, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterMapAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterMapAttribute.java index 87148fd71e..a3d1e5b7f3 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterMapAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterMapAttribute.java @@ -16,12 +16,12 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.MappingAttribute; import com.blazebit.persistence.view.metamodel.MappingConstructor; import java.lang.annotation.Annotation; import java.util.Map; -import java.util.Set; /** * @@ -31,8 +31,8 @@ public class MappingParameterMapAttribute extends AbstractParameterMapAttribute implements MappingAttribute> { @SuppressWarnings("unchecked") - public MappingParameterMapAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, Set> entityViews, Set errors) { - super(mappingConstructor, index, mapping, entityViews, errors); + public MappingParameterMapAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, MetamodelBuildingContext context) { + super(mappingConstructor, index, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterMappingSingularAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterMappingSingularAttribute.java index 1cf55b49fb..e7aaa2208e 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterMappingSingularAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterMappingSingularAttribute.java @@ -16,13 +16,13 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; -import java.lang.annotation.Annotation; -import java.util.Set; - import com.blazebit.persistence.view.impl.metamodel.AbstractParameterSingularAttribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.MappingAttribute; import com.blazebit.persistence.view.metamodel.MappingConstructor; +import java.lang.annotation.Annotation; + /** * * @author Christian Beikov @@ -30,8 +30,8 @@ */ public class MappingParameterMappingSingularAttribute extends AbstractParameterSingularAttribute implements MappingAttribute { - public MappingParameterMappingSingularAttribute(MappingConstructor constructor, int index, Annotation mapping, Set> entityViews, Set errors) { - super(constructor, index, mapping, entityViews, errors); + public MappingParameterMappingSingularAttribute(MappingConstructor constructor, int index, Annotation mapping, MetamodelBuildingContext context) { + super(constructor, index, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterSetAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterSetAttribute.java index 71c6deb400..65f6157fd3 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterSetAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/MappingParameterSetAttribute.java @@ -16,6 +16,7 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.MappingAttribute; import com.blazebit.persistence.view.metamodel.MappingConstructor; @@ -29,8 +30,8 @@ */ public class MappingParameterSetAttribute extends AbstractParameterSetAttribute implements MappingAttribute> { - public MappingParameterSetAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, Set> entityViews, Set errors) { - super(mappingConstructor, index, mapping, entityViews, errors); + public MappingParameterSetAttribute(MappingConstructor mappingConstructor, int index, Annotation mapping, MetamodelBuildingContext context) { + super(mappingConstructor, index, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/SubqueryMethodSingularAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/SubqueryMethodSingularAttribute.java index eee5e636de..76c1475622 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/SubqueryMethodSingularAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/SubqueryMethodSingularAttribute.java @@ -16,14 +16,14 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.util.Set; - import com.blazebit.persistence.view.impl.metamodel.AbstractMethodSingularAttribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.ManagedViewType; import com.blazebit.persistence.view.metamodel.SubqueryAttribute; +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; + /** * * @author Christian Beikov @@ -31,8 +31,8 @@ */ public class SubqueryMethodSingularAttribute extends AbstractMethodSingularAttribute implements SubqueryAttribute { - public SubqueryMethodSingularAttribute(ManagedViewType viewType, Method method, Annotation mapping, Set> entityViews, Set errors) { - super(viewType, method, mapping, entityViews, errors); + public SubqueryMethodSingularAttribute(ManagedViewType viewType, Method method, Annotation mapping, MetamodelBuildingContext context) { + super(viewType, method, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/SubqueryParameterSingularAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/SubqueryParameterSingularAttribute.java index f4764abdc7..dd75ef03da 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/SubqueryParameterSingularAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/attribute/SubqueryParameterSingularAttribute.java @@ -16,13 +16,13 @@ package com.blazebit.persistence.view.impl.metamodel.attribute; -import java.lang.annotation.Annotation; -import java.util.Set; - import com.blazebit.persistence.view.impl.metamodel.AbstractParameterSingularAttribute; +import com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContext; import com.blazebit.persistence.view.metamodel.MappingConstructor; import com.blazebit.persistence.view.metamodel.SubqueryAttribute; +import java.lang.annotation.Annotation; + /** * * @author Christian Beikov @@ -30,8 +30,8 @@ */ public class SubqueryParameterSingularAttribute extends AbstractParameterSingularAttribute implements SubqueryAttribute { - public SubqueryParameterSingularAttribute(MappingConstructor constructor, int index, Annotation mapping, Set> entityViews, Set errors) { - super(constructor, index, mapping, entityViews, errors); + public SubqueryParameterSingularAttribute(MappingConstructor constructor, int index, Annotation mapping, MetamodelBuildingContext context) { + super(constructor, index, mapping, context); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/ViewTypeObjectBuilderTemplate.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/ViewTypeObjectBuilderTemplate.java index 39a02d282a..5cf6390b6e 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/ViewTypeObjectBuilderTemplate.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/ViewTypeObjectBuilderTemplate.java @@ -244,10 +244,12 @@ private ViewTypeObjectBuilderTemplate(ManagedViewType viewRoot, String viewRo } for (int i = 0; i < attributes.length; i++) { - applyMapping(attributes[i], attributePath, mappingList, parameterMappingList, featuresFound); + String newAttributePath = getAttributePath(attributePath, attributes[i], false); + applyMapping(attributes[i], newAttributePath, mappingList, parameterMappingList, featuresFound); } for (int i = 0; i < parameterAttributes.length; i++) { - applyMapping(parameterAttributes[i], attributePath, mappingList, parameterMappingList, featuresFound); + String newAttributePath = getAttributePath(attributePath, parameterAttributes[i], false); + applyMapping(parameterAttributes[i], newAttributePath, mappingList, parameterMappingList, featuresFound); } this.hasParameters = featuresFound[FEATURE_PARAMETERS]; @@ -527,8 +529,13 @@ private void applyCorrelatedSubviewMapping(CorrelatedAttribute cor ManagedViewType managedViewType = (ManagedViewType) evm.getMetamodel().managedView(subviewClass); String subviewAliasPrefix = getAlias(aliasPrefix, correlatedAttribute, false); String correlationBasis = getMapping(mappingPrefix, correlatedAttribute.getCorrelationBasis()); - List subviewMappingPrefix = Collections.singletonList(correlationResult); - String subviewIdPrefix = correlationResult; + String subviewIdPrefix; + if (correlationResult.isEmpty()) { + subviewIdPrefix = CorrelationProviderHelper.getDefaultCorrelationAlias(attributePath); + } else { + subviewIdPrefix = correlationResult; + } + List subviewMappingPrefix = Collections.singletonList(subviewIdPrefix); int[] subviewIdPositions; int startIndex; @@ -550,7 +557,7 @@ private void applyCorrelatedSubviewMapping(CorrelatedAttribute cor parameterMappingList.add(null); } tupleTransformatorFactory.add(template.tupleTransformatorFactory); - tupleTransformatorFactory.add(new CorrelatedSubviewJoinTupleTransformerFactory(template, factory, correlationBasis, correlationResult)); + tupleTransformatorFactory.add(new CorrelatedSubviewJoinTupleTransformerFactory(template, factory, correlationBasis, correlationResult, attributePath)); } else if (correlatedAttribute.getFetchStrategy() == FetchStrategy.SELECT) { String subviewAliasPrefix = getAlias(aliasPrefix, correlatedAttribute, false); int startIndex = tupleOffset + mappingList.size(); @@ -635,7 +642,7 @@ private void applyCorrelatedSubviewMapping(CorrelatedAttribute cor if (!correlatedAttribute.isCollection()) { tupleTransformatorFactory.add(new CorrelatedSingularSubselectTupleListTransformerFactory( new SubviewCorrelator(managedViewType, evm, subviewAliasPrefix), - subviewClass, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, startIndex, correlationBasisType, correlationBasisEntity + subviewClass, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, attributePath, startIndex, correlationBasisType, correlationBasisEntity )); } else { PluralAttribute pluralAttribute = (PluralAttribute) correlatedAttribute; @@ -646,7 +653,7 @@ private void applyCorrelatedSubviewMapping(CorrelatedAttribute cor } else { tupleTransformatorFactory.add(new CorrelatedListSubselectTupleListTransformerFactory( new SubviewCorrelator(managedViewType, evm, subviewAliasPrefix), - subviewClass, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, startIndex, correlationBasisType, correlationBasisEntity + subviewClass, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, attributePath, startIndex, correlationBasisType, correlationBasisEntity )); } break; @@ -656,7 +663,7 @@ private void applyCorrelatedSubviewMapping(CorrelatedAttribute cor } else { tupleTransformatorFactory.add(new CorrelatedListSubselectTupleListTransformerFactory( new SubviewCorrelator(managedViewType, evm, subviewAliasPrefix), - subviewClass, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, startIndex, correlationBasisType, correlationBasisEntity + subviewClass, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, attributePath, startIndex, correlationBasisType, correlationBasisEntity )); } break; @@ -664,17 +671,17 @@ private void applyCorrelatedSubviewMapping(CorrelatedAttribute cor if (pluralAttribute.isSorted()) { tupleTransformatorFactory.add(new CorrelatedSortedSetSubselectTupleListTransformerFactory( new SubviewCorrelator(managedViewType, evm, subviewAliasPrefix), - subviewClass, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, startIndex, correlationBasisType, correlationBasisEntity, pluralAttribute.getComparator() + subviewClass, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, attributePath, startIndex, correlationBasisType, correlationBasisEntity, pluralAttribute.getComparator() )); } else if (pluralAttribute.isOrdered()) { tupleTransformatorFactory.add(new CorrelatedOrderedSetSubselectTupleListTransformerFactory( new SubviewCorrelator(managedViewType, evm, subviewAliasPrefix), - subviewClass, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, startIndex, correlationBasisType, correlationBasisEntity + subviewClass, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, attributePath, startIndex, correlationBasisType, correlationBasisEntity )); } else { tupleTransformatorFactory.add(new CorrelatedSetSubselectTupleListTransformerFactory( new SubviewCorrelator(managedViewType, evm, subviewAliasPrefix), - subviewClass, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, startIndex, correlationBasisType, correlationBasisEntity + subviewClass, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, attributePath, startIndex, correlationBasisType, correlationBasisEntity )); } break; @@ -741,18 +748,18 @@ private void applySubqueryMapping(SubqueryAttribute attribute, List correlatedAttribute, String attributePath, List mappingList, List parameterMappingList, int batchSize) { + String correlationResult = correlatedAttribute.getCorrelationResult(); if (correlatedAttribute.getFetchStrategy() == FetchStrategy.JOIN) { @SuppressWarnings("unchecked") CorrelationProviderFactory factory = CorrelationProviderHelper.getFactory(correlatedAttribute.getCorrelationProvider()); String alias = getAlias(aliasPrefix, correlatedAttribute, false); - String correlationResult = correlatedAttribute.getCorrelationResult(); String correlationBasis = getMapping(mappingPrefix, correlatedAttribute.getCorrelationBasis()); TupleElementMapper mapper; if (factory.isParameterized()) { - mapper = new ParameterizedExpressionCorrelationJoinTupleElementMapper(factory, correlationBasis, correlationResult, alias); + mapper = new ParameterizedExpressionCorrelationJoinTupleElementMapper(factory, correlationBasis, correlationResult, alias, attributePath); } else { - mapper = new ExpressionCorrelationJoinTupleElementMapper(factory.create(null, null), correlationBasis, correlationResult, alias); + mapper = new ExpressionCorrelationJoinTupleElementMapper(factory.create(null, null), correlationBasis, correlationResult, alias, attributePath); } mappingList.add(mapper); parameterMappingList.add(null); @@ -768,7 +775,6 @@ private void applyBasicCorrelatedMapping(CorrelatedAttribute correlatedAtt Class resultType; CorrelationProviderFactory factory = CorrelationProviderHelper.getFactory(correlatedAttribute.getCorrelationProvider()); - String correlationResult = correlatedAttribute.getCorrelationResult(); if (batchSize == -1) { batchSize = 1; @@ -842,13 +848,12 @@ private void applyBasicCorrelatedMapping(CorrelatedAttribute correlatedAtt Class resultType; CorrelationProviderFactory factory = CorrelationProviderHelper.getFactory(correlatedAttribute.getCorrelationProvider()); - String correlationResult = correlatedAttribute.getCorrelationResult(); if (!correlatedAttribute.isCollection()) { resultType = correlatedAttribute.getJavaType(); tupleTransformatorFactory.add(new CorrelatedSingularSubselectTupleListTransformerFactory( new BasicCorrelator(), - resultType, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, startIndex, correlationBasisType, correlationBasisEntity + resultType, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, attributePath, startIndex, correlationBasisType, correlationBasisEntity )); } else { PluralAttribute pluralAttribute = (PluralAttribute) correlatedAttribute; @@ -860,7 +865,7 @@ private void applyBasicCorrelatedMapping(CorrelatedAttribute correlatedAtt } else { tupleTransformatorFactory.add(new CorrelatedListSubselectTupleListTransformerFactory( new BasicCorrelator(), - resultType, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, startIndex, correlationBasisType, correlationBasisEntity + resultType, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, attributePath, startIndex, correlationBasisType, correlationBasisEntity )); } break; @@ -870,7 +875,7 @@ private void applyBasicCorrelatedMapping(CorrelatedAttribute correlatedAtt } else { tupleTransformatorFactory.add(new CorrelatedListSubselectTupleListTransformerFactory( new BasicCorrelator(), - resultType, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, startIndex, correlationBasisType, correlationBasisEntity + resultType, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, attributePath, startIndex, correlationBasisType, correlationBasisEntity )); } break; @@ -878,17 +883,17 @@ private void applyBasicCorrelatedMapping(CorrelatedAttribute correlatedAtt if (pluralAttribute.isSorted()) { tupleTransformatorFactory.add(new CorrelatedSortedSetSubselectTupleListTransformerFactory( new BasicCorrelator(), - resultType, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, startIndex, correlationBasisType, correlationBasisEntity, pluralAttribute.getComparator() + resultType, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, attributePath, startIndex, correlationBasisType, correlationBasisEntity, pluralAttribute.getComparator() )); } else if (pluralAttribute.isOrdered()) { tupleTransformatorFactory.add(new CorrelatedOrderedSetSubselectTupleListTransformerFactory( new BasicCorrelator(), - resultType, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, startIndex, correlationBasisType, correlationBasisEntity + resultType, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, attributePath, startIndex, correlationBasisType, correlationBasisEntity )); } else { tupleTransformatorFactory.add(new CorrelatedSetSubselectTupleListTransformerFactory( new BasicCorrelator(), - resultType, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, startIndex, correlationBasisType, correlationBasisEntity + resultType, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, factory, attributePath, startIndex, correlationBasisType, correlationBasisEntity )); } break; diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/mapper/ExpressionCorrelationJoinTupleElementMapper.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/mapper/ExpressionCorrelationJoinTupleElementMapper.java index 30c40d4a6a..d7afb507b0 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/mapper/ExpressionCorrelationJoinTupleElementMapper.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/mapper/ExpressionCorrelationJoinTupleElementMapper.java @@ -36,17 +36,19 @@ public class ExpressionCorrelationJoinTupleElementMapper implements TupleElement private final String correlationBasis; private final String correlationResult; private final String alias; + private final String attributePath; - public ExpressionCorrelationJoinTupleElementMapper(CorrelationProvider provider, String correlationBasis, String correlationResult, String alias) { + public ExpressionCorrelationJoinTupleElementMapper(CorrelationProvider provider, String correlationBasis, String correlationResult, String alias, String attributePath) { this.provider = provider; this.correlationBasis = correlationBasis; this.correlationResult = correlationResult; this.alias = alias; + this.attributePath = attributePath; } @Override public void applyMapping(SelectBuilder queryBuilder, CommonQueryBuilder parameterSource, Map optionalParameters) { - CorrelationBuilder correlationBuilder = new JoinCorrelationBuilder((FullQueryBuilder) queryBuilder, optionalParameters, correlationBasis, correlationResult, alias); + CorrelationBuilder correlationBuilder = new JoinCorrelationBuilder((FullQueryBuilder) queryBuilder, optionalParameters, correlationBasis, correlationResult, alias, attributePath); provider.applyCorrelation(correlationBuilder, correlationBasis); } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/mapper/ParameterizedExpressionCorrelationJoinTupleElementMapper.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/mapper/ParameterizedExpressionCorrelationJoinTupleElementMapper.java index 9bfbaee931..a89c1dd119 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/mapper/ParameterizedExpressionCorrelationJoinTupleElementMapper.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/mapper/ParameterizedExpressionCorrelationJoinTupleElementMapper.java @@ -36,17 +36,19 @@ public class ParameterizedExpressionCorrelationJoinTupleElementMapper implements private final String correlationBasis; private final String correlationResult; private final String alias; + private final String attributePath; - public ParameterizedExpressionCorrelationJoinTupleElementMapper(CorrelationProviderFactory providerFactory, String correlationBasis, String correlationResult, String alias) { + public ParameterizedExpressionCorrelationJoinTupleElementMapper(CorrelationProviderFactory providerFactory, String correlationBasis, String correlationResult, String alias, String attributePath) { this.providerFactory = providerFactory; this.correlationBasis = correlationBasis; this.correlationResult = correlationResult; this.alias = alias; + this.attributePath = attributePath; } @Override public void applyMapping(SelectBuilder queryBuilder, CommonQueryBuilder parameterSource, Map optionalParameters) { - CorrelationBuilder correlationBuilder = new JoinCorrelationBuilder((FullQueryBuilder) queryBuilder, optionalParameters, correlationBasis, correlationResult, alias); + CorrelationBuilder correlationBuilder = new JoinCorrelationBuilder((FullQueryBuilder) queryBuilder, optionalParameters, correlationBasis, correlationResult, alias, attributePath); providerFactory.create(parameterSource, optionalParameters).applyCorrelation(correlationBuilder, correlationBasis); } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedBatchTupleListTransformer.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedBatchTupleListTransformer.java index 373c24172f..eb1ff7e199 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedBatchTupleListTransformer.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedBatchTupleListTransformer.java @@ -52,7 +52,7 @@ public abstract class AbstractCorrelatedBatchTupleListTransformer extends Abstra protected Query query; public AbstractCorrelatedBatchTupleListTransformer(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String correlationResult, CorrelationProviderFactory correlationProviderFactory, String attributePath, int tupleIndex, int defaultBatchSize, Class correlationBasisType, Class correlationBasisEntity, EntityViewConfiguration entityViewConfiguration) { - super(correlator, criteriaBuilderRoot, viewRootType, correlationResult, correlationProviderFactory, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); + super(correlator, criteriaBuilderRoot, viewRootType, correlationResult, correlationProviderFactory, attributePath, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); this.batchSize = entityViewConfiguration.getBatchSize(attributePath, defaultBatchSize); this.expectBatchCorrelationValues = entityViewConfiguration.getExpectBatchCorrelationValues(attributePath); } @@ -95,7 +95,7 @@ private String applyAndGetCorrelationRoot(boolean batchCorrelationValues) { this.viewRootJpqlMacro = new CorrelatedSubqueryViewRootJpqlMacro(criteriaBuilder, optionalParameters, viewRootEntityClass, idAttributePath, viewRootExpression); this.criteriaBuilder.registerMacro("view_root", viewRootJpqlMacro); - SubqueryCorrelationBuilder correlationBuilder = new SubqueryCorrelationBuilder(criteriaBuilder, correlationResult, correlationBasisType, correlationBasisEntityType, CORRELATION_KEY_ALIAS, batchSize, false); + SubqueryCorrelationBuilder correlationBuilder = new SubqueryCorrelationBuilder(criteriaBuilder, correlationResult, correlationBasisType, correlationBasisEntityType, CORRELATION_KEY_ALIAS, batchSize, false, attributePath); CorrelationProvider provider = correlationProviderFactory.create(entityViewConfiguration.getCriteriaBuilder(), entityViewConfiguration.getOptionalParameters()); if (batchSize > 1) { diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedCollectionSubselectTupleListTransformer.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedCollectionSubselectTupleListTransformer.java index 6f5bc6d284..de0a8d44a6 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedCollectionSubselectTupleListTransformer.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedCollectionSubselectTupleListTransformer.java @@ -33,9 +33,9 @@ */ public abstract class AbstractCorrelatedCollectionSubselectTupleListTransformer extends AbstractCorrelatedSubselectTupleListTransformer { - public AbstractCorrelatedCollectionSubselectTupleListTransformer(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, int tupleIndex, Class correlationBasisType, + public AbstractCorrelatedCollectionSubselectTupleListTransformer(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, String attributePath, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity, EntityViewConfiguration entityViewConfiguration) { - super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); + super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, attributePath, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedSubselectTupleListTransformer.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedSubselectTupleListTransformer.java index cfdd36fceb..9577acf4ef 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedSubselectTupleListTransformer.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedSubselectTupleListTransformer.java @@ -40,9 +40,9 @@ public abstract class AbstractCorrelatedSubselectTupleListTransformer extends Ab protected FullQueryBuilder criteriaBuilder; protected CorrelatedSubqueryViewRootJpqlMacro viewRootJpqlMacro; - public AbstractCorrelatedSubselectTupleListTransformer(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, int tupleIndex, Class correlationBasisType, + public AbstractCorrelatedSubselectTupleListTransformer(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, String attributePath, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity, EntityViewConfiguration entityViewConfiguration) { - super(correlator, criteriaBuilderRoot, viewRootType, correlationResult, correlationProviderFactory, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); + super(correlator, criteriaBuilderRoot, viewRootType, correlationResult, correlationProviderFactory, attributePath, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); this.viewRootAlias = viewRootAlias; this.correlationKeyExpression = correlationKeyExpression; } @@ -61,7 +61,7 @@ private String applyAndGetCorrelationRoot() { this.viewRootJpqlMacro = new CorrelatedSubqueryViewRootJpqlMacro(criteriaBuilder, optionalParameters, viewRootEntityClass, idAttributePath, viewRootExpression); this.criteriaBuilder.registerMacro("view_root", viewRootJpqlMacro); - SubqueryCorrelationBuilder correlationBuilder = new SubqueryCorrelationBuilder(criteriaBuilder, correlationResult, correlationBasisType, correlationBasisEntityType, null, 1, true); + SubqueryCorrelationBuilder correlationBuilder = new SubqueryCorrelationBuilder(criteriaBuilder, correlationResult, correlationBasisType, correlationBasisEntityType, null, 1, true, attributePath); CorrelationProvider provider = correlationProviderFactory.create(entityViewConfiguration.getCriteriaBuilder(), entityViewConfiguration.getOptionalParameters()); provider.applyCorrelation(correlationBuilder, correlationKeyExpression); diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedSubselectTupleListTransformerFactory.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedSubselectTupleListTransformerFactory.java index 3cfad7a6ee..16d074c524 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedSubselectTupleListTransformerFactory.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedSubselectTupleListTransformerFactory.java @@ -34,11 +34,12 @@ public abstract class AbstractCorrelatedSubselectTupleListTransformerFactory imp protected final String correlationResult; protected final String correlationKeyExpression; protected final CorrelationProviderFactory correlationProviderFactory; + protected final String attributePath; protected final int tupleIndex; protected final Class correlationBasisType; protected final Class correlationBasisEntity; - public AbstractCorrelatedSubselectTupleListTransformerFactory(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity) { + public AbstractCorrelatedSubselectTupleListTransformerFactory(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, String attributePath, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity) { this.correlator = correlator; this.criteriaBuilderRoot = criteriaBuilderRoot; this.viewRootType = viewRootType; @@ -46,6 +47,7 @@ public AbstractCorrelatedSubselectTupleListTransformerFactory(Correlator correla this.correlationResult = correlationResult; this.correlationKeyExpression = correlationKeyExpression; this.correlationProviderFactory = correlationProviderFactory; + this.attributePath = attributePath; this.tupleIndex = tupleIndex; this.correlationBasisType = correlationBasisType; this.correlationBasisEntity = correlationBasisEntity; diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedTupleListTransformer.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedTupleListTransformer.java index 0609edb646..9cac561f86 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedTupleListTransformer.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/AbstractCorrelatedTupleListTransformer.java @@ -48,10 +48,11 @@ public abstract class AbstractCorrelatedTupleListTransformer extends TupleListTr protected final CorrelationProviderFactory correlationProviderFactory; protected final Class correlationBasisType; protected final Class correlationBasisEntity; + protected final String attributePath; protected final EntityViewConfiguration entityViewConfiguration; - public AbstractCorrelatedTupleListTransformer(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String correlationResult, CorrelationProviderFactory correlationProviderFactory, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity, EntityViewConfiguration entityViewConfiguration) { + public AbstractCorrelatedTupleListTransformer(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String correlationResult, CorrelationProviderFactory correlationProviderFactory, String attributePath, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity, EntityViewConfiguration entityViewConfiguration) { super(tupleIndex); this.correlator = correlator; this.criteriaBuilderRoot = criteriaBuilderRoot; @@ -60,6 +61,7 @@ public AbstractCorrelatedTupleListTransformer(Correlator correlator, Class cr this.correlationProviderFactory = correlationProviderFactory; this.correlationBasisType = correlationBasisType; this.correlationBasisEntity = correlationBasisEntity; + this.attributePath = attributePath; this.entityViewConfiguration = entityViewConfiguration; } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedListSubselectTupleListTransformer.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedListSubselectTupleListTransformer.java index f9a9b9d6a2..71d9472101 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedListSubselectTupleListTransformer.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedListSubselectTupleListTransformer.java @@ -30,9 +30,9 @@ */ public class CorrelatedListSubselectTupleListTransformer extends AbstractCorrelatedCollectionSubselectTupleListTransformer { - public CorrelatedListSubselectTupleListTransformer(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, int tupleIndex, Class correlationBasisType, + public CorrelatedListSubselectTupleListTransformer(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, String attributePath, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity, EntityViewConfiguration entityViewConfiguration) { - super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); + super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, attributePath, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedListSubselectTupleListTransformerFactory.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedListSubselectTupleListTransformerFactory.java index 3a83bd0f07..8ff3e0b848 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedListSubselectTupleListTransformerFactory.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedListSubselectTupleListTransformerFactory.java @@ -31,13 +31,13 @@ */ public class CorrelatedListSubselectTupleListTransformerFactory extends AbstractCorrelatedSubselectTupleListTransformerFactory { - public CorrelatedListSubselectTupleListTransformerFactory(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity) { - super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, tupleIndex, correlationBasisType, correlationBasisEntity); + public CorrelatedListSubselectTupleListTransformerFactory(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, String attributePath, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity) { + super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, attributePath, tupleIndex, correlationBasisType, correlationBasisEntity); } @Override public TupleListTransformer create(FullQueryBuilder queryBuilder, Map optionalParameters, EntityViewConfiguration entityViewConfiguration) { - return new CorrelatedListSubselectTupleListTransformer(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); + return new CorrelatedListSubselectTupleListTransformer(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, attributePath, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); } } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedOrderedSetSubselectTupleListTransformer.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedOrderedSetSubselectTupleListTransformer.java index a6d1d95062..129df9b22e 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedOrderedSetSubselectTupleListTransformer.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedOrderedSetSubselectTupleListTransformer.java @@ -30,9 +30,9 @@ */ public class CorrelatedOrderedSetSubselectTupleListTransformer extends AbstractCorrelatedCollectionSubselectTupleListTransformer { - public CorrelatedOrderedSetSubselectTupleListTransformer(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, int tupleIndex, Class correlationBasisType, + public CorrelatedOrderedSetSubselectTupleListTransformer(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, String attributePath, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity, EntityViewConfiguration entityViewConfiguration) { - super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); + super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, attributePath, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedOrderedSetSubselectTupleListTransformerFactory.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedOrderedSetSubselectTupleListTransformerFactory.java index f98927915f..243dd8951d 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedOrderedSetSubselectTupleListTransformerFactory.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedOrderedSetSubselectTupleListTransformerFactory.java @@ -31,13 +31,13 @@ */ public class CorrelatedOrderedSetSubselectTupleListTransformerFactory extends AbstractCorrelatedSubselectTupleListTransformerFactory { - public CorrelatedOrderedSetSubselectTupleListTransformerFactory(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity) { - super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, tupleIndex, correlationBasisType, correlationBasisEntity); + public CorrelatedOrderedSetSubselectTupleListTransformerFactory(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, String attributePath, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity) { + super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, attributePath, tupleIndex, correlationBasisType, correlationBasisEntity); } @Override public TupleListTransformer create(FullQueryBuilder queryBuilder, Map optionalParameters, EntityViewConfiguration entityViewConfiguration) { - return new CorrelatedOrderedSetSubselectTupleListTransformer(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); + return new CorrelatedOrderedSetSubselectTupleListTransformer(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, attributePath, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); } } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSetSubselectTupleListTransformer.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSetSubselectTupleListTransformer.java index b383605cda..49c602fb7f 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSetSubselectTupleListTransformer.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSetSubselectTupleListTransformer.java @@ -30,9 +30,9 @@ */ public class CorrelatedSetSubselectTupleListTransformer extends AbstractCorrelatedCollectionSubselectTupleListTransformer { - public CorrelatedSetSubselectTupleListTransformer(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, int tupleIndex, Class correlationBasisType, + public CorrelatedSetSubselectTupleListTransformer(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, String attributePath, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity, EntityViewConfiguration entityViewConfiguration) { - super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); + super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, attributePath, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSetSubselectTupleListTransformerFactory.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSetSubselectTupleListTransformerFactory.java index 05887793a3..e989718d62 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSetSubselectTupleListTransformerFactory.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSetSubselectTupleListTransformerFactory.java @@ -31,13 +31,13 @@ */ public class CorrelatedSetSubselectTupleListTransformerFactory extends AbstractCorrelatedSubselectTupleListTransformerFactory { - public CorrelatedSetSubselectTupleListTransformerFactory(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity) { - super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, tupleIndex, correlationBasisType, correlationBasisEntity); + public CorrelatedSetSubselectTupleListTransformerFactory(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, String attributePath, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity) { + super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, attributePath, tupleIndex, correlationBasisType, correlationBasisEntity); } @Override public TupleListTransformer create(FullQueryBuilder queryBuilder, Map optionalParameters, EntityViewConfiguration entityViewConfiguration) { - return new CorrelatedSetSubselectTupleListTransformer(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); + return new CorrelatedSetSubselectTupleListTransformer(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, attributePath, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); } } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSingularSubselectTupleListTransformer.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSingularSubselectTupleListTransformer.java index 332646a872..8a6f8c5562 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSingularSubselectTupleListTransformer.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSingularSubselectTupleListTransformer.java @@ -30,9 +30,9 @@ */ public class CorrelatedSingularSubselectTupleListTransformer extends AbstractCorrelatedSubselectTupleListTransformer { - public CorrelatedSingularSubselectTupleListTransformer(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, int tupleIndex, Class correlationBasisType, + public CorrelatedSingularSubselectTupleListTransformer(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, String attributePath, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity, EntityViewConfiguration entityViewConfiguration) { - super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); + super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, attributePath, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); } @Override diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSingularSubselectTupleListTransformerFactory.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSingularSubselectTupleListTransformerFactory.java index 383b68ae30..a436661f1e 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSingularSubselectTupleListTransformerFactory.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSingularSubselectTupleListTransformerFactory.java @@ -31,13 +31,13 @@ */ public class CorrelatedSingularSubselectTupleListTransformerFactory extends AbstractCorrelatedSubselectTupleListTransformerFactory { - public CorrelatedSingularSubselectTupleListTransformerFactory(Correlator correlator, Class criteriaBuilderResult, ManagedViewType viewRoot, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity) { - super(correlator, criteriaBuilderResult, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, tupleIndex, correlationBasisType, correlationBasisEntity); + public CorrelatedSingularSubselectTupleListTransformerFactory(Correlator correlator, Class criteriaBuilderResult, ManagedViewType viewRoot, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, String attributePath, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity) { + super(correlator, criteriaBuilderResult, viewRoot, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, attributePath, tupleIndex, correlationBasisType, correlationBasisEntity); } @Override public TupleListTransformer create(FullQueryBuilder queryBuilder, Map optionalParameters, EntityViewConfiguration entityViewConfiguration) { - return new CorrelatedSingularSubselectTupleListTransformer(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); + return new CorrelatedSingularSubselectTupleListTransformer(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, attributePath, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); } } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSortedSetSubselectTupleListTransformer.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSortedSetSubselectTupleListTransformer.java index c4c8215b4a..683f7fe671 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSortedSetSubselectTupleListTransformer.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSortedSetSubselectTupleListTransformer.java @@ -33,9 +33,9 @@ public class CorrelatedSortedSetSubselectTupleListTransformer extends AbstractCo private final Comparator comparator; - public CorrelatedSortedSetSubselectTupleListTransformer(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity, + public CorrelatedSortedSetSubselectTupleListTransformer(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, String attributePath, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity, EntityViewConfiguration entityViewConfiguration, Comparator comparator) { - super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); + super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, attributePath, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration); this.comparator = comparator; } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSortedSetSubselectTupleListTransformerFactory.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSortedSetSubselectTupleListTransformerFactory.java index a23454830f..7fb4cc67d6 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSortedSetSubselectTupleListTransformerFactory.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSortedSetSubselectTupleListTransformerFactory.java @@ -34,14 +34,15 @@ public class CorrelatedSortedSetSubselectTupleListTransformerFactory extends Abs private final Comparator comparator; - public CorrelatedSortedSetSubselectTupleListTransformerFactory(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, int tupleIndex, Class correlationBasisType, Class correlationBasisEntity, Comparator comparator) { - super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, tupleIndex, correlationBasisType, correlationBasisEntity); + public CorrelatedSortedSetSubselectTupleListTransformerFactory(Correlator correlator, Class criteriaBuilderRoot, ManagedViewType viewRootType, String viewRootAlias, String correlationResult, String correlationKeyExpression, CorrelationProviderFactory correlationProviderFactory, String attributePath, int tupleIndex, + Class correlationBasisType, Class correlationBasisEntity, Comparator comparator) { + super(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, attributePath, tupleIndex, correlationBasisType, correlationBasisEntity); this.comparator = comparator; } @Override public TupleListTransformer create(FullQueryBuilder queryBuilder, Map optionalParameters, EntityViewConfiguration entityViewConfiguration) { - return new CorrelatedSortedSetSubselectTupleListTransformer(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration, comparator); + return new CorrelatedSortedSetSubselectTupleListTransformer(correlator, criteriaBuilderRoot, viewRootType, viewRootAlias, correlationResult, correlationKeyExpression, correlationProviderFactory, attributePath, tupleIndex, correlationBasisType, correlationBasisEntity, entityViewConfiguration, comparator); } } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSubviewJoinTupleTransformerFactory.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSubviewJoinTupleTransformerFactory.java index 7895c296e8..5b78433c61 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSubviewJoinTupleTransformerFactory.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/CorrelatedSubviewJoinTupleTransformerFactory.java @@ -38,19 +38,21 @@ public class CorrelatedSubviewJoinTupleTransformerFactory implements TupleTransf private final CorrelationProviderFactory correlationProviderFactory; private final String correlationBasis; private final String correlationResult; + private final String attributePath; - public CorrelatedSubviewJoinTupleTransformerFactory(ViewTypeObjectBuilderTemplate template, CorrelationProviderFactory correlationProviderFactory, String correlationBasis, String correlationResult) { + public CorrelatedSubviewJoinTupleTransformerFactory(ViewTypeObjectBuilderTemplate template, CorrelationProviderFactory correlationProviderFactory, String correlationBasis, String correlationResult, String attributePath) { this.template = template; this.correlationProviderFactory = correlationProviderFactory; this.correlationBasis = correlationBasis; this.correlationResult = correlationResult; + this.attributePath = attributePath; } @Override public TupleTransformer create(FullQueryBuilder queryBuilder, Map optionalParameters, EntityViewConfiguration entityViewConfiguration) { CorrelationProvider provider = correlationProviderFactory.create(queryBuilder, optionalParameters); - provider.applyCorrelation(new JoinCorrelationBuilder(queryBuilder, optionalParameters, correlationBasis, correlationResult, null), correlationBasis); + provider.applyCorrelation(new JoinCorrelationBuilder(queryBuilder, optionalParameters, correlationBasis, correlationResult, null, attributePath), correlationBasis); ObjectBuilder objectBuilder = template.createObjectBuilder(queryBuilder, optionalParameters, entityViewConfiguration, true); return new CorrelatedSubviewJoinTupleTransformer(template, objectBuilder); diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/JoinCorrelationBuilder.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/JoinCorrelationBuilder.java index 1461556d37..c538536862 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/JoinCorrelationBuilder.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/JoinCorrelationBuilder.java @@ -20,6 +20,7 @@ import com.blazebit.persistence.JoinOnBuilder; import com.blazebit.persistence.ParameterHolder; import com.blazebit.persistence.view.CorrelationBuilder; +import com.blazebit.persistence.view.impl.CorrelationProviderHelper; import java.util.Map; @@ -35,29 +36,41 @@ public class JoinCorrelationBuilder implements CorrelationBuilder { private final String correlationBasis; private final String correlationResult; private final String selectAlias; + private final String correlationAlias; private boolean correlated; - public JoinCorrelationBuilder(FullQueryBuilder criteriaBuilder, Map optionalParameters, String correlationBasis, String correlationResult, String selectAlias) { + public JoinCorrelationBuilder(FullQueryBuilder criteriaBuilder, Map optionalParameters, String correlationBasis, String correlationResult, String selectAlias, String attributePath) { this.criteriaBuilder = criteriaBuilder; this.optionalParameters = optionalParameters; this.correlationBasis = correlationBasis; this.correlationResult = correlationResult; this.selectAlias = selectAlias; + this.correlationAlias = CorrelationProviderHelper.getDefaultCorrelationAlias(attributePath); } @Override - public JoinOnBuilder> correlate(Class entityClass, String alias) { + public T getService(Class serviceClass) { + return criteriaBuilder.getService(serviceClass); + } + + @Override + public String getCorrelationAlias() { + return correlationAlias; + } + + @Override + public JoinOnBuilder> correlate(Class entityClass) { if (correlated) { throw new IllegalArgumentException("Can not correlate with multiple entity classes!"); } String selectExpression; if (correlationResult.isEmpty()) { - selectExpression = alias; - } else if (correlationResult.startsWith(alias) && (correlationResult.length() == alias.length() || correlationResult.charAt(alias.length()) == '.')) { + selectExpression = correlationAlias; + } else if (correlationResult.startsWith(correlationAlias) && (correlationResult.length() == correlationAlias.length() || correlationResult.charAt(correlationAlias.length()) == '.')) { selectExpression = correlationResult; } else { - selectExpression = alias + '.' + correlationResult; + selectExpression = correlationAlias + '.' + correlationResult; } // Basic element has an alias, subviews don't @@ -66,7 +79,7 @@ public JoinOnBuilder> correlate(Class entityClass, String } correlated = true; - return (JoinOnBuilder>) (JoinOnBuilder) criteriaBuilder.leftJoinOn(correlationBasis, entityClass, alias); + return (JoinOnBuilder>) (JoinOnBuilder) criteriaBuilder.leftJoinOn(correlationBasis, entityClass, correlationAlias); } } diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/SubqueryCorrelationBuilder.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/SubqueryCorrelationBuilder.java index 17051be101..f04f629191 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/SubqueryCorrelationBuilder.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/transformer/correlation/SubqueryCorrelationBuilder.java @@ -20,6 +20,7 @@ import com.blazebit.persistence.JoinOnBuilder; import com.blazebit.persistence.ParameterHolder; import com.blazebit.persistence.view.CorrelationBuilder; +import com.blazebit.persistence.view.impl.CorrelationProviderHelper; /** * @@ -35,9 +36,10 @@ public class SubqueryCorrelationBuilder implements CorrelationBuilder { private final String correllationKeyAlias; private final int batchSize; private final boolean innerJoin; + private final String correlationAlias; private String correlationRoot; - public SubqueryCorrelationBuilder(FullQueryBuilder criteriaBuilder, String correlationResult, Class correlationBasisType, Class correlationBasisEntity, String correllationKeyAlias, int batchSize, boolean innerJoin) { + public SubqueryCorrelationBuilder(FullQueryBuilder criteriaBuilder, String correlationResult, Class correlationBasisType, Class correlationBasisEntity, String correllationKeyAlias, int batchSize, boolean innerJoin, String attributePath) { this.criteriaBuilder = criteriaBuilder; this.correlationResult = correlationResult; this.correlationBasisType = correlationBasisType; @@ -45,6 +47,17 @@ public SubqueryCorrelationBuilder(FullQueryBuilder criteriaBuilder, String this.correllationKeyAlias = correllationKeyAlias; this.batchSize = batchSize; this.innerJoin = innerJoin; + this.correlationAlias = CorrelationProviderHelper.getDefaultCorrelationAlias(attributePath); + } + + @Override + public T getService(Class serviceClass) { + return criteriaBuilder.getService(serviceClass); + } + + @Override + public String getCorrelationAlias() { + return correlationAlias; } public String getCorrelationRoot() { @@ -52,7 +65,7 @@ public String getCorrelationRoot() { } @Override - public JoinOnBuilder> correlate(Class entityClass, String alias) { + public JoinOnBuilder> correlate(Class entityClass) { if (correlationRoot != null) { throw new IllegalArgumentException("Can not correlate with multiple entity classes!"); } @@ -65,23 +78,21 @@ public JoinOnBuilder> correlate(Class entityClass, String criteriaBuilder.fromValues(correlationBasisType, correllationKeyAlias, batchSize); } - correlationBuilder = (JoinOnBuilder>) (JoinOnBuilder) criteriaBuilder.innerJoinOn(entityClass, alias); + correlationBuilder = (JoinOnBuilder>) (JoinOnBuilder) criteriaBuilder.innerJoinOn(entityClass, correlationAlias); } else { if (innerJoin) { - correlationBuilder = (JoinOnBuilder>) (JoinOnBuilder) criteriaBuilder.innerJoinOn(entityClass, alias); + correlationBuilder = (JoinOnBuilder>) (JoinOnBuilder) criteriaBuilder.innerJoinOn(entityClass, correlationAlias); } else { - criteriaBuilder.from(entityClass, alias); + criteriaBuilder.from(entityClass, correlationAlias); correlationBuilder = criteriaBuilder.getService(JoinOnBuilder.class); } } String correlationRoot; if (correlationResult.isEmpty()) { - correlationRoot = alias; - } else if (correlationResult.startsWith(alias) && (correlationResult.length() == alias.length() || correlationResult.charAt(alias.length()) == '.')) { - correlationRoot = correlationResult; + correlationRoot = correlationAlias; } else { - correlationRoot = alias + '.' + correlationResult; + correlationRoot = correlationAlias + '.' + correlationResult; } this.correlationRoot = correlationRoot; return correlationBuilder; diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/proxy/ProxyFactory.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/proxy/ProxyFactory.java index 8690a7554e..a0ccf37b8e 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/proxy/ProxyFactory.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/proxy/ProxyFactory.java @@ -23,8 +23,11 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Logger; +import com.blazebit.persistence.view.CorrelationProvider; +import com.blazebit.persistence.view.impl.CorrelationProviderProxyBase; import com.blazebit.persistence.view.metamodel.ManagedViewType; import com.blazebit.persistence.view.metamodel.MappingConstructor; import com.blazebit.persistence.view.metamodel.MethodAttribute; @@ -58,6 +61,8 @@ public class ProxyFactory { private static final Logger LOG = Logger.getLogger(ProxyFactory.class.getName()); + // This has to be static since runtime generated correlation providers can't be matched in a later run, so we always create a new one with a unique name + private static final ConcurrentMap, AtomicInteger> CORRELATION_PROVIDER_CLASS_COUNT = new ConcurrentHashMap<>(); private final ConcurrentMap, Class> proxyClasses = new ConcurrentHashMap, Class>(); private final ConcurrentMap, Class> unsafeProxyClasses = new ConcurrentHashMap, Class>(); private final Object proxyLock = new Object(); @@ -74,6 +79,62 @@ public Class getProxy(ManagedViewType viewType) { public Class getUnsafeProxy(ManagedViewType viewType) { return getProxy(viewType, true); } + + public Class getCorrelationProviderProxy(Class correlated, String correlationKeyAlias, String correlationExpression) { + AtomicInteger counter = CORRELATION_PROVIDER_CLASS_COUNT.get(correlated); + if (counter == null) { + counter = new AtomicInteger(0); + AtomicInteger oldCounter = CORRELATION_PROVIDER_CLASS_COUNT.putIfAbsent(correlated, counter); + if (oldCounter != null) { + counter = oldCounter; + } + } + int value = counter.getAndIncrement(); + String proxyClassName = correlated.getName() + "CorrelationProvider_$$_javassist_entityview_" + value; + + ClassPath classPath = new ClassClassPath(CorrelationProviderProxyBase.class); + pool.insertClassPath(classPath); + + try { + CtClass cc = pool.getAndRename(CorrelationProviderProxyBase.class.getName(), proxyClassName); + + // We only have one other constructor + CtConstructor otherConstructor = cc.getDeclaredConstructors()[0]; + + // Create a new constructor + CtClass[] emptyParamTypes = new CtClass[0]; + CtConstructor newConstructor = new CtConstructor(emptyParamTypes, cc); + newConstructor.setModifiers(Modifier.PUBLIC); + ConstPool constPool = cc.getClassFile().getConstPool(); + Bytecode bytecode = new Bytecode(constPool, 4, 1); + + // Add the correlation params as constants to the constant pool + int correlatedIndex = constPool.addClassInfo(correlated.getName()); + int correlationKeyAliasIndex = constPool.addStringInfo(correlationKeyAlias); + int correlationExpressionIndex = constPool.addStringInfo(correlationExpression); + + // Invocation target + bytecode.addAload(0); + + // In the byte code load the constants + bytecode.addLdc(correlatedIndex); + bytecode.addLdc(correlationKeyAliasIndex); + bytecode.addLdc(correlationExpressionIndex); + + // Invoke the parameterized constructor + bytecode.addInvokespecial(cc, "", Descriptor.ofConstructor(otherConstructor.getParameterTypes())); + + bytecode.add(Bytecode.RETURN); + newConstructor.getMethodInfo().setCodeAttribute(bytecode.toCodeAttribute()); + cc.addConstructor(newConstructor); + + return cc.toClass(correlated.getClassLoader(), null); + } catch (Exception ex) { + throw new RuntimeException("Probably we did something wrong, please contact us if you see this message.", ex); + } finally { + pool.removeClassPath(classPath); + } + } @SuppressWarnings("unchecked") private Class getProxy(ManagedViewType viewType, boolean unsafe) { diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/AbstractClassViewTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/AbstractClassViewTest.java index 77c721e4c2..6b7635fe74 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/AbstractClassViewTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/AbstractClassViewTest.java @@ -21,12 +21,10 @@ import java.util.List; import javax.persistence.EntityManager; -import javax.persistence.EntityTransaction; import com.blazebit.persistence.testsuite.base.category.NoEclipselink; import com.blazebit.persistence.testsuite.tx.TxVoidWork; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import com.blazebit.persistence.CriteriaBuilder; @@ -57,7 +55,7 @@ public void initEvm() { cfg.addEntityView(DocumentViewInterface.class); cfg.addEntityView(DocumentViewAbstractClass.class); cfg.addEntityView(PersonView.class); - evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + evm = cfg.createEntityViewManager(cbf); } private Document doc1; diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/CovariantViewTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/CovariantViewTest.java index db3b0325b2..b3447b86a2 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/CovariantViewTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/CovariantViewTest.java @@ -21,7 +21,6 @@ import java.util.List; import javax.persistence.EntityManager; -import javax.persistence.EntityTransaction; import com.blazebit.persistence.testsuite.tx.TxVoidWork; import org.junit.Before; @@ -50,7 +49,7 @@ public class CovariantViewTest extends AbstractEntityViewTest { public void initEvm() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(CovariantPersonView.class); - evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + evm = cfg.createEntityViewManager(cbf); } private Person pers1; diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/EmbeddableTestEntityViewTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/EmbeddableTestEntityViewTest.java index e8f332e145..3d848ccd8d 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/EmbeddableTestEntityViewTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/EmbeddableTestEntityViewTest.java @@ -27,7 +27,6 @@ import java.util.Set; import javax.persistence.EntityManager; -import javax.persistence.EntityTransaction; import com.blazebit.persistence.testsuite.tx.TxVoidWork; import org.junit.Before; @@ -81,7 +80,7 @@ public void initEvm() { cfg.addEntityView(EmbeddableTestEntityEmbeddableSubView.class); cfg.addEntityView(EmbeddableTestEntitySimpleEmbeddableSubView.class); cfg.addEntityView(EmbeddableTestEntitySubView.class); - evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + evm = cfg.createEntityViewManager(cbf); } private EmbeddableTestEntity entity1; diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/EntityViewSettingTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/EntityViewSettingTest.java index fa133d2092..0c15879fdd 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/EntityViewSettingTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/EntityViewSettingTest.java @@ -19,13 +19,10 @@ import static org.junit.Assert.assertEquals; import javax.persistence.EntityManager; -import javax.persistence.EntityTransaction; import com.blazebit.persistence.testsuite.tx.TxVoidWork; import com.blazebit.persistence.view.testsuite.basic.model.CustomRootPersonView; -import com.blazebit.persistence.view.testsuite.basic.model.PersonView; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; import com.blazebit.persistence.CriteriaBuilder; @@ -96,7 +93,7 @@ public void work(EntityManager em) { public void testEntityViewSetting() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(FilteredDocument.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); // Base setting EntityViewSetting> setting = EntityViewSetting.create( @@ -123,7 +120,7 @@ public void testEntityViewSetting() { public void testEntityViewSettingWithEntityAttribute() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(DocumentWithEntityView.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); // Base setting EntityViewSetting> setting = EntityViewSetting @@ -146,7 +143,7 @@ public void testEntityViewSettingWithEntityAttribute() { public void testEntityViewSettingNotExistingFilterAttribute() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(DocumentWithEntityView.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); // Base setting EntityViewSetting> setting = EntityViewSetting @@ -169,7 +166,7 @@ public void testEntityViewSettingNotExistingFilterAttribute() { public void testEntityViewSettingCustomRoot() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(CustomRootPersonView.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); // Base setting EntityViewSetting> setting = EntityViewSetting.create(CustomRootPersonView.class); @@ -178,7 +175,7 @@ public void testEntityViewSettingCustomRoot() { CriteriaBuilder cb = cbf.create(em, Document.class); setting.addAttributeFilter("name", "pers1"); CriteriaBuilder criteriaBuilder = evm.applySetting(setting, cb, "owner"); - assertEquals("SELECT " + singleValuedAssociationIdPath("document.owner.id", "owner_1") + " AS CustomRootPersonView_id, owner_1.name AS CustomRootPersonView_name " + + assertEquals("SELECT " + singleValuedAssociationIdPath("owner_1.id", "owner_1") + " AS CustomRootPersonView_id, owner_1.name AS CustomRootPersonView_name " + "FROM Document document JOIN document.owner owner_1 " + "WHERE owner_1.name <> :param_0", criteriaBuilder.getQueryString()); List result = criteriaBuilder.getResultList(); diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/InterfaceViewTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/InterfaceViewTest.java index 9d3d5e5005..73ab595162 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/InterfaceViewTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/InterfaceViewTest.java @@ -55,7 +55,7 @@ public void initEvm() { cfg.addEntityView(DocumentViewInterface.class); cfg.addEntityView(DocumentViewAbstractClass.class); cfg.addEntityView(PersonView.class); - evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + evm = cfg.createEntityViewManager(cbf); } private Document doc1; diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/JoinOrderTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/JoinOrderTest.java index 739b09990f..bc2a8897fd 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/JoinOrderTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/JoinOrderTest.java @@ -45,7 +45,7 @@ public class JoinOrderTest extends AbstractEntityViewTest { public void initEvm() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(InvalidJoinOrderPersonView.class); - evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + evm = cfg.createEntityViewManager(cbf); } @Test diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/PolymorphicTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/PolymorphicTest.java index 73dc7a625b..492308b4ca 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/PolymorphicTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/PolymorphicTest.java @@ -21,7 +21,6 @@ import java.util.List; import javax.persistence.EntityManager; -import javax.persistence.EntityTransaction; import com.blazebit.persistence.testsuite.tx.TxVoidWork; import org.junit.Before; @@ -68,7 +67,7 @@ public void testApplyParent() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(NamedView.class); cfg.addEntityView(TestEntityView.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); // Base setting EntityViewSetting> setting = EntityViewSetting.create(NamedView.class); diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/PrimitiveViewTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/PrimitiveViewTest.java index 277b4082bd..a33065c852 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/PrimitiveViewTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/PrimitiveViewTest.java @@ -32,7 +32,6 @@ import org.junit.experimental.categories.Category; import javax.persistence.EntityManager; -import javax.persistence.EntityTransaction; import java.util.List; import static org.junit.Assert.assertEquals; @@ -62,7 +61,7 @@ public void initEvm() { cfg.addEntityView(PrimitiveSimpleDocumentView.class); cfg.addEntityView(PrimitiveDocumentView.class); cfg.addEntityView(PrimitivePersonView.class); - evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + evm = cfg.createEntityViewManager(cbf); } private PrimitiveDocument doc1; diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/ValidationTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/ValidationTest.java index 90c53e09e7..ffc36f43aa 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/ValidationTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/ValidationTest.java @@ -39,7 +39,7 @@ public void testValidation() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(DocumentValidationView.class); cfg.addEntityView(PersonValidationView.class); - cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + cfg.createEntityViewManager(cbf); } @Test @@ -48,7 +48,7 @@ public void testValidationDuplicateCollection() { cfg.addEntityView(PersonDuplicateCollectionUsageValidationView.class); try { - cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + cfg.createEntityViewManager(cbf); Assert.fail("Expected validation exception!"); } catch (IllegalArgumentException ex) { if (!ex.getMessage().contains("'ownedDocuments'")) { @@ -63,7 +63,7 @@ public void testValidationInvalidMapping() { cfg.addEntityView(PersonInvalidMappingValidationView.class); try { - cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + cfg.createEntityViewManager(cbf); Assert.fail("Expected validation exception!"); } catch (IllegalArgumentException ex) { if (!ex.getMessage().contains("'defaultContact'")) { diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/ViewConstructorTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/ViewConstructorTest.java index e6455b5ad5..5b536b84d8 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/ViewConstructorTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/ViewConstructorTest.java @@ -37,7 +37,7 @@ public void testAbstractClass() { cfg.addEntityView(DocumentViewWithMissingMappingParameter.class); try { - cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + cfg.createEntityViewManager(cbf); Assert.fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException ex) { } diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/ViewMetamodelTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/ViewMetamodelTest.java index 4357b4f46d..2899349f3c 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/ViewMetamodelTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/basic/ViewMetamodelTest.java @@ -63,7 +63,7 @@ private ViewMetamodel getViewMetamodel() { cfg.addEntityView(DocumentViewInterface.class); cfg.addEntityView(DocumentViewAbstractClass.class); cfg.addEntityView(PersonView.class); - return cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()).getMetamodel(); + return cfg.createEntityViewManager(cbf).getMetamodel(); } @Test @@ -71,7 +71,7 @@ public void testCircularViews() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(CircularDocument.class); cfg.addEntityView(CircularPerson.class); - verifyException(cfg, IllegalArgumentException.class).createEntityViewManager(cbf, em.getEntityManagerFactory()); + verifyException(cfg, IllegalArgumentException.class).createEntityViewManager(cbf); } @Test @@ -80,7 +80,7 @@ public void testGetViewsContainsViews() { cfg.addEntityView(DocumentViewInterface.class); cfg.addEntityView(DocumentViewAbstractClass.class); cfg.addEntityView(PersonView.class); - ViewMetamodel viewMetamodel = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()).getMetamodel(); + ViewMetamodel viewMetamodel = cfg.createEntityViewManager(cbf).getMetamodel(); assertEquals(3, viewMetamodel.getViews().size()); assertTrue(viewMetamodel.getViews().contains(viewMetamodel.view(DocumentViewInterface.class))); @@ -92,7 +92,7 @@ public void testGetViewsContainsViews() { public void testMappingSingularView() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(PersonViewWithSingularMapping.class); - ViewMetamodel viewMetamodel = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()).getMetamodel(); + ViewMetamodel viewMetamodel = cfg.createEntityViewManager(cbf).getMetamodel(); ViewType viewType = viewMetamodel.view(PersonViewWithSingularMapping.class); assertNotNull(viewType); @@ -408,7 +408,7 @@ public void testMappingConstructor() throws Exception { public void testConflictingMapping() throws Exception { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(ConflictingDoc.class); - verifyException(cfg, IllegalArgumentException.class).createEntityViewManager(cbf, em.getEntityManagerFactory()); + verifyException(cfg, IllegalArgumentException.class).createEntityViewManager(cbf); Throwable t = caughtException(); assertTrue(t.getMessage().contains("'name'")); assertTrue(t.getMessage().contains(ConflictingDoc1.class.getName() + ".getName")); @@ -433,7 +433,7 @@ public static interface ConflictingDoc extends ConflictingDoc1, ConflictingDoc2 public void testResolveConflictingMapping() throws Exception { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(ResolveConflictingDoc.class); - ViewMetamodel metamodel = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()).getMetamodel(); + ViewMetamodel metamodel = cfg.createEntityViewManager(cbf).getMetamodel(); MappingAttribute mappingAttribute = (MappingAttribute) metamodel.view(ResolveConflictingDoc.class).getAttribute("name"); assertEquals("UPPER(name)", mappingAttribute.getMapping()); } @@ -458,7 +458,7 @@ public static interface ResolveConflictingDoc extends ResolveConflictingDoc1, Re public void testInheritancePrecedenceNonConflictingMapping() throws Exception { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(InheritancePrecedenceNonConflictingDoc.class); - ViewMetamodel metamodel = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()).getMetamodel(); + ViewMetamodel metamodel = cfg.createEntityViewManager(cbf).getMetamodel(); MappingAttribute mappingAttribute = (MappingAttribute) metamodel.view(InheritancePrecedenceNonConflictingDoc.class).getAttribute("name"); assertEquals("COALESCE(name, '')", mappingAttribute.getMapping()); } @@ -481,7 +481,7 @@ public static interface InheritancePrecedenceNonConflictingDoc extends Inheritan public void testNoMappingNonConflictingMapping() throws Exception { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(NoMappingNonConflictingDoc.class); - ViewMetamodel metamodel = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()).getMetamodel(); + ViewMetamodel metamodel = cfg.createEntityViewManager(cbf).getMetamodel(); MappingAttribute mappingAttribute = (MappingAttribute) metamodel.view(NoMappingNonConflictingDoc.class).getAttribute("name"); assertEquals("COALESCE(name, '')", mappingAttribute.getMapping()); } diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/basic/BasicCollectionsTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/basic/BasicCollectionsTest.java index 3c395aa6e1..7bd68f052e 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/basic/BasicCollectionsTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/basic/BasicCollectionsTest.java @@ -23,7 +23,6 @@ import java.util.List; import javax.persistence.EntityManager; -import javax.persistence.EntityTransaction; import com.blazebit.persistence.testsuite.base.category.NoDatanucleus; import com.blazebit.persistence.testsuite.base.category.NoEclipselink; @@ -147,7 +146,7 @@ public static Collection entityViewCombinations() { public void testCollections() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(viewType); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); CriteriaBuilder criteria = cbf.create(em, DocumentForCollections.class, "d") .orderByAsc("id"); diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/embeddable/extended/ExtendedEmbeddableCollectionsTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/embeddable/extended/ExtendedEmbeddableCollectionsTest.java index 60b24575e5..d286eac188 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/embeddable/extended/ExtendedEmbeddableCollectionsTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/embeddable/extended/ExtendedEmbeddableCollectionsTest.java @@ -146,7 +146,7 @@ public static Collection entityViewCombinations() { public void testCollections() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(viewType); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); CriteriaBuilder criteria = cbf.create(em, ExtendedDocumentForElementCollections.class, "d") .orderByAsc("id").where("id").gt(doc0.getId()); diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/embeddable/simple/EmbeddableCollectionsTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/embeddable/simple/EmbeddableCollectionsTest.java index d2fd0f9d8c..3a41e9d7aa 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/embeddable/simple/EmbeddableCollectionsTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/embeddable/simple/EmbeddableCollectionsTest.java @@ -23,7 +23,6 @@ import java.util.List; import javax.persistence.EntityManager; -import javax.persistence.EntityTransaction; import com.blazebit.persistence.testsuite.base.category.NoEclipselink; import com.blazebit.persistence.testsuite.tx.TxVoidWork; @@ -146,7 +145,7 @@ public static Collection entityViewCombinations() { public void testCollections() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(viewType); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); CriteriaBuilder criteria = cbf.create(em, DocumentForElementCollections.class, "d") .orderByAsc("id").where("id").gt(doc0.getId()); diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/ordered/ViewSetAsListTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/ordered/ViewSetAsListTest.java index f05147ac3c..95abfaa86c 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/ordered/ViewSetAsListTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/ordered/ViewSetAsListTest.java @@ -138,7 +138,7 @@ public void testCollections() { cfg.addEntityView(PersonWithSetAsListView.class); cfg.addEntityView(DocumentWithSetAsListView.class); cfg.addEntityView(PersonForCollectionsView.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); CriteriaBuilder criteria = cbf.create(em, DocumentForCollections.class, "d") .where("id").in(d1.getId(), d2.getId()) diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/EntityMapKeySubviewTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/EntityMapKeySubviewTest.java index 6d9e1b7985..db30e775e9 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/EntityMapKeySubviewTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/EntityMapKeySubviewTest.java @@ -111,7 +111,7 @@ public void testCollections() { cfg.addEntityView(SubviewDocumentForEntityKeyMapsView.class); cfg.addEntityView(SubviewSimpleDocumentForEntityKeyMapsView.class); cfg.addEntityView(SubviewPersonForEntityKeyMapsView.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); CriteriaBuilder criteria = cbf.create(em, DocumentForEntityKeyMaps.class, "d") .orderByAsc("id"); diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/NestedCollectionsTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/NestedCollectionsTest.java index 8a313c3499..5e791afbdc 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/NestedCollectionsTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/NestedCollectionsTest.java @@ -25,7 +25,6 @@ import java.util.Set; import javax.persistence.EntityManager; -import javax.persistence.EntityTransaction; import com.blazebit.persistence.testsuite.tx.TxVoidWork; import org.junit.Assert; @@ -170,7 +169,7 @@ public void testCollections() { cfg.addEntityView(viewType); cfg.addEntityView(subviewType); cfg.addEntityView(SubviewPersonForCollectionsView.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); CriteriaBuilder criteria = cbf.create(em, PersonForCollections.class, "p") .where("id").in(pers1.getId(), pers2.getId()) diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/NestedEmptyCollectionsTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/NestedEmptyCollectionsTest.java index 5257d3fde9..449d232d80 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/NestedEmptyCollectionsTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/NestedEmptyCollectionsTest.java @@ -25,7 +25,6 @@ import java.util.Set; import javax.persistence.EntityManager; -import javax.persistence.EntityTransaction; import com.blazebit.persistence.testsuite.tx.TxVoidWork; import org.junit.Assert; @@ -139,7 +138,7 @@ public void testCollections() { cfg.addEntityView(viewType); cfg.addEntityView(subviewType); cfg.addEntityView(SubviewPersonForCollectionsView.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); CriteriaBuilder criteria = cbf.create(em, PersonForCollections.class, "p") .where("id").in(pers1.getId(), pers2.getId()) diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/SimpleCollectionsTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/SimpleCollectionsTest.java index 51a092e4d7..8e4f08ce3b 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/SimpleCollectionsTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/SimpleCollectionsTest.java @@ -143,7 +143,7 @@ public void testCollections() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(viewType); cfg.addEntityView(SubviewPersonForCollectionsView.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); CriteriaBuilder criteria = cbf.create(em, DocumentForCollections.class, "d") .orderByAsc("id"); diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/SubviewClassCollectionsTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/SubviewClassCollectionsTest.java index b8448af7f2..71f88c8075 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/SubviewClassCollectionsTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/collections/subview/SubviewClassCollectionsTest.java @@ -24,7 +24,6 @@ import java.util.List; import javax.persistence.EntityManager; -import javax.persistence.EntityTransaction; import com.blazebit.persistence.testsuite.tx.TxVoidWork; import org.junit.Before; @@ -159,7 +158,7 @@ public void testCollections() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(SubviewClassDocumentForCollectionsView.class); cfg.addEntityView(SubviewPersonForCollectionsView.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); CriteriaBuilder criteria = cbf.create(em, DocumentForCollections.class, "d") .orderByAsc("id"); diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/CorrelationProviderTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/GeneralCorrelationTest.java similarity index 94% rename from entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/CorrelationProviderTest.java rename to entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/GeneralCorrelationTest.java index 27e9ea15b8..f34a34fe80 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/CorrelationProviderTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/GeneralCorrelationTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.blazebit.persistence.view.testsuite.subview; +package com.blazebit.persistence.view.testsuite.correlation.general; import com.blazebit.persistence.CriteriaBuilder; import com.blazebit.persistence.testsuite.base.category.*; @@ -25,6 +25,11 @@ import com.blazebit.persistence.view.impl.ConfigurationProperties; import com.blazebit.persistence.view.spi.EntityViewConfiguration; import com.blazebit.persistence.view.testsuite.AbstractEntityViewTest; +import com.blazebit.persistence.view.testsuite.correlation.general.model.DocumentCorrelationView; +import com.blazebit.persistence.view.testsuite.correlation.general.model.DocumentCorrelationViewJoinId; +import com.blazebit.persistence.view.testsuite.correlation.general.model.DocumentCorrelationViewJoinNormal; +import com.blazebit.persistence.view.testsuite.correlation.general.model.DocumentCorrelationViewSubquery; +import com.blazebit.persistence.view.testsuite.correlation.general.model.DocumentCorrelationViewSubselect; import com.blazebit.persistence.view.testsuite.entity.Document; import com.blazebit.persistence.view.testsuite.entity.Person; import com.blazebit.persistence.view.testsuite.subview.model.*; @@ -34,7 +39,6 @@ import org.junit.experimental.categories.Category; import javax.persistence.EntityManager; -import javax.persistence.EntityTransaction; import java.util.Collection; import java.util.Iterator; import java.util.List; @@ -44,9 +48,9 @@ /** * * @author Christian Beikov - * @since 1.0 + * @since 1.2.0 */ -public class CorrelationProviderTest extends AbstractEntityViewTest { +public class GeneralCorrelationTest extends AbstractEntityViewTest { private Document doc1; private Document doc2; @@ -94,8 +98,6 @@ public void setUp() { } @Test - // NOTE: since entity joins are not supported in Datanucleus 4 we hit a bug in our workaround: https://github.com/datanucleus/datanucleus-core/issues/170 - @Category({ NoDatanucleus4.class }) public void testSubqueryCorrelation() { testCorrelation(DocumentCorrelationViewSubquery.class, null); } @@ -127,7 +129,6 @@ public void testSubqueryBatchedCorrelationSize20() { // TODO: make explicit test for correlation key batching with view root usage maybe via nested subviews through collections? @Test - // NOTE: since entity joins are not supported in Datanucleus 4 we hit a bug in our workaround: https://github.com/datanucleus/datanucleus-core/issues/170 // NOTE: Datanucleus does not optimize the join for the relation away so this will run into a cyclic join node dependency: https://github.com/datanucleus/datanucleus-rdbms/issues/161 // NOTE: EclipseLink does not optimize the join for the relation away so this will run into a cyclic join node dependency @Category({ NoDatanucleus4.class, NoDatanucleus.class, NoEclipselink.class }) @@ -159,7 +160,7 @@ private void testCorrelation(Class entity cfg.addEntityView(entityView); cfg.addEntityView(DocumentRelatedView.class); cfg.addEntityView(SimplePersonSubView.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); CriteriaBuilder criteria = cbf.create(em, Document.class, "d").orderByAsc("id"); EntityViewSetting> setting = EntityViewSetting.create(entityView); diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/DocumentCorrelationView.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/DocumentCorrelationView.java similarity index 87% rename from entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/DocumentCorrelationView.java rename to entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/DocumentCorrelationView.java index a6a8be19dd..b63dc8c425 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/DocumentCorrelationView.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/DocumentCorrelationView.java @@ -14,9 +14,10 @@ * limitations under the License. */ -package com.blazebit.persistence.view.testsuite.subview.model; +package com.blazebit.persistence.view.testsuite.correlation.general.model; import com.blazebit.persistence.view.IdMapping; +import com.blazebit.persistence.view.testsuite.subview.model.DocumentRelatedView; import java.util.Set; diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/DocumentCorrelationViewJoinId.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/DocumentCorrelationViewJoinId.java similarity index 70% rename from entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/DocumentCorrelationViewJoinId.java rename to entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/DocumentCorrelationViewJoinId.java index 66de68addb..c6e4d6047b 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/DocumentCorrelationViewJoinId.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/DocumentCorrelationViewJoinId.java @@ -14,12 +14,13 @@ * limitations under the License. */ -package com.blazebit.persistence.view.testsuite.subview.model; +package com.blazebit.persistence.view.testsuite.correlation.general.model; import com.blazebit.persistence.view.FetchStrategy; import com.blazebit.persistence.view.EntityView; import com.blazebit.persistence.view.MappingCorrelated; import com.blazebit.persistence.view.testsuite.entity.Document; +import com.blazebit.persistence.view.testsuite.subview.model.DocumentRelatedView; import java.util.Set; @@ -32,19 +33,19 @@ public interface DocumentCorrelationViewJoinId extends DocumentCorrelationView { // TODO: need to use owner.id instead of owner because of HHH-2772 - @MappingCorrelated(correlationBasis = "owner.id", correlationResult = "correlatedDocumentForId.id", correlator = OwnerRelatedCorrelationIdProviderId.class, fetch = FetchStrategy.JOIN) + @MappingCorrelated(correlationBasis = "owner.id", correlationResult = "id", correlator = OwnerRelatedCorrelationIdProviderId.class, fetch = FetchStrategy.JOIN) public Set getOwnerRelatedDocumentIds(); // TODO: need to use owner.id instead of owner because of HHH-2772 - @MappingCorrelated(correlationBasis = "owner.id", correlationResult = "correlatedDocumentForSubview", correlator = OwnerRelatedCorrelationProviderId.class, fetch = FetchStrategy.JOIN) + @MappingCorrelated(correlationBasis = "owner.id", correlator = OwnerRelatedCorrelationProviderId.class, fetch = FetchStrategy.JOIN) public Set getOwnerRelatedDocuments(); // TODO: need to use owner.id instead of owner because of HHH-2772 - @MappingCorrelated(correlationBasis = "owner.id", correlationResult = "correlatedDocumentOnlyForId.id", correlator = OwnerOnlyRelatedCorrelationIdProviderId.class, fetch = FetchStrategy.JOIN) + @MappingCorrelated(correlationBasis = "owner.id", correlationResult = "id", correlator = OwnerOnlyRelatedCorrelationIdProviderId.class, fetch = FetchStrategy.JOIN) public Set getOwnerOnlyRelatedDocumentIds(); // TODO: need to use owner.id instead of owner because of HHH-2772 - @MappingCorrelated(correlationBasis = "owner.id", correlationResult = "correlatedDocumentOnlyForSubview", correlator = OwnerOnlyRelatedCorrelationProviderId.class, fetch = FetchStrategy.JOIN) + @MappingCorrelated(correlationBasis = "owner.id", correlator = OwnerOnlyRelatedCorrelationProviderId.class, fetch = FetchStrategy.JOIN) public Set getOwnerOnlyRelatedDocuments(); } diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/DocumentCorrelationViewJoinNormal.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/DocumentCorrelationViewJoinNormal.java similarity index 66% rename from entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/DocumentCorrelationViewJoinNormal.java rename to entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/DocumentCorrelationViewJoinNormal.java index e037a922fc..841dfc1ce2 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/DocumentCorrelationViewJoinNormal.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/DocumentCorrelationViewJoinNormal.java @@ -14,12 +14,13 @@ * limitations under the License. */ -package com.blazebit.persistence.view.testsuite.subview.model; +package com.blazebit.persistence.view.testsuite.correlation.general.model; import com.blazebit.persistence.view.FetchStrategy; import com.blazebit.persistence.view.EntityView; import com.blazebit.persistence.view.MappingCorrelated; import com.blazebit.persistence.view.testsuite.entity.Document; +import com.blazebit.persistence.view.testsuite.subview.model.DocumentRelatedView; import java.util.Set; @@ -31,16 +32,16 @@ @EntityView(Document.class) public interface DocumentCorrelationViewJoinNormal extends DocumentCorrelationView { - @MappingCorrelated(correlationBasis = "owner", correlationResult = "correlatedDocumentForId.id", correlator = OwnerRelatedCorrelationIdProviderNormal.class, fetch = FetchStrategy.JOIN) + @MappingCorrelated(correlationBasis = "owner", correlationResult = "id", correlator = OwnerRelatedCorrelationIdProviderNormal.class, fetch = FetchStrategy.JOIN) public Set getOwnerRelatedDocumentIds(); - @MappingCorrelated(correlationBasis = "owner", correlationResult = "correlatedDocumentForSubview", correlator = OwnerRelatedCorrelationProviderNormal.class, fetch = FetchStrategy.JOIN) + @MappingCorrelated(correlationBasis = "owner", correlator = OwnerRelatedCorrelationProviderNormal.class, fetch = FetchStrategy.JOIN) public Set getOwnerRelatedDocuments(); - @MappingCorrelated(correlationBasis = "owner", correlationResult = "correlatedDocumentOnlyForId.id", correlator = OwnerOnlyRelatedCorrelationIdProviderNormal.class, fetch = FetchStrategy.JOIN) + @MappingCorrelated(correlationBasis = "owner", correlationResult = "id", correlator = OwnerOnlyRelatedCorrelationIdProviderNormal.class, fetch = FetchStrategy.JOIN) public Set getOwnerOnlyRelatedDocumentIds(); - @MappingCorrelated(correlationBasis = "owner", correlationResult = "correlatedDocumentOnlyForSubview", correlator = OwnerOnlyRelatedCorrelationProviderNormal.class, fetch = FetchStrategy.JOIN) + @MappingCorrelated(correlationBasis = "owner", correlator = OwnerOnlyRelatedCorrelationProviderNormal.class, fetch = FetchStrategy.JOIN) public Set getOwnerOnlyRelatedDocuments(); } diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/DocumentCorrelationViewSubquery.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/DocumentCorrelationViewSubquery.java similarity index 68% rename from entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/DocumentCorrelationViewSubquery.java rename to entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/DocumentCorrelationViewSubquery.java index b5f3ed62b0..bbfed05345 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/DocumentCorrelationViewSubquery.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/DocumentCorrelationViewSubquery.java @@ -14,10 +14,11 @@ * limitations under the License. */ -package com.blazebit.persistence.view.testsuite.subview.model; +package com.blazebit.persistence.view.testsuite.correlation.general.model; import com.blazebit.persistence.view.*; import com.blazebit.persistence.view.testsuite.entity.Document; +import com.blazebit.persistence.view.testsuite.subview.model.DocumentRelatedView; import java.util.Set; @@ -30,19 +31,19 @@ public interface DocumentCorrelationViewSubquery extends DocumentCorrelationView { // TODO: need to use owner.id instead of owner because of HHH-2772 - @MappingCorrelated(correlationBasis = "owner.id", correlationResult = "correlatedDocumentForId.id", correlator = OwnerRelatedCorrelationIdProviderId.class, fetch = FetchStrategy.SELECT) + @MappingCorrelated(correlationBasis = "owner.id", correlationResult = "id", correlator = OwnerRelatedCorrelationIdProviderId.class, fetch = FetchStrategy.SELECT) public Set getOwnerRelatedDocumentIds(); // TODO: need to use owner.id instead of owner because of HHH-2772 - @MappingCorrelated(correlationBasis = "owner.id", correlationResult = "correlatedDocumentForSubview", correlator = OwnerRelatedCorrelationProviderId.class, fetch = FetchStrategy.SELECT) + @MappingCorrelated(correlationBasis = "owner.id", correlator = OwnerRelatedCorrelationProviderId.class, fetch = FetchStrategy.SELECT) public Set getOwnerRelatedDocuments(); // TODO: need to use owner.id instead of owner because of HHH-2772 - @MappingCorrelated(correlationBasis = "owner.id", correlationResult = "correlatedDocumentOnlyForId.id", correlator = OwnerOnlyRelatedCorrelationIdProviderId.class, fetch = FetchStrategy.SELECT) + @MappingCorrelated(correlationBasis = "owner.id", correlationResult = "id", correlator = OwnerOnlyRelatedCorrelationIdProviderId.class, fetch = FetchStrategy.SELECT) public Set getOwnerOnlyRelatedDocumentIds(); // TODO: need to use owner.id instead of owner because of HHH-2772 - @MappingCorrelated(correlationBasis = "owner.id", correlationResult = "correlatedDocumentOnlyForSubview", correlator = OwnerOnlyRelatedCorrelationProviderId.class, fetch = FetchStrategy.SELECT) + @MappingCorrelated(correlationBasis = "owner.id", correlator = OwnerOnlyRelatedCorrelationProviderId.class, fetch = FetchStrategy.SELECT) public Set getOwnerOnlyRelatedDocuments(); } diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/DocumentCorrelationViewSubselect.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/DocumentCorrelationViewSubselect.java similarity index 55% rename from entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/DocumentCorrelationViewSubselect.java rename to entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/DocumentCorrelationViewSubselect.java index 7e3594288a..d529388002 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/DocumentCorrelationViewSubselect.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/DocumentCorrelationViewSubselect.java @@ -14,15 +14,13 @@ * limitations under the License. */ -package com.blazebit.persistence.view.testsuite.subview.model; +package com.blazebit.persistence.view.testsuite.correlation.general.model; -import com.blazebit.persistence.view.CorrelationBuilder; -import com.blazebit.persistence.view.CorrelationProvider; import com.blazebit.persistence.view.FetchStrategy; import com.blazebit.persistence.view.EntityView; import com.blazebit.persistence.view.MappingCorrelated; import com.blazebit.persistence.view.testsuite.entity.Document; -import com.blazebit.persistence.view.testsuite.entity.Person; +import com.blazebit.persistence.view.testsuite.subview.model.DocumentRelatedView; import java.util.Set; @@ -32,39 +30,22 @@ * @since 1.2.0 */ @EntityView(Document.class) -public abstract class DocumentCorrelationViewSubselect implements DocumentCorrelationView {//extends DocumentCorrelationView { +public abstract class DocumentCorrelationViewSubselect implements DocumentCorrelationView { // TODO: need to use owner.id instead of owner because of HHH-2772 - @MappingCorrelated(correlationBasis = "owner.id", correlationResult = "correlatedDocumentForId.id", correlator = OwnerRelatedCorrelationIdProviderId.class, fetch = FetchStrategy.SUBSELECT) + @MappingCorrelated(correlationBasis = "owner.id", correlationResult = "id", correlator = OwnerRelatedCorrelationIdProviderId.class, fetch = FetchStrategy.SUBSELECT) public abstract Set getOwnerRelatedDocumentIds(); // TODO: need to use owner.id instead of owner because of HHH-2772 - @MappingCorrelated(correlationBasis = "owner.id", correlationResult = "correlatedDocumentForSubview", correlator = OwnerRelatedCorrelationProviderId.class, fetch = FetchStrategy.SUBSELECT) + @MappingCorrelated(correlationBasis = "owner.id", correlator = OwnerRelatedCorrelationProviderId.class, fetch = FetchStrategy.SUBSELECT) public abstract Set getOwnerRelatedDocuments(); // TODO: need to use owner.id instead of owner because of HHH-2772 - @MappingCorrelated(correlationBasis = "owner.id", correlationResult = "correlatedDocumentOnlyForId.id", correlator = OwnerOnlyRelatedCorrelationIdProviderId.class, fetch = FetchStrategy.SUBSELECT) + @MappingCorrelated(correlationBasis = "owner.id", correlationResult = "id", correlator = OwnerOnlyRelatedCorrelationIdProviderId.class, fetch = FetchStrategy.SUBSELECT) public abstract Set getOwnerOnlyRelatedDocumentIds(); // TODO: need to use owner.id instead of owner because of HHH-2772 - @MappingCorrelated(correlationBasis = "owner.id", correlationResult = "correlatedDocumentOnlyForSubview", correlator = OwnerOnlyRelatedCorrelationProviderId.class, fetch = FetchStrategy.SUBSELECT) + @MappingCorrelated(correlationBasis = "owner.id", correlator = OwnerOnlyRelatedCorrelationProviderId.class, fetch = FetchStrategy.SUBSELECT) public abstract Set getOwnerOnlyRelatedDocuments(); - -// public Set getOwnerRelatedDocumentIds() { -// return null; -// } -// -// public Set getOwnerRelatedDocuments() { -// return null; -// } -// -// public Set getOwnerOnlyRelatedDocumentIds() { -// return null; -// } -// -// public Set getOwnerOnlyRelatedDocuments() { -// return null; -// } - } diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerOnlyRelatedCorrelationIdProviderId.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerOnlyRelatedCorrelationIdProviderId.java similarity index 78% rename from entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerOnlyRelatedCorrelationIdProviderId.java rename to entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerOnlyRelatedCorrelationIdProviderId.java index c9624c0476..fe79fabe29 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerOnlyRelatedCorrelationIdProviderId.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerOnlyRelatedCorrelationIdProviderId.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.blazebit.persistence.view.testsuite.subview.model; +package com.blazebit.persistence.view.testsuite.correlation.general.model; import com.blazebit.persistence.view.CorrelationBuilder; import com.blazebit.persistence.view.CorrelationProvider; @@ -29,8 +29,9 @@ public class OwnerOnlyRelatedCorrelationIdProviderId implements CorrelationProvi @Override public void applyCorrelation(CorrelationBuilder correlationBuilder, String correlationExpression) { - correlationBuilder.correlate(Document.class, "correlatedDocumentOnlyForId") - .on("correlatedDocumentOnlyForId.owner.id").inExpressions(correlationExpression) + String correlatedDocument = correlationBuilder.getCorrelationAlias(); + correlationBuilder.correlate(Document.class) + .on(correlatedDocument + ".owner.id").inExpressions(correlationExpression) .end(); } } \ No newline at end of file diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerOnlyRelatedCorrelationIdProviderNormal.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerOnlyRelatedCorrelationIdProviderNormal.java similarity index 78% rename from entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerOnlyRelatedCorrelationIdProviderNormal.java rename to entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerOnlyRelatedCorrelationIdProviderNormal.java index 9218b38d4e..78234a9fc5 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerOnlyRelatedCorrelationIdProviderNormal.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerOnlyRelatedCorrelationIdProviderNormal.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.blazebit.persistence.view.testsuite.subview.model; +package com.blazebit.persistence.view.testsuite.correlation.general.model; import com.blazebit.persistence.view.CorrelationBuilder; import com.blazebit.persistence.view.CorrelationProvider; @@ -29,8 +29,9 @@ public class OwnerOnlyRelatedCorrelationIdProviderNormal implements CorrelationP @Override public void applyCorrelation(CorrelationBuilder correlationBuilder, String correlationExpression) { - correlationBuilder.correlate(Document.class, "correlatedDocumentOnlyForId") - .on("correlatedDocumentOnlyForId.owner").inExpressions(correlationExpression) + String correlatedDocument = correlationBuilder.getCorrelationAlias(); + correlationBuilder.correlate(Document.class) + .on(correlatedDocument + ".owner").inExpressions(correlationExpression) .end(); } } \ No newline at end of file diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerOnlyRelatedCorrelationProviderId.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerOnlyRelatedCorrelationProviderId.java similarity index 78% rename from entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerOnlyRelatedCorrelationProviderId.java rename to entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerOnlyRelatedCorrelationProviderId.java index 0d2268e842..5fcc311124 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerOnlyRelatedCorrelationProviderId.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerOnlyRelatedCorrelationProviderId.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.blazebit.persistence.view.testsuite.subview.model; +package com.blazebit.persistence.view.testsuite.correlation.general.model; import com.blazebit.persistence.view.CorrelationBuilder; import com.blazebit.persistence.view.CorrelationProvider; @@ -29,8 +29,9 @@ public class OwnerOnlyRelatedCorrelationProviderId implements CorrelationProvide @Override public void applyCorrelation(CorrelationBuilder correlationBuilder, String correlationExpression) { - correlationBuilder.correlate(Document.class, "correlatedDocumentOnlyForSubview") - .on("correlatedDocumentOnlyForSubview.owner.id").inExpressions(correlationExpression) + String correlatedDocument = correlationBuilder.getCorrelationAlias(); + correlationBuilder.correlate(Document.class) + .on(correlatedDocument + ".owner.id").inExpressions(correlationExpression) .end(); } } \ No newline at end of file diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerOnlyRelatedCorrelationProviderNormal.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerOnlyRelatedCorrelationProviderNormal.java similarity index 78% rename from entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerOnlyRelatedCorrelationProviderNormal.java rename to entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerOnlyRelatedCorrelationProviderNormal.java index 710a338035..d5febec35c 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerOnlyRelatedCorrelationProviderNormal.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerOnlyRelatedCorrelationProviderNormal.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.blazebit.persistence.view.testsuite.subview.model; +package com.blazebit.persistence.view.testsuite.correlation.general.model; import com.blazebit.persistence.view.CorrelationBuilder; import com.blazebit.persistence.view.CorrelationProvider; @@ -29,8 +29,9 @@ public class OwnerOnlyRelatedCorrelationProviderNormal implements CorrelationPro @Override public void applyCorrelation(CorrelationBuilder correlationBuilder, String correlationExpression) { - correlationBuilder.correlate(Document.class, "correlatedDocumentOnlyForSubview") - .on("correlatedDocumentOnlyForSubview.owner").inExpressions(correlationExpression) + String correlatedDocument = correlationBuilder.getCorrelationAlias(); + correlationBuilder.correlate(Document.class) + .on(correlatedDocument + ".owner").inExpressions(correlationExpression) .end(); } } \ No newline at end of file diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerRelatedCorrelationIdProviderId.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerRelatedCorrelationIdProviderId.java similarity index 74% rename from entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerRelatedCorrelationIdProviderId.java rename to entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerRelatedCorrelationIdProviderId.java index 71621d3a17..9b92624d22 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerRelatedCorrelationIdProviderId.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerRelatedCorrelationIdProviderId.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.blazebit.persistence.view.testsuite.subview.model; +package com.blazebit.persistence.view.testsuite.correlation.general.model; import com.blazebit.persistence.view.CorrelationBuilder; import com.blazebit.persistence.view.CorrelationProvider; @@ -29,9 +29,10 @@ public class OwnerRelatedCorrelationIdProviderId implements CorrelationProvider @Override public void applyCorrelation(CorrelationBuilder correlationBuilder, String correlationExpression) { - correlationBuilder.correlate(Document.class, "correlatedDocumentForId") - .on("correlatedDocumentForId.owner.id").inExpressions(correlationExpression) - .on("correlatedDocumentForId.id").notInExpressions("VIEW_ROOT(id)") + String correlatedDocument = correlationBuilder.getCorrelationAlias(); + correlationBuilder.correlate(Document.class) + .on(correlatedDocument + ".owner.id").inExpressions(correlationExpression) + .on(correlatedDocument + ".id").notInExpressions("VIEW_ROOT(id)") .end(); } } \ No newline at end of file diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerRelatedCorrelationIdProviderNormal.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerRelatedCorrelationIdProviderNormal.java similarity index 74% rename from entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerRelatedCorrelationIdProviderNormal.java rename to entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerRelatedCorrelationIdProviderNormal.java index ccacbeecdb..88931e0540 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerRelatedCorrelationIdProviderNormal.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerRelatedCorrelationIdProviderNormal.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.blazebit.persistence.view.testsuite.subview.model; +package com.blazebit.persistence.view.testsuite.correlation.general.model; import com.blazebit.persistence.view.CorrelationBuilder; import com.blazebit.persistence.view.CorrelationProvider; @@ -29,9 +29,10 @@ public class OwnerRelatedCorrelationIdProviderNormal implements CorrelationProvi @Override public void applyCorrelation(CorrelationBuilder correlationBuilder, String correlationExpression) { - correlationBuilder.correlate(Document.class, "correlatedDocumentForId") - .on("correlatedDocumentForId.owner").inExpressions(correlationExpression) - .on("correlatedDocumentForId").notInExpressions("VIEW_ROOT()") + String correlatedDocument = correlationBuilder.getCorrelationAlias(); + correlationBuilder.correlate(Document.class) + .on(correlatedDocument + ".owner").inExpressions(correlationExpression) + .on(correlatedDocument).notInExpressions("VIEW_ROOT()") .end(); } } \ No newline at end of file diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerRelatedCorrelationProviderId.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerRelatedCorrelationProviderId.java similarity index 74% rename from entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerRelatedCorrelationProviderId.java rename to entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerRelatedCorrelationProviderId.java index e14e9de4d8..32088016ed 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerRelatedCorrelationProviderId.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerRelatedCorrelationProviderId.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.blazebit.persistence.view.testsuite.subview.model; +package com.blazebit.persistence.view.testsuite.correlation.general.model; import com.blazebit.persistence.view.CorrelationBuilder; import com.blazebit.persistence.view.CorrelationProvider; @@ -29,9 +29,10 @@ public class OwnerRelatedCorrelationProviderId implements CorrelationProvider { @Override public void applyCorrelation(CorrelationBuilder correlationBuilder, String correlationExpression) { - correlationBuilder.correlate(Document.class, "correlatedDocumentForSubview") - .on("correlatedDocumentForSubview.owner.id").inExpressions(correlationExpression) - .on("correlatedDocumentForSubview.id").notInExpressions("VIEW_ROOT(id)") + String correlatedDocument = correlationBuilder.getCorrelationAlias(); + correlationBuilder.correlate(Document.class) + .on(correlatedDocument + ".owner.id").inExpressions(correlationExpression) + .on(correlatedDocument + ".id").notInExpressions("VIEW_ROOT(id)") .end(); } } \ No newline at end of file diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerRelatedCorrelationProviderNormal.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerRelatedCorrelationProviderNormal.java similarity index 74% rename from entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerRelatedCorrelationProviderNormal.java rename to entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerRelatedCorrelationProviderNormal.java index 1ddb9a4899..bdd2e0935a 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/model/OwnerRelatedCorrelationProviderNormal.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/general/model/OwnerRelatedCorrelationProviderNormal.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.blazebit.persistence.view.testsuite.subview.model; +package com.blazebit.persistence.view.testsuite.correlation.general.model; import com.blazebit.persistence.view.CorrelationBuilder; import com.blazebit.persistence.view.CorrelationProvider; @@ -29,9 +29,10 @@ public class OwnerRelatedCorrelationProviderNormal implements CorrelationProvide @Override public void applyCorrelation(CorrelationBuilder correlationBuilder, String correlationExpression) { - correlationBuilder.correlate(Document.class, "correlatedDocumentForSubview") - .on("correlatedDocumentForSubview.owner").inExpressions(correlationExpression) - .on("correlatedDocumentForSubview").notInExpressions("VIEW_ROOT()") + String correlatedDocument = correlationBuilder.getCorrelationAlias(); + correlationBuilder.correlate(Document.class) + .on(correlatedDocument + ".owner").inExpressions(correlationExpression) + .on(correlatedDocument).notInExpressions("VIEW_ROOT()") .end(); } } \ No newline at end of file diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/SimpleCorrelationTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/SimpleCorrelationTest.java new file mode 100644 index 0000000000..e129ba7f9f --- /dev/null +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/SimpleCorrelationTest.java @@ -0,0 +1,265 @@ +/* + * Copyright 2014 - 2017 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.view.testsuite.correlation.simple; + +import com.blazebit.persistence.CriteriaBuilder; +import com.blazebit.persistence.testsuite.base.category.NoDatanucleus; +import com.blazebit.persistence.testsuite.base.category.NoDatanucleus4; +import com.blazebit.persistence.testsuite.base.category.NoEclipselink; +import com.blazebit.persistence.testsuite.base.category.NoHibernate42; +import com.blazebit.persistence.testsuite.base.category.NoHibernate43; +import com.blazebit.persistence.testsuite.base.category.NoHibernate50; +import com.blazebit.persistence.testsuite.base.category.NoHibernate51; +import com.blazebit.persistence.testsuite.base.category.NoOpenJPA; +import com.blazebit.persistence.testsuite.tx.TxVoidWork; +import com.blazebit.persistence.view.EntityViewManager; +import com.blazebit.persistence.view.EntityViewSetting; +import com.blazebit.persistence.view.EntityViews; +import com.blazebit.persistence.view.impl.ConfigurationProperties; +import com.blazebit.persistence.view.spi.EntityViewConfiguration; +import com.blazebit.persistence.view.testsuite.AbstractEntityViewTest; +import com.blazebit.persistence.view.testsuite.correlation.simple.model.DocumentSimpleCorrelationView; +import com.blazebit.persistence.view.testsuite.correlation.simple.model.DocumentSimpleCorrelationViewJoinId; +import com.blazebit.persistence.view.testsuite.correlation.simple.model.DocumentSimpleCorrelationViewJoinNormal; +import com.blazebit.persistence.view.testsuite.correlation.simple.model.DocumentSimpleCorrelationViewSubquery; +import com.blazebit.persistence.view.testsuite.correlation.simple.model.DocumentSimpleCorrelationViewSubselect; +import com.blazebit.persistence.view.testsuite.entity.Document; +import com.blazebit.persistence.view.testsuite.entity.Person; +import com.blazebit.persistence.view.testsuite.subview.model.DocumentRelatedView; +import com.blazebit.persistence.view.testsuite.subview.model.SimplePersonSubView; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import javax.persistence.EntityManager; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +/** + * + * @author Christian Beikov + * @since 1.2.0 + */ +public class SimpleCorrelationTest extends AbstractEntityViewTest { + + private Document doc1; + private Document doc2; + private Document doc3; + private Document doc4; + + @Override + public void setUpOnce() { + cleanDatabase(); + transactional(new TxVoidWork() { + @Override + public void work(EntityManager em) { + doc1 = new Document("doc1"); + doc2 = new Document("doc2"); + doc3 = new Document("doc3"); + doc4 = new Document("doc4"); + + Person o1 = new Person("pers1"); + Person o2 = new Person("pers2"); + Person o3 = new Person("pers3"); + + doc1.setOwner(o1); + doc2.setOwner(o2); + doc3.setOwner(o2); + doc4.setOwner(o2); + + em.persist(o1); + em.persist(o2); + em.persist(o3); + + em.persist(doc1); + em.persist(doc2); + em.persist(doc3); + em.persist(doc4); + } + }); + } + + @Before + public void setUp() { + doc1 = cbf.create(em, Document.class).where("name").eq("doc1").getSingleResult(); + doc2 = cbf.create(em, Document.class).where("name").eq("doc2").getSingleResult(); + doc3 = cbf.create(em, Document.class).where("name").eq("doc3").getSingleResult(); + doc4 = cbf.create(em, Document.class).where("name").eq("doc4").getSingleResult(); + } + + @Test + public void testSubqueryCorrelation() { + testCorrelation(DocumentSimpleCorrelationViewSubquery.class, null); + } + + @Test + // NOTE: Requires values clause which currently is only available for Hibernate + // Eclipselink needs values clause implementation to allow batching + @Category({ NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoDatanucleus4.class, NoDatanucleus.class, NoOpenJPA.class, NoEclipselink.class}) + public void testSubqueryBatchedCorrelationSize2() { + testCorrelation(DocumentSimpleCorrelationViewSubquery.class, 2); + } + + @Test + // NOTE: Requires values clause which currently is only available for Hibernate + // Eclipselink needs values clause implementation to allow batching + @Category({ NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoDatanucleus4.class, NoDatanucleus.class, NoOpenJPA.class, NoEclipselink.class}) + public void testSubqueryBatchedCorrelationSize4() { + testCorrelation(DocumentSimpleCorrelationViewSubquery.class, 4); + } + + @Test + // NOTE: Requires values clause which currently is only available for Hibernate + @Category({ NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoDatanucleus.class, NoOpenJPA.class, NoEclipselink.class}) + public void testSubqueryBatchedCorrelationSize20() { + testCorrelation(DocumentSimpleCorrelationViewSubquery.class, 20); + } + + // TODO: test batch correlation expectation configuration + // TODO: make explicit test for correlation key batching with view root usage maybe via nested subviews through collections? + + @Test + // NOTE: Datanucleus does not optimize the join for the relation away so this will run into a cyclic join node dependency: https://github.com/datanucleus/datanucleus-rdbms/issues/161 + // NOTE: EclipseLink does not optimize the join for the relation away so this will run into a cyclic join node dependency + @Category({ NoDatanucleus4.class, NoDatanucleus.class, NoEclipselink.class }) + public void testSubselectCorrelation() { + testCorrelation(DocumentSimpleCorrelationViewSubselect.class, null); + } + + @Test + // NOTE: Requires entity joins which are supported since Hibernate 5.1, Datanucleus 5 and latest Eclipselink + // Since Hibernate does not support relation access in on clause in < 5.2 because of HHH-2772, we skip it + // Eclipselink renders a cross join at the wrong position + @Category({ NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoHibernate51.class, NoDatanucleus4.class, NoOpenJPA.class, NoEclipselink.class }) + public void testJoinCorrelationNormal() { + testCorrelation(DocumentSimpleCorrelationViewJoinNormal.class, null); + } + + @Test + // NOTE: Requires entity joins which are supported since Hibernate 5.1, Datanucleus 5 and latest Eclipselink + // NOTE: Datanucleus does not optimize the join for the relation away and also fails to properly order the joins: https://github.com/datanucleus/datanucleus-rdbms/issues/161 + // Eclipselink requires joins for the on clauses since it does not support the single valued association id paths optimization. + @Category({ NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoDatanucleus4.class, NoDatanucleus.class, NoOpenJPA.class, NoEclipselink.class}) + public void testJoinCorrelationId() { + // NOTE: can not use sub-property of a joined relation in on clause because of HHH-2772 + testCorrelation(DocumentSimpleCorrelationViewJoinId.class, null); + } + + private void testCorrelation(Class entityView, Integer batchSize) { + EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); + cfg.addEntityView(entityView); + cfg.addEntityView(DocumentRelatedView.class); + cfg.addEntityView(SimplePersonSubView.class); + EntityViewManager evm = cfg.createEntityViewManager(cbf); + + CriteriaBuilder criteria = cbf.create(em, Document.class, "d").orderByAsc("id"); + EntityViewSetting> setting = EntityViewSetting.create(entityView); + if (batchSize != null) { + setting.setProperty(ConfigurationProperties.DEFAULT_BATCH_SIZE + ".ownerRelatedDocumentIds", batchSize); + } + CriteriaBuilder cb = evm.applySetting(setting, criteria); + List results = cb.getResultList(); + + assertEquals(4, results.size()); + // Doc1 + assertEquals(doc1.getName(), results.get(0).getName()); + assertEquals(0, results.get(0).getOwnerRelatedDocuments().size()); + assertEquals(0, results.get(0).getOwnerRelatedDocumentIds().size()); + + assertEquals(1, results.get(0).getOwnerOnlyRelatedDocuments().size()); + assertRemovedByName(doc1.getName(), results.get(0).getOwnerOnlyRelatedDocuments()); + assertEquals(1, results.get(0).getOwnerOnlyRelatedDocumentIds().size()); + assertRemoved(doc1.getId(), results.get(0).getOwnerOnlyRelatedDocumentIds()); + + // Doc2 + assertEquals(doc2.getName(), results.get(1).getName()); + assertEquals(2, results.get(1).getOwnerRelatedDocuments().size()); + assertRemovedByName(doc3.getName(), results.get(1).getOwnerRelatedDocuments()); + assertRemovedByName(doc4.getName(), results.get(1).getOwnerRelatedDocuments()); + assertEquals(2, results.get(1).getOwnerRelatedDocumentIds().size()); + assertRemoved(doc3.getId(), results.get(1).getOwnerRelatedDocumentIds()); + assertRemoved(doc4.getId(), results.get(1).getOwnerRelatedDocumentIds()); + + assertEquals(3, results.get(1).getOwnerOnlyRelatedDocuments().size()); + assertRemovedByName(doc2.getName(), results.get(1).getOwnerOnlyRelatedDocuments()); + assertRemovedByName(doc3.getName(), results.get(1).getOwnerOnlyRelatedDocuments()); + assertRemovedByName(doc4.getName(), results.get(1).getOwnerOnlyRelatedDocuments()); + assertEquals(3, results.get(1).getOwnerOnlyRelatedDocumentIds().size()); + assertRemoved(doc2.getId(), results.get(1).getOwnerOnlyRelatedDocumentIds()); + assertRemoved(doc3.getId(), results.get(1).getOwnerOnlyRelatedDocumentIds()); + assertRemoved(doc4.getId(), results.get(1).getOwnerOnlyRelatedDocumentIds()); + + // Doc3 + assertEquals(doc3.getName(), results.get(2).getName()); + assertEquals(2, results.get(2).getOwnerRelatedDocuments().size()); + assertRemovedByName(doc2.getName(), results.get(2).getOwnerRelatedDocuments()); + assertRemovedByName(doc4.getName(), results.get(2).getOwnerRelatedDocuments()); + assertEquals(2, results.get(2).getOwnerRelatedDocumentIds().size()); + assertRemoved(doc2.getId(), results.get(2).getOwnerRelatedDocumentIds()); + assertRemoved(doc4.getId(), results.get(2).getOwnerRelatedDocumentIds()); + + assertEquals(3, results.get(2).getOwnerOnlyRelatedDocuments().size()); + assertRemovedByName(doc2.getName(), results.get(2).getOwnerOnlyRelatedDocuments()); + assertRemovedByName(doc3.getName(), results.get(2).getOwnerOnlyRelatedDocuments()); + assertRemovedByName(doc4.getName(), results.get(2).getOwnerOnlyRelatedDocuments()); + assertEquals(3, results.get(2).getOwnerOnlyRelatedDocumentIds().size()); + assertRemoved(doc2.getId(), results.get(2).getOwnerOnlyRelatedDocumentIds()); + assertRemoved(doc3.getId(), results.get(2).getOwnerOnlyRelatedDocumentIds()); + assertRemoved(doc4.getId(), results.get(2).getOwnerOnlyRelatedDocumentIds()); + + // Doc4 + assertEquals(doc4.getName(), results.get(3).getName()); + assertEquals(2, results.get(3).getOwnerRelatedDocuments().size()); + assertRemovedByName(doc2.getName(), results.get(3).getOwnerRelatedDocuments()); + assertRemovedByName(doc3.getName(), results.get(3).getOwnerRelatedDocuments()); + assertEquals(2, results.get(3).getOwnerRelatedDocumentIds().size()); + assertRemoved(doc2.getId(), results.get(3).getOwnerRelatedDocumentIds()); + assertRemoved(doc3.getId(), results.get(3).getOwnerRelatedDocumentIds()); + + assertEquals(3, results.get(3).getOwnerOnlyRelatedDocuments().size()); + assertRemovedByName(doc2.getName(), results.get(3).getOwnerOnlyRelatedDocuments()); + assertRemovedByName(doc3.getName(), results.get(3).getOwnerOnlyRelatedDocuments()); + assertRemovedByName(doc4.getName(), results.get(3).getOwnerOnlyRelatedDocuments()); + assertEquals(3, results.get(3).getOwnerOnlyRelatedDocumentIds().size()); + assertRemoved(doc2.getId(), results.get(3).getOwnerOnlyRelatedDocumentIds()); + assertRemoved(doc3.getId(), results.get(3).getOwnerOnlyRelatedDocumentIds()); + assertRemoved(doc4.getId(), results.get(3).getOwnerOnlyRelatedDocumentIds()); + } + + private void assertRemovedByName(String expectedName, Collection views) { + Iterator iter = views.iterator(); + while (iter.hasNext()) { + DocumentRelatedView v = iter.next(); + if (expectedName.equals(v.getName())) { + iter.remove(); + return; + } + } + + Assert.fail("Could not find '" + expectedName + "' in: " + views); + } + + private void assertRemoved(T expectedValue, Collection collection) { + if (!collection.remove(expectedValue)) { + Assert.fail("Could not find '" + expectedValue + "' in: " + collection); + } + } +} diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationView.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationView.java new file mode 100644 index 0000000000..aefc0bef9c --- /dev/null +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationView.java @@ -0,0 +1,44 @@ +/* + * Copyright 2014 - 2017 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.view.testsuite.correlation.simple.model; + +import com.blazebit.persistence.view.IdMapping; +import com.blazebit.persistence.view.testsuite.subview.model.DocumentRelatedView; + +import java.util.Set; + +/** + * + * @author Christian Beikov + * @since 1.2.0 + */ +public interface DocumentSimpleCorrelationView { + + @IdMapping("id") + public Long getId(); + + public String getName(); + + public Set getOwnerRelatedDocumentIds(); + + public Set getOwnerRelatedDocuments(); + + public Set getOwnerOnlyRelatedDocumentIds(); + + public Set getOwnerOnlyRelatedDocuments(); + +} diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationViewJoinId.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationViewJoinId.java new file mode 100644 index 0000000000..b1704691a7 --- /dev/null +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationViewJoinId.java @@ -0,0 +1,51 @@ +/* + * Copyright 2014 - 2017 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.view.testsuite.correlation.simple.model; + +import com.blazebit.persistence.view.EntityView; +import com.blazebit.persistence.view.FetchStrategy; +import com.blazebit.persistence.view.MappingCorrelatedSimple; +import com.blazebit.persistence.view.testsuite.entity.Document; +import com.blazebit.persistence.view.testsuite.subview.model.DocumentRelatedView; + +import java.util.Set; + +/** + * + * @author Christian Beikov + * @since 1.2.0 + */ +@EntityView(Document.class) +public interface DocumentSimpleCorrelationViewJoinId extends DocumentSimpleCorrelationView { + + // TODO: need to use owner.id instead of owner because of HHH-2772 + @MappingCorrelatedSimple(correlationBasis = "owner.id", correlationResult = "id", correlated = Document.class, correlationExpression = "owner.id IN correlationKey AND id NOT IN VIEW_ROOT(id)", fetch = FetchStrategy.JOIN) + public Set getOwnerRelatedDocumentIds(); + + // TODO: need to use owner.id instead of owner because of HHH-2772 + @MappingCorrelatedSimple(correlationBasis = "owner.id", correlated = Document.class, correlationExpression = "owner.id IN correlationKey AND id NOT IN VIEW_ROOT(id)", fetch = FetchStrategy.JOIN) + public Set getOwnerRelatedDocuments(); + + // TODO: need to use owner.id instead of owner because of HHH-2772 + @MappingCorrelatedSimple(correlationBasis = "owner.id", correlationResult = "id", correlated = Document.class, correlationExpression = "owner.id IN correlationKey", fetch = FetchStrategy.JOIN) + public Set getOwnerOnlyRelatedDocumentIds(); + + // TODO: need to use owner.id instead of owner because of HHH-2772 + @MappingCorrelatedSimple(correlationBasis = "owner.id", correlated = Document.class, correlationExpression = "owner.id IN correlationKey", fetch = FetchStrategy.JOIN) + public Set getOwnerOnlyRelatedDocuments(); + +} diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationViewJoinNormal.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationViewJoinNormal.java new file mode 100644 index 0000000000..4bc4eb006f --- /dev/null +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationViewJoinNormal.java @@ -0,0 +1,47 @@ +/* + * Copyright 2014 - 2017 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.view.testsuite.correlation.simple.model; + +import com.blazebit.persistence.view.EntityView; +import com.blazebit.persistence.view.FetchStrategy; +import com.blazebit.persistence.view.MappingCorrelatedSimple; +import com.blazebit.persistence.view.testsuite.entity.Document; +import com.blazebit.persistence.view.testsuite.subview.model.DocumentRelatedView; + +import java.util.Set; + +/** + * + * @author Christian Beikov + * @since 1.2.0 + */ +@EntityView(Document.class) +public interface DocumentSimpleCorrelationViewJoinNormal extends DocumentSimpleCorrelationView { + + @MappingCorrelatedSimple(correlationBasis = "owner", correlationResult = "id", correlated = Document.class, correlationExpression = "owner IN correlationKey AND id NOT IN VIEW_ROOT(id)", fetch = FetchStrategy.JOIN) + public Set getOwnerRelatedDocumentIds(); + + @MappingCorrelatedSimple(correlationBasis = "owner", correlated = Document.class, correlationExpression = "owner IN correlationKey AND id NOT IN VIEW_ROOT(id)", fetch = FetchStrategy.JOIN) + public Set getOwnerRelatedDocuments(); + + @MappingCorrelatedSimple(correlationBasis = "owner", correlationResult = "id", correlated = Document.class, correlationExpression = "owner IN correlationKey", fetch = FetchStrategy.JOIN) + public Set getOwnerOnlyRelatedDocumentIds(); + + @MappingCorrelatedSimple(correlationBasis = "owner", correlated = Document.class, correlationExpression = "owner IN correlationKey", fetch = FetchStrategy.JOIN) + public Set getOwnerOnlyRelatedDocuments(); + +} diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationViewSubquery.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationViewSubquery.java new file mode 100644 index 0000000000..5c65358f14 --- /dev/null +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationViewSubquery.java @@ -0,0 +1,51 @@ +/* + * Copyright 2014 - 2017 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.view.testsuite.correlation.simple.model; + +import com.blazebit.persistence.view.EntityView; +import com.blazebit.persistence.view.FetchStrategy; +import com.blazebit.persistence.view.MappingCorrelatedSimple; +import com.blazebit.persistence.view.testsuite.entity.Document; +import com.blazebit.persistence.view.testsuite.subview.model.DocumentRelatedView; + +import java.util.Set; + +/** + * + * @author Christian Beikov + * @since 1.2.0 + */ +@EntityView(Document.class) +public interface DocumentSimpleCorrelationViewSubquery extends DocumentSimpleCorrelationView { + + // TODO: need to use owner.id instead of owner because of HHH-2772 + @MappingCorrelatedSimple(correlationBasis = "owner.id", correlationResult = "id", correlated = Document.class, correlationExpression = "owner.id IN correlationKey AND id NOT IN VIEW_ROOT(id)", fetch = FetchStrategy.SELECT) + public Set getOwnerRelatedDocumentIds(); + + // TODO: need to use owner.id instead of owner because of HHH-2772 + @MappingCorrelatedSimple(correlationBasis = "owner.id", correlated = Document.class, correlationExpression = "owner.id IN correlationKey AND id NOT IN VIEW_ROOT(id)", fetch = FetchStrategy.SELECT) + public Set getOwnerRelatedDocuments(); + + // TODO: need to use owner.id instead of owner because of HHH-2772 + @MappingCorrelatedSimple(correlationBasis = "owner.id", correlationResult = "id", correlated = Document.class, correlationExpression = "owner.id IN correlationKey", fetch = FetchStrategy.SELECT) + public Set getOwnerOnlyRelatedDocumentIds(); + + // TODO: need to use owner.id instead of owner because of HHH-2772 + @MappingCorrelatedSimple(correlationBasis = "owner.id", correlated = Document.class, correlationExpression = "owner.id IN correlationKey", fetch = FetchStrategy.SELECT) + public Set getOwnerOnlyRelatedDocuments(); + +} diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationViewSubselect.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationViewSubselect.java new file mode 100644 index 0000000000..3347615163 --- /dev/null +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/correlation/simple/model/DocumentSimpleCorrelationViewSubselect.java @@ -0,0 +1,51 @@ +/* + * Copyright 2014 - 2017 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.view.testsuite.correlation.simple.model; + +import com.blazebit.persistence.view.EntityView; +import com.blazebit.persistence.view.FetchStrategy; +import com.blazebit.persistence.view.MappingCorrelatedSimple; +import com.blazebit.persistence.view.testsuite.entity.Document; +import com.blazebit.persistence.view.testsuite.subview.model.DocumentRelatedView; + +import java.util.Set; + +/** + * + * @author Christian Beikov + * @since 1.2.0 + */ +@EntityView(Document.class) +public abstract class DocumentSimpleCorrelationViewSubselect implements DocumentSimpleCorrelationView { + + // TODO: need to use owner.id instead of owner because of HHH-2772 + @MappingCorrelatedSimple(correlationBasis = "owner.id", correlationResult = "id", correlated = Document.class, correlationExpression = "owner.id IN correlationKey AND id NOT IN VIEW_ROOT(id)", fetch = FetchStrategy.SUBSELECT) + public abstract Set getOwnerRelatedDocumentIds(); + + // TODO: need to use owner.id instead of owner because of HHH-2772 + @MappingCorrelatedSimple(correlationBasis = "owner.id", correlated = Document.class, correlationExpression = "owner.id IN correlationKey AND id NOT IN VIEW_ROOT(id)", fetch = FetchStrategy.SUBSELECT) + public abstract Set getOwnerRelatedDocuments(); + + // TODO: need to use owner.id instead of owner because of HHH-2772 + @MappingCorrelatedSimple(correlationBasis = "owner.id", correlationResult = "id", correlated = Document.class, correlationExpression = "owner.id IN correlationKey", fetch = FetchStrategy.SUBSELECT) + public abstract Set getOwnerOnlyRelatedDocumentIds(); + + // TODO: need to use owner.id instead of owner because of HHH-2772 + @MappingCorrelatedSimple(correlationBasis = "owner.id", correlated = Document.class, correlationExpression = "owner.id IN correlationKey", fetch = FetchStrategy.SUBSELECT) + public abstract Set getOwnerOnlyRelatedDocuments(); + +} diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/filter/AttributeFilterTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/filter/AttributeFilterTest.java index 6c8cc99b00..283659fce3 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/filter/AttributeFilterTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/filter/AttributeFilterTest.java @@ -97,7 +97,7 @@ public void setUp() { public void testMultipleDefaultFilters() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(MultipleDefaultAttributeFiltersView.class); - verifyException(cfg, IllegalArgumentException.class).createEntityViewManager(cbf, em.getEntityManagerFactory()); + verifyException(cfg, IllegalArgumentException.class).createEntityViewManager(cbf); assertMessageContains("Illegal duplicate filter name mapping ''", caughtException()); } @@ -105,7 +105,7 @@ public void testMultipleDefaultFilters() { public void testFilterNameClash() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(AttributeFilterNameClashView.class); - verifyException(cfg, IllegalArgumentException.class).createEntityViewManager(cbf, em.getEntityManagerFactory()); + verifyException(cfg, IllegalArgumentException.class).createEntityViewManager(cbf); assertMessageContains("Illegal duplicate filter name mapping 'filter'", caughtException()); } @@ -113,7 +113,7 @@ public void testFilterNameClash() { public void testMultipleActiveFilterPerAttribute() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(AttributeFilterPrimitiveDocumentView.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); EntityViewSetting> setting = EntityViewSetting.create(AttributeFilterPrimitiveDocumentView.class); setting.addAttributeFilter("name", "pete"); @@ -132,7 +132,7 @@ public void testMultipleActiveFilterPerAttribute() { public void testOverwriteDefaultAttributeFilterValue() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(AttributeFilterPrimitiveDocumentView.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); EntityViewSetting> setting = EntityViewSetting.create(AttributeFilterPrimitiveDocumentView.class); setting.addAttributeFilter("name", "pete"); @@ -145,7 +145,7 @@ public void testOverwriteDefaultAttributeFilterValue() { public void testOverwriteAttributeFilterValue() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(AttributeFilterPrimitiveDocumentView.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); EntityViewSetting> setting = EntityViewSetting.create(AttributeFilterPrimitiveDocumentView.class); setting.addAttributeFilter("name", "caseSensitiveNameFilter", "pete"); @@ -158,7 +158,7 @@ public void testOverwriteAttributeFilterValue() { public void testViewFilter() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(ViewFilterPrimitiveDocumentView.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); EntityViewSetting> setting = EntityViewSetting.create(ViewFilterPrimitiveDocumentView.class); setting.addViewFilter("viewFilter1"); @@ -171,7 +171,7 @@ public void testViewFilter() { public void testMultipleViewFilter() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(ViewFilterPrimitiveDocumentView.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); EntityViewSetting> setting = EntityViewSetting.create(ViewFilterPrimitiveDocumentView.class); setting.addViewFilter("viewFilter1"); diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/pagination/BasicViewPaginationTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/pagination/BasicViewPaginationTest.java index fc3075ddac..6f599e9e27 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/pagination/BasicViewPaginationTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/pagination/BasicViewPaginationTest.java @@ -21,7 +21,6 @@ import java.util.List; import javax.persistence.EntityManager; -import javax.persistence.EntityTransaction; import com.blazebit.persistence.testsuite.tx.TxVoidWork; import org.junit.Before; @@ -49,7 +48,7 @@ public class BasicViewPaginationTest extends AbstractEntityViewTest { public void initEvm() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(DocumentViewInterface.class); - evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + evm = cfg.createEntityViewManager(cbf); } @Override diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/proxy/ProxyFactoryTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/proxy/ProxyFactoryTest.java index f5262b08e8..778cf104f9 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/proxy/ProxyFactoryTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/proxy/ProxyFactoryTest.java @@ -58,7 +58,7 @@ private ViewMetamodel getViewMetamodel() { cfg.addEntityView(DocumentInterfaceView.class); cfg.addEntityView(DocumentClassView.class); cfg.addEntityView(UnsafeDocumentClassView.class); - return cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()).getMetamodel(); + return cfg.createEntityViewManager(cbf).getMetamodel(); } @Test diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subquery/MappingSubqueryTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subquery/MappingSubqueryTest.java index dcb305e5b4..50a895e87b 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subquery/MappingSubqueryTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subquery/MappingSubqueryTest.java @@ -21,7 +21,6 @@ import java.util.List; import javax.persistence.EntityManager; -import javax.persistence.EntityTransaction; import com.blazebit.persistence.testsuite.tx.TxVoidWork; import com.blazebit.persistence.view.testsuite.subquery.model.DocumentWithSubqueryViewRoot; @@ -109,7 +108,7 @@ public void setUp() { public void testSubquery() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(DocumentWithSubquery.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); CriteriaBuilder cb = cbf.create(em, Document.class).orderByAsc("id"); EntityViewSetting> setting; @@ -129,7 +128,7 @@ public void testSubquery() { public void testSubqueryWithExpression() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(DocumentWithExpressionSubqueryView.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); // Base setting EntityViewSetting> setting = EntityViewSetting @@ -160,7 +159,7 @@ public void testSubqueryWithExpression() { public void testSubqueryEntityViewSettings() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(DocumentWithSubquery.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); CriteriaBuilder cb = cbf.create(em, Document.class).orderByDesc("id"); EntityViewSetting> setting = EntityViewSetting @@ -179,7 +178,7 @@ public void testSubqueryEntityViewSettings() { public void testSubqueryViewRootEntityViewSettings() { EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(DocumentWithSubqueryViewRoot.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); CriteriaBuilder cb = cbf.create(em, Person.class); EntityViewSetting> setting = EntityViewSetting @@ -189,11 +188,11 @@ public void testSubqueryViewRootEntityViewSettings() { List list = evm.applySetting(setting, cb, "partnerDocument").getResultList(); assertEquals("SELECT " + - singleValuedAssociationIdPath("person.partnerDocument.id", "partnerDocument_1") + " AS DocumentWithSubqueryViewRoot_id, " + + singleValuedAssociationIdPath("partnerDocument_1.id", "partnerDocument_1") + " AS DocumentWithSubqueryViewRoot_id, " + "(SELECT COUNT(person_1.id) " + "FROM Person person_1" + singleValuedAssociationIdJoin("person_1.partnerDocument", "partnerDocument_2", true) + - " WHERE " + singleValuedAssociationIdPath("person_1.partnerDocument.id", "partnerDocument_2") + " = " + singleValuedAssociationIdPath("person.partnerDocument.id", "partnerDocument_1") + + " WHERE " + singleValuedAssociationIdPath("person_1.partnerDocument.id", "partnerDocument_2") + " = " + singleValuedAssociationIdPath("partnerDocument_1.id", "partnerDocument_1") + ") AS DocumentWithSubqueryViewRoot_contactCount, " + "partnerDocument_1.name AS DocumentWithSubqueryViewRoot_name " + "FROM Person person " + diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/NullSubviewTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/NullSubviewTest.java index 0d1a0a292d..76974b6f2e 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/NullSubviewTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/NullSubviewTest.java @@ -84,7 +84,7 @@ public void testSubview() { cfg.addEntityView(DocumentMasterView.class); cfg.addEntityView(PersonSubView.class); cfg.addEntityView(PersonSubViewFiltered.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); CriteriaBuilder criteria = cbf.create(em, Document.class, "d") .orderByAsc("id"); diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/SubviewEntityViewSettingTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/SubviewEntityViewSettingTest.java index a26a87b006..0713eec1c7 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/SubviewEntityViewSettingTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/SubviewEntityViewSettingTest.java @@ -22,7 +22,6 @@ import com.blazebit.persistence.testsuite.base.category.NoEclipselink; import com.blazebit.persistence.testsuite.tx.TxVoidWork; -import org.junit.Before; import org.junit.Test; import com.blazebit.persistence.CriteriaBuilder; @@ -97,7 +96,7 @@ public void testEntityViewSettingFilterSubview() { cfg.addEntityView(DocumentMasterView.class); cfg.addEntityView(PersonSubView.class); cfg.addEntityView(PersonSubViewFiltered.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); // Base setting EntityViewSetting> setting = EntityViewSetting.create( @@ -128,7 +127,7 @@ public void testEntityViewSettingFilterFilteredSubview() { cfg.addEntityView(DocumentMasterView.class); cfg.addEntityView(PersonSubView.class); cfg.addEntityView(PersonSubViewFiltered.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); // Base setting EntityViewSetting> setting = EntityViewSetting.create( diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/SubviewTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/SubviewTest.java index 2809060148..3f872b53eb 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/SubviewTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/subview/SubviewTest.java @@ -25,7 +25,6 @@ import java.util.Set; import javax.persistence.EntityManager; -import javax.persistence.EntityTransaction; import com.blazebit.persistence.testsuite.base.category.NoEclipselink; import com.blazebit.persistence.testsuite.tx.TxVoidWork; @@ -122,7 +121,7 @@ public void testSubview() { cfg.addEntityView(DocumentMasterView.class); cfg.addEntityView(PersonSubView.class); cfg.addEntityView(PersonSubViewFiltered.class); - EntityViewManager evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + EntityViewManager evm = cfg.createEntityViewManager(cbf); CriteriaBuilder criteria = cbf.create(em, Document.class, "d") .orderByAsc("id"); diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/update/EntityViewUpdateTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/update/EntityViewUpdateTest.java index c99648def1..a2b56aa1a7 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/update/EntityViewUpdateTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/update/EntityViewUpdateTest.java @@ -78,7 +78,7 @@ public void setUp() { cleanDatabase(); EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(viewType); - evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + evm = cfg.createEntityViewManager(cbf); transactional(new TxVoidWork() { diff --git a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/update/EntityViewUpdateWithCollectionsTest.java b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/update/EntityViewUpdateWithCollectionsTest.java index 80d57a0657..205f60949c 100644 --- a/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/update/EntityViewUpdateWithCollectionsTest.java +++ b/entity-view/testsuite/src/test/java/com/blazebit/persistence/view/testsuite/update/EntityViewUpdateWithCollectionsTest.java @@ -78,7 +78,7 @@ public void setUp() { cleanDatabase(); EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); cfg.addEntityView(viewType); - evm = cfg.createEntityViewManager(cbf, em.getEntityManagerFactory()); + evm = cfg.createEntityViewManager(cbf); transactional(new TxVoidWork() { diff --git a/examples/cdi-showcase/src/main/java/com/blazebit/persistence/examples/cdi/producer/BlazePersistenceProducer.java b/examples/cdi-showcase/src/main/java/com/blazebit/persistence/examples/cdi/producer/BlazePersistenceProducer.java index 31a767bb9b..251e927f03 100644 --- a/examples/cdi-showcase/src/main/java/com/blazebit/persistence/examples/cdi/producer/BlazePersistenceProducer.java +++ b/examples/cdi-showcase/src/main/java/com/blazebit/persistence/examples/cdi/producer/BlazePersistenceProducer.java @@ -50,7 +50,7 @@ public CriteriaBuilderFactory createCriteriaBuilderFactory() { @Produces @ApplicationScoped public EntityViewManager createEntityViewManager(CriteriaBuilderFactory criteriaBuilderFactory) { - return entityViewConfiguration.createEntityViewManager(criteriaBuilderFactory, emf); + return entityViewConfiguration.createEntityViewManager(criteriaBuilderFactory); } } diff --git a/examples/spring-showcase/src/main/java/com/blazebit/persistence/examples/spring/config/BlazePersistenceConfiguration.java b/examples/spring-showcase/src/main/java/com/blazebit/persistence/examples/spring/config/BlazePersistenceConfiguration.java index 43f18139ba..9cba16b8f1 100644 --- a/examples/spring-showcase/src/main/java/com/blazebit/persistence/examples/spring/config/BlazePersistenceConfiguration.java +++ b/examples/spring-showcase/src/main/java/com/blazebit/persistence/examples/spring/config/BlazePersistenceConfiguration.java @@ -52,6 +52,6 @@ public CriteriaBuilderFactory createCriteriaBuilderFactory() { @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) @Lazy(false) public EntityViewManager createEntityViewManager(CriteriaBuilderFactory cbf, EntityViewConfiguration entityViewConfiguration) { - return entityViewConfiguration.createEntityViewManager(cbf, entityManagerFactory); + return entityViewConfiguration.createEntityViewManager(cbf); } } diff --git a/integration/spring-data/src/test/java/com/blazebit/persistence/impl/springdata/config/BlazePersistenceConfiguration.java b/integration/spring-data/src/test/java/com/blazebit/persistence/impl/springdata/config/BlazePersistenceConfiguration.java index 6a30e7485f..2b9554a6b3 100644 --- a/integration/spring-data/src/test/java/com/blazebit/persistence/impl/springdata/config/BlazePersistenceConfiguration.java +++ b/integration/spring-data/src/test/java/com/blazebit/persistence/impl/springdata/config/BlazePersistenceConfiguration.java @@ -52,6 +52,6 @@ public CriteriaBuilderFactory createCriteriaBuilderFactory() { @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) @Lazy(false) public EntityViewManager createEntityViewManager(CriteriaBuilderFactory cbf, EntityViewConfiguration entityViewConfiguration) { - return entityViewConfiguration.createEntityViewManager(cbf, entityManagerFactory); + return entityViewConfiguration.createEntityViewManager(cbf); } } diff --git a/parent/pom.xml b/parent/pom.xml index 03d7c5d0bc..0522aa44b7 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -50,13 +50,13 @@ 5.2.8.Final 6.0.0-SNAPSHOT - 4.1.16 - 4.1.18 - 4.1.14 + 4.1.17 + 4.1.19 + 4.1.15 4.0.6 - 5.0.6 - 5.0.6 - 5.0.6 + 5.0.7 + 5.0.7 + 5.0.10 5.0.1 2.6.4