Search in sources :

Example 16 with RequiresDialectFeature

use of org.hibernate.testing.RequiresDialectFeature in project hibernate-orm by hibernate.

the class CompositeUserTypeTest method testLessThanOperator.

/**
	 * Tests the {@code <} operator on composite types. As long as we don't support it, we need to throw an exception
	 * rather than create a random query.
	 */
@Test
@TestForIssue(jiraKey = "HHH-5946")
@RequiresDialectFeature(value = DialectChecks.DoesNotSupportRowValueConstructorSyntax.class)
public void testLessThanOperator() {
    final Session s = openSession();
    try {
        final Query q = s.createQuery("from Transaction where value < :amount");
        q.setParameter("amount", new MonetoryAmount(BigDecimal.ZERO, Currency.getInstance("EUR")));
        q.list();
    } catch (IllegalArgumentException e) {
        assertTyping(QuerySyntaxException.class, e.getCause());
    //expected
    } finally {
        s.close();
    }
}
Also used : Query(org.hibernate.Query) QuerySyntaxException(org.hibernate.hql.internal.ast.QuerySyntaxException) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature) TestForIssue(org.hibernate.testing.TestForIssue)

Example 17 with RequiresDialectFeature

use of org.hibernate.testing.RequiresDialectFeature in project hibernate-orm by hibernate.

the class CompositeUserTypeTest method testLessOrEqualOperator.

/**
	 * Tests the {@code <=} operator on composite types. As long as we don't support it, we need to throw an exception
	 * rather than create a random query.
	 */
@Test
@TestForIssue(jiraKey = "HHH-5946")
@RequiresDialectFeature(value = DialectChecks.DoesNotSupportRowValueConstructorSyntax.class)
public void testLessOrEqualOperator() {
    final Session s = openSession();
    try {
        final Query q = s.createQuery("from Transaction where value <= :amount");
        q.setParameter("amount", new MonetoryAmount(BigDecimal.ZERO, Currency.getInstance("USD")));
        q.list();
    } catch (IllegalArgumentException e) {
        assertTyping(QuerySyntaxException.class, e.getCause());
    //expected
    } finally {
        s.close();
    }
}
Also used : Query(org.hibernate.Query) QuerySyntaxException(org.hibernate.hql.internal.ast.QuerySyntaxException) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature) TestForIssue(org.hibernate.testing.TestForIssue)

Example 18 with RequiresDialectFeature

use of org.hibernate.testing.RequiresDialectFeature in project hibernate-orm by hibernate.

the class ExtraLazyTest method testSQLQuery.

@Test
@RequiresDialectFeature(DialectChecks.DoubleQuoteQuoting.class)
public void testSQLQuery() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    User gavin = new User("gavin", "secret");
    User turin = new User("turin", "tiger");
    gavin.getSession().put("foo", new SessionAttribute("foo", "foo bar baz"));
    gavin.getSession().put("bar", new SessionAttribute("bar", "foo bar baz 2"));
    s.persist(gavin);
    s.persist(turin);
    s.flush();
    s.clear();
    List results = s.getNamedQuery("userSessionData").setParameter("uname", "%in").list();
    assertEquals(results.size(), 2);
    gavin = (User) ((Object[]) results.get(0))[0];
    assertEquals(gavin.getName(), "gavin");
    assertEquals(gavin.getSession().size(), 2);
    s.createQuery("delete SessionAttribute").executeUpdate();
    s.createQuery("delete User").executeUpdate();
    t.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) List(java.util.List) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature)

Example 19 with RequiresDialectFeature

use of org.hibernate.testing.RequiresDialectFeature in project hibernate-orm by hibernate.

the class ASTParserLoadingTest method testSimpleSelectWithLimitAndOffset.

@Test
@RequiresDialectFeature(value = DialectChecks.SupportLimitAndOffsetCheck.class, comment = "dialect does not support offset and limit combo")
public void testSimpleSelectWithLimitAndOffset() throws Exception {
    // just checking correctness of param binding code...
    Session session = openSession();
    Transaction t = session.beginTransaction();
    session.createQuery("from Animal").setFirstResult(2).setMaxResults(1).list();
    t.commit();
    session.close();
}
Also used : Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature)

Example 20 with RequiresDialectFeature

use of org.hibernate.testing.RequiresDialectFeature in project hibernate-orm by hibernate.

the class BulkManipulationTest method testInsertWithGeneratedTimestampVersion.

@Test
@RequiresDialectFeature(value = DialectChecks.SupportsParametersInInsertSelectCheck.class, comment = "dialect does not support parameter in INSERT ... SELECT")
public void testInsertWithGeneratedTimestampVersion() {
    // Make sure the env supports bulk inserts with generated ids...
    if (!supportsBulkInsertIdGeneration(TimestampVersioned.class)) {
        SkipLog.reportSkip("bulk id generation not supported", "test bulk inserts with generated id and generated timestamp");
        return;
    }
    Session s = openSession();
    Transaction t = s.beginTransaction();
    TimestampVersioned entity = new TimestampVersioned("int-vers");
    s.save(entity);
    s.createQuery("select id, name, version from TimestampVersioned").list();
    t.commit();
    s.close();
    Long initialId = entity.getId();
    //Date initialVersion = entity.getVersion();
    s = openSession();
    t = s.beginTransaction();
    int count = s.createQuery("insert into TimestampVersioned ( name ) select name from TimestampVersioned").executeUpdate();
    t.commit();
    s.close();
    assertEquals("unexpected insertion count", 1, count);
    s = openSession();
    t = s.beginTransaction();
    TimestampVersioned created = (TimestampVersioned) s.createQuery("from TimestampVersioned where id <> :initialId").setLong("initialId", initialId.longValue()).uniqueResult();
    t.commit();
    s.close();
    assertNotNull(created.getVersion());
    //assertEquals( "version was not seeded", initialVersion, created.getVersion() );
    s = openSession();
    t = s.beginTransaction();
    s.createQuery("delete TimestampVersioned").executeUpdate();
    t.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature)

Aggregations

RequiresDialectFeature (org.hibernate.testing.RequiresDialectFeature)46 Test (org.junit.Test)45 Session (org.hibernate.Session)34 Transaction (org.hibernate.Transaction)17 TestForIssue (org.hibernate.testing.TestForIssue)10 EntityManager (javax.persistence.EntityManager)8 HashMap (java.util.HashMap)7 RequiresDialect (org.hibernate.testing.RequiresDialect)7 List (java.util.List)6 Callable (java.util.concurrent.Callable)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 Query (org.hibernate.Query)6 LockTimeoutException (javax.persistence.LockTimeoutException)5 ArrayList (java.util.ArrayList)4 QuerySyntaxException (org.hibernate.hql.internal.ast.QuerySyntaxException)4 SkipForDialect (org.hibernate.testing.SkipForDialect)4 Query (javax.persistence.Query)3 BigDecimal (java.math.BigDecimal)2 Map (java.util.Map)2 QueryTimeoutException (javax.persistence.QueryTimeoutException)2