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)); } }
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); } }
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); } } }
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); } }
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(); } } } }
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; } }