@Test
    public void testManyVarcharBindValues() throws Exception {

        // [#1726] Check if large amounts of VARCHAR bind values can be handled
        Record record = create().select(Collections.nCopies(1000, val("abc"))).fetchOne();
        assertEquals(1000, record.size());
        assertEquals(Collections.nCopies(1000, "abc"), asList(record.intoArray()));

        assertEquals(1, create().selectOne()
            .where(val("abc").in(Collections.nCopies(1000, val("abc")).toArray(new Field[0])))
            .fetchOne(0));
    }
Beispiel #2
0
    @Test
    public void testH2V2603WithExcludedColumns() throws Exception {

        // The generated table only has two columns
        V_2603Record record =
        create().selectFrom(V_2603)
                .fetchOne();

        assertEquals(2, record.size());
        assertEquals(1, (int) record.getCol1());
        assertEquals(4, (int) record.getCol4());

        // The actual table has four columns
        Record r =
        create().selectFrom(table(V_2603.getName()))
                .fetchOne();

        assertEquals(4, r.size());
        assertEquals(asList(1, 2, 3, 4), asList(r.intoArray()));
    }
Beispiel #3
0
  @Override
  public int compareTo(Record that) {
    // Note: keep this implementation in-sync with AbstractStore.equals()!

    if (that == null) {
      throw new NullPointerException();
    }
    if (size() != that.size()) {
      throw new ClassCastException(
          String.format(
              "Trying to compare incomparable records (wrong degree):\n%s\n%s", this, that));
    }

    Class<?>[] thisTypes = this.fieldsRow().types();
    Class<?>[] thatTypes = that.fieldsRow().types();

    if (!asList(thisTypes).equals(asList(thatTypes))) {
      throw new ClassCastException(
          String.format(
              "Trying to compare incomparable records (type mismatch):\n%s\n%s", this, that));
    }

    for (int i = 0; i < size(); i++) {
      final Object thisValue = getValue(i);
      final Object thatValue = that.getValue(i);

      // [#1850] Only return -1/+1 early. In all other cases,
      // continue checking the remaining fields
      if (thisValue == null && thatValue == null) {
        continue;
      }

      // Order column values in a SQL NULLS LAST manner
      else if (thisValue == null) {
        return 1;
      } else if (thatValue == null) {
        return -1;
      }

      // [#985] Compare arrays too.
      else if (thisValue.getClass().isArray() && thatValue.getClass().isArray()) {

        // Might be byte[]
        if (thisValue.getClass() == byte[].class) {
          int compare = compare((byte[]) thisValue, (byte[]) thatValue);

          if (compare != 0) {
            return compare;
          }
        }

        // Other primitive types are not expected
        else if (!thisValue.getClass().getComponentType().isPrimitive()) {
          int compare = compare((Object[]) thisValue, (Object[]) thatValue);

          if (compare != 0) {
            return compare;
          }
        } else {
          throw new ClassCastException(
              String.format("Unsupported data type in natural ordering: %s", thisValue.getClass()));
        }
      } else {
        int compare = ((Comparable) thisValue).compareTo(thatValue);

        if (compare != 0) {
          return compare;
        }
      }
    }

    // If we got through the above loop, the two records are equal
    return 0;
  }