Search in sources :

Example 1 with ClobTestEntity

use of org.apache.cayenne.testdo.lob.ClobTestEntity in project cayenne by apache.

the class SelectQueryClobIT method testSelectEqualsClob.

@Test
public void testSelectEqualsClob() throws Exception {
    if (accessStackAdapter.supportsLobComparisons()) {
        createClobDataSet();
        SelectQuery<ClobTestEntity> query = new SelectQuery<ClobTestEntity>(ClobTestEntity.class);
        Expression qual = ExpressionFactory.matchExp("clobCol", "clob1");
        query.setQualifier(qual);
        List<?> objects = context.performQuery(query);
        assertEquals(1, objects.size());
    }
}
Also used : Expression(org.apache.cayenne.exp.Expression) ClobTestEntity(org.apache.cayenne.testdo.lob.ClobTestEntity) Test(org.junit.Test)

Example 2 with ClobTestEntity

use of org.apache.cayenne.testdo.lob.ClobTestEntity in project cayenne by apache.

the class DataContextClobIT method runWithClobSize.

protected void runWithClobSize(int sizeBytes) throws Exception {
    // insert new clob
    ClobTestEntity clobObj1 = context.newObject(ClobTestEntity.class);
    // init CLOB of a specified size
    if (sizeBytes == 0) {
        clobObj1.setClobCol("");
    } else {
        byte[] bytes = new byte[sizeBytes];
        for (int i = 0; i < sizeBytes; i++) {
            bytes[i] = (byte) (65 + (50 + i) % 50);
        }
        clobObj1.setClobCol(new String(bytes));
    }
    context.commitChanges();
    // read the CLOB in the new context
    List<?> objects2 = context2.performQuery(new SelectQuery(ClobTestEntity.class));
    assertEquals(1, objects2.size());
    ClobTestEntity clobObj2 = (ClobTestEntity) objects2.get(0);
    assertEquals(clobObj1.getClobCol(), clobObj2.getClobCol());
    // update and save Clob
    clobObj2.setClobCol("updated rather small clob...");
    context2.commitChanges();
    // read into yet another context and check for changes
    List<?> objects3 = context3.performQuery(new SelectQuery(ClobTestEntity.class));
    assertEquals(1, objects3.size());
    ClobTestEntity clobObj3 = (ClobTestEntity) objects3.get(0);
    assertEquals(clobObj2.getClobCol(), clobObj3.getClobCol());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClobTestEntity(org.apache.cayenne.testdo.lob.ClobTestEntity)

Example 3 with ClobTestEntity

use of org.apache.cayenne.testdo.lob.ClobTestEntity in project cayenne by apache.

the class DataContextClobIT method testNullClob.

@Test
public void testNullClob() throws Exception {
    if (skipTests()) {
        return;
    }
    // insert new clob
    context.newObject(ClobTestEntity.class);
    context.commitChanges();
    // read the CLOB in the new context
    List<?> objects2 = context2.performQuery(new SelectQuery(ClobTestEntity.class));
    assertEquals(1, objects2.size());
    ClobTestEntity clobObj2 = (ClobTestEntity) objects2.get(0);
    assertNull("Expected null, got: '" + clobObj2.getClobCol() + "'", clobObj2.getClobCol());
    // update and save Clob
    clobObj2.setClobCol("updated rather small clob...");
    context2.commitChanges();
    // read into yet another context and check for changes
    List<?> objects3 = context3.performQuery(new SelectQuery(ClobTestEntity.class));
    assertEquals(1, objects3.size());
    ClobTestEntity clobObj3 = (ClobTestEntity) objects3.get(0);
    assertEquals(clobObj2.getClobCol(), clobObj3.getClobCol());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClobTestEntity(org.apache.cayenne.testdo.lob.ClobTestEntity) Test(org.junit.Test)

Example 4 with ClobTestEntity

use of org.apache.cayenne.testdo.lob.ClobTestEntity in project cayenne by apache.

the class SelectActionIT method insertClobDb.

protected void insertClobDb() {
    ClobTestEntity obj;
    for (int i = 0; i < 80; i++) {
        if (i < 20) {
            obj = (ClobTestEntity) context.newObject("ClobTestEntity");
            obj.setClobCol("a1" + i);
            insetrClobRel(obj);
        } else {
            obj = (ClobTestEntity) context.newObject("ClobTestEntity");
            obj.setClobCol("a2");
            insetrClobRel(obj);
        }
    }
    context.commitChanges();
}
Also used : ClobTestEntity(org.apache.cayenne.testdo.lob.ClobTestEntity)

Example 5 with ClobTestEntity

use of org.apache.cayenne.testdo.lob.ClobTestEntity in project cayenne by apache.

the class SelectQueryClobIT method testSelectLikeIgnoreCaseClob.

/**
 * Test how "like ignore case" works when using uppercase parameter.
 */
@Test
public void testSelectLikeIgnoreCaseClob() throws Exception {
    if (accessStackAdapter.supportsLobs()) {
        createClobDataSet();
        SelectQuery<ClobTestEntity> query = new SelectQuery<ClobTestEntity>(ClobTestEntity.class);
        Expression qual = ExpressionFactory.likeIgnoreCaseExp("clobCol", "clob%");
        query.setQualifier(qual);
        List<?> objects = context.performQuery(query);
        assertEquals(2, objects.size());
    }
}
Also used : Expression(org.apache.cayenne.exp.Expression) ClobTestEntity(org.apache.cayenne.testdo.lob.ClobTestEntity) Test(org.junit.Test)

Aggregations

ClobTestEntity (org.apache.cayenne.testdo.lob.ClobTestEntity)5 Test (org.junit.Test)3 Expression (org.apache.cayenne.exp.Expression)2 SelectQuery (org.apache.cayenne.query.SelectQuery)2