Java Code Examples for org.hibernate.util.ReflectHelper#getConstantValue()

The following examples show how to use org.hibernate.util.ReflectHelper#getConstantValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LiteralProcessor.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void lookupConstant(DotNode node) throws SemanticException {
	String text = ASTUtil.getPathText( node );
	Queryable persister = walker.getSessionFactoryHelper().findQueryableUsingImports( text );
	if ( persister != null ) {
		// the name of an entity class
		final String discrim = persister.getDiscriminatorSQLValue();
		node.setDataType( persister.getDiscriminatorType() );
		if ( InFragment.NULL.equals(discrim) || InFragment.NOT_NULL.equals(discrim) ) {
			throw new InvalidPathException( "subclass test not allowed for null or not null discriminator: '" + text + "'" );
		}
		else {
			setSQLValue( node, text, discrim ); //the class discriminator value
		}
	}
	else {
		Object value = ReflectHelper.getConstantValue( text );
		if ( value == null ) {
			throw new InvalidPathException( "Invalid path: '" + text + "'" );
		}
		else {
			setConstantValue( node, text, value );
		}
	}
}
 
Example 2
Source File: JavaConstantNode.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void setText(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 );
	}
}
 
Example 3
Source File: QueryTranslatorImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void handleDotStructure(AST dotStructureRoot) {
	String expression = ASTUtil.getPathText( dotStructureRoot );
	Object constant = ReflectHelper.getConstantValue( expression );
	if ( constant != null ) {
		dotStructureRoot.setFirstChild( null );
		dotStructureRoot.setType( HqlTokenTypes.JAVA_CONSTANT );
		dotStructureRoot.setText( expression );
	}
}
 
Example 4
Source File: WhereParser.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void doToken(String token, QueryTranslatorImpl q) throws QueryException {
	if ( q.isName( StringHelper.root( token ) ) ) { //path expression
		doPathExpression( q.unalias( token ), q );
	}
	else if ( token.startsWith( ParserHelper.HQL_VARIABLE_PREFIX ) ) { //named query parameter
		q.addNamedParameter( token.substring( 1 ) );
		appendToken( q, "?" );
	}
	else {
		Queryable persister = q.getEntityPersisterUsingImports( token );
		if ( persister != null ) { // the name of a class
			final String discrim = persister.getDiscriminatorSQLValue();
			if ( InFragment.NULL.equals(discrim) || InFragment.NOT_NULL.equals(discrim) ) {
				throw new QueryException( "subclass test not allowed for null or not null discriminator" );
			}
			else {
				appendToken( q, discrim );
			}
		}
		else {
			Object constant;
			if (
					token.indexOf( '.' ) > -1 &&
					( constant = ReflectHelper.getConstantValue( token ) ) != null
			) {
				Type type;
				try {
					type = TypeFactory.heuristicType( constant.getClass().getName() );
				}
				catch ( MappingException me ) {
					throw new QueryException( me );
				}
				if ( type == null ) throw new QueryException( QueryTranslator.ERROR_CANNOT_DETERMINE_TYPE + token );
				try {
					appendToken( q, ( ( LiteralType ) type ).objectToSQLString( constant, q.getFactory().getDialect() ) );
				}
				catch ( Exception e ) {
					throw new QueryException( QueryTranslator.ERROR_CANNOT_FORMAT_LITERAL + token, e );
				}
			}
			else { //anything else

				String negatedToken = negated ? ( String ) NEGATIONS.get( token.toLowerCase() ) : null;
				if ( negatedToken != null && ( !betweenSpecialCase || !"or".equals( negatedToken ) ) ) {
					appendToken( q, negatedToken );
				}
				else {
					appendToken( q, token );
				}
			}
		}
	}
}