org.jdbi.v3.core.statement.Query.collectInto()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(154)

本文整理了Java中org.jdbi.v3.core.statement.Query.collectInto方法的一些代码示例,展示了Query.collectInto的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.collectInto方法的具体详情如下:
包路径:org.jdbi.v3.core.statement.Query
类名称:Query
方法名:collectInto

Query.collectInto介绍

暂无

代码示例

代码示例来源:origin: jdbi/jdbi

@Test
public void testTuple1CollectorWithMultiSelectShouldFail() {
  // first selection is not projectable to tuple param
  assertThatThrownBy(() -> dbRule.getSharedHandle()
    .createQuery("select t2, t3 from tuples")
    .collectInto(new GenericType<List<Tuple1<Integer>>>() {})).isInstanceOf(ResultSetException.class);
}

代码示例来源:origin: jdbi/jdbi

@Test
public void optionalMultiple() {
  assertThatThrownBy(() -> dbRule.getSharedHandle().createQuery("select intValue from something")
    .collectInto(new GenericType<Optional<Integer>>() {})).isInstanceOf(IllegalStateException.class);
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testMapCollectorReversedShouldFail() {
  assertThatThrownBy(() -> dbRule.getSharedHandle()
      .createQuery("select intValue, name from something")
      .collectInto(new GenericType<HashMap<String, Integer>>() {}))
      .isInstanceOf(ResultSetException.class);
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testBindOptionalInt() {
  assertThat(handle.createQuery("SELECT :value")
      .bind("value", OptionalInt.empty())
      .collectInto(OptionalInt.class))
      .isEmpty();
  assertThat(handle.createQuery("SELECT :value")
      .bind("value", OptionalInt.of(123))
      .collectInto(OptionalInt.class))
      .hasValue(123);
}

代码示例来源:origin: jdbi/jdbi

private <T extends Traversable<Tuple2<Integer, String>>> void testMapType(GenericType<T> containerType) {
  T values = dbRule.getSharedHandle().createQuery("select intValue, name from something")
      .collectInto(containerType);
  assertThat(values).containsOnlyElementsOf(expectedMap);
}

代码示例来源:origin: jdbi/jdbi

private <T extends Iterable<Integer>> void testType(GenericType<T> containerType) {
  T values = dbRule.getSharedHandle().createQuery("select intValue from something")
      .collectInto(containerType);
  assertThat(values).containsOnlyElementsOf(expected);
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testOptionMappedWithoutNestedMapperShouldFail() {
  assertThatThrownBy(() -> dbRule.getSharedHandle()
      .createQuery("select id, name from something")
      .collectInto(new GenericType<Set<Option<SomethingWithOption>>>() {}))
      .isInstanceOf(NoSuchMapperException.class)
      .hasMessageContaining("nested");
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testBindOptionalLong() {
  assertThat(handle.createQuery("SELECT :value")
      .bind("value", OptionalLong.empty())
      .collectInto(OptionalLong.class))
      .isEmpty();
  assertThat(handle.createQuery("SELECT :value")
      .bind("value", OptionalLong.of(123))
      .collectInto(OptionalLong.class))
      .hasValue(123);
}

代码示例来源:origin: jdbi/jdbi

@Test
public void immutableSortedSet() {
  ImmutableSortedSet<Integer> set = dbRule.getSharedHandle().createQuery("select intValue from something")
      .collectInto(new GenericType<ImmutableSortedSet<Integer>>(){});
  assertThat(set).containsExactlyElementsOf(expected);
}

代码示例来源:origin: jdbi/jdbi

@Test
public void immutableList() {
  ImmutableList<Integer> list = dbRule.getSharedHandle().createQuery("select intValue from something")
      .collectInto(new GenericType<ImmutableList<Integer>>(){});
  assertThat(list).containsOnlyElementsOf(expected);
}

代码示例来源:origin: jdbi/jdbi

@Test
public void immutableSet() {
  ImmutableSet<Integer> set = dbRule.getSharedHandle().createQuery("select intValue from something")
      .collectInto(new GenericType<ImmutableSet<Integer>>(){});
  assertThat(set).containsOnlyElementsOf(expected);
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testBindOptionalDouble() {
  assertThat(handle.createQuery("SELECT :value")
      .bind("value", OptionalDouble.empty())
      .collectInto(OptionalDouble.class))
      .isEmpty();
  assertThat(handle.createQuery("SELECT :value")
      .bind("value", OptionalDouble.of(123.45))
      .collectInto(OptionalDouble.class))
      .hasValue(123.45);
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testOptionMappedWithoutGenericParameterShouldFail() {
  assertThatThrownBy(() -> dbRule.getSharedHandle()
      .registerRowMapper(ConstructorMapper.factory(SomethingWithOption.class))
      .createQuery("select name from something")
      .collectInto(new GenericType<Set<Option>>() {}))
      .isInstanceOf(NoSuchMapperException.class)
      .hasMessageContaining("raw");
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testTuple1CollectorWithMultiSelectShouldSucceed() {
  List<Tuple1<Integer>> firstColumnTuples = expected.map(Tuple1::new);
  List<Tuple1<Integer>> tupleProjection = dbRule.getSharedHandle()
      .createQuery("select * from tuples")
      .collectInto(new GenericType<List<Tuple1<Integer>>>() {});
  assertThat(tupleProjection).containsOnlyElementsOf(firstColumnTuples);
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testOptionMappedShouldSucceed() {
  final Set<Option<String>> result = dbRule.getSharedHandle()
      .createQuery("select name from something")
      .collectInto(new GenericType<Set<Option<String>>>() {});
  assertThat(result).hasSize(2);
  assertThat(result).contains(Option.none(), Option.of("eric"));
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testTuple3CollectorWithSelectedKeyValueShouldSucceed() {
  List<Tuple3<Integer, String, String>> expectedTuples = expected.map(i -> new Tuple3<>(i, "t2" + i, "t3" + (i + 1)));
  List<Tuple3<Integer, String, String>> tupleProjection = dbRule.getSharedHandle()
      .createQuery("select t1, t2, t3 from tuples")
      .collectInto(new GenericType<List<Tuple3<Integer, String, String>>>() {});
  assertThat(tupleProjection).containsOnlyElementsOf(expectedTuples);
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testMapCollectorWithCorrespondingTupleColsShouldSucceed() {
  HashMap<String, String> valueMap = dbRule.getSharedHandle()
      .configure(TupleMappers.class, c -> c.setColumn(1, "key_c").setColumn(2, "val_c"))
      .createQuery("select val_c, key_c from keyval")
      .collectInto(new GenericType<HashMap<String, String>>() {});
  assertThat(valueMap).containsOnlyElementsOf(expectedMap);
}

代码示例来源:origin: jdbi/jdbi

@Test
public void optionalPresent() {
  Optional<Integer> shouldBePresent = dbRule.getSharedHandle().createQuery("select intValue from something where intValue = 1")
      .collectInto(new GenericType<Optional<Integer>>(){});
  assertThat(shouldBePresent).contains(1);
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testMapCollectorWithTupleConfigShouldSucceed() {
  HashMap<String, String> valueMap = dbRule.getSharedHandle()
      .configure(TupleMappers.class, c -> c.setKeyColumn("key_c").setValueColumn("val_c"))
      .createQuery("select val_c, key_c from keyval")
      .collectInto(new GenericType<HashMap<String, String>>() {});
  assertThat(valueMap).containsOnlyElementsOf(expectedMap);
}

代码示例来源:origin: jdbi/jdbi

@Test
public void optionalAbsent() {
  Optional<Integer> shouldBeAbsent = dbRule.getSharedHandle().createQuery("select intValue from something where intValue = 100")
      .collectInto(new GenericType<Optional<Integer>>(){});
  assertThat(shouldBeAbsent).isAbsent();
}

相关文章