Search in sources :

Example 46 with DataRow

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

the class ReturnTypesMappingIT method testVARCHAR.

@Test
public void testVARCHAR() throws Exception {
    String columnName = "VARCHAR_COLUMN";
    ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
    String varcharValue = "VARChar string for tests!";
    test.setVarcharColumn(varcharValue);
    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(varcharValue, columnValue);
}
Also used : ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 47 with DataRow

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

the class ReturnTypesMappingIT method testSMALLINT.

@Test
public void testSMALLINT() throws Exception {
    String columnName = "SMALLINT_COLUMN";
    ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
    Short smallintValue = 32564;
    Integer intValue = 32564;
    test.setSmallintColumn(smallintValue);
    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());
        assertEquals(intValue, columnValue);
    } else {
        assertEquals(Short.class, columnValue.getClass());
        assertEquals(smallintValue, columnValue);
    }
}
Also used : ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 48 with DataRow

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

the class ReturnTypesMappingIT method testREAL.

@Test
public void testREAL() throws Exception {
    String columnName = "REAL_COLUMN";
    ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
    Float realValue = 5788.57843f;
    test.setRealColumn(realValue);
    context.commitChanges();
    DataRow testRead = (DataRow) context.performQuery(MappedSelect.query("SelectReturnTypesMap1")).get(0);
    Object columnValue = testRead.get(columnName);
    assertNotNull(columnValue);
    // engine settings
    if (unitDbAdapter.onlyGenericNumberType()) {
        assertEquals(BigDecimal.class, columnValue.getClass());
    } else {
        if (unitDbAdapter.realAsDouble()) {
            assertEquals(Double.class, columnValue.getClass());
            assertEquals(Double.valueOf(realValue), (Double) columnValue, 0.0001);
        } else {
            assertEquals(Float.class, columnValue.getClass());
            assertEquals(realValue, columnValue);
        }
    }
}
Also used : ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 49 with DataRow

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

the class ReturnTypesMappingIT method testTIMESTAMP.

@Test
public void testTIMESTAMP() throws Exception {
    String columnName = "TIMESTAMP_COLUMN";
    ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
    Date timestampValue = Calendar.getInstance().getTime();
    test.setTimestampColumn(timestampValue);
    context.commitChanges();
    DataRow testRead = (DataRow) context.performQuery(MappedSelect.query("SelectReturnTypesMap1")).get(0);
    Object columnValue = testRead.get(columnName);
    assertNotNull(columnValue);
    assertEquals(Date.class, columnValue.getClass());
    // some DB's, noteably MySQL, strip the milliseconds from timestamps,
    // so comparing within 1 second precision
    long delta = timestampValue.getTime() - ((Date) columnValue).getTime();
    assertTrue(delta < 1000);
}
Also used : ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) DataRow(org.apache.cayenne.DataRow) Date(java.util.Date) Test(org.junit.Test)

Example 50 with DataRow

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

the class ReturnTypesMappingIT method testLONGVARCHAR.

@Test
public void testLONGVARCHAR() throws Exception {
    String columnName = "LONGVARCHAR_COLUMN";
    ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 500; i++) {
        buffer.append("LONGVARCHAR large string for tests!!!!\n");
    }
    String longvarcharValue = buffer.toString();
    test.setLongvarcharColumn(longvarcharValue);
    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(longvarcharValue, 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