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

org.hibernate.jpa.criteria.expression.CaseLiteralExpression Maven / Gradle / Ivy

There is a newer version: 5.4.2.Final
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.jpa.criteria.expression;

import org.hibernate.jpa.criteria.CriteriaBuilderImpl;
import org.hibernate.jpa.criteria.compile.RenderingContext;
import org.hibernate.jpa.criteria.expression.function.CastFunction;

/**
 * @author Andrea Boriero
 */
public class CaseLiteralExpression extends LiteralExpression {

	public CaseLiteralExpression(CriteriaBuilderImpl criteriaBuilder, Class type, T literal) {
		super( criteriaBuilder, type, literal );
	}

	@Override
	public String render(RenderingContext renderingContext) {
		// There's no need to cast a boolean value and it actually breaks on
		// MySQL and MariaDB because they don't support casting to bit.
		// Skip the cast for a boolean literal.
		if ( getJavaType() == Boolean.class && Boolean.class.isInstance( getLiteral() ) ) {
			return super.render( renderingContext );
		}

		// wrapping the result in a cast to determine the node type during the antlr hql parsing phase
		return CastFunction.CAST_NAME + '(' +
				super.render( renderingContext ) +
				" as " +
				renderingContext.getCastType( getJavaType() ) +
				')';
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy