use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class ObjectStoreGCIT method testReleaseUnreferenced.
@Test
public void testReleaseUnreferenced() throws Exception {
context.performGenericQuery(new SQLTemplate(Artist.class, "insert into ARTIST (ARTIST_ID, ARTIST_NAME) values (1, 'aa')"));
assertEquals(0, context.getObjectStore().registeredObjectsCount());
context.performQuery(new SelectQuery(Artist.class));
assertEquals(1, context.getObjectStore().registeredObjectsCount());
// allow for slow GC
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
System.gc();
assertEquals(0, context.getObjectStore().registeredObjectsCount());
}
}.runTest(2000);
}
use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class ObjectStoreGCIT method testRetainUnreferencedModified.
@Test
public void testRetainUnreferencedModified() throws Exception {
context.performGenericQuery(new SQLTemplate(Artist.class, "insert into ARTIST (ARTIST_ID, ARTIST_NAME) values (1, 'aa')"));
assertEquals(0, context.getObjectStore().registeredObjectsCount());
Artist a = Cayenne.objectForPK(context, Artist.class, 1);
a.setArtistName("Y");
a = null;
assertEquals(1, context.getObjectStore().registeredObjectsCount());
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
System.gc();
assertEquals(1, context.getObjectStore().registeredObjectsCount());
}
}.runTest(2000);
context.commitChanges();
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
System.gc();
assertEquals(0, context.getObjectStore().registeredObjectsCount());
}
}.runTest(2000);
}
use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class DataContextExtendedTypeOperationsIT method testStoreExtendedType.
@Test
public void testStoreExtendedType() {
ExtendedTypeEntity e1 = context.newObject(ExtendedTypeEntity.class);
e1.setName(new StringET1("X"));
e1.getObjectContext().commitChanges();
SQLTemplate checkQ = new SQLTemplate(ExtendedTypeEntity.class, "SELECT * FROM EXTENDED_TYPE_TEST WHERE NAME = 'X'");
checkQ.setFetchingDataRows(true);
checkQ.setColumnNamesCapitalization(CapsStrategy.UPPER);
assertEquals(1, e1.getObjectContext().performQuery(checkQ).size());
}
use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class DataContextIT method testPerformNonSelectingQuery.
@Test
public void testPerformNonSelectingQuery() throws Exception {
createSingleArtistDataSet();
SelectQuery select = new SelectQuery(Painting.class, ExpressionFactory.exp("db:PAINTING_ID = 1"));
assertEquals(0, context.performQuery(select).size());
SQLTemplate query = new SQLTemplate(Painting.class, "INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ARTIST_ID, ESTIMATED_PRICE) " + "VALUES (1, 'PX', 33001, 1)");
context.performNonSelectingQuery(query);
assertEquals(1, context.performQuery(select).size());
}
use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class DataContextIT method testPerformNonSelectingQueryCounts1.
@Test
public void testPerformNonSelectingQueryCounts1() throws Exception {
createArtistsDataSet();
SQLTemplate query = new SQLTemplate(Painting.class, "INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ARTIST_ID, ESTIMATED_PRICE) " + "VALUES ($pid, '$pt', $aid, $price)");
Map<String, Object> map = new HashMap<>();
map.put("pid", new Integer(1));
map.put("pt", "P1");
map.put("aid", new Integer(33002));
map.put("price", new Double(1.1));
// single batch of parameters
query.setParameters(map);
int[] counts = context.performNonSelectingQuery(query);
assertNotNull(counts);
assertEquals(1, counts.length);
assertEquals(1, counts[0]);
}
Aggregations