@Override public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) throws HibernateException { return getFunction( criteriaQuery ).render( null, ARGS, criteriaQuery.getFactory() ) + " as y" + position + '_'; }
public boolean aggregateFuncNoArgsHasParenthesis(String funcToken, QueryTranslatorImpl q) { return getFunction( funcToken, q ).hasParenthesesIfNoArguments(); }
private String locateAppropriateDialectFunctionNameForAliasTest() { for (Iterator itr = getDialect().getFunctions().entrySet().iterator(); itr.hasNext(); ) { final Map.Entry entry = (Map.Entry) itr.next(); final SQLFunction function = (SQLFunction) entry.getValue(); if ( !function.hasArguments() && !function.hasParenthesesIfNoArguments() ) { return (String) entry.getKey(); } } return null; }
public Type aggregateType(List funcTokenList, Type type, QueryTranslatorImpl q) throws QueryException { Type retType = type; Type argType; for ( int i = funcTokenList.size() - 1; i >= 0; i-- ) { argType = retType; String funcToken = ( String ) funcTokenList.get( i ); retType = getFunction( funcToken, q ).getReturnType( argType, q.getFactory() ); } return retType; }
public boolean aggregateHasArgs(String funcToken, QueryTranslatorImpl q) { return getFunction( funcToken, q ).hasArguments(); }
@Override public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { final Type countFunctionReturnType = getFunction( criteriaQuery ).getReturnType( null, criteriaQuery.getFactory() ); return new Type[] { countFunctionReturnType }; }
@Override public boolean hasArguments() { return function.hasArguments(); }
return resolveBothSpaceTrimFunction().render( argumentType, args, factory ); return resolveBothSpaceTrimFromFunction().render( argumentType, args, factory ); return resolveBothSpaceTrimFunction().render( argumentType, argsToUse, factory ); return resolveLeadingSpaceTrimFunction().render( argumentType, argsToUse, factory ); return resolveTrailingSpaceTrimFunction().render( argumentType, argsToUse, factory ); return resolveBothTrimFunction().render( argumentType, argsToUse, factory ); return resolveLeadingTrimFunction().render( argumentType, argsToUse, factory ); return resolveTrailingTrimFunction().render( argumentType, argsToUse, factory );
private static boolean isFunction(String lcToken, String nextToken, SQLFunctionRegistry functionRegistry) { // checking for "(" is currently redundant because it is checked before getting here; // doing the check anyhow, in case that earlier check goes away; if ( "(".equals( nextToken ) ) { return true; } SQLFunction function = functionRegistry.findSQLFunction(lcToken); if ( function == null ) { // lcToken does not refer to a function return false; } // if function.hasParenthesesIfNoArguments() is true, then assume // lcToken is not a function (since it is not followed by '(') return ! function.hasParenthesesIfNoArguments(); }
public Type findFunctionReturnType(String functionName, SQLFunction sqlFunction, AST firstArgument) { // determine the type of the first argument... Type argumentType = null; if ( firstArgument != null ) { if ( "cast".equals( functionName ) ) { argumentType = sfi.getTypeResolver().heuristicType( firstArgument.getNextSibling().getText() ); } else if ( SqlNode.class.isInstance( firstArgument ) ) { argumentType = ( (SqlNode) firstArgument ).getDataType(); } } return sqlFunction.getReturnType( argumentType, sfi ); }
@SuppressWarnings( {"ForLoopReplaceableByForEach"}) private String locateAppropriateDialectFunctionNameForAliasTest() { for (Iterator itr = getDialect().getFunctions().entrySet().iterator(); itr.hasNext(); ) { final Map.Entry entry = (Map.Entry) itr.next(); final SQLFunction function = (SQLFunction) entry.getValue(); if ( !function.hasArguments() && !function.hasParenthesesIfNoArguments() ) { return (String) entry.getKey(); } } return null; }
public boolean aggregateHasArgs(String funcToken, QueryTranslatorImpl q) { return getFunction( funcToken, q ).hasArguments(); }
@Override protected void endFunctionTemplate(AST node) { FunctionNode functionNode = (FunctionNode) node; SQLFunction sqlFunction = functionNode.getSQLFunction(); if ( sqlFunction == null ) { super.endFunctionTemplate( node ); } else { final Type functionType = functionNode.getFirstArgumentType(); // this function has a registered SQLFunction -> redirect output and catch the arguments FunctionArgumentsCollectingWriter functionArguments = (FunctionArgumentsCollectingWriter) writer; writer = outputStack.removeFirst(); out( sqlFunction.render( functionType, functionArguments.getArgs(), sessionFactory ) ); } }
@Override @SuppressWarnings("SimplifiableIfStatement") protected boolean isFunctionName(AST ast) { /* * Semantic predicate used to determine whether a given AST node represents a function call */ AST child = ast.getFirstChild(); // assume it is a function if it has parameters if ( child != null && "{param list}".equals( child.getText() ) ) { return true; } // otherwise, in order for this to be a function logically it has to be a function that does not // have arguments. So try to assert that using the registry of known functions final SQLFunction function = context.getSqlFunctionRegistry().findSQLFunction( ast.getText() ); if ( function == null ) { // no registered function, so we cannot know for certain return false; } else { // if function.hasParenthesesIfNoArguments() is true, then assume the node is not a function return !function.hasParenthesesIfNoArguments(); } }
@Override public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { return new Type[] { getFunction( criteriaQuery ).getReturnType( criteriaQuery.getType( criteria, getPropertyName() ), criteriaQuery.getFactory() ) }; }
public boolean aggregateHasArgs(String funcToken, QueryTranslatorImpl q) { return getFunction( funcToken, q ).hasArguments(); }
@Override public String toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery) throws HibernateException { final String functionFragment = getFunction( criteriaQuery ).render( criteriaQuery.getType( criteria, getPropertyName() ), buildFunctionParameterList( criteria, criteriaQuery ), criteriaQuery.getFactory() ); return functionFragment + " as y" + loc + '_'; }
@Test public void testNoArgFcnAndColumnSameNameAsNoArgFunctionHQL() { SQLFunction function = sessionFactory().getSqlFunctionRegistry().findSQLFunction( "current_date" ); if ( function == null || function.hasParenthesesIfNoArguments() ) { SkipLog.reportSkip( "current_date reuires ()", "tests noarg function that does not require ()" ); return;
@Override public Type getDataType() { Type type = super.getDataType(); if ( type != null ) { return type; } FromElement fe = getFromElement(); if ( fe != null ) { return fe.getDataType(); } SQLFunction sf = getWalker().getSessionFactoryHelper().findSQLFunction( getText() ); if ( sf != null ) { return sf.getReturnType( null, getWalker().getSessionFactoryHelper().getFactory() ); } return null; }
public boolean aggregateHasArgs(String funcToken, QueryTranslatorImpl q) { return getFunction( funcToken, q ).hasArguments(); }