Search in sources :

Example 1 with SqmFromClause

use of org.hibernate.query.sqm.tree.from.SqmFromClause in project hibernate-orm by hibernate.

the class SqmSubQuery method getCorrelatedJoins.

@Override
public Set<Join<?, ?>> getCorrelatedJoins() {
    final Set<Join<?, ?>> correlatedJoins = new HashSet<>();
    final SqmFromClause fromClause = getQuerySpec().getFromClause();
    if (fromClause == null) {
        return correlatedJoins;
    }
    for (SqmRoot<?> root : fromClause.getRoots()) {
        if (root instanceof SqmCorrelation<?, ?>) {
            for (SqmJoin<?, ?> sqmJoin : root.getSqmJoins()) {
                if (sqmJoin instanceof SqmCorrelation<?, ?> && sqmJoin instanceof Join<?, ?>) {
                    correlatedJoins.add((Join<?, ?>) sqmJoin);
                }
            }
        }
    }
    return correlatedJoins;
}
Also used : SqmCorrelation(org.hibernate.query.sqm.tree.domain.SqmCorrelation) SqmAttributeJoin(org.hibernate.query.sqm.tree.from.SqmAttributeJoin) SqmCorrelatedMapJoin(org.hibernate.query.sqm.tree.domain.SqmCorrelatedMapJoin) SqmEntityJoin(org.hibernate.query.sqm.tree.from.SqmEntityJoin) CollectionJoin(jakarta.persistence.criteria.CollectionJoin) SqmCorrelatedSetJoin(org.hibernate.query.sqm.tree.domain.SqmCorrelatedSetJoin) SqmMapJoin(org.hibernate.query.sqm.tree.domain.SqmMapJoin) SqmSingularJoin(org.hibernate.query.sqm.tree.domain.SqmSingularJoin) SetJoin(jakarta.persistence.criteria.SetJoin) MapJoin(jakarta.persistence.criteria.MapJoin) SqmJoin(org.hibernate.query.sqm.tree.from.SqmJoin) SqmCorrelatedBagJoin(org.hibernate.query.sqm.tree.domain.SqmCorrelatedBagJoin) SqmCorrelatedSingularJoin(org.hibernate.query.sqm.tree.domain.SqmCorrelatedSingularJoin) SqmCrossJoin(org.hibernate.query.sqm.tree.from.SqmCrossJoin) SqmCorrelatedListJoin(org.hibernate.query.sqm.tree.domain.SqmCorrelatedListJoin) PluralJoin(jakarta.persistence.criteria.PluralJoin) SqmListJoin(org.hibernate.query.sqm.tree.domain.SqmListJoin) SqmSetJoin(org.hibernate.query.sqm.tree.domain.SqmSetJoin) ListJoin(jakarta.persistence.criteria.ListJoin) SqmCorrelatedEntityJoin(org.hibernate.query.sqm.tree.domain.SqmCorrelatedEntityJoin) SqmBagJoin(org.hibernate.query.sqm.tree.domain.SqmBagJoin) SqmCorrelatedCrossJoin(org.hibernate.query.sqm.tree.domain.SqmCorrelatedCrossJoin) Join(jakarta.persistence.criteria.Join) SqmFromClause(org.hibernate.query.sqm.tree.from.SqmFromClause) HashSet(java.util.HashSet)

Example 2 with SqmFromClause

use of org.hibernate.query.sqm.tree.from.SqmFromClause in project hibernate-orm by hibernate.

the class FromClauseTests method testSimpleFrom.

@Test
public void testSimpleFrom() {
    final SqmSelectStatement<?> selectStatement = interpretSelect("select p.nickName from Person p");
    final SqmFromClause fromClause = selectStatement.getQuerySpec().getFromClause();
    assertThat(fromClause, notNullValue());
    assertThat(fromClause.getRoots(), hasSize(1));
    final SqmRoot<?> firstRoot = fromClause.getRoots().get(0);
    assertThat(firstRoot, notNullValue());
    assertThat(firstRoot.getJoins(), isEmpty());
    assertThat(firstRoot.getExplicitAlias(), is("p"));
}
Also used : SqmFromClause(org.hibernate.query.sqm.tree.from.SqmFromClause) BaseSqmUnitTest(org.hibernate.orm.test.query.sqm.BaseSqmUnitTest) Test(org.junit.jupiter.api.Test)

Example 3 with SqmFromClause

use of org.hibernate.query.sqm.tree.from.SqmFromClause in project hibernate-orm by hibernate.

the class FromClauseTests method testFromElementReferenceInSelect.

@Test
public void testFromElementReferenceInSelect() {
    final String query = "select p from Person p";
    SqmSelectStatement<?> selectStatement = interpretSelect(query);
    final SqmFromClause fromClause = selectStatement.getQuerySpec().getFromClause();
    assertThat(fromClause, notNullValue());
    assertThat(fromClause.getRoots(), hasSize(1));
    final SqmRoot<?> sqmRoot = fromClause.getRoots().get(0);
    assertThat(sqmRoot, notNullValue());
    assertThat(selectStatement.getQuerySpec().getSelectClause().getSelections(), hasSize(1));
    final SqmSelection<?> sqmSelection = selectStatement.getQuerySpec().getSelectClause().getSelections().get(0);
    assertThat(sqmSelection.getSelectableNode(), instanceOf(SqmRoot.class));
}
Also used : SqmFromClause(org.hibernate.query.sqm.tree.from.SqmFromClause) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) SqmRoot(org.hibernate.query.sqm.tree.from.SqmRoot) BaseSqmUnitTest(org.hibernate.orm.test.query.sqm.BaseSqmUnitTest) Test(org.junit.jupiter.api.Test)

Example 4 with SqmFromClause

use of org.hibernate.query.sqm.tree.from.SqmFromClause in project hibernate-orm by hibernate.

the class FromClauseTests method testMultipleSpaces.

@Test
public void testMultipleSpaces() {
    final SqmSelectStatement<?> selectStatement = interpretSelect("select p.nickName from Person p, Person p2");
    final SqmFromClause fromClause = selectStatement.getQuerySpec().getFromClause();
    assertNotNull(fromClause);
    assertThat(fromClause, notNullValue());
    assertThat(fromClause.getRoots(), hasSize(2));
    final SqmRoot<?> firstRoot = fromClause.getRoots().get(0);
    assertThat(firstRoot, notNullValue());
    assertThat(firstRoot.getJoins(), isEmpty());
    assertThat(firstRoot.getExplicitAlias(), is("p"));
    final SqmRoot<?> secondRoot = fromClause.getRoots().get(0);
    assertThat(secondRoot, notNullValue());
    assertThat(secondRoot.getJoins(), isEmpty());
    assertThat(secondRoot.getExplicitAlias(), is("p"));
}
Also used : SqmFromClause(org.hibernate.query.sqm.tree.from.SqmFromClause) BaseSqmUnitTest(org.hibernate.orm.test.query.sqm.BaseSqmUnitTest) Test(org.junit.jupiter.api.Test)

Example 5 with SqmFromClause

use of org.hibernate.query.sqm.tree.from.SqmFromClause in project hibernate-orm by hibernate.

the class FromClauseTests method testPathExpression.

@Test
public void testPathExpression() {
    final String query = "select p.mate from Person p";
    SqmSelectStatement<?> selectStatement = interpretSelect(query);
    final SqmFromClause fromClause = selectStatement.getQuerySpec().getFromClause();
    assertThat(fromClause, notNullValue());
    assertThat(fromClause.getRoots(), hasSize(1));
    final SqmRoot<?> sqmRoot = fromClause.getRoots().get(0);
    assertThat(sqmRoot, notNullValue());
    assertThat(sqmRoot.getExplicitAlias(), is("p"));
    assertThat(sqmRoot.getSqmJoins(), hasSize(0));
}
Also used : SqmFromClause(org.hibernate.query.sqm.tree.from.SqmFromClause) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BaseSqmUnitTest(org.hibernate.orm.test.query.sqm.BaseSqmUnitTest) Test(org.junit.jupiter.api.Test)

Aggregations

SqmFromClause (org.hibernate.query.sqm.tree.from.SqmFromClause)13 BaseSqmUnitTest (org.hibernate.orm.test.query.sqm.BaseSqmUnitTest)7 Test (org.junit.jupiter.api.Test)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 SqmRoot (org.hibernate.query.sqm.tree.from.SqmRoot)3 ParseTree (org.antlr.v4.runtime.tree.ParseTree)2 HqlParser (org.hibernate.grammars.hql.HqlParser)2 SqmCorrelation (org.hibernate.query.sqm.tree.domain.SqmCorrelation)2 SqmSubQuery (org.hibernate.query.sqm.tree.select.SqmSubQuery)2 CollectionJoin (jakarta.persistence.criteria.CollectionJoin)1 Join (jakarta.persistence.criteria.Join)1 ListJoin (jakarta.persistence.criteria.ListJoin)1 MapJoin (jakarta.persistence.criteria.MapJoin)1 PluralJoin (jakarta.persistence.criteria.PluralJoin)1 SetJoin (jakarta.persistence.criteria.SetJoin)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 PluralPersistentAttribute (org.hibernate.metamodel.model.domain.PluralPersistentAttribute)1 PathException (org.hibernate.query.PathException)1