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();
}
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();
}
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));
}
}
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();
}
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();
}
Aggregations