use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class DataContextObjectIdQueryIT method testNoRefreshValuesNew.
@Test
public void testNoRefreshValuesNew() {
Artist a = context.newObject(Artist.class);
a.setArtistName("X");
context.commitChanges();
context.performGenericQuery(new SQLTemplate(Artist.class, "UPDATE ARTIST SET ARTIST_NAME = 'Y'"));
long id = Cayenne.longPKForObject(a);
ObjectIdQuery query = new ObjectIdQuery(new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, id), false, ObjectIdQuery.CACHE);
Artist a1 = (Artist) Cayenne.objectForQuery(context, query);
assertEquals("X", a1.getArtistName());
}
use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class DataContextPerformQueryAPIIT method testPerfomQueryNonSelecting.
@Test
public void testPerfomQueryNonSelecting() throws Exception {
Artist a = context.newObject(Artist.class);
a.setArtistName("aa");
context.commitChanges();
SQLTemplate q = new SQLTemplate(Artist.class, "DELETE FROM ARTIST");
// this way of executing a query makes no sense, but it shouldn't blow
// either...
List<?> result = context.performQuery(q);
assertNotNull(result);
assertEquals(0, result.size());
}
use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class DataContextSQLTemplateCompoundIT method testBindObjectNotEqualCompound.
@Test
public void testBindObjectNotEqualCompound() throws Exception {
createTwoCompoundPKsAndCompoundFKsDataSet();
Map<String, String> pk = new HashMap<>();
pk.put(CompoundPkTestEntity.KEY1_PK_COLUMN, "a1");
pk.put(CompoundPkTestEntity.KEY2_PK_COLUMN, "a2");
CompoundPkTestEntity a = Cayenne.objectForPK(context, CompoundPkTestEntity.class, pk);
String template = "SELECT * FROM COMPOUND_FK_TEST t0" + " WHERE #bindObjectNotEqual($a [ 't0.F_KEY1', 't0.F_KEY2' ] [ 'KEY1', 'KEY2' ] ) ORDER BY PKEY";
SQLTemplate query = new SQLTemplate(CompoundFkTestEntity.class, template);
query.setColumnNamesCapitalization(CapsStrategy.UPPER);
query.setParams(Collections.singletonMap("a", a));
List<CompoundFkTestEntity> objects = context.performQuery(query);
assertEquals(1, objects.size());
CompoundFkTestEntity p = objects.get(0);
assertEquals(7, Cayenne.intPKForObject(p));
}
use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class DataContextSQLTemplateIT method testBindObjectNotEqualFull.
@Test
public void testBindObjectNotEqualFull() throws Exception {
createFourArtistsAndThreePaintingsDataSet();
Artist a = Cayenne.objectForPK(context, Artist.class, 101);
String template = "SELECT * FROM PAINTING t0" + " WHERE #bindObjectNotEqual($a [ 't0.ARTIST_ID' ] [ 'ARTIST_ID' ] ) ORDER BY PAINTING_ID";
SQLTemplate query = new SQLTemplate(Painting.class, template);
query.setColumnNamesCapitalization(CapsStrategy.UPPER);
query.setParams(Collections.singletonMap("a", a));
List<?> objects = context.performQuery(query);
// null comparison is unpredictable across DB's ... some would return
// true on null
// <> value, some - false
assertTrue(objects.size() == 1 || objects.size() == 2);
Painting p = (Painting) objects.get(0);
assertEquals(6, Cayenne.intPKForObject(p));
}
use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class DataContextSQLTemplateIT method testBindEqualNull.
@Test
public void testBindEqualNull() throws Exception {
createFourArtistsAndThreePaintingsDataSet();
String template = "SELECT * FROM PAINTING t0" + " WHERE t0.ARTIST_ID #bindEqual($id) ORDER BY PAINTING_ID";
SQLTemplate query = new SQLTemplate(Painting.class, template);
query.setColumnNamesCapitalization(CapsStrategy.UPPER);
query.setParams(Collections.singletonMap("id", null));
List<Painting> objects = context.performQuery(query);
assertEquals(1, objects.size());
Painting p = objects.get(0);
assertEquals(8, Cayenne.intPKForObject(p));
}
Aggregations