예제 #1
0
  private Map<RowKey, Tuple> createAssociationMap(
      AssociationKey associationKey, AssociationContext associationContext, EntityKey entityKey) {
    String relationshipType = associationContext.getAssociationTypeContext().getRoleOnMainSide();
    ResourceIterator<Relationship> relationships =
        entityQueries
            .get(entityKey.getMetadata())
            .findAssociation(dataBase, entityKey.getColumnValues(), relationshipType);

    Map<RowKey, Tuple> tuples = new HashMap<RowKey, Tuple>();
    try {
      while (relationships.hasNext()) {
        Relationship relationship = relationships.next();
        AssociatedEntityKeyMetadata associatedEntityKeyMetadata =
            associationContext.getAssociationTypeContext().getAssociatedEntityKeyMetadata();
        EmbeddedNeo4jTupleAssociationSnapshot snapshot =
            new EmbeddedNeo4jTupleAssociationSnapshot(
                relationship, associationKey, associatedEntityKeyMetadata);
        RowKey rowKey = convert(associationKey, snapshot);
        tuples.put(rowKey, new Tuple(snapshot, SnapshotType.UPDATE));
      }
      return tuples;
    } finally {
      relationships.close();
    }
  }
예제 #2
0
  @Test
  public void shouldCloseTransactionsWhenIteratingOverSingleColumn() throws Exception {
    // Given an execution result that has been started but not exhausted
    createNode();
    createNode();
    ExecutionResult executionResult = engine.execute("MATCH (n) RETURN n");
    ResourceIterator<Node> resultIterator = executionResult.columnAs("n");
    resultIterator.next();
    assertThat(activeTransaction(), is(notNullValue()));

    // When
    resultIterator.close();

    // Then
    assertThat(activeTransaction(), is(nullValue()));
  }
예제 #3
0
  @Override
  public List<Tuple> getTuples(EntityKey[] keys, TupleContext tupleContext) {
    if (keys.length == 0) {
      return Collections.emptyList();
    }

    // We only supports one metadata for now
    EntityKeyMetadata metadata = keys[0].getMetadata();
    // The result returned by the query might not be in the same order as the keys.
    ResourceIterator<Node> nodes = entityQueries.get(metadata).findEntities(dataBase, keys);
    try {
      return tuplesResult(keys, tupleContext, nodes);
    } finally {
      nodes.close();
    }
  }
예제 #4
0
 @Override
 public void forEachTuple(ModelConsumer consumer, EntityKeyMetadata... entityKeyMetadatas) {
   for (EntityKeyMetadata entityKeyMetadata : entityKeyMetadatas) {
     ResourceIterator<Node> queryNodes =
         entityQueries.get(entityKeyMetadata).findEntities(dataBase);
     try {
       while (queryNodes.hasNext()) {
         Node next = queryNodes.next();
         Tuple tuple = new Tuple(new Neo4jTupleSnapshot(next, entityKeyMetadata));
         consumer.consume(tuple);
       }
     } finally {
       queryNodes.close();
     }
   }
 }
예제 #5
0
 @Override
 public void forEachTuple(
     ModelConsumer consumer,
     TupleTypeContext tupleTypeContext,
     EntityKeyMetadata entityKeyMetadata) {
   ResourceIterator<Node> queryNodes = entityQueries.get(entityKeyMetadata).findEntities(dataBase);
   try {
     while (queryNodes.hasNext()) {
       Node next = queryNodes.next();
       Tuple tuple =
           new Tuple(
               EmbeddedNeo4jTupleSnapshot.fromNode(
                   next,
                   tupleTypeContext.getAllAssociatedEntityKeyMetadata(),
                   tupleTypeContext.getAllRoles(),
                   entityKeyMetadata),
               SnapshotType.UPDATE);
       consumer.consume(tuple);
     }
   } finally {
     queryNodes.close();
   }
 }