Search in sources :

Example 96 with DataRow

use of org.apache.cayenne.DataRow in project cayenne by apache.

the class ReturnTypesMappingIT method testBOOLEAN.

@Test
public void testBOOLEAN() throws Exception {
    String columnName = "BOOLEAN_COLUMN";
    ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
    Boolean booleanValue = true;
    test.setBooleanColumn(booleanValue);
    context.commitChanges();
    DataRow testRead = (DataRow) context.performQuery(MappedSelect.query("SelectReturnTypesMap1")).get(0);
    Object columnValue = testRead.get(columnName);
    assertNotNull(columnValue);
    assertTrue(Boolean.class.equals(columnValue.getClass()) || Short.class.equals(columnValue.getClass()) || Integer.class.equals(columnValue.getClass()));
    assertTrue(booleanValue.equals(columnValue) || ((Number) columnValue).intValue() == 1);
}
Also used : ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 97 with DataRow

use of org.apache.cayenne.DataRow in project cayenne by apache.

the class ReturnTypesMappingIT method testTINYINT.

@Test
public void testTINYINT() throws Exception {
    String columnName = "TINYINT_COLUMN";
    ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
    Byte tinyintValue = 89;
    Integer intValue = 89;
    test.setTinyintColumn(tinyintValue);
    context.commitChanges();
    DataRow testRead = (DataRow) context.performQuery(MappedSelect.query("SelectReturnTypesMap1")).get(0);
    Object columnValue = testRead.get(columnName);
    assertNotNull(columnValue);
    if (unitDbAdapter.onlyGenericNumberType()) {
        assertEquals(Integer.class, columnValue.getClass());
    } else {
        assertEquals(Short.class, columnValue.getClass());
    }
    assertEquals(tinyintValue.intValue(), ((Number) columnValue).intValue());
}
Also used : ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 98 with DataRow

use of org.apache.cayenne.DataRow in project cayenne by apache.

the class ReturnTypesMappingIT method testVARBINARY.

@Test
public void testVARBINARY() throws Exception {
    if (unitDbAdapter.supportsLobs()) {
        String columnName = "VARBINARY_COLUMN";
        ReturnTypesMap2 test = context.newObject(ReturnTypesMap2.class);
        byte[] varbinaryValue = { 3, 4, 5, -6, 7, 0, 2, 9, 45, 64, 3, 127, -128, -60 };
        test.setVarbinaryColumn(varbinaryValue);
        context.commitChanges();
        DataRow testRead = (DataRow) context.performQuery(MappedSelect.query("SelectReturnTypesMap2")).get(0);
        Object columnValue = testRead.get(columnName);
        assertNotNull(columnValue);
        assertEquals(byte[].class, columnValue.getClass());
        assertTrue(Arrays.equals(varbinaryValue, (byte[]) columnValue));
    }
}
Also used : ReturnTypesMap2(org.apache.cayenne.testdo.return_types.ReturnTypesMap2) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 99 with DataRow

use of org.apache.cayenne.DataRow in project cayenne by apache.

the class ReturnTypesMappingIT method testDATE.

@Test
public void testDATE() throws Exception {
    String columnName = "DATE_COLUMN";
    ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(2002, 1, 1);
    Date dateValue = cal.getTime();
    test.setDateColumn(dateValue);
    context.commitChanges();
    DataRow testRead = (DataRow) context.performQuery(MappedSelect.query("SelectReturnTypesMap1")).get(0);
    Object columnValue = testRead.get(columnName);
    assertNotNull(columnValue);
    assertEquals(Date.class, columnValue.getClass());
    assertEquals(dateValue.toString(), columnValue.toString());
}
Also used : ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) Calendar(java.util.Calendar) DataRow(org.apache.cayenne.DataRow) Date(java.util.Date) Test(org.junit.Test)

Example 100 with DataRow

use of org.apache.cayenne.DataRow in project cayenne by apache.

the class ReturnTypesMappingIT method testCHAR.

@Test
public void testCHAR() throws Exception {
    String columnName = "CHAR_COLUMN";
    ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
    String charValue = "Char string for tests!";
    test.setCharColumn(charValue);
    context.commitChanges();
    DataRow testRead = (DataRow) context.performQuery(MappedSelect.query("SelectReturnTypesMap1")).get(0);
    Object columnValue = testRead.get(columnName);
    assertNotNull(columnValue);
    assertEquals(String.class, columnValue.getClass());
    assertEquals(charValue, columnValue);
}
Also used : ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Aggregations

DataRow (org.apache.cayenne.DataRow)152 Test (org.junit.Test)113 Artist (org.apache.cayenne.testdo.testmap.Artist)31 ObjectId (org.apache.cayenne.ObjectId)25 DataObject (org.apache.cayenne.DataObject)20 ReturnTypesMap1 (org.apache.cayenne.testdo.return_types.ReturnTypesMap1)20 SQLTemplate (org.apache.cayenne.query.SQLTemplate)18 Date (java.util.Date)14 HashMap (java.util.HashMap)14 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)14 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)12 ArrayList (java.util.ArrayList)9 List (java.util.List)8 Persistent (org.apache.cayenne.Persistent)8 Painting (org.apache.cayenne.testdo.testmap.Painting)8 Connection (java.sql.Connection)6 Calendar (java.util.Calendar)5 Map (java.util.Map)5 QueryResponse (org.apache.cayenne.QueryResponse)5 DataMap (org.apache.cayenne.map.DataMap)5