org.hibernate.query.sqm.tree.domain.SqmMaxElementPath Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-core Show documentation
Show all versions of hibernate-core Show documentation
Hibernate's core ORM functionality
/*
* 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.query.sqm.tree.domain;
import org.hibernate.metamodel.model.domain.ManagedDomainType;
import org.hibernate.metamodel.model.domain.PluralPersistentAttribute;
import org.hibernate.query.SemanticException;
import org.hibernate.query.hql.spi.SemanticPathPart;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.hql.spi.SqmCreationState;
/**
* @author Steve Ebersole
*/
public class SqmMaxElementPath extends AbstractSqmSpecificPluralPartPath {
public static final String NAVIGABLE_NAME = "{max-element}";
public SqmMaxElementPath(SqmPath pluralDomainPath) {
//noinspection unchecked
super(
pluralDomainPath.getNavigablePath().append( NAVIGABLE_NAME ),
pluralDomainPath,
(PluralPersistentAttribute) pluralDomainPath.getReferencedPathSource()
);
}
@Override
public SemanticPathPart resolvePathPart(
String name,
boolean isTerminal,
SqmCreationState creationState) {
if ( getPluralAttribute().getElementPathSource().getSqmPathType() instanceof ManagedDomainType ) {
//noinspection unchecked
return getPluralAttribute().getElementPathSource().createSqmPath( this, creationState );
}
throw new SemanticException( "Collection element cannot be de-referenced : " + getPluralDomainPath().getNavigablePath() );
}
@Override
public SqmPathSource getReferencedPathSource() {
//noinspection unchecked
return getPluralAttribute().getElementPathSource();
}
@Override
public X accept(SemanticQueryWalker walker) {
return walker.visitMaxElementPath( this );
}
}