Skip to content

Commit

Permalink
HHH-3356 Support for normal and lateral subquery in from clause
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Jun 2, 2022
1 parent a488e1a commit 6bef368
Show file tree
Hide file tree
Showing 47 changed files with 4,404 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ IS : [iI] [sS];
JOIN : [jJ] [oO] [iI] [nN];
KEY : [kK] [eE] [yY];
LAST : [lL] [aA] [sS] [tT];
LATERAL : [lL] [aA] [tT] [eE] [rR] [aA] [lL];
LEADING : [lL] [eE] [aA] [dD] [iI] [nN] [gG];
LEFT : [lL] [eE] [fF] [tT];
LIKE : [lL] [iI] [kK] [eE];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,15 @@ fromClause
* The declaration of a root entity in 'from' clause, along with its joins
*/
entityWithJoins
: rootEntity (join | crossJoin | jpaCollectionJoin)*
: fromRoot (join | crossJoin | jpaCollectionJoin)*
;

/**
* A root entity declaration in the 'from' clause, with optional identification variable
*/
rootEntity
: entityName variable?
fromRoot
: entityName variable? # RootEntity
| LATERAL? LEFT_PAREN subquery RIGHT_PAREN variable? # RootSubquery
;

/**
Expand Down Expand Up @@ -212,7 +213,7 @@ jpaCollectionJoin
* A 'join', with an optional 'on' or 'with' clause
*/
join
: joinType JOIN FETCH? joinPath joinRestriction?
: joinType JOIN FETCH? joinTarget joinRestriction?
;

/**
Expand All @@ -226,8 +227,9 @@ joinType
/**
* The joined path, with an optional identification variable
*/
joinPath
: path variable?
joinTarget
: path variable? #JoinPath
| LATERAL? LEFT_PAREN subquery RIGHT_PAREN variable? #JoinSubquery
;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

import java.util.List;

import org.hibernate.Incubating;
import org.hibernate.query.sqm.SqmExpressible;
import org.hibernate.sql.ast.spi.FromClauseAccess;
import org.hibernate.sql.ast.spi.SqlSelection;
import org.hibernate.sql.ast.tree.from.TableGroupProducer;

/**
* Describes any structural type without a direct java type representation.
Expand All @@ -23,4 +27,12 @@ public interface TupleType<J> extends SqmExpressible<J> {

SqmExpressible<?> get(int index);
SqmExpressible<?> get(String componentName);

@Incubating
default TableGroupProducer resolveTableGroupProducer(
String aliasStem,
List<SqlSelection> sqlSelections,
FromClauseAccess fromClauseAccess) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.metamodel.model.domain.internal;

import org.hibernate.Incubating;
import org.hibernate.engine.spi.IdentifierValue;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.query.sqm.SqmExpressible;

/**
* @author Christian Beikov
*/
@Incubating
public class AnonymousTupleBasicEntityIdentifierMapping extends AnonymousTupleBasicValuedModelPart
implements BasicEntityIdentifierMapping {

private final BasicEntityIdentifierMapping delegate;

public AnonymousTupleBasicEntityIdentifierMapping(
String selectionExpression,
SqmExpressible<?> expressible,
JdbcMapping jdbcMapping,
BasicEntityIdentifierMapping delegate) {
super( delegate.getAttributeName(), selectionExpression, expressible, jdbcMapping );
this.delegate = delegate;
}

@Override
public IdentifierValue getUnsavedStrategy() {
return delegate.getUnsavedStrategy();
}

@Override
public Object getIdentifier(Object entity, SharedSessionContractImplementor session) {
return delegate.getIdentifier( entity, session );
}

@Override
public Object getIdentifier(Object entity) {
return delegate.getIdentifier( entity );
}

@Override
public void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session) {
delegate.setIdentifier( entity, id, session );
}

@Override
public Object instantiate() {
return delegate.instantiate();
}

@Override
public PropertyAccess getPropertyAccess() {
return delegate.getPropertyAccess();
}

@Override
public String getAttributeName() {
return getPartName();
}
}
Loading

0 comments on commit 6bef368

Please sign in to comment.