static void cg_java_proc_result_set_getter()

in sources/cg_java.c [83:196]


static void cg_java_proc_result_set_getter(
  bool_t fetch_proc,
  CSTR name,
  CSTR col_name,
  int32_t col,
  charbuf *java,
  sem_t sem_type,
  bool_t encode,
  bool_t custom_type_for_encoded_column,
  uint32_t frag_type,
  uint32_t col_count_for_base)
{
  Contract(is_unitary(sem_type));
  Contract(core_type_of(sem_type) != SEM_TYPE_NULL);
  Contract(frag_type != FRAG_TYPE_SHARED);
  Contract(frag_type != FRAG_TYPE_EXTENSION);

  bool_t notnull = is_not_nullable(sem_type);
  sem_t core_type = core_type_of(sem_type);

  CSTR return_type;
  CSTR field_type;
  CSTR prefix = "get_";
  CSTR nullable_prefix = notnull ? "" : "_nullable_";
  CSTR nullable_attr = notnull ? "" : "@Nullable\n";

  switch (core_type) {
    case SEM_TYPE_INTEGER:
      if (notnull) {
        return_type = rt->cql_int32;
      } else {
        return_type = rt->cql_int32_nullable;
      }
      field_type = rt->cql_int32_nullable;
      break;

    case SEM_TYPE_TEXT:
      nullable_prefix = "";
      if (encode && custom_type_for_encoded_column) {
        return_type = rt->cql_string_ref_encode;
        field_type = rt->cql_string_ref_encode;
      } else {
        return_type = rt->cql_string_ref;
        field_type = rt->cql_string_ref;
      }
      break;

    case SEM_TYPE_LONG_INTEGER:
      if (notnull) {
        return_type = rt->cql_int64;
      } else {
        return_type = rt->cql_int64_nullable;
      }
      field_type = rt->cql_int64_nullable;
      break;

    case SEM_TYPE_REAL:
      if (notnull) {
        return_type = rt->cql_double;
      } else {
        return_type = rt->cql_double_nullable;
      }
      field_type = rt->cql_double_nullable;
      break;

    case SEM_TYPE_BOOL:
      if (notnull) {
        prefix = "";
        return_type = rt->cql_bool;
      } else {
        return_type = rt->cql_bool_nullable;
      }
      field_type = rt->cql_bool_nullable;
      break;

    case SEM_TYPE_BLOB:
      nullable_prefix = "";
      return_type = rt->cql_blob_ref;
      field_type = "Blob";
      break;
  }

  CG_CHARBUF_OPEN_SYM(col_name_camel, prefix, col_name);
  CG_CHARBUF_OPEN_SYM(method_name, nullable_prefix, field_type);

  CHARBUF_OPEN(col_index);
  bprintf(&col_index, "%d", col);

  bprintf(java, nullable_attr);
  CHARBUF_OPEN(getter_sig);
  // patternlint-disable-next-line prefer-sized-ints-in-msys
  cg_java_getter_sig(&getter_sig, return_type, col_name_camel.ptr, fetch_proc ? "" : "int row");
  if (!options.java_fragment_interface_mode || cg_java_frag_type_query_proc(frag_type)) {
    bprintf(java,
            rt->cql_result_set_get_data,
            getter_sig.ptr,
            method_name.ptr,
            fetch_proc ? "0" : "row",
            col_index.ptr);
  } else {
    bprintf(java, "%s;\n\n", getter_sig.ptr);
  }

  if (encode) {
    bprintf(java, "public %s %sIsEncoded() {\n", rt->cql_bool, col_name_camel.ptr);
    bprintf(java, "  return mResultSet.getIsEncoded(%s);\n", col_index.ptr);
    bprintf(java, "}\n\n");
  }

  CHARBUF_CLOSE(getter_sig);
  CHARBUF_CLOSE(col_index);
  CHARBUF_CLOSE(method_name);
  CHARBUF_CLOSE(col_name_camel);
}