use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class DataContextEntityWithMeaningfulPKIT method testInsertWithMeaningfulPK.
@Test
public void testInsertWithMeaningfulPK() {
MeaningfulPKTest1 obj = context.newObject(MeaningfulPKTest1.class);
obj.setPkAttribute(1000);
obj.setDescr("aaa-aaa");
context.commitChanges();
ObjectId objId = new ObjectId("MeaningfulPKTest1", MeaningfulPKTest1.PK_ATTRIBUTE_PK_COLUMN, 1000);
ObjectIdQuery q = new ObjectIdQuery(objId, true, ObjectIdQuery.CACHE_REFRESH);
@SuppressWarnings("unchecked") List<DataRow> result = (List<DataRow>) context.performQuery(q);
assertEquals(1, result.size());
assertEquals(1000, result.get(0).get(MeaningfulPKTest1.PK_ATTRIBUTE_PK_COLUMN));
}
use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class DataContextObjectIdQueryIT method testNoRefreshValuesNew.
@Test
public void testNoRefreshValuesNew() {
Artist a = context.newObject(Artist.class);
a.setArtistName("X");
context.commitChanges();
context.performGenericQuery(new SQLTemplate(Artist.class, "UPDATE ARTIST SET ARTIST_NAME = 'Y'"));
long id = Cayenne.longPKForObject(a);
ObjectIdQuery query = new ObjectIdQuery(new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, id), false, ObjectIdQuery.CACHE);
Artist a1 = (Artist) Cayenne.objectForQuery(context, query);
assertEquals("X", a1.getArtistName());
}
use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class DataContextObjectIdQuery_PolymorphicIT method testPolymorphicSharedCache_AfterCayenneInsert.
@Test
public void testPolymorphicSharedCache_AfterCayenneInsert() throws SQLException {
// see CAY-2101... we are trying to get a snapshot from a new object in the shared cache, and then read this
// object via a relationship, so that shared cache is consulted
Employee e = context1.newObject(Employee.class);
e.setName("E1");
e.setSalary(1234.01f);
context1.commitChanges();
final ObjectIdQuery q1 = new ObjectIdQuery(new ObjectId("AbstractPerson", "PERSON_ID", Cayenne.intPKForObject(e)), false, ObjectIdQuery.CACHE);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
@Override
public void execute() {
// use different context to ensure we hit shared cache
AbstractPerson ap1 = (AbstractPerson) Cayenne.objectForQuery(context2, q1);
assertTrue(ap1 instanceof Employee);
}
});
}
use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class CompoundPkChangeIT method testCompoundPkChangeSingleElement.
@Test
public void testCompoundPkChangeSingleElement() throws Exception {
CompoundPkTestEntity object = context.newObject(CompoundPkTestEntity.class);
CompoundPkTestEntity refreshedObject = null;
object.setKey1(key1v1);
object.setKey2(key2v1);
object.setName("testing testing");
context.commitChanges();
assertEquals(key1v1, object.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY1_PK_COLUMN));
assertEquals(key2v1, object.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY2_PK_COLUMN));
ObjectIdQuery refetch = new ObjectIdQuery(object.getObjectId(), false, ObjectIdQuery.CACHE_REFRESH);
refreshedObject = (CompoundPkTestEntity) Cayenne.objectForQuery(context, refetch);
assertEquals(object.getObjectId(), refreshedObject.getObjectId());
object.setKey2(key2v2);
context.commitChanges();
assertEquals(key1v1, object.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY1_PK_COLUMN));
assertEquals(key2v2, object.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY2_PK_COLUMN));
ObjectIdQuery refetch1 = new ObjectIdQuery(object.getObjectId(), false, ObjectIdQuery.CACHE_REFRESH);
refreshedObject = (CompoundPkTestEntity) Cayenne.objectForQuery(context, refetch1);
assertEquals(object.getObjectId(), refreshedObject.getObjectId());
object.setKey2(key2v3);
context.commitChanges();
assertEquals(key1v1, object.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY1_PK_COLUMN));
assertEquals(key2v3, object.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY2_PK_COLUMN));
ObjectIdQuery refetch2 = new ObjectIdQuery(object.getObjectId(), false, ObjectIdQuery.CACHE_REFRESH);
refreshedObject = (CompoundPkTestEntity) Cayenne.objectForQuery(context, refetch2);
assertEquals(object.getObjectId(), refreshedObject.getObjectId());
}
use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class CompoundPkChangeIT method testCompoundPkChangeAllElements.
@Test
public void testCompoundPkChangeAllElements() throws Exception {
CompoundPkTestEntity object = context.newObject(CompoundPkTestEntity.class);
CompoundPkTestEntity refreshedObject = null;
object.setKey1(key1v1);
object.setKey2(key2v1);
object.setName("testing testing");
context.commitChanges();
assertEquals(key1v1, object.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY1_PK_COLUMN));
assertEquals(key2v1, object.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY2_PK_COLUMN));
ObjectIdQuery refetch = new ObjectIdQuery(object.getObjectId(), false, ObjectIdQuery.CACHE_REFRESH);
refreshedObject = (CompoundPkTestEntity) Cayenne.objectForQuery(context, refetch);
assertEquals(object.getObjectId(), refreshedObject.getObjectId());
object.setKey1(key1v2);
object.setKey2(key2v2);
context.commitChanges();
assertEquals(key1v2, object.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY1_PK_COLUMN));
assertEquals(key2v2, object.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY2_PK_COLUMN));
ObjectIdQuery refetch1 = new ObjectIdQuery(object.getObjectId(), false, ObjectIdQuery.CACHE_REFRESH);
refreshedObject = (CompoundPkTestEntity) Cayenne.objectForQuery(context, refetch1);
assertEquals(object.getObjectId(), refreshedObject.getObjectId());
object.setKey1(key1v3);
object.setKey2(key2v3);
context.commitChanges();
assertEquals(key1v3, object.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY1_PK_COLUMN));
assertEquals(key2v3, object.getObjectId().getIdSnapshot().get(CompoundPkTestEntity.KEY2_PK_COLUMN));
ObjectIdQuery refetch2 = new ObjectIdQuery(object.getObjectId(), false, ObjectIdQuery.CACHE_REFRESH);
refreshedObject = (CompoundPkTestEntity) Cayenne.objectForQuery(context, refetch2);
assertEquals(object.getObjectId(), refreshedObject.getObjectId());
}
Aggregations