Search in sources :

Example 21 with RequiresDialectFeature

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

the class BulkManipulationTest method testSimpleDeleteOnAnimal.

@Test
@RequiresDialectFeature(value = DialectChecks.HasSelfReferentialForeignKeyBugCheck.class, comment = "self referential FK bug")
public void testSimpleDeleteOnAnimal() {
    TestData data = new TestData();
    data.prepare();
    Session s = openSession();
    Transaction t = s.beginTransaction();
    int count = s.createQuery("delete from Animal as a where a.id = :id").setLong("id", data.polliwog.getId().longValue()).executeUpdate();
    assertEquals("Incorrect delete count", 1, count);
    count = s.createQuery("delete Animal where id = :id").setLong("id", data.catepillar.getId().longValue()).executeUpdate();
    assertEquals("incorrect delete count", 1, count);
    if (getDialect().supportsSubqueryOnMutatingTable()) {
        count = s.createQuery("delete from User u where u not in (select u from User u)").executeUpdate();
        assertEquals(0, count);
    }
    count = s.createQuery("delete Animal a").executeUpdate();
    assertEquals("Incorrect delete count", 4, count);
    List list = s.createQuery("select a from Animal as a").list();
    assertTrue("table not empty", list.isEmpty());
    t.commit();
    s.close();
    data.cleanup();
}
Also used : Transaction(org.hibernate.Transaction) ArrayList(java.util.ArrayList) List(java.util.List) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature)

Example 22 with RequiresDialectFeature

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

the class ScrollableCollectionFetchingTest method testScrollingJoinFetchesForward.

@Test
@RequiresDialectFeature(value = DialectChecks.SupportsResultSetPositioningOnForwardOnlyCursorCheck.class, comment = "Driver does not support result set positioning  methods on forward-only cursors")
public void testScrollingJoinFetchesForward() {
    TestData data = new TestData();
    data.prepare();
    Session s = openSession();
    Transaction txn = s.beginTransaction();
    ScrollableResults results = s.createQuery("from Animal a left join fetch a.offspring where a.description like :desc order by a.id").setString("desc", "root%").scroll(ScrollMode.FORWARD_ONLY);
    int counter = 0;
    while (results.next()) {
        counter++;
        Animal animal = (Animal) results.get(0);
        checkResult(animal);
    }
    assertEquals("unexpected result count", 2, counter);
    txn.commit();
    s.close();
    data.cleanup();
}
Also used : Transaction(org.hibernate.Transaction) ScrollableResults(org.hibernate.ScrollableResults) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature)

Example 23 with RequiresDialectFeature

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

the class HQLTest method testRowValueConstructorSyntaxInInList.

@Test
@RequiresDialectFeature(DialectChecks.SupportsRowValueConstructorSyntaxInInListCheck.class)
public void testRowValueConstructorSyntaxInInList() {
    QueryTranslatorImpl translator = createNewQueryTranslator("from LineItem l where l.id in (?)");
    assertInExist(" 'in' should be kept, since the dialect supports this syntax", true, translator);
    translator = createNewQueryTranslator("from LineItem l where l.id in ?");
    assertInExist(" 'in' should be kept, since the dialect supports this syntax", true, translator);
    translator = createNewQueryTranslator("from LineItem l where l.id in (('a1',1,'b1'),('a2',2,'b2'))");
    assertInExist(" 'in' should be kept, since the dialect supports this syntax", true, translator);
    translator = createNewQueryTranslator("from Animal a where a.id in (?)");
    assertInExist("only translated tuple has 'in' syntax", true, translator);
    translator = createNewQueryTranslator("from Animal a where a.id in ?");
    assertInExist("only translated tuple has 'in' syntax", true, translator);
    translator = createNewQueryTranslator("from LineItem l where l.id in (select a1 from Animal a1 left join a1.offspring o where a1.id = 1)");
    assertInExist("do not translate sub-queries", true, translator);
}
Also used : QueryTranslatorImpl(org.hibernate.hql.internal.ast.QueryTranslatorImpl) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature)

Example 24 with RequiresDialectFeature

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

the class InterfaceProxyTest method testInterfaceProxies.

@Test
@RequiresDialectFeature(value = DialectChecks.SupportsExpectedLobUsagePattern.class, comment = "database/driver does not support expected LOB usage pattern")
public void testInterfaceProxies() {
    Session s = openSession(new DocumentInterceptor());
    Transaction t = s.beginTransaction();
    Document d = new DocumentImpl();
    d.setName("Hibernate in Action");
    d.setContent(s.getLobHelper().createBlob("blah blah blah".getBytes()));
    Long did = (Long) s.save(d);
    SecureDocument d2 = new SecureDocumentImpl();
    d2.setName("Secret");
    d2.setContent(s.getLobHelper().createBlob("wxyz wxyz".getBytes()));
    // SybaseASE15Dialect only allows 7-bits in a byte to be inserted into a tinyint 
    // column (0 <= val < 128)		
    d2.setPermissionBits((byte) 127);
    d2.setOwner("gavin");
    Long d2id = (Long) s.save(d2);
    t.commit();
    s.close();
    s = openSession(new DocumentInterceptor());
    t = s.beginTransaction();
    d = (Document) s.load(ItemImpl.class, did);
    assertEquals(did, d.getId());
    assertEquals("Hibernate in Action", d.getName());
    assertNotNull(d.getContent());
    d2 = (SecureDocument) s.load(ItemImpl.class, d2id);
    assertEquals(d2id, d2.getId());
    assertEquals("Secret", d2.getName());
    assertNotNull(d2.getContent());
    s.clear();
    d = (Document) s.load(DocumentImpl.class, did);
    assertEquals(did, d.getId());
    assertEquals("Hibernate in Action", d.getName());
    assertNotNull(d.getContent());
    d2 = (SecureDocument) s.load(SecureDocumentImpl.class, d2id);
    assertEquals(d2id, d2.getId());
    assertEquals("Secret", d2.getName());
    assertNotNull(d2.getContent());
    assertEquals("gavin", d2.getOwner());
    //s.clear();
    d2 = (SecureDocument) s.load(SecureDocumentImpl.class, did);
    assertEquals(did, d2.getId());
    assertEquals("Hibernate in Action", d2.getName());
    assertNotNull(d2.getContent());
    try {
        //CCE
        d2.getOwner();
        assertFalse(true);
    } catch (ClassCastException cce) {
    //correct
    }
    s.createQuery("delete ItemImpl").executeUpdate();
    t.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature)

Example 25 with RequiresDialectFeature

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

the class CustomSQLTest method testInsert.

@Test
@RequiresDialectFeature(NonIdentityGeneratorChecker.class)
@SkipForDialect(value = { PostgreSQL81Dialect.class, PostgreSQLDialect.class }, jiraKey = "HHH-6704")
public void testInsert() throws HibernateException, SQLException {
    Session s = openSession();
    s.beginTransaction();
    Role p = new Role();
    p.setName("Patient");
    s.save(p);
    s.getTransaction().commit();
    s.close();
    sessionFactory().getCache().evictEntityRegion(Role.class);
    s = openSession();
    s.beginTransaction();
    Role p2 = (Role) s.get(Role.class, Long.valueOf(p.getId()));
    assertNotSame(p, p2);
    assertEquals(p2.getId(), p.getId());
    assertTrue(p2.getName().equalsIgnoreCase(p.getName()));
    s.delete(p2);
    s.getTransaction().commit();
    s.close();
}
Also used : Session(org.hibernate.Session) SkipForDialect(org.hibernate.testing.SkipForDialect) 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