Search in sources :

Example 1 with SqmSimplePath

use of org.hibernate.query.sqm.tree.domain.SqmSimplePath in project hibernate-orm by hibernate.

the class AliasCollisionTest method testSubqueryUsingIdentificationVariableDefinedInRootQuery.

@Test
public void testSubqueryUsingIdentificationVariableDefinedInRootQuery() {
    final String query = "select a from SimpleEntity a where a.someString in " + "( select b.someString from SimpleEntity b where a.someLong = b.someLong )";
    final SqmSelectStatement<?> sqm = interpretSelect(query);
    final SqmQuerySpec<?> querySpec = sqm.getQuerySpec();
    final List<SqmSelection<?>> selections = querySpec.getSelectClause().getSelections();
    assertThat(selections, hasSize(1));
    assertThat(selections.get(0).getAlias(), nullValue());
    final List<SqmRoot<?>> roots = querySpec.getFromClause().getRoots();
    assertThat(roots, hasSize(1));
    assertThat(roots.get(0).getJoins(), isEmpty());
    assertThat(roots.get(0).getExplicitAlias(), is("a"));
    assertThat(querySpec.getWhereClause().getPredicate(), instanceOf(SqmInSubQueryPredicate.class));
    final SqmInSubQueryPredicate predicate = (SqmInSubQueryPredicate) querySpec.getWhereClause().getPredicate();
    final SqmQuerySpec subQuerySpec = predicate.getSubQueryExpression().getQuerySpec();
    assertThat(subQuerySpec.getFromClause().getRoots().get(0).getExplicitAlias(), is("b"));
    final SqmComparisonPredicate correlation = (SqmComparisonPredicate) subQuerySpec.getWhereClause().getPredicate();
    final SqmSimplePath leftHandExpression = (SqmSimplePath) correlation.getLeftHandExpression();
    assertThat(leftHandExpression.getLhs().getExplicitAlias(), is("a"));
    final SqmSimplePath rightHandExpression = (SqmSimplePath) correlation.getRightHandExpression();
    assertThat(rightHandExpression.getLhs().getExplicitAlias(), is("b"));
}
Also used : SqmSelection(org.hibernate.query.sqm.tree.select.SqmSelection) SqmSimplePath(org.hibernate.query.sqm.tree.domain.SqmSimplePath) SqmComparisonPredicate(org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate) SqmQuerySpec(org.hibernate.query.sqm.tree.select.SqmQuerySpec) SqmRoot(org.hibernate.query.sqm.tree.from.SqmRoot) SqmInSubQueryPredicate(org.hibernate.query.sqm.tree.predicate.SqmInSubQueryPredicate) BaseSqmUnitTest(org.hibernate.orm.test.query.sqm.BaseSqmUnitTest) Test(org.junit.jupiter.api.Test)

Example 2 with SqmSimplePath

use of org.hibernate.query.sqm.tree.domain.SqmSimplePath in project hibernate-orm by hibernate.

the class AttributePathTests method assertPropertyPath.

private void assertPropertyPath(SqmExpression expression, String expectedFullPath) {
    assertThat(expression, instanceOf(SqmSimplePath.class));
    final SqmSimplePath domainReferenceBinding = (SqmSimplePath) expression;
    assertThat(domainReferenceBinding.getNavigablePath().getFullPath(), is(expectedFullPath));
}
Also used : SqmSimplePath(org.hibernate.query.sqm.tree.domain.SqmSimplePath)

Example 3 with SqmSimplePath

use of org.hibernate.query.sqm.tree.domain.SqmSimplePath in project hibernate-orm by hibernate.

the class SelectClauseTests method collectionIndexFunctionAssertions.

private void collectionIndexFunctionAssertions(SqmSelectStatement<?> statement, CollectionClassification expectedCollectionClassification, Class<? extends DomainType> expectedIndexDomainTypeType, String expectedAlias) {
    assertEquals(1, statement.getQuerySpec().getSelectClause().getSelections().size());
    final SqmSelectableNode<?> selectedExpr = statement.getQuerySpec().getSelectClause().getSelections().get(0).getSelectableNode();
    assertThat(selectedExpr, instanceOf(SqmSimplePath.class));
    final SqmSimplePath<?> selectedPath = (SqmSimplePath<?>) selectedExpr;
    assertThat(selectedPath.getLhs().getExplicitAlias(), is(expectedAlias));
    final PluralPersistentAttribute attribute = (PluralPersistentAttribute) selectedPath.getLhs().getReferencedPathSource();
    assertThat(attribute.getCollectionClassification(), is(expectedCollectionClassification));
    final SimpleDomainType<?> indexDomainType = attribute.getKeyGraphType();
    assertThat(indexDomainType, instanceOf(expectedIndexDomainTypeType));
    assertThat(selectedPath.getReferencedPathSource(), sameInstance(attribute.getIndexPathSource()));
}
Also used : SqmSimplePath(org.hibernate.query.sqm.tree.domain.SqmSimplePath) PluralPersistentAttribute(org.hibernate.metamodel.model.domain.PluralPersistentAttribute)

Aggregations

SqmSimplePath (org.hibernate.query.sqm.tree.domain.SqmSimplePath)3 PluralPersistentAttribute (org.hibernate.metamodel.model.domain.PluralPersistentAttribute)1 BaseSqmUnitTest (org.hibernate.orm.test.query.sqm.BaseSqmUnitTest)1 SqmRoot (org.hibernate.query.sqm.tree.from.SqmRoot)1 SqmComparisonPredicate (org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate)1 SqmInSubQueryPredicate (org.hibernate.query.sqm.tree.predicate.SqmInSubQueryPredicate)1 SqmQuerySpec (org.hibernate.query.sqm.tree.select.SqmQuerySpec)1 SqmSelection (org.hibernate.query.sqm.tree.select.SqmSelection)1 Test (org.junit.jupiter.api.Test)1