All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.query.criteria.internal.expression.MapEntryExpression Maven / Gradle / Ivy

There is a newer version: 7.0.0.Alpha1
Show newest version
/*
 * 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 .
 */
package org.hibernate.query.criteria.internal.expression;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import javax.persistence.criteria.CompoundSelection;
import javax.persistence.criteria.Selection;

import org.hibernate.query.criteria.internal.CriteriaBuilderImpl;
import org.hibernate.query.criteria.internal.ParameterRegistry;
import org.hibernate.query.criteria.internal.compile.RenderingContext;
import org.hibernate.query.criteria.internal.path.MapAttributeJoin;
import org.hibernate.sql.ast.Clause;

/**
 * TODO : javadoc
 *
 * @author Steve Ebersole
 */
public class MapEntryExpression
		extends ExpressionImpl>
		implements CompoundSelection>, Serializable {

	private final MapAttributeJoin original;

	public MapEntryExpression(
			CriteriaBuilderImpl criteriaBuilder,
			Class> javaType,
			MapAttributeJoin original) {
		super( criteriaBuilder, javaType );
		this.original = original;
	}

	@Override
	public void registerParameters(ParameterRegistry registry) {
		// none to register
	}

	@Override
	public String render(RenderingContext renderingContext) {
		if ( renderingContext.getClauseStack().getCurrent() == Clause.SELECT ) {
			return "entry(" + original.render( renderingContext ) + ")";
		}

		// don't think this is valid outside of select clause...
		throw new IllegalStateException( "illegal reference to map entry outside of select clause." );
	}

	@Override
	public boolean isCompoundSelection() {
		return true;
	}

	@Override
	public List> getCompoundSelectionItems() {
		return Arrays.asList( original.key(), original.value() );
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy