FileDocCategorySizeDatePackage
JavaConstantNode.javaAPI DocHibernate 3.2.52036Tue Jun 27 21:53:40 BST 2006org.hibernate.hql.ast.tree

JavaConstantNode

public class JavaConstantNode extends Node implements ExpectedTypeAwareNode, SessionFactoryAwareNode
A node representing a static Java constant.
author
Steve Ebersole

Fields Summary
private org.hibernate.engine.SessionFactoryImplementor
factory
private String
constantExpression
private Object
constantValue
private org.hibernate.type.Type
heuristicType
private org.hibernate.type.Type
expectedType
Constructors Summary
Methods Summary
public org.hibernate.type.TypegetExpectedType()

		return expectedType;
	
public java.lang.StringgetRenderText(org.hibernate.engine.SessionFactoryImplementor sessionFactory)

		Type type = expectedType == null ? heuristicType : expectedType;
		return resolveToLiteralString( type );
	
private java.lang.StringresolveToLiteralString(org.hibernate.type.Type type)

		try {
			LiteralType literalType = ( LiteralType ) type;
			Dialect dialect = factory.getDialect();
			return literalType.objectToSQLString( constantValue, dialect );
		}
		catch ( Throwable t ) {
			throw new QueryException( QueryTranslator.ERROR_CANNOT_FORMAT_LITERAL + constantExpression, t );
		}
	
public voidsetExpectedType(org.hibernate.type.Type expectedType)

		this.expectedType = expectedType;
	
public voidsetSessionFactory(org.hibernate.engine.SessionFactoryImplementor factory)

		this.factory = factory;
	
public voidsetText(java.lang.String s)

		// for some reason the antlr.CommonAST initialization routines force
		// this method to get called twice.  The first time with an empty string
		if ( StringHelper.isNotEmpty( s ) ) {
			constantExpression = s;
			constantValue = ReflectHelper.getConstantValue( s );
			heuristicType = TypeFactory.heuristicType( constantValue.getClass().getName() );
			super.setText( s );
		}