Search in sources :

Example 71 with SelectQuery

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

the class NumericTypesIT method testBigDecimal.

@Test
public void testBigDecimal() throws Exception {
    BigDecimalEntity test = context.newObject(BigDecimalEntity.class);
    BigDecimal i = new BigDecimal("1234567890.44");
    test.setBigDecimalField(i);
    context.commitChanges();
    SelectQuery<BigDecimalEntity> q = new SelectQuery<>(BigDecimalEntity.class);
    BigDecimalEntity testRead = (BigDecimalEntity) context.performQuery(q).get(0);
    assertNotNull(testRead.getBigDecimalField());
    assertEquals(i, testRead.getBigDecimalField());
    test.setBigDecimalField(null);
    context.commitChanges();
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) BigDecimalEntity(org.apache.cayenne.testdo.numeric_types.BigDecimalEntity) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 72 with SelectQuery

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

the class QuotedIdentifiersIT method testPrefetchQuote.

@Test
public void testPrefetchQuote() throws Exception {
    DbEntity entity = context.getEntityResolver().getObjEntity(QuoteAdress.class).getDbEntity();
    List idAttributes = Collections.singletonList(entity.getAttribute("City"));
    List updatedAttributes = Collections.singletonList(entity.getAttribute("City"));
    UpdateBatchQuery updateQuery = new UpdateBatchQuery(entity, idAttributes, updatedAttributes, Collections.<String>emptySet(), 1);
    List objects3 = context.performQuery(updateQuery);
    assertEquals(0, objects3.size());
    SelectQuery qQuote_Person2 = new SelectQuery(Quote_Person.class);
    List objects4 = context.performQuery(qQuote_Person2);
    assertEquals(2, objects4.size());
    SelectQuery qQuote_Person3 = new SelectQuery(Quote_Person.class, ExpressionFactory.matchExp("salary", 100));
    List objects5 = context.performQuery(qQuote_Person3);
    assertEquals(1, objects5.size());
    SelectQuery qQuote_Person4 = new SelectQuery(Quote_Person.class, ExpressionFactory.matchExp("group", "107324"));
    List objects6 = context.performQuery(qQuote_Person4);
    assertEquals(1, objects6.size());
    SelectQuery quoteAdress1 = new SelectQuery(QuoteAdress.class, ExpressionFactory.matchExp("group", "324"));
    List objects7 = context.performQuery(quoteAdress1);
    assertEquals(1, objects7.size());
    ObjectIdQuery queryObjectId = new ObjectIdQuery(new ObjectId("QuoteAdress", QuoteAdress.GROUP.getName(), "324"));
    List objects8 = context.performQuery(queryObjectId);
    assertEquals(1, objects8.size());
    ObjectIdQuery queryObjectId2 = new ObjectIdQuery(new ObjectId("Quote_Person", "GROUP", "1111"));
    List objects9 = context.performQuery(queryObjectId2);
    assertEquals(1, objects9.size());
    SelectQuery person2Query = new SelectQuery(Quote_Person.class, ExpressionFactory.matchExp("name", "Name"));
    Quote_Person quote_Person2 = (Quote_Person) context.performQuery(person2Query).get(0);
    RelationshipQuery relationshipQuery = new RelationshipQuery(quote_Person2.getObjectId(), "address_Rel");
    List objects10 = context.performQuery(relationshipQuery);
    assertEquals(1, objects10.size());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) DbEntity(org.apache.cayenne.map.DbEntity) ObjectId(org.apache.cayenne.ObjectId) RelationshipQuery(org.apache.cayenne.query.RelationshipQuery) UpdateBatchQuery(org.apache.cayenne.query.UpdateBatchQuery) QuoteAdress(org.apache.cayenne.testdo.quotemap.QuoteAdress) List(java.util.List) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Quote_Person(org.apache.cayenne.testdo.quotemap.Quote_Person) Test(org.junit.Test)

Example 73 with SelectQuery

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

the class ReturnTypesMappingIT method testFLOAT2.

@Test
public void testFLOAT2() throws Exception {
    ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
    Float floatValue = 375.437f;
    test.setFloatColumn(floatValue);
    context.commitChanges();
    SelectQuery q = new SelectQuery(ReturnTypesMap1.class);
    ReturnTypesMap1 testRead = (ReturnTypesMap1) context.performQuery(q).get(0);
    Float columnValue = testRead.getFloatColumn();
    assertNotNull(columnValue);
    assertEquals(Float.class, columnValue.getClass());
    assertEquals(floatValue, columnValue);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) Test(org.junit.Test)

Example 74 with SelectQuery

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

the class ReturnTypesMappingIT method testDOUBLE2.

@Test
public void testDOUBLE2() throws Exception {
    ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
    Double doubleValue = 3298.4349783d;
    test.setDoubleColumn(doubleValue);
    context.commitChanges();
    SelectQuery q = new SelectQuery(ReturnTypesMap1.class);
    ReturnTypesMap1 testRead = (ReturnTypesMap1) context.performQuery(q).get(0);
    Double columnValue = testRead.getDoubleColumn();
    assertNotNull(columnValue);
    assertEquals(Double.class, columnValue.getClass());
    assertEquals(doubleValue, columnValue);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) Test(org.junit.Test)

Example 75 with SelectQuery

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

the class ReturnTypesMappingIT method testBIGINT2.

@Test
public void testBIGINT2() throws Exception {
    ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
    Long bigintValue = 5326457654783454355l;
    test.setBigintColumn(bigintValue);
    context.commitChanges();
    SelectQuery q = new SelectQuery(ReturnTypesMap1.class);
    ReturnTypesMap1 testRead = (ReturnTypesMap1) context.performQuery(q).get(0);
    Long columnValue = testRead.getBigintColumn();
    assertNotNull(columnValue);
    assertEquals(Long.class, columnValue.getClass());
    assertEquals(bigintValue, columnValue);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) 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