Package org.hibernate.hql.ast

Examples of org.hibernate.hql.ast.QueryTranslatorImpl$JavaConstantConverter


    return createNewQueryTranslator( hql, replacements, scalar, factory );
  }

  private QueryTranslatorImpl createNewQueryTranslator(String hql, Map replacements, boolean scalar, SessionFactoryImplementor factory) {
    QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
    QueryTranslatorImpl newQueryTranslator = ( QueryTranslatorImpl ) ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, factory );
    newQueryTranslator.compile( replacements, scalar );
    return newQueryTranslator;
  }
View Full Code Here


    return new FunctionalTestClassTestSuite( CriteriaClassicAggregationReturnTest.class );
  }

  public void testClassicHQLAggregationReturnTypes() {
    // EJB3: COUNT returns Long
    QueryTranslatorImpl translator = createNewQueryTranslator( "select count(*) from Human h", sfi() );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.INTEGER, translator.getReturnTypes()[0] );

    translator = createNewQueryTranslator( "select count(h.heightInches) from Human h", sfi() );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.INTEGER, translator.getReturnTypes()[0] );

    // MAX, MIN return the type of the state-field to which they are applied.
    translator = createNewQueryTranslator( "select max(h.heightInches) from Human h", sfi() );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );

    translator = createNewQueryTranslator( "select max(h.id) from Human h", sfi() );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.LONG, translator.getReturnTypes()[0] );

    // AVG returns Float integrals, and otherwise the field type.
    translator = createNewQueryTranslator( "select avg(h.heightInches) from Human h", sfi() );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );

    translator = createNewQueryTranslator( "select avg(h.id) from Human h", sfi() );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.FLOAT, translator.getReturnTypes()[0] );

    translator = createNewQueryTranslator( "select avg(h.bigIntegerValue) from Human h", sfi() );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.BIG_INTEGER, translator.getReturnTypes()[0] );

        // SUM returns underlying type sum
       translator = createNewQueryTranslator( "select sum(h.id) from Human h", sfi() );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.LONG, translator.getReturnTypes()[0] );

    translator = createNewQueryTranslator( "select sum(h.intValue) from Human h", sfi() );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.INTEGER, translator.getReturnTypes()[0] );

    translator = createNewQueryTranslator( "select sum(h.heightInches) from Human h", sfi() );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );

    translator = createNewQueryTranslator( "select sum(h.floatValue) from Human h", sfi() );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.FLOAT, translator.getReturnTypes()[0] );

    translator = createNewQueryTranslator( "select sum(h.bigIntegerValue) from Human h", sfi() );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.BIG_INTEGER, translator.getReturnTypes()[0] );

    translator = createNewQueryTranslator( "select sum(h.bigDecimalValue) from Human h", sfi() );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.BIG_DECIMAL, translator.getReturnTypes()[0] );

    // special case to test classicquery special case handling of count(*)
    QueryTranslator oldQueryTranslator = null;
    String hql = "select count(*) from Human h";
    QueryTranslatorFactory classic = new ClassicQueryTranslatorFactory();
View Full Code Here

  public boolean createSchema() {
    return false;
  }

  public void testEjb3PositionalParameters() throws Exception {
    QueryTranslatorImpl qt = compile( "from Animal a where a.bodyWeight = ?1" );
    AST ast = ( AST ) qt.getSqlAST();

    // make certain that the ejb3-positional param got recognized as a named param
    List namedParams = ASTUtil.collectChildren(
            ast,
            new ASTUtil.FilterPredicate() {
View Full Code Here

    return new FunctionalTestClassTestSuite( CriteriaHQLAlignmentTest.class );
  }

  public void testHQLAggregationReturnType() {
    // EJB3: COUNT returns Long
    QueryTranslatorImpl translator = createNewQueryTranslator( "select count(*) from Human h" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.LONG, translator.getReturnTypes()[0] );
   
    translator = createNewQueryTranslator( "select count(h.heightInches) from Human h" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.LONG, translator.getReturnTypes()[0] );
       
    // MAX, MIN return the type of the state-field to which they are applied.
    translator = createNewQueryTranslator( "select max(h.heightInches) from Human h" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );
   
    translator = createNewQueryTranslator( "select max(h.id) from Human h" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.LONG, translator.getReturnTypes()[0] );
   
    // AVG returns Double.
    translator = createNewQueryTranslator( "select avg(h.heightInches) from Human h" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );
   
    translator = createNewQueryTranslator( "select avg(h.id) from Human h" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );
   
    translator = createNewQueryTranslator( "select avg(h.bigIntegerValue) from Human h" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );
   
        // SUM returns Long when applied to state-fields of integral types (other than BigInteger);
       translator = createNewQueryTranslator( "select sum(h.id) from Human h" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.LONG, translator.getReturnTypes()[0] );
   
    translator = createNewQueryTranslator( "select sum(h.intValue) from Human h" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.LONG, translator.getReturnTypes()[0] );
   
    // SUM returns Double when applied to state-fields of floating point types;
    translator = createNewQueryTranslator( "select sum(h.heightInches) from Human h" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );

    translator = createNewQueryTranslator( "select sum(h.floatValue) from Human h" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );
   
      // SUM returns BigInteger when applied to state-fields of type BigInteger
    translator = createNewQueryTranslator( "select sum(h.bigIntegerValue) from Human h" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.BIG_INTEGER, translator.getReturnTypes()[0] );
   
    // SUM and BigDecimal when applied to state-fields of type BigDecimal.
    translator = createNewQueryTranslator( "select sum(h.bigDecimalValue) from Human h" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.BIG_DECIMAL, translator.getReturnTypes()[0] );

    // special case to test classicquery special case handling of count(*)
    QueryTranslator oldQueryTranslator = null;
    String hql = "select count(*) from Human h";
    QueryTranslatorFactory classic = new ClassicQueryTranslatorFactory();
View Full Code Here

    }

    public void testRowValueConstructorSyntaxInInList() {
      if (!getDialect().supportsRowValueConstructorSyntaxInInList())
        return;
    QueryTranslatorImpl translator = createNewQueryTranslator("from LineItem l where l.id in (?)");
    assertInExist("'in' should be translated to 'and'", false, translator);
    translator = createNewQueryTranslator("from LineItem l where l.id in ?");
    assertInExist("'in' should be translated to 'and'", false, translator);
    translator = createNewQueryTranslator("from LineItem l where l.id in (('a1',1,'b1'),('a2',2,'b2'))");
    assertInExist("'in' should be translated to 'and'", false, translator);
View Full Code Here

  public void testEmptyInListFailureExpected() {
    assertTranslation( "select a from Animal a where a.description in ()" );
  }

  public void testDateTimeArithmeticReturnTypesAndParameterGuessing() {
    QueryTranslatorImpl translator = createNewQueryTranslator( "select o.orderDate - o.orderDate from Order o" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );
    translator = createNewQueryTranslator( "select o.orderDate + 2 from Order o" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.CALENDAR_DATE, translator.getReturnTypes()[0] );
    translator = createNewQueryTranslator( "select o.orderDate -2 from Order o" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.CALENDAR_DATE, translator.getReturnTypes()[0] );

    translator = createNewQueryTranslator( "from Order o where o.orderDate > ?" );
    assertEquals( "incorrect expected param type", Hibernate.CALENDAR_DATE, translator.getParameterTranslations().getOrdinalParameterExpectedType( 1 ) );

    translator = createNewQueryTranslator( "select o.orderDate + ? from Order o" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.CALENDAR_DATE, translator.getReturnTypes()[0] );
    assertEquals( "incorrect expected param type", Hibernate.DOUBLE, translator.getParameterTranslations().getOrdinalParameterExpectedType( 1 ) );

  }
View Full Code Here

  public void testEmptyInListFailureExpected() {
    assertTranslation( "select a from Animal a where a.description in ()" );
  }

  public void testDateTimeArithmeticReturnTypesAndParameterGuessing() {
    QueryTranslatorImpl translator = createNewQueryTranslator( "select o.orderDate - o.orderDate from Order o" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );
    translator = createNewQueryTranslator( "select o.orderDate + 2 from Order o" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.CALENDAR_DATE, translator.getReturnTypes()[0] );
    translator = createNewQueryTranslator( "select o.orderDate -2 from Order o" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.CALENDAR_DATE, translator.getReturnTypes()[0] );

    translator = createNewQueryTranslator( "from Order o where o.orderDate > ?" );
    assertEquals( "incorrect expected param type", Hibernate.CALENDAR_DATE, translator.getParameterTranslations().getOrdinalParameterExpectedType( 1 ) );

    translator = createNewQueryTranslator( "select o.orderDate + ? from Order o" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.CALENDAR_DATE, translator.getReturnTypes()[0] );
    assertEquals( "incorrect expected param type", Hibernate.DOUBLE, translator.getParameterTranslations().getOrdinalParameterExpectedType( 1 ) );

  }
View Full Code Here

    return createNewQueryTranslator( hql, replacements, scalar, factory );
  }

  private QueryTranslatorImpl createNewQueryTranslator(String hql, Map replacements, boolean scalar, SessionFactoryImplementor factory) {
    QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
    QueryTranslatorImpl newQueryTranslator = ( QueryTranslatorImpl ) ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, factory );
    newQueryTranslator.compile( replacements, scalar );
    return newQueryTranslator;
  }
View Full Code Here

  public boolean createSchema() {
    return false;
  }

  public void testEjb3PositionalParameters() throws Exception {
    QueryTranslatorImpl qt = compile( "from Animal a where a.bodyWeight = ?1" );
    AST ast = ( AST ) qt.getSqlAST();

    // make certain that the ejb3-positional param got recognized as a named param
    List namedParams = ASTUtil.collectChildren(
            ast,
            new ASTUtil.FilterPredicate() {
View Full Code Here

  public void testEmptyInListFailureExpected() {
    assertTranslation( "select a from Animal a where a.description in ()" );
  }

  public void testDateTimeArithmeticReturnTypesAndParameterGuessing() {
    QueryTranslatorImpl translator = createNewQueryTranslator( "select o.orderDate - o.orderDate from Order o" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );
    translator = createNewQueryTranslator( "select o.orderDate + 2 from Order o" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.CALENDAR_DATE, translator.getReturnTypes()[0] );
    translator = createNewQueryTranslator( "select o.orderDate -2 from Order o" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.CALENDAR_DATE, translator.getReturnTypes()[0] );

    translator = createNewQueryTranslator( "from Order o where o.orderDate > ?" );
    assertEquals( "incorrect expected param type", Hibernate.CALENDAR_DATE, translator.getParameterTranslations().getOrdinalParameterExpectedType( 1 ) );

    translator = createNewQueryTranslator( "select o.orderDate + ? from Order o" );
    assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
    assertEquals( "incorrect return type", Hibernate.CALENDAR_DATE, translator.getReturnTypes()[0] );
    assertEquals( "incorrect expected param type", Hibernate.DOUBLE, translator.getParameterTranslations().getOrdinalParameterExpectedType( 1 ) );

  }
View Full Code Here

TOP

Related Classes of org.hibernate.hql.ast.QueryTranslatorImpl$JavaConstantConverter

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.