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"));
});
}
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);
}
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));
}
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());
}
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());
}
Aggregations