Package org.hibernate.dialect.function

Examples of org.hibernate.dialect.function.SQLFunction


    PersistentClass user = mappings.getClass( User.class.getName() );
    org.hibernate.mapping.Property personProperty = user.getProperty( "person" );
    Component component = ( Component ) personProperty.getValue();
    Formula f = ( Formula ) component.getProperty( "yob" ).getValue().getColumnIterator().next();

    SQLFunction yearFunction = ( SQLFunction ) dialect.getFunctions().get( "year" );
    if ( yearFunction == null ) {
      // the dialect not know to support a year() function, so rely on the
      // ANSI SQL extract function
      f.setFormula( "extract( year from dob )");
    }
    else {
      List args = new ArrayList();
      args.add( "dob" );
      f.setFormula( yearFunction.render( args, null ) );
    }
  }
View Full Code Here


   * @param functionName The name of the function to locate
   * @return The sql function.
   * @throws QueryException Indicates no matching sql functions could be found.
   */
  private SQLFunction requireSQLFunction(String functionName) {
    SQLFunction f = findSQLFunction( functionName );
    if ( f == null ) {
      throw new QueryException( "Unable to find SQL function: " + functionName );
    }
    return f;
  }
View Full Code Here

   * @param functionName The function name.
   * @param first        The first argument expression.
   * @return the function return type given the function name and the first argument expression node.
   */
  public Type findFunctionReturnType(String functionName, AST first) {
    SQLFunction sqlFunction = requireSQLFunction( functionName );
    return findFunctionReturnType( functionName, sqlFunction, first );
  }
View Full Code Here

  @Override
    protected void beginFunctionTemplate(AST node, AST nameNode) {
    // NOTE for AGGREGATE both nodes are the same; for METHOD the first is the METHOD, the second is the
    //     METHOD_NAME
    FunctionNode functionNode = ( FunctionNode ) node;
    SQLFunction sqlFunction = functionNode.getSQLFunction();
    if ( sqlFunction == null ) {
      // if SQLFunction is null we just write the function out as it appears in the hql statement
      super.beginFunctionTemplate( node, nameNode );
    }
    else {
View Full Code Here

  }

  @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
      FunctionArguments functionArguments = ( FunctionArguments ) writer;
      writer = outputStack.removeFirst();
      out( sqlFunction.render( functionType, functionArguments.getArgs(), sessionFactory ) );
    }
  }
View Full Code Here

   * @param functionName The name of the function to locate
   * @return The sql function.
   * @throws QueryException Indicates no matching sql functions could be found.
   */
  private SQLFunction requireSQLFunction(String functionName) {
    SQLFunction f = findSQLFunction( functionName );
    if ( f == null ) {
      throw new QueryException( "Unable to find SQL function: " + functionName );
    }
    return f;
  }
View Full Code Here

   * @param functionName The function name.
   * @param first        The first argument expression.
   * @return the function return type given the function name and the first argument expression node.
   */
  public Type findFunctionReturnType(String functionName, AST first) {
    SQLFunction sqlFunction = requireSQLFunction( functionName );
    return findFunctionReturnType( functionName, sqlFunction, first );
  }
View Full Code Here

  @Override
    protected void beginFunctionTemplate(AST node, AST nameNode) {
    // NOTE for AGGREGATE both nodes are the same; for METHOD the first is the METHOD, the second is the
    //     METHOD_NAME
    FunctionNode functionNode = ( FunctionNode ) node;
    SQLFunction sqlFunction = functionNode.getSQLFunction();
    if ( sqlFunction == null ) {
      // if SQLFunction is null we just write the function out as it appears in the hql statement
      super.beginFunctionTemplate( node, nameNode );
    }
    else {
View Full Code Here

  }

  @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
      FunctionArguments functionArguments = ( FunctionArguments ) writer;
      writer = outputStack.removeFirst();
      out( sqlFunction.render( functionType, functionArguments.getArgs(), sessionFactory ) );
    }
  }
View Full Code Here

  public void testExpressionInFunction() throws Exception {
    assertTranslation( "from Animal an where an.bodyWeight > abs(3-5)" );
    assertTranslation( "from Animal an where an.bodyWeight > abs(3/5)" );
    assertTranslation( "from Animal an where an.bodyWeight > abs(3+5)" );
    assertTranslation( "from Animal an where an.bodyWeight > abs(3*5)" );
    SQLFunction concat = getSessionFactoryImplementor().getSqlFunctionRegistry().findSQLFunction( "concat");
    List list = new ArrayList(); list.add("'fat'"); list.add("'skinny'");
    assertTranslation( "from Animal an where an.description = " + concat.render(list, getSessionFactoryImplementor()) );
  }
View Full Code Here

TOP

Related Classes of org.hibernate.dialect.function.SQLFunction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.