Пример #1
0
  private void putOneToOneAssociation(
      Tuple tuple,
      Node node,
      TupleOperation operation,
      TupleContext tupleContext,
      Set<String> processedAssociationRoles) {
    String associationRole = tupleContext.getTupleTypeContext().getRole(operation.getColumn());

    if (!processedAssociationRoles.contains(associationRole)) {
      processedAssociationRoles.add(associationRole);

      EntityKey targetKey =
          getEntityKey(
              tuple,
              tupleContext
                  .getTupleTypeContext()
                  .getAssociatedEntityKeyMetadata(operation.getColumn()));

      // delete the previous relationship if there is one; for a to-one association, the
      // relationship won't have any
      // properties, so the type is uniquely identifying it
      Iterator<Relationship> relationships =
          node.getRelationships(withName(associationRole)).iterator();
      if (relationships.hasNext()) {
        relationships.next().delete();
      }

      // create a new relationship
      Node targetNode =
          entityQueries
              .get(targetKey.getMetadata())
              .findEntity(dataBase, targetKey.getColumnValues());
      node.createRelationshipTo(targetNode, withName(associationRole));
    }
  }
Пример #2
0
 private void putProperty(EntityKey entityKey, Node node, TupleOperation operation) {
   try {
     node.setProperty(operation.getColumn(), operation.getValue());
   } catch (ConstraintViolationException e) {
     throw log.constraintViolation(entityKey, operation, e);
   }
 }
Пример #3
0
 private void putProperty(EntityKey entityKey, Node node, TupleOperation operation) {
   try {
     node.setProperty(operation.getColumn(), operation.getValue());
   } catch (ConstraintViolationException e) {
     String message = e.getMessage();
     if (message.contains("already exists")) {
       throw log.mustNotInsertSameEntityTwice(String.valueOf(operation), e);
     } else {
       throw log.constraintViolation(entityKey, String.valueOf(operation), e);
     }
   }
 }
Пример #4
0
 private void putTupleOperation(
     EntityKey entityKey,
     Tuple tuple,
     Node node,
     TupleOperation operation,
     TupleContext tupleContext,
     Set<String> processedAssociationRoles) {
   if (tupleContext.getTupleTypeContext().isPartOfAssociation(operation.getColumn())) {
     // the column represents a to-one association, map it as relationship
     putOneToOneAssociation(tuple, node, operation, tupleContext, processedAssociationRoles);
   } else if (isPartOfRegularEmbedded(
       entityKey.getMetadata().getColumnNames(), operation.getColumn())) {
     entityQueries
         .get(entityKey.getMetadata())
         .updateEmbeddedColumn(
             dataBase, entityKey.getColumnValues(), operation.getColumn(), operation.getValue());
   } else {
     putProperty(entityKey, node, operation);
   }
 }
Пример #5
0
  private void removeTupleOperation(
      EntityKey entityKey,
      Node node,
      TupleOperation operation,
      TupleContext tupleContext,
      Set<String> processedAssociationRoles) {
    if (!tupleContext.getTupleTypeContext().isPartOfAssociation(operation.getColumn())) {
      if (isPartOfRegularEmbedded(entityKey.getColumnNames(), operation.getColumn())) {
        // Embedded node
        String[] split = split(operation.getColumn());
        removePropertyForEmbedded(node, split, 0);
      } else if (node.hasProperty(operation.getColumn())) {
        node.removeProperty(operation.getColumn());
      }
    }
    // if the column represents a to-one association, remove the relationship
    else {
      String associationRole = tupleContext.getTupleTypeContext().getRole(operation.getColumn());
      if (!processedAssociationRoles.contains(associationRole)) {

        Iterator<Relationship> relationships =
            node.getRelationships(withName(associationRole)).iterator();

        if (relationships.hasNext()) {
          relationships.next().delete();
        }
      }
    }
  }
Пример #6
0
 private void applyOperation(
     EntityKey entityKey,
     Tuple tuple,
     Node node,
     TupleOperation operation,
     TupleContext tupleContext,
     Set<String> processedAssociationRoles) {
   switch (operation.getType()) {
     case PUT:
       putTupleOperation(
           entityKey, tuple, node, operation, tupleContext, processedAssociationRoles);
       break;
     case PUT_NULL:
     case REMOVE:
       removeTupleOperation(entityKey, node, operation, tupleContext, processedAssociationRoles);
       break;
   }
 }