use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class ChildDiffLoader method nodeCreated.
public void nodeCreated(Object nodeId) {
setExternalChange(Boolean.TRUE);
try {
ObjectId id = (ObjectId) nodeId;
if (id.getEntityName() == null) {
throw new NullPointerException("Null entity name in id " + id);
}
ObjEntity entity = context.getEntityResolver().getObjEntity(id.getEntityName());
if (entity == null) {
throw new IllegalArgumentException("Entity not mapped with Cayenne: " + id);
}
Persistent dataObject;
try {
dataObject = (Persistent) entity.getJavaClass().newInstance();
} catch (Exception ex) {
throw new CayenneRuntimeException("Error instantiating object.", ex);
}
dataObject.setObjectId(id);
context.registerNewObject(dataObject);
} finally {
setExternalChange(Boolean.FALSE);
}
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class FlattenedArcKeyIT method testAttributes.
@Test
public void testAttributes() {
ObjectId src = new ObjectId("X");
ObjectId target = new ObjectId("Y");
ObjRelationship r1 = entityResolver.getObjEntity(FlattenedTest3.class).getRelationship(FlattenedTest3.TO_FT1.getName());
FlattenedArcKey update = new FlattenedArcKey(src, target, r1);
assertSame(src, update.id1.getSourceId());
assertSame(target, update.id2.getSourceId());
assertSame(r1, update.relationship);
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class FlattenedArcKeyIT method testEquals.
@Test
public void testEquals() {
ObjectId src = new ObjectId("X");
ObjectId target = new ObjectId("Y");
ObjRelationship r1 = entityResolver.getObjEntity(FlattenedTest3.class).getRelationship(FlattenedTest3.TO_FT1.getName());
FlattenedArcKey update = new FlattenedArcKey(src, target, r1);
FlattenedArcKey update1 = new FlattenedArcKey(target, src, r1.getReverseRelationship());
ObjRelationship r3 = entityResolver.getObjEntity(FlattenedTest1.class).getRelationship(FlattenedTest1.FT3OVER_COMPLEX.getName());
FlattenedArcKey update2 = new FlattenedArcKey(target, src, r3);
assertTrue(update.equals(update1));
assertFalse(update.equals(update2));
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class IdentityColumnsIT method testCAY823.
/**
* Tests a bug casued by the ID Java type mismatch vs the default JDBC type
* of the ID column.
*/
@Test
public void testCAY823() throws Exception {
GeneratedColumnTestEntity idObject = context.newObject(GeneratedColumnTestEntity.class);
String name = "n_" + System.currentTimeMillis();
idObject.setName(name);
idObject.getObjectContext().commitChanges();
ObjectId id = idObject.getObjectId();
context.invalidateObjects(idObject);
SelectQuery q = new SelectQuery(GeneratedColumnTestEntity.class);
q.setPageSize(10);
List<?> results = context.performQuery(q);
assertEquals(1, results.size());
// per CAY-823 an attempt to resolve an object results in an exception
assertEquals(id, ((Persistent) results.get(0)).getObjectId());
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class NestedDataContextReadIT method testPrefetchingToOne.
@Test
public void testPrefetchingToOne() throws Exception {
createPrefetchingDataSet();
final ObjectContext child = runtime.newContext(context);
final ObjectId prefetchedId = new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, new Integer(33001));
SelectQuery<Painting> q = new SelectQuery<>(Painting.class);
q.addOrdering(Painting.PAINTING_TITLE.asc());
q.addPrefetch(Painting.TO_ARTIST.disjoint());
final List<Painting> results = q.select(child);
// blockQueries();
queryInterceptor.runWithQueriesBlocked(() -> {
assertEquals(2, results.size());
for (Painting o : results) {
assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
assertSame(child, o.getObjectContext());
Artist o1 = o.getToArtist();
assertNotNull(o1);
assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
assertSame(child, o1.getObjectContext());
assertEquals(prefetchedId, o1.getObjectId());
}
});
}
Aggregations