package org.hibernate.jpa.criteria.expression;
import java.io.Serializable;
import java.util.Map;
import javax.persistence.criteria.Expression;
import javax.persistence.metamodel.MapAttribute;
import org.hibernate.jpa.criteria.CriteriaBuilderImpl;
import org.hibernate.jpa.criteria.ParameterRegistry;
import org.hibernate.jpa.criteria.PathImplementor;
import org.hibernate.jpa.criteria.Renderable;
import org.hibernate.jpa.criteria.compile.RenderingContext;
public class MapEntryExpression<K,V>
extends ExpressionImpl<Map.Entry<K,V>>
implements Expression<Map.Entry<K,V>>, Serializable {
private final PathImplementor origin;
private final MapAttribute<?, K, V> attribute;
public MapEntryExpression(
CriteriaBuilderImpl criteriaBuilder,
Class<Map.Entry<K, V>> javaType,
PathImplementor origin,
MapAttribute<?, K, V> attribute) {
super( criteriaBuilder, javaType);
this.origin = origin;
this.attribute = attribute;
}
public MapAttribute<?, K, V> getAttribute() {
return attribute;
}
public void registerParameters(ParameterRegistry registry) {
}
public String render(RenderingContext renderingContext) {
throw new IllegalStateException( "illegal reference to map entry outside of select clause." );
}
public String renderProjection(RenderingContext renderingContext) {
return "entry(" + path( renderingContext ) + ")";
}
private String path(RenderingContext renderingContext) {
return origin.getPathIdentifier()
+ '.'
+ ( (Renderable) getAttribute() ).renderProjection( renderingContext );
}
}