Search in sources :

Example 61 with SQLTemplate

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);
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) Artist(org.apache.cayenne.testdo.testmap.Artist) SelectQuery(org.apache.cayenne.query.SelectQuery) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Example 62 with SQLTemplate

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);
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) Artist(org.apache.cayenne.testdo.testmap.Artist) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Example 63 with SQLTemplate

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());
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) ExtendedTypeEntity(org.apache.cayenne.testdo.extended_type.ExtendedTypeEntity) StringET1(org.apache.cayenne.testdo.extended_type.StringET1) Test(org.junit.Test)

Example 64 with SQLTemplate

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());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) SQLTemplate(org.apache.cayenne.query.SQLTemplate) Test(org.junit.Test)

Example 65 with SQLTemplate

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]);
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) HashMap(java.util.HashMap) DataObject(org.apache.cayenne.DataObject) Test(org.junit.Test)

Aggregations

SQLTemplate (org.apache.cayenne.query.SQLTemplate)118 Test (org.junit.Test)108 Artist (org.apache.cayenne.testdo.testmap.Artist)27 DataRow (org.apache.cayenne.DataRow)18 HashMap (java.util.HashMap)16 MockOperationObserver (org.apache.cayenne.access.MockOperationObserver)14 Query (org.apache.cayenne.query.Query)14 SelectQuery (org.apache.cayenne.query.SelectQuery)11 Painting (org.apache.cayenne.testdo.testmap.Painting)11 List (java.util.List)8 Connection (java.sql.Connection)7 SQLAction (org.apache.cayenne.query.SQLAction)7 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)6 Map (java.util.Map)5 OperationObserver (org.apache.cayenne.access.OperationObserver)5 DataMap (org.apache.cayenne.map.DataMap)5 AbstractPerson (org.apache.cayenne.testdo.inheritance_people.AbstractPerson)5 PersonNotes (org.apache.cayenne.testdo.inheritance_people.PersonNotes)5 Date (java.sql.Date)4 FrontBaseAdapter (org.apache.cayenne.dba.frontbase.FrontBaseAdapter)4