Search in sources :

Example 1 with QuerySyntaxException

use of org.hibernate.hql.internal.ast.QuerySyntaxException in project hibernate-orm by hibernate.

the class AnyTypeTest method testJoinFetchOfAnAnyTypeAttribute.

@Test
public void testJoinFetchOfAnAnyTypeAttribute() {
    // Query translator should dis-allow join fetching of an <any/> mapping.  Let's make sure it does...
    Session session = openSession();
    try {
        session.beginTransaction();
        session.createQuery("select p from Person p join fetch p.data").list();
        session.getTransaction().commit();
    } catch (IllegalArgumentException e) {
        //expected
        assertTyping(QuerySyntaxException.class, e.getCause());
        session.getTransaction().rollback();
    } catch (QuerySyntaxException qe) {
    //expected
    } finally {
        session.close();
    }
}
Also used : QuerySyntaxException(org.hibernate.hql.internal.ast.QuerySyntaxException) Session(org.hibernate.Session) Test(org.junit.Test)

Example 2 with QuerySyntaxException

use of org.hibernate.hql.internal.ast.QuerySyntaxException in project hibernate-orm by hibernate.

the class HQLTest method testExceptions.

@Test
public void testExceptions() throws Exception {
    DetailedSemanticException dse = new DetailedSemanticException("test");
    dse.printStackTrace();
    dse.printStackTrace(new PrintWriter(new StringWriter()));
    QuerySyntaxException qse = QuerySyntaxException.convert(new RecognitionException("test"), "from bozo b where b.clown = true");
    assertNotNull(qse.getMessage());
}
Also used : StringWriter(java.io.StringWriter) QuerySyntaxException(org.hibernate.hql.internal.ast.QuerySyntaxException) DetailedSemanticException(org.hibernate.hql.internal.ast.DetailedSemanticException) RecognitionException(antlr.RecognitionException) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 3 with QuerySyntaxException

use of org.hibernate.hql.internal.ast.QuerySyntaxException in project hibernate-orm by hibernate.

the class HQLTest method testInvalidHql.

@Test
@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" })
public void testInvalidHql() throws Exception {
    Exception newException = compileBadHql("from Animal foo where an.bodyWeight > 10", false);
    assertTrue("Wrong exception type!", newException instanceof QuerySyntaxException);
    newException = compileBadHql("select an.name from Animal foo", false);
    assertTrue("Wrong exception type!", newException instanceof QuerySyntaxException);
    newException = compileBadHql("from Animal foo where an.verybogus > 10", false);
    assertTrue("Wrong exception type!", newException instanceof QuerySyntaxException);
    newException = compileBadHql("select an.boguspropertyname from Animal foo", false);
    assertTrue("Wrong exception type!", newException instanceof QuerySyntaxException);
    newException = compileBadHql("select an.name", false);
    assertTrue("Wrong exception type!", newException instanceof QuerySyntaxException);
    newException = compileBadHql("from Animal an where (((an.bodyWeight > 10 and an.bodyWeight < 100)) or an.bodyWeight is null", false);
    assertTrue("Wrong exception type!", newException instanceof QuerySyntaxException);
    newException = compileBadHql("from Animal an where an.bodyWeight is null where an.bodyWeight is null", false);
    assertTrue("Wrong exception type!", newException instanceof QuerySyntaxException);
    newException = compileBadHql("from where name='foo'", false);
    assertTrue("Wrong exception type!", newException instanceof QuerySyntaxException);
    newException = compileBadHql("from NonexistentClass where name='foo'", false);
    assertTrue("Wrong exception type!", newException instanceof QuerySyntaxException);
    newException = compileBadHql("select new FOO_BOGUS_Animal(an.description, an.bodyWeight) from Animal an", false);
    assertTrue("Wrong exception type!", newException instanceof QuerySyntaxException);
    newException = compileBadHql("select new Animal(an.description, an.bodyWeight, 666) from Animal an", false);
    assertTrue("Wrong exception type!", newException instanceof QuerySyntaxException);
}
Also used : QuerySyntaxException(org.hibernate.hql.internal.ast.QuerySyntaxException) RecognitionException(antlr.RecognitionException) QuerySyntaxException(org.hibernate.hql.internal.ast.QuerySyntaxException) DetailedSemanticException(org.hibernate.hql.internal.ast.DetailedSemanticException) QueryException(org.hibernate.QueryException) Test(org.junit.Test)

Example 4 with QuerySyntaxException

use of org.hibernate.hql.internal.ast.QuerySyntaxException in project hibernate-orm by hibernate.

the class BinaryLogicOperatorNode method mutateRowValueConstructorSyntax.

/**
	 * Mutate the subtree relating to a row-value-constructor to instead use
	 * a series of ANDed predicates.  This allows multi-column type comparisons
	 * and explicit row-value-constructor syntax even on databases which do
	 * not support row-value-constructor.
	 * <p/>
	 * For example, here we'd mutate "... where (col1, col2) = ('val1', 'val2) ..." to
	 * "... where col1 = 'val1' and col2 = 'val2' ..."
	 *
	 * @param valueElements The number of elements in the row value constructor list.
	 */
private void mutateRowValueConstructorSyntax(int valueElements) {
    // mutation depends on the types of nodes involved...
    int comparisonType = getType();
    String comparisonText = getText();
    switch(comparisonType) {
        case HqlSqlTokenTypes.EQ:
            setType(HqlSqlTokenTypes.AND);
            setText("AND");
            break;
        case HqlSqlTokenTypes.NE:
            setType(HqlSqlTokenTypes.OR);
            setText("OR");
            break;
        default:
            throw new QuerySyntaxException(comparisonText + " operator not supported on composite types.");
    }
    String[] lhsElementTexts = extractMutationTexts(getLeftHandOperand(), valueElements);
    String[] rhsElementTexts = extractMutationTexts(getRightHandOperand(), valueElements);
    ParameterSpecification lhsEmbeddedCompositeParameterSpecification = getLeftHandOperand() == null || (!ParameterNode.class.isInstance(getLeftHandOperand())) ? null : ((ParameterNode) getLeftHandOperand()).getHqlParameterSpecification();
    ParameterSpecification rhsEmbeddedCompositeParameterSpecification = getRightHandOperand() == null || (!ParameterNode.class.isInstance(getRightHandOperand())) ? null : ((ParameterNode) getRightHandOperand()).getHqlParameterSpecification();
    translate(valueElements, comparisonType, comparisonText, lhsElementTexts, rhsElementTexts, lhsEmbeddedCompositeParameterSpecification, rhsEmbeddedCompositeParameterSpecification, this);
}
Also used : ParameterSpecification(org.hibernate.param.ParameterSpecification) QuerySyntaxException(org.hibernate.hql.internal.ast.QuerySyntaxException)

Aggregations

QuerySyntaxException (org.hibernate.hql.internal.ast.QuerySyntaxException)4 Test (org.junit.Test)3 RecognitionException (antlr.RecognitionException)2 DetailedSemanticException (org.hibernate.hql.internal.ast.DetailedSemanticException)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 QueryException (org.hibernate.QueryException)1 Session (org.hibernate.Session)1 ParameterSpecification (org.hibernate.param.ParameterSpecification)1