@Override
  public PrimitiveIntIterator nodeGetRelationshipTypes(KernelStatement state, long nodeId)
      throws EntityNotFoundException {
    if (state.hasTxStateWithChanges() && state.txState().nodeModifiedInThisTx(nodeId)) {
      ReadableTxState tx = state.txState();
      if (tx.nodeIsDeletedInThisTx(nodeId)) {
        return PrimitiveIntCollections.emptyIterator();
      }

      if (tx.nodeIsAddedInThisTx(nodeId)) {
        return tx.nodeRelationshipTypes(nodeId);
      }

      Set<Integer> types = new HashSet<>();

      // Add types in the current transaction
      PrimitiveIntIterator typesInTx = tx.nodeRelationshipTypes(nodeId);
      while (typesInTx.hasNext()) {
        types.add(typesInTx.next());
      }

      // Augment with types stored on disk, minus any types where all rels of that type are deleted
      // in current tx.
      PrimitiveIntIterator committedTypes = storeLayer.nodeGetRelationshipTypes(nodeId);
      while (committedTypes.hasNext()) {
        int current = committedTypes.next();
        if (!types.contains(current) && nodeGetDegree(state, nodeId, Direction.BOTH, current) > 0) {
          types.add(current);
        }
      }

      return PrimitiveIntCollections.toPrimitiveIterator(types.iterator());
    } else {
      return storeLayer.nodeGetRelationshipTypes(nodeId);
    }
  }