Search in sources :

Example 1 with SybaseASE157Dialect

use of org.hibernate.dialect.SybaseASE157Dialect in project hibernate-orm by hibernate.

the class ClobLocatorTest method testBoundedClobLocatorAccess.

@Test
@SkipForDialect(value = TeradataDialect.class, jiraKey = "HHH-6637", comment = "Teradata requires locator to be used in same session where it was created/retrieved")
public void testBoundedClobLocatorAccess() throws Throwable {
    String original = buildString(CLOB_SIZE, 'x');
    String changed = buildString(CLOB_SIZE, 'y');
    String empty = "";
    Session s = openSession();
    s.beginTransaction();
    LobHolder entity = new LobHolder();
    entity.setClobLocator(s.getLobHelper().createClob(original));
    s.save(entity);
    s.getTransaction().commit();
    s.close();
    s = openSession();
    s.beginTransaction();
    entity = s.get(LobHolder.class, entity.getId());
    assertEquals(CLOB_SIZE, entity.getClobLocator().length());
    assertEquals(original, extractData(entity.getClobLocator()));
    s.getTransaction().commit();
    s.close();
    // test mutation via setting the new clob data...
    if (getDialect().supportsLobValueChangePropogation()) {
        s = openSession();
        s.beginTransaction();
        entity = (LobHolder) s.byId(LobHolder.class).with(LockOptions.UPGRADE).load(entity.getId());
        entity.getClobLocator().truncate(1);
        entity.getClobLocator().setString(1, changed);
        s.getTransaction().commit();
        s.close();
        s = openSession();
        s.beginTransaction();
        entity = (LobHolder) s.byId(LobHolder.class).with(LockOptions.UPGRADE).load(entity.getId());
        assertNotNull(entity.getClobLocator());
        assertEquals(CLOB_SIZE, entity.getClobLocator().length());
        assertEquals(changed, extractData(entity.getClobLocator()));
        entity.getClobLocator().truncate(1);
        entity.getClobLocator().setString(1, original);
        s.getTransaction().commit();
        s.close();
    }
    // test mutation via supplying a new clob locator instance...
    s = openSession();
    s.beginTransaction();
    entity = (LobHolder) s.byId(LobHolder.class).with(LockOptions.UPGRADE).load(entity.getId());
    assertNotNull(entity.getClobLocator());
    assertEquals(CLOB_SIZE, entity.getClobLocator().length());
    assertEquals(original, extractData(entity.getClobLocator()));
    entity.setClobLocator(s.getLobHelper().createClob(changed));
    s.getTransaction().commit();
    s.close();
    // test empty clob
    if (!(getDialect() instanceof SybaseASE157Dialect)) {
        // Skip for Sybase. HHH-6425
        s = openSession();
        s.beginTransaction();
        entity = s.get(LobHolder.class, entity.getId());
        assertEquals(CLOB_SIZE, entity.getClobLocator().length());
        assertEquals(changed, extractData(entity.getClobLocator()));
        entity.setClobLocator(s.getLobHelper().createClob(empty));
        s.getTransaction().commit();
        s.close();
        s = openSession();
        s.beginTransaction();
        entity = s.get(LobHolder.class, entity.getId());
        if (entity.getClobLocator() != null) {
            assertEquals(empty.length(), entity.getClobLocator().length());
            assertEquals(empty, extractData(entity.getClobLocator()));
        }
        s.delete(entity);
        s.getTransaction().commit();
        s.close();
    }
}
Also used : SybaseASE157Dialect(org.hibernate.dialect.SybaseASE157Dialect) Session(org.hibernate.Session) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Aggregations

Session (org.hibernate.Session)1 SybaseASE157Dialect (org.hibernate.dialect.SybaseASE157Dialect)1 SkipForDialect (org.hibernate.testing.SkipForDialect)1 Test (org.junit.Test)1