Ejemplo n.º 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));
    }
  }
Ejemplo n.º 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);
   }
 }
Ejemplo n.º 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);
     }
   }
 }
Ejemplo n.º 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);
   }
 }
Ejemplo n.º 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();
        }
      }
    }
  }
Ejemplo n.º 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;
   }
 }