Search in sources :

Example 46 with ObjectId

use of org.apache.cayenne.ObjectId in project cayenne by apache.

the class JointPrefetchIT method testJointPrefetchSQLSelectNestedJoint.

@Test
public void testJointPrefetchSQLSelectNestedJoint() throws Exception {
    createJointPrefetchDataSet();
    SQLSelect.query(Artist.class, "SELECT " + "#result('GALLERY_ID' 'int' '' 'paintingArray.toGallery.GALLERY_ID')," + "#result('GALLERY_NAME' 'String' '' 'paintingArray.toGallery.GALLERY_NAME')," + "#result('t0.ARTIST_ID' 'int' '' 'ARTIST_ID') " + "FROM ARTIST t0, GALLERY t2 ").addPrefetch(Artist.PAINTING_ARRAY.dot(Painting.TO_GALLERY).joint()).select(context);
    queryInterceptor.runWithQueriesBlocked(() -> {
        DataObject g1 = (DataObject) context.getGraphManager().getNode(new ObjectId("Gallery", Gallery.GALLERY_ID_PK_COLUMN, 33001));
        assertNotNull(g1);
        assertEquals("G1", g1.readProperty("galleryName"));
    });
}
Also used : DataObject(org.apache.cayenne.DataObject) ObjectId(org.apache.cayenne.ObjectId) Test(org.junit.Test)

Example 47 with ObjectId

use of org.apache.cayenne.ObjectId in project cayenne by apache.

the class NestedDataContextPeerEventsIT method testPeerObjectUpdatedTempOID.

@Test
public void testPeerObjectUpdatedTempOID() throws Exception {
    ObjectContext peer1 = runtime.newContext(context);
    final Artist a1 = peer1.newObject(Artist.class);
    a1.setArtistName("Y");
    ObjectId a1TempId = a1.getObjectId();
    assertTrue(a1TempId.isTemporary());
    ObjectContext peer2 = runtime.newContext(context);
    final Artist a2 = peer2.localObject(a1);
    assertEquals(a1TempId, a2.getObjectId());
    peer1.commitChanges();
    // pause to let the context events propagate
    new ParallelTestContainer() {

        @Override
        protected void assertResult() throws Exception {
            assertFalse(a1.getObjectId().isTemporary());
            assertFalse(a2.getObjectId().isTemporary());
            assertEquals(a2.getObjectId(), a1.getObjectId());
        }
    }.runTest(2000);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ObjectId(org.apache.cayenne.ObjectId) ObjectContext(org.apache.cayenne.ObjectContext) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Example 48 with ObjectId

use of org.apache.cayenne.ObjectId in project cayenne by apache.

the class NumericTypesIT method testDecimalPK1.

@Test
public void testDecimalPK1() throws Exception {
    // populate (testing insert as well)
    DecimalPKTest1 object = context.newObject(DecimalPKTest1.class);
    object.setName("o2");
    object.setDecimalPK(1.25);
    context.commitChanges();
    ObjectId syntheticId = new ObjectId("DecimalPKTest1", "DECIMAL_PK", 1.25);
    assertSame(object, context.getGraphManager().getNode(syntheticId));
}
Also used : ObjectId(org.apache.cayenne.ObjectId) DecimalPKTest1(org.apache.cayenne.testdo.numeric_types.DecimalPKTest1) Test(org.junit.Test)

Example 49 with ObjectId

use of org.apache.cayenne.ObjectId 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 50 with ObjectId

use of org.apache.cayenne.ObjectId in project cayenne by apache.

the class DataContextSharedCacheIT method testSnapshotDeletePropagationToModified.

/**
 * Test case to prove that deleting an object in one ObjectStore and committed to the
 * database will be reflected in the peer ObjectStore using the same DataRowCache. By
 * default MODIFIED objects will be changed to NEW.
 */
@Test
public void testSnapshotDeletePropagationToModified() throws Exception {
    // make sure we have a fully resolved copy of an artist object
    // in the second context
    final Artist altArtist = context1.localObject(artist);
    altArtist.getArtistName();
    assertNotNull(altArtist);
    assertFalse(altArtist == artist);
    // modify peer
    altArtist.setArtistName("version2");
    assertEquals(PersistenceState.MODIFIED, altArtist.getPersistenceState());
    // Update Artist
    context.deleteObjects(artist);
    context.commitChanges();
    // check underlying cache
    assertNull(context.getObjectStore().getDataRowCache().getCachedSnapshot(altArtist.getObjectId()));
    // check peer artist
    ParallelTestContainer helper = new ParallelTestContainer() {

        @Override
        protected void assertResult() throws Exception {
            assertEquals(PersistenceState.NEW, altArtist.getPersistenceState());
        }
    };
    helper.runTest(3000);
    // check if now we can save this object again, and with the original
    // ObjectId
    ObjectId id = altArtist.getObjectId();
    assertNotNull(id);
    assertNotNull(id.getIdSnapshot().get(Artist.ARTIST_ID_PK_COLUMN));
    assertFalse(id.isTemporary());
    context1.commitChanges();
    assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ObjectId(org.apache.cayenne.ObjectId) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Aggregations

ObjectId (org.apache.cayenne.ObjectId)156 Test (org.junit.Test)104 Persistent (org.apache.cayenne.Persistent)38 DataObject (org.apache.cayenne.DataObject)20 DataRow (org.apache.cayenne.DataRow)20 ObjectContext (org.apache.cayenne.ObjectContext)20 ObjEntity (org.apache.cayenne.map.ObjEntity)20 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)18 HashMap (java.util.HashMap)17 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)16 ArrayList (java.util.ArrayList)14 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)14 Artist (org.apache.cayenne.testdo.testmap.Artist)14 Map (java.util.Map)13 EntityResolver (org.apache.cayenne.map.EntityResolver)13 InvocationOnMock (org.mockito.invocation.InvocationOnMock)13 ChangeMap (org.apache.cayenne.commitlog.model.ChangeMap)12 ObjRelationship (org.apache.cayenne.map.ObjRelationship)10 SelectQuery (org.apache.cayenne.query.SelectQuery)10 ObjectChange (org.apache.cayenne.commitlog.model.ObjectChange)9