// check flag again in the synced block...
if (!dbRelationshipsRefreshNeeded) {
return;
}
EventManager eventLoop = EventManager.getDefaultManager();
// remove existing relationships
Iterator removeIt = dbRelationships.iterator();
while (removeIt.hasNext()) {
DbRelationship relationship = (DbRelationship) removeIt.next();
eventLoop.removeListener(
this,
DbRelationship.PROPERTY_DID_CHANGE,
relationship);
removeIt.remove();
}
if (this.dbRelationshipPath != null) {
ObjEntity entity = (ObjEntity) getSourceEntity();
if (entity == null) {
throw new CayenneRuntimeException(
"Can't resolve DbRelationships, null source ObjEntity");
}
try {
// add new relationships from path
Iterator it = entity.resolvePathComponents(new ASTDbPath(
this.dbRelationshipPath));
while (it.hasNext()) {
DbRelationship relationship = (DbRelationship) it.next();
// listen for changes
eventLoop.addListener(
this,
"dbRelationshipDidChange",
RelationshipEvent.class,
DbRelationship.PROPERTY_DID_CHANGE,
relationship);