예제 #1
0
  private void putAssociationOperation(
      Association association,
      AssociationKey associationKey,
      AssociationOperation action,
      AssociatedEntityKeyMetadata associatedEntityKeyMetadata) {
    Relationship relationship =
        associationQueries
            .get(associationKey.getMetadata())
            .findRelationship(dataBase, associationKey, action.getKey());

    if (relationship != null) {
      for (String relationshipProperty : associationKey.getMetadata().getRowKeyIndexColumnNames()) {
        relationship.setProperty(relationshipProperty, action.getValue().get(relationshipProperty));
      }

      for (String column :
          associationKey
              .getMetadata()
              .getColumnsWithoutKeyColumns(action.getValue().getColumnNames())) {
        if (!isRowKeyColumn(associationKey.getMetadata(), column)) {
          relationship.getEndNode().setProperty(column, action.getValue().get(column));
        }
      }

      GraphLogger.log("Updated relationship: %1$s", relationship);
    } else {
      relationship =
          createRelationship(associationKey, action.getValue(), associatedEntityKeyMetadata);
      GraphLogger.log("Created relationship: %1$s", relationship);
    }
  }
예제 #2
0
  @Override
  public void insertOrUpdateTuple(EntityKey key, Tuple tuple, TupleContext tupleContext) {
    Neo4jTupleSnapshot snapshot = (Neo4jTupleSnapshot) tuple.getSnapshot();

    // insert
    if (snapshot.isNew()) {
      Node node = insertTuple(key, tuple);
      snapshot.setNode(node);
      applyTupleOperations(key, tuple, node, tuple.getOperations(), tupleContext);
      GraphLogger.log("Inserted node: %1$s", node);
    }
    // update
    else {
      Node node = snapshot.getNode();
      applyTupleOperations(key, tuple, node, tuple.getOperations(), tupleContext);
      GraphLogger.log("Updated node: %1$s", node);
    }
  }
예제 #3
0
  @Override
  public Association getAssociation(
      AssociationKey associationKey, AssociationContext associationContext) {
    EntityKey entityKey = associationKey.getEntityKey();
    Node entityNode =
        entityQueries
            .get(entityKey.getMetadata())
            .findEntity(dataBase, entityKey.getColumnValues());
    GraphLogger.log("Found owner node: %1$s", entityNode);
    if (entityNode == null) {
      return null;
    }

    Map<RowKey, Tuple> tuples = createAssociationMap(associationKey, associationContext, entityKey);
    return new Association(new EmbeddedNeo4jAssociationSnapshot(tuples));
  }