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