本文整理了Java中org.jdbi.v3.core.statement.Update.bindByType()
方法的一些代码示例,展示了Update.bindByType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Update.bindByType()
方法的具体详情如下:
包路径:org.jdbi.v3.core.statement.Update
类名称:Update
方法名:bindByType
暂无
代码示例来源:origin: jdbi/jdbi
@Test
public void testUuidArrayList() {
assertThat(
h.createUpdate(U_INSERT)
.bindByType("u", new ArrayList<>(Arrays.asList(testUuids)), UUID_LIST)
.execute())
.isEqualTo(1);
assertThat(
h.createQuery(U_SELECT)
.mapTo(UUID_ARRAYLIST)
.findOnly())
.containsExactly(testUuids);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testUuidList() {
assertThat(
h.createUpdate(U_INSERT)
.bindByType("u", Arrays.asList(testUuids), UUID_LIST)
.execute())
.isEqualTo(1);
assertThat(
h.createQuery(U_SELECT)
.mapTo(UUID_LIST)
.findOnly())
.containsExactly(testUuids);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testUuidHashSet() {
assertThat(
h.createUpdate(U_INSERT)
.bindByType("u", new HashSet<>(Arrays.asList(testUuids)), UUID_SET)
.execute())
.isEqualTo(1);
assertThat(
h.createQuery(U_SELECT)
.mapTo(UUID_HASHSET)
.findOnly())
.containsExactlyInAnyOrder(testUuids);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testInsertNullUrlUsingBindByType() {
handle.createUpdate("INSERT INTO foo VALUES (:url)")
.bindByType("url", null, URL.class)
.execute();
assertThatThrownBy(() -> handle.createQuery("SELECT url FROM foo").mapTo(URL.class).findOnly())
.isInstanceOf(ResultSetException.class);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testInsertUrlUsingBindByType() throws MalformedURLException {
URL githubUrl = new URL("http://www.github.com");
handle.createUpdate("INSERT INTO foo VALUES (:url)")
.bindByType("url", githubUrl, URL.class)
.execute();
URL dbUrl = handle.createQuery("SELECT * FROM foo").mapTo(URL.class).findOnly();
Assertions.assertThat(dbUrl).hasToString(githubUrl.toString());
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testUuidLinkedHashSet() {
assertThat(
h.createUpdate(U_INSERT)
.bindByType("u", new LinkedHashSet<>(Arrays.asList(testUuids)), UUID_SET)
.execute())
.isEqualTo(1);
assertThat(
h.createQuery(U_SELECT)
.mapTo(UUID_LINKEDHASHSET)
.findOnly())
.isInstanceOf(LinkedHashSet.class)
.containsExactly(testUuids);
}
}
代码示例来源:origin: jdbi/jdbi
@Test
public void factoryChainWorks() {
Object instance = new Foo();
String json = "foo";
when(jsonMapper.toJson(eq(Foo.class), eq(instance), any(ConfigRegistry.class))).thenReturn(json);
when(jsonMapper.fromJson(eq(Foo.class), eq(json), any(ConfigRegistry.class))).thenReturn(instance);
Object result = db.getJdbi().withHandle(h -> {
h.createUpdate("insert into foo(bar) values(:foo)")
.bindByType("foo", instance, QualifiedType.of(Foo.class).with(Json.class))
.execute();
assertThat(h.createQuery("select bar from foo").mapTo(String.class).findOnly())
.isEqualTo(json);
return h.createQuery("select bar from foo")
.mapTo(QualifiedType.of(Foo.class).with(Json.class))
.findOnly();
});
assertThat(result).isSameAs(instance);
verify(jsonMapper).fromJson(eq(Foo.class), eq(json), any(ConfigRegistry.class));
verify(jsonMapper).toJson(eq(Foo.class), eq(instance), any(ConfigRegistry.class));
}
代码示例来源:origin: jdbi/jdbi
@Test
public void methodCallCanBeAnnotatedAsByOrdinal() {
db.getJdbi().useHandle(h -> {
h.createUpdate("create table enums(id int, ordinal int)").execute();
h.createUpdate("insert into enums (id, ordinal) values (1, :ordinal)")
.bindByType("ordinal", Foobar.FOO, QualifiedType.of(Foobar.class).with(EnumByOrdinal.class))
.execute();
Integer inserted = h.createQuery("select ordinal from enums")
.mapTo(Integer.class)
.findOnly();
assertThat(inserted).isEqualTo(Foobar.FOO.ordinal());
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void registerArgumentFactory() {
dbRule.getJdbi()
.registerArgument(new ReversedStringArgumentFactory())
.useHandle(handle -> {
handle.createUpdate("INSERT INTO something (id, name) VALUES (1, :name)")
.bindByType("name", "abc", QualifiedType.of(String.class).with(Reversed.class))
.execute();
assertThat(
handle.select("SELECT name FROM something")
.mapTo(String.class)
.findOnly())
.isEqualTo("cba");
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void methodCallOverridesClassForOrdinal() {
db.getJdbi().useHandle(h -> {
h.createUpdate("create table enums(id int, ordinal int)").execute();
h.createUpdate("insert into enums(id, ordinal) values(1, :ordinal)")
.bindByType("ordinal", ByName.ALPHABETIC, QualifiedType.of(ByName.class).with(EnumByOrdinal.class))
.execute();
Integer inserted = h.createQuery("select ordinal from enums")
.mapTo(Integer.class)
.findOnly();
assertThat(inserted).isEqualTo(ByName.ALPHABETIC.ordinal());
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testFluentApi() {
jdbi.useHandle(h -> {
h.execute("create table subjects (id serial primary key, subject json not null)");
JsonBean in = new JsonBean("nom", 10);
h.createUpdate("insert into subjects(id, subject) values(1, :bean)")
.bindByType("bean", in, QualifiedType.of(JsonBean.class).with(Json.class))
.execute();
JsonBean out = h.createQuery("select subject from subjects")
.mapTo(QualifiedType.of(JsonBean.class).with(Json.class))
.findOnly();
assertThat(out).isEqualTo(in);
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void configArgumentsRegister() {
dbRule.getJdbi()
.configure(Arguments.class, config -> config.register(new ReversedStringArgumentFactory()))
.useHandle(handle -> {
handle.createUpdate("INSERT INTO something (id, name) VALUES (1, :name)")
.bindByType("name", "abc", QualifiedType.of(String.class).with(Reversed.class))
.execute();
assertThat(
handle.select("SELECT name FROM something")
.mapTo(String.class)
.findOnly())
.isEqualTo("cba");
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void methodCallCanBeAnnotatedAsByName() {
db.getJdbi().useHandle(h -> {
h.getConfig(Enums.class).setEnumStrategy(EnumStrategy.BY_ORDINAL);
h.createUpdate("create table enums(id int, name varchar)").execute();
h.createUpdate("insert into enums (id, name) values (1, :name)")
.bindByType("name", Foobar.FOO, QualifiedType.of(Foobar.class).with(EnumByName.class))
.execute();
String inserted = h.createQuery("select name from enums")
.mapTo(String.class)
.findOnly();
assertThat(inserted).isEqualTo(Foobar.FOO.name());
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void methodCallOverridesClassForName() {
db.getJdbi().useHandle(h -> {
h.getConfig(Enums.class).setEnumStrategy(EnumStrategy.BY_ORDINAL);
h.createUpdate("create table enums(id int, name varchar)").execute();
h.createUpdate("insert into enums(id, name) values(1, :name)")
.bindByType("name", ByOrdinal.NUMERIC, QualifiedType.of(ByOrdinal.class).with(EnumByName.class))
.execute();
String inserted = h.createQuery("select name from enums")
.mapTo(String.class)
.findOnly();
assertThat(inserted).isEqualTo(ByOrdinal.NUMERIC.name());
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testWritesViaFluentApi() {
handle.createUpdate("insert into campaigns(id, caps) values (:id, :caps)")
.bind("id", 3)
.bindByType("caps", caps, QualifiedType.of(STRING_MAP).with(HStore.class))
.execute();
Map<String, String> newCaps = handle.createQuery("select caps from campaigns where id=?")
.bind(0, 3)
.mapTo(QualifiedType.of(STRING_MAP).with(HStore.class))
.findOnly();
assertThat(newCaps).isEqualTo(caps);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testNull() {
db.getJdbi().useHandle(h -> {
h.createUpdate("create table enums(value varchar)").execute();
h.createUpdate("insert into enums(value) values(:enum)")
.bindByType("enum", null, Foobar.class)
.execute();
String inserted = h.createQuery("select value from enums")
.mapTo(String.class)
.findOnly();
assertThat(inserted).isNull();
Foobar mapped = h.createQuery("select value from enums")
.mapTo(Foobar.class)
.findOnly();
assertThat(mapped).isNull();
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void bindMultipleQualifiers() {
dbRule.getJdbi()
// should use this one - register first so it's consulted last
.registerArgument(new ReversedUpperCaseStringArgumentFactory())
.registerArgument(new ReversedStringArgumentFactory())
.registerArgument(new UpperCaseArgumentFactory())
.useHandle(handle -> {
handle.createUpdate("INSERT INTO something (id, name) VALUES (1, :name)")
.bindByType("name", "abc", QualifiedType.of(String.class).with(Reversed.class, UpperCase.class))
.execute();
assertThat(handle.select("SELECT name FROM something")
.mapTo(String.class)
.findOnly())
.isEqualTo("CBA");
});
}
代码示例来源:origin: jdbi/jdbi
.bindByType(1, "baz", NVARCHAR_STRING)
.execute();
.bindByType("name", "qux", NVARCHAR_STRING)
.execute();
代码示例来源:origin: org.jdbi/jdbi3-json
@Test
public void factoryChainWorks() {
Object instance = new Foo();
String json = "foo";
when(jsonMapper.toJson(eq(Foo.class), eq(instance), any(StatementContext.class))).thenReturn(json);
when(jsonMapper.fromJson(eq(Foo.class), eq(json), any(StatementContext.class))).thenReturn(instance);
Object result = db.getJdbi().withHandle(h -> {
h.createUpdate("insert into foo(bar) values(:foo)")
.bindByType("foo", instance, QualifiedType.of(Foo.class).with(Json.class))
.execute();
assertThat(h.createQuery("select bar from foo").mapTo(String.class).findOnly())
.isEqualTo(json);
return h.createQuery("select bar from foo")
.mapTo(QualifiedType.of(Foo.class).with(Json.class))
.findOnly();
});
assertThat(result).isSameAs(instance);
verify(jsonMapper).fromJson(eq(Foo.class), eq(json), any(StatementContext.class));
verify(jsonMapper).toJson(eq(Foo.class), eq(instance), any(StatementContext.class));
}
代码示例来源:origin: org.jdbi/jdbi3-json
@Test
public void testFluentApi() {
jdbi.useHandle(h -> {
h.execute("create table subjects (id serial primary key, subject json not null)");
JsonBean in = new JsonBean("nom", 10);
h.createUpdate("insert into subjects(id, subject) values(1, :bean)")
.bindByType("bean", in, QualifiedType.of(JsonBean.class).with(Json.class))
.execute();
JsonBean out = h.createQuery("select subject from subjects")
.mapTo(QualifiedType.of(JsonBean.class).with(Json.class))
.findOnly();
assertThat(out).isEqualTo(in);
});
}
内容来源于网络,如有侵权,请联系作者删除!