Ejemplo n.º 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);
    }
  }
Ejemplo n.º 2
0
  @Override
  public void insertOrUpdateAssociation(
      AssociationKey key, Association association, AssociationContext associationContext) {
    Map<SerializableRowKey, Map<String, Object>> associationRows =
        ((SerializableMapAssociationSnapshot) association.getSnapshot()).getUnderlyingMap();

    for (AssociationOperation action : association.getOperations()) {
      switch (action.getType()) {
        case CLEAR:
          associationRows.clear();
        case PUT:
          associationRows.put(
              new SerializableRowKey(action.getKey()),
              MapHelpers.associationRowToMap(action.getValue()));
          break;
        case REMOVE:
          associationRows.remove(new SerializableRowKey(action.getKey()));
          break;
      }
    }

    final Cache<AK> associationCache = getCacheManager().getAssociationCache(key.getMetadata());
    associationCache.put(
        new Element(getKeyProvider().getAssociationCacheKey(key), associationRows));
  }