Search in sources :

Example 26 with RequiresDialectFeature

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

the class BlobLocatorTest method testUnboundedBlobLocatorAccess.

@Test
@RequiresDialectFeature(value = DialectChecks.SupportsUnboundedLobLocatorMaterializationCheck.class, comment = "database/driver does not support materializing a LOB locator outside the owning transaction")
public void testUnboundedBlobLocatorAccess() throws Throwable {
    // Note: unbounded mutation of the underlying lob data is completely
    // unsupported; most databases would not allow such a construct anyway.
    // Thus here we are only testing materialization...
    byte[] original = buildByteArray(BLOB_SIZE, true);
    Session s = openSession();
    s.beginTransaction();
    LobHolder entity = new LobHolder();
    entity.setBlobLocator(Hibernate.getLobCreator(s).createBlob(original));
    s.save(entity);
    s.getTransaction().commit();
    s.close();
    // load the entity with the clob locator, and close the session/transaction;
    // at that point it is unbounded...
    s = openSession();
    s.beginTransaction();
    entity = s.get(LobHolder.class, entity.getId());
    s.getTransaction().commit();
    s.close();
    Assert.assertEquals(BLOB_SIZE, entity.getBlobLocator().length());
    assertEquals(original, extractData(entity.getBlobLocator()));
    s = openSession();
    s.beginTransaction();
    s.delete(entity);
    s.getTransaction().commit();
    s.close();
}
Also used : Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature)

Example 27 with RequiresDialectFeature

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

the class OnDeleteTest method testJoinedSubclass.

@Test
@RequiresDialectFeature(value = DialectChecks.SupportsCircularCascadeDeleteCheck.class, comment = "db/dialect does not support circular cascade delete constraints")
public void testJoinedSubclass() {
    Statistics statistics = sessionFactory().getStatistics();
    statistics.clear();
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Salesperson mark = new Salesperson();
    mark.setName("Mark");
    mark.setTitle("internal sales");
    mark.setSex('M');
    mark.setAddress("buckhead");
    mark.setZip("30305");
    mark.setCountry("USA");
    Person joe = new Person();
    joe.setName("Joe");
    joe.setAddress("San Francisco");
    joe.setZip("XXXXX");
    joe.setCountry("USA");
    joe.setSex('M');
    joe.setSalesperson(mark);
    mark.getCustomers().add(joe);
    s.save(mark);
    t.commit();
    assertEquals(statistics.getEntityInsertCount(), 2);
    assertEquals(statistics.getPrepareStatementCount(), 5);
    statistics.clear();
    t = s.beginTransaction();
    s.delete(mark);
    t.commit();
    assertEquals(statistics.getEntityDeleteCount(), 2);
    if (getDialect().supportsCascadeDelete()) {
        assertEquals(statistics.getPrepareStatementCount(), 1);
    }
    t = s.beginTransaction();
    List names = s.createQuery("select name from Person").list();
    assertTrue(names.isEmpty());
    t.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) List(java.util.List) Statistics(org.hibernate.stat.Statistics) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature)

Example 28 with RequiresDialectFeature

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

the class PaginationTest method testLimitWithExpreesionAndFetchJoin.

/**
	 * @author Piotr Findeisen <piotr.findeisen@gmail.com>
	 */
@Test
@TestForIssue(jiraKey = "HHH-951")
@RequiresDialectFeature(value = DialectChecks.SupportLimitCheck.class, comment = "Dialect does not support limit")
public void testLimitWithExpreesionAndFetchJoin() {
    Session session = openSession();
    session.beginTransaction();
    String hql = "SELECT b, 1 FROM DataMetaPoint b inner join fetch b.dataPoint dp";
    session.createQuery(hql).setMaxResults(3).list();
    HQLQueryPlan queryPlan = new HQLQueryPlan(hql, false, Collections.EMPTY_MAP, sessionFactory());
    String sqlQuery = queryPlan.getTranslators()[0].collectSqlStrings().get(0);
    session.getTransaction().commit();
    session.close();
    Matcher matcher = Pattern.compile("(?is)\\b(?<column>\\w+\\.\\w+)\\s+as\\s+(?<alias>\\w+)\\b.*\\k<column>\\s+as\\s+\\k<alias>").matcher(sqlQuery);
    if (matcher.find()) {
        fail(format("Column %s mapped to alias %s twice in generated SQL: %s", matcher.group("column"), matcher.group("alias"), sqlQuery));
    }
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) Matcher(java.util.regex.Matcher) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature) TestForIssue(org.hibernate.testing.TestForIssue)

Example 29 with RequiresDialectFeature

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

the class PaginationTest method testLimit.

@Test
@RequiresDialectFeature(value = DialectChecks.SupportLimitCheck.class, comment = "Dialect does not support limit")
public void testLimit() {
    prepareTestData();
    Session session = openSession();
    session.beginTransaction();
    int count;
    count = generateBaseHQLQuery(session).setMaxResults(5).list().size();
    assertEquals(5, count);
    count = generateBaseCriteria(session).setMaxResults(18).list().size();
    assertEquals(18, count);
    count = generateBaseSQLQuery(session).setMaxResults(13).list().size();
    assertEquals(13, count);
    session.getTransaction().commit();
    session.close();
    cleanupTestData();
}
Also used : Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature)

Example 30 with RequiresDialectFeature

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

the class QueryCacheTest method testCaseInsensitiveComparison.

@Test
@RequiresDialectFeature(value = DialectChecks.CaseSensitiveCheck.class, comment = "i.name='widget' should not match on case sensitive database.")
public void testCaseInsensitiveComparison() {
    Session s = openSession();
    s.beginTransaction();
    Item i = new Item();
    i.setName("Widget");
    i.setDescription("A really top-quality, full-featured widget.");
    s.save(i);
    s.getTransaction().commit();
    s.close();
    s = openSession();
    s.beginTransaction();
    List result = s.createQuery(queryString).list();
    assertEquals(1, result.size());
    i = (Item) s.get(Item.class, new Long(i.getId()));
    assertEquals(i.getName(), "Widget");
    s.delete(i);
    s.getTransaction().commit();
    s.close();
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) 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