use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class PersistentObjectInContextIT method testResolveToOneReverseResolved.
@Test
public void testResolveToOneReverseResolved() throws Exception {
createTwoMtTable1sAnd2sDataSet();
ObjectId gid = new ObjectId("MtTable2", MtTable2.TABLE2_ID_PK_COLUMN, new Integer(1));
ClientMtTable2 mtTable21 = (ClientMtTable2) Cayenne.objectForQuery(context, new ObjectIdQuery(gid));
assertNotNull(mtTable21);
ClientMtTable1 mtTable1 = mtTable21.getTable1();
assertNotNull("To one relationship incorrectly resolved to null", mtTable1);
List<ClientMtTable2> list = mtTable1.getTable2Array();
assertNotNull(list);
assertTrue(list instanceof ValueHolder);
assertTrue(((ValueHolder) list).isFault());
// resolve it here...
assertEquals(2, list.size());
for (ClientMtTable2 t2 : list) {
PersistentObjectHolder holder = (PersistentObjectHolder) t2.getTable1Direct();
assertFalse(holder.isFault());
assertSame(mtTable1, holder.getValue());
}
assertEquals("g1", mtTable1.getGlobalAttribute1());
}
use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class ShallowMergeOperationIT method testMerge_NoOverride.
@Test
public void testMerge_NoOverride() throws Exception {
createArtistsDataSet();
ObjectContext childContext = runtime.newContext(context);
final ShallowMergeOperation op = new ShallowMergeOperation(childContext);
int modifiedId = 33003;
final Artist modified = (Artist) Cayenne.objectForQuery(context, new ObjectIdQuery(new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, modifiedId)));
final Artist peerModified = (Artist) Cayenne.objectForQuery(childContext, new ObjectIdQuery(new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, modifiedId)));
modified.setArtistName("M1");
peerModified.setArtistName("M2");
assertEquals(PersistenceState.MODIFIED, modified.getPersistenceState());
assertEquals(PersistenceState.MODIFIED, peerModified.getPersistenceState());
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
Persistent peerModified2 = op.merge(modified);
assertSame(peerModified, peerModified2);
assertEquals(PersistenceState.MODIFIED, peerModified2.getPersistenceState());
assertEquals("M2", peerModified.getArtistName());
assertEquals("M1", modified.getArtistName());
}
});
}
use of org.apache.cayenne.query.ObjectIdQuery 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.query.ObjectIdQuery in project cayenne by apache.
the class DataContextIT method testCurrentSnapshotWithToOneFault.
/**
* Testing snapshot with to-one fault. This was a bug CAY-96.
*/
@Test
public void testCurrentSnapshotWithToOneFault() throws Exception {
createGalleriesAndExhibitsDataSet();
// Exhibit with Gallery as Fault must still include Gallery
// Artist and Exhibit (Exhibit has unresolved to-one to gallery as in
// the
// CAY-96 bug report)
ObjectId eId = new ObjectId("Exhibit", Exhibit.EXHIBIT_ID_PK_COLUMN, 2);
Exhibit e = (Exhibit) context.performQuery(new ObjectIdQuery(eId)).get(0);
assertTrue(e.readPropertyDirectly(Exhibit.TO_GALLERY.getName()) instanceof Fault);
DataRow snapshot = context.currentSnapshot(e);
// assert that after taking a snapshot, we have FK in, but the
// relationship
// is still a Fault
assertTrue(e.readPropertyDirectly(Exhibit.TO_GALLERY.getName()) instanceof Fault);
assertEquals(new Integer(33002), snapshot.get("GALLERY_ID"));
}
use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class DataContextObjectIdQueryIT method testRefreshNullifiedValuesNew.
@Test
public void testRefreshNullifiedValuesNew() {
Artist a = context.newObject(Artist.class);
a.setArtistName("X");
a.setDateOfBirth(new Date());
context.commitChanges();
context.performGenericQuery(new SQLTemplate(Artist.class, "UPDATE ARTIST SET DATE_OF_BIRTH = NULL"));
long id = Cayenne.longPKForObject(a);
ObjectIdQuery query = new ObjectIdQuery(new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, id), false, ObjectIdQuery.CACHE_REFRESH);
Artist a1 = (Artist) Cayenne.objectForQuery(context, query);
assertNull(a1.getDateOfBirth());
assertEquals("X", a1.getArtistName());
}
Aggregations