Java 类org.hibernate.type.LiteralType 实例源码

项目:lams    文件:JavaConstantNode.java   
@Override
@SuppressWarnings("unchecked")
public String getRenderText(SessionFactoryImplementor sessionFactory) {
    final Type type = expectedType == null
            ? heuristicType
            : Number.class.isAssignableFrom( heuristicType.getReturnedClass() )
            ? heuristicType
            : expectedType;
    try {
        final LiteralType literalType = (LiteralType) type;
        final Dialect dialect = factory.getDialect();
        return literalType.objectToSQLString( constantValue, dialect );
    }
    catch (Exception t) {
        throw new QueryException( QueryTranslator.ERROR_CANNOT_FORMAT_LITERAL + constantExpression, t );
    }
}
项目:cacheonix-core    文件:JavaConstantNode.java   
private String resolveToLiteralString(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 );
    }
}
项目:lams    文件:Insert.java   
public Insert addColumn(String columnName, Object value, LiteralType type) throws Exception {
    return addColumn( columnName, type.objectToSQLString(value, dialect) );
}
项目:lams    文件:Update.java   
public Update addColumn(String columnName, Object value, LiteralType type) throws Exception {
    return addColumn( columnName, type.objectToSQLString(value, dialect) );
}
项目:lams    文件:LiteralProcessor.java   
private void setConstantValue(DotNode node, String text, Object value) {
    if ( LOG.isDebugEnabled() ) {
        LOG.debugf( "setConstantValue() %s -> %s %s", text, value, value.getClass().getName() );
    }
    // Chop off the rest of the tree.
    node.setFirstChild( null );
    if ( value instanceof String ) {
        node.setType( SqlTokenTypes.QUOTED_STRING );
    }
    else if ( value instanceof Character ) {
        node.setType( SqlTokenTypes.QUOTED_STRING );
    }
    else if ( value instanceof Byte ) {
        node.setType( SqlTokenTypes.NUM_INT );
    }
    else if ( value instanceof Short ) {
        node.setType( SqlTokenTypes.NUM_INT );
    }
    else if ( value instanceof Integer ) {
        node.setType( SqlTokenTypes.NUM_INT );
    }
    else if ( value instanceof Long ) {
        node.setType( SqlTokenTypes.NUM_LONG );
    }
    else if ( value instanceof Double ) {
        node.setType( SqlTokenTypes.NUM_DOUBLE );
    }
    else if ( value instanceof Float ) {
        node.setType( SqlTokenTypes.NUM_FLOAT );
    }
    else {
        node.setType( SqlTokenTypes.CONSTANT );
    }
    Type type;
    try {
        type = walker.getSessionFactoryHelper().getFactory().getTypeResolver().heuristicType(
                value.getClass().getName()
        );
    }
    catch (MappingException me) {
        throw new QueryException( me );
    }
    if ( type == null ) {
        throw new QueryException( QueryTranslator.ERROR_CANNOT_DETERMINE_TYPE + node.getText() );
    }
    try {
        LiteralType literalType = (LiteralType) type;
        Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
        //noinspection unchecked
        node.setText( literalType.objectToSQLString( value, dialect ) );
    }
    catch (Exception e) {
        throw new QueryException( QueryTranslator.ERROR_CANNOT_FORMAT_LITERAL + node.getText(), e );
    }
    node.setDataType( type );
    node.setResolvedConstant( text );
}
项目:lams    文件:WhereParser.java   
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 = q.getFactory().getTypeResolver().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 );
                }
            }
        }
    }
}
项目:cacheonix-core    文件:Insert.java   
public Insert addColumn(String columnName, Object value, LiteralType type) throws Exception {
    return addColumn( columnName, type.objectToSQLString(value, dialect) );
}
项目:cacheonix-core    文件:Update.java   
public Update addColumn(String columnName, Object value, LiteralType type) throws Exception {
    return addColumn( columnName, type.objectToSQLString(value, dialect) );
}
项目:cacheonix-core    文件:LiteralProcessor.java   
private void setConstantValue(DotNode node, String text, Object value) {
    if ( log.isDebugEnabled() ) {
        log.debug( "setConstantValue() " + text + " -> " + value + " " + value.getClass().getName() );
    }
    node.setFirstChild( null ); // Chop off the rest of the tree.
    if ( value instanceof String ) {
        node.setType( SqlTokenTypes.QUOTED_STRING );
    }
    else if ( value instanceof Character ) {
        node.setType( SqlTokenTypes.QUOTED_STRING );
    }
    else if ( value instanceof Byte ) {
        node.setType( SqlTokenTypes.NUM_INT );
    }
    else if ( value instanceof Short ) {
        node.setType( SqlTokenTypes.NUM_INT );
    }
    else if ( value instanceof Integer ) {
        node.setType( SqlTokenTypes.NUM_INT );
    }
    else if ( value instanceof Long ) {
        node.setType( SqlTokenTypes.NUM_LONG );
    }
    else if ( value instanceof Double ) {
        node.setType( SqlTokenTypes.NUM_DOUBLE );
    }
    else if ( value instanceof Float ) {
        node.setType( SqlTokenTypes.NUM_FLOAT );
    }
    else {
        node.setType( SqlTokenTypes.CONSTANT );
    }
    Type type;
    try {
        type = TypeFactory.heuristicType( value.getClass().getName() );
    }
    catch ( MappingException me ) {
        throw new QueryException( me );
    }
    if ( type == null ) {
        throw new QueryException( QueryTranslator.ERROR_CANNOT_DETERMINE_TYPE + node.getText() );
    }
    try {
        LiteralType literalType = ( LiteralType ) type;
        Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
        node.setText( literalType.objectToSQLString( value, dialect ) );
    }
    catch ( Exception e ) {
        throw new QueryException( QueryTranslator.ERROR_CANNOT_FORMAT_LITERAL + node.getText(), e );
    }
    node.setDataType( type );
    node.setResolvedConstant( text );
}
项目:cacheonix-core    文件:WhereParser.java   
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 );
                }
            }
        }
    }
}
项目:lams    文件:BooleanLiteralNode.java   
private LiteralType typeAsLiteralType() {
    return (LiteralType) getDataType();

}