public AdaptIntermediateStructCollectingCursor()

in old/dekaf-core/src/main/java/org/jetbrains/dekaf/intermediate/AdaptIntermediateStructCollectingCursor.java [47:93]


  public AdaptIntermediateStructCollectingCursor(@NotNull final PrimeIntermediateCursor<List<Object[]>> remoteCursor,
                                                 @NotNull final ResultLayout<T> resultLayout) {
    super(remoteCursor);
    assert resultLayout.kind == ResultLayout.Kind.SINGLE_ROW
        || resultLayout.kind == ResultLayout.Kind.ARRAY
        || resultLayout.kind == ResultLayout.Kind.LIST
        || resultLayout.kind == ResultLayout.Kind.SET;

    assert resultLayout.row.kind == RowLayout.Kind.STRUCT;

    final Class<?> rowClass = resultLayout.row.rowClass;
    myResultLayout = resultLayout;
    myRowConstructor = defaultConstructorOf(rowClass);
    myRowConstructor.setAccessible(true);

    final NameAndClass[] components = myResultLayout.row.components;
    final int n = components.length;
    myRowClassFields = new Field[n];

    myHasRows = remoteCursor.hasRows();
    if (!hasRows()) {
      return;
    }

    boolean somethingMatched = false;

    for (int i = 0; i < n; i++) {
      final String name = components[i].name;

      final Field field;
      try {
        field = rowClass.getDeclaredField(name);
        field.setAccessible(true);
        myRowClassFields[i] = field;
        somethingMatched = true;
      }
      catch (NoSuchFieldException e) {
        // it's strange
      }
    }

    if (!somethingMatched) {
      String msg = format("The query result and the class %s have no common fields. Fields of the class: [%s].",
                          rowClass.getName(), arrayToString(components, ", "));
      throw new IllegalStateException(msg);
    }
  }