Search in sources :

Example 1 with PropagatedValueFactory

use of org.apache.cayenne.access.DataDomainSyncBucket.PropagatedValueFactory in project cayenne by apache.

the class FlattenedArcKey method lazyJoinSnapshot.

private Map<String, Object> lazyJoinSnapshot() {
    List<DbRelationship> relList = relationship.getDbRelationships();
    if (relList.size() != 2) {
        throw new CayenneRuntimeException("Only single-step flattened relationships are supported in this operation: %s", relationship);
    }
    DbRelationship firstDbRel = relList.get(0);
    DbRelationship secondDbRel = relList.get(1);
    List<DbJoin> fromSourceJoins = firstDbRel.getJoins();
    List<DbJoin> toTargetJoins = secondDbRel.getJoins();
    Map<String, Object> snapshot = new HashMap<>(fromSourceJoins.size() + toTargetJoins.size(), 1);
    for (DbJoin join : fromSourceJoins) {
        Object value = new PropagatedValueFactory(id1.getSourceId(), join.getSourceName());
        snapshot.put(join.getTargetName(), value);
    }
    for (DbJoin join : toTargetJoins) {
        Object value = new PropagatedValueFactory(id2.getSourceId(), join.getTargetName());
        snapshot.put(join.getSourceName(), value);
    }
    return snapshot;
}
Also used : HashMap(java.util.HashMap) DbRelationship(org.apache.cayenne.map.DbRelationship) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) DbJoin(org.apache.cayenne.map.DbJoin) PropagatedValueFactory(org.apache.cayenne.access.DataDomainSyncBucket.PropagatedValueFactory)

Example 2 with PropagatedValueFactory

use of org.apache.cayenne.access.DataDomainSyncBucket.PropagatedValueFactory in project cayenne by apache.

the class DataDomainDBDiffBuilder method appendForeignKeys.

private void appendForeignKeys(Map<String, Object> dbDiff) {
    // populate changed FKs
    if (currentArcDiff != null) {
        for (Entry<Object, Object> entry : currentArcDiff.entrySet()) {
            DbRelationship dbRelation;
            String arcIdString = entry.getKey().toString();
            ObjRelationship relation = objEntity.getRelationship(arcIdString);
            if (relation == null) {
                dbRelation = dbEntity.getRelationship(arcIdString.substring(ASTDbPath.DB_PREFIX.length()));
            } else {
                dbRelation = relation.getDbRelationships().get(0);
            }
            // In case of a vertical inheritance, ensure that it belongs to this bucket...
            if (dbRelation.getSourceEntity() == dbEntity) {
                ObjectId targetId = (ObjectId) entry.getValue();
                for (DbJoin join : dbRelation.getJoins()) {
                    Object value = (targetId != null) ? new PropagatedValueFactory(targetId, join.getTargetName()) : null;
                    dbDiff.put(join.getSourceName(), value);
                }
            }
        }
    }
}
Also used : ObjectId(org.apache.cayenne.ObjectId) PropagatedValueFactory(org.apache.cayenne.access.DataDomainSyncBucket.PropagatedValueFactory)

Aggregations

PropagatedValueFactory (org.apache.cayenne.access.DataDomainSyncBucket.PropagatedValueFactory)2 HashMap (java.util.HashMap)1 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 ObjectId (org.apache.cayenne.ObjectId)1 DbJoin (org.apache.cayenne.map.DbJoin)1 DbRelationship (org.apache.cayenne.map.DbRelationship)1