Search in sources :

Example 76 with SelectQuery

use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.

the class ReturnTypesMappingIT method testDECIMAL2.

@Test
public void testDECIMAL2() throws Exception {
    ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
    BigDecimal decimalValue = new BigDecimal("578438.57843");
    test.setDecimalColumn(decimalValue);
    context.commitChanges();
    SelectQuery q = new SelectQuery(ReturnTypesMap1.class);
    ReturnTypesMap1 testRead = (ReturnTypesMap1) context.performQuery(q).get(0);
    BigDecimal columnValue = testRead.getDecimalColumn();
    assertNotNull(columnValue);
    assertEquals(BigDecimal.class, columnValue.getClass());
    assertEquals(decimalValue, columnValue);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 77 with SelectQuery

use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.

the class ReturnTypesMappingIT method testTIMESTAMP2.

@Test
public void testTIMESTAMP2() throws Exception {
    ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
    Date timestampValue = Calendar.getInstance().getTime();
    test.setTimestampColumn(timestampValue);
    context.commitChanges();
    SelectQuery q = new SelectQuery(ReturnTypesMap1.class);
    ReturnTypesMap1 testRead = (ReturnTypesMap1) context.performQuery(q).get(0);
    Date columnValue = testRead.getTimestampColumn();
    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 : SelectQuery(org.apache.cayenne.query.SelectQuery) ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) Date(java.util.Date) Test(org.junit.Test)

Example 78 with SelectQuery

use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.

the class ReturnTypesMappingIT method testINTEGER2.

@Test
public void testINTEGER2() throws Exception {
    ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
    Integer integerValue = 54235;
    test.setIntegerColumn(integerValue);
    context.commitChanges();
    SelectQuery q = new SelectQuery(ReturnTypesMap1.class);
    ReturnTypesMap1 testRead = (ReturnTypesMap1) context.performQuery(q).get(0);
    Integer columnValue = testRead.getIntegerColumn();
    assertNotNull(columnValue);
    assertEquals(Integer.class, columnValue.getClass());
    assertEquals(integerValue, columnValue);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) Test(org.junit.Test)

Example 79 with SelectQuery

use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.

the class ReturnTypesMappingIT method testBLOB2.

@Test
public void testBLOB2() throws Exception {
    if (unitDbAdapter.supportsLobs()) {
        ReturnTypesMap2 test = context.newObject(ReturnTypesMap2.class);
        byte[] blobValue = { 3, 4, 5, -6, 7, 0, 2, 9, 45, 64, 3, 127, -128, -60 };
        test.setBlobColumn(blobValue);
        context.commitChanges();
        SelectQuery q = new SelectQuery(ReturnTypesMap2.class);
        ReturnTypesMap2 testRead = (ReturnTypesMap2) context.performQuery(q).get(0);
        byte[] columnValue = testRead.getBlobColumn();
        assertNotNull(columnValue);
        assertEquals(byte[].class, columnValue.getClass());
        assertTrue(Arrays.equals(blobValue, columnValue));
    }
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ReturnTypesMap2(org.apache.cayenne.testdo.return_types.ReturnTypesMap2) Test(org.junit.Test)

Example 80 with SelectQuery

use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.

the class ReturnTypesMappingIT method testTIME2.

@Test
public void testTIME2() throws Exception {
    ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(2003, 1, 1, 1, 20, 30);
    Date timeValue = new Time(cal.getTime().getTime());
    test.setTimeColumn(timeValue);
    context.commitChanges();
    SelectQuery q = new SelectQuery(ReturnTypesMap1.class);
    ReturnTypesMap1 testRead = (ReturnTypesMap1) context.performQuery(q).get(0);
    Date columnValue = testRead.getTimeColumn();
    assertNotNull(columnValue);
    assertEquals(Date.class, columnValue.getClass());
    assertEquals(timeValue.toString(), new Time(columnValue.getTime()).toString());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) Calendar(java.util.Calendar) Time(java.sql.Time) Date(java.util.Date) Test(org.junit.Test)

Aggregations

SelectQuery (org.apache.cayenne.query.SelectQuery)360 Test (org.junit.Test)348 Artist (org.apache.cayenne.testdo.testmap.Artist)128 Painting (org.apache.cayenne.testdo.testmap.Painting)75 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)64 Expression (org.apache.cayenne.exp.Expression)47 List (java.util.List)43 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)26 ValueHolder (org.apache.cayenne.ValueHolder)21 ReturnTypesMap1 (org.apache.cayenne.testdo.return_types.ReturnTypesMap1)18 ArrayList (java.util.ArrayList)16 Date (java.util.Date)13 DataRow (org.apache.cayenne.DataRow)12 ObjectContext (org.apache.cayenne.ObjectContext)12 DbEntity (org.apache.cayenne.map.DbEntity)12 SQLTemplate (org.apache.cayenne.query.SQLTemplate)11 ROArtist (org.apache.cayenne.testdo.testmap.ROArtist)11 HashMap (java.util.HashMap)10 ObjectId (org.apache.cayenne.ObjectId)10 Query (org.apache.cayenne.query.Query)10