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"));
}
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));
}
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()));
}
Aggregations