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

x33g5p2x  于2022-02-01 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(197)

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

Update.bindBean介绍

暂无

代码示例

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

@Test
public void testBean() {
  handle.createUpdate(INSERT_NAMED).bindBean(new StringBean("herp")).execute();
  assertThat(named).isEqualTo("herp");
}

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

private void insert(String binding, Object bean) {
  dbRule.getJdbi().useHandle(h -> {
    String insert = String.format("INSERT INTO test VALUES(:id, :%s)", binding);
    h.createUpdate(insert).bindBean(bean).execute();
  });
}

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

@Test
public void testCascadedLazyArgs() {
  Handle h = dbRule.openHandle();
  Update s = h.createUpdate("insert into something (id, name) values (:id, :name)");
  Map<String, Object> args = new HashMap<>();
  args.put("id", 0);
  s.bindMap(args);
  s.bindBean(new Keith());
  int insertCount = s.execute();
  assertThat(insertCount).isEqualTo(1);
  Something something = h.createQuery("select id, name from something").mapToBean(Something.class).findOnly();
  assertThat(something).isEqualTo(new Something(0, "Keith"));
}

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

@Test
public void testBeanPropertyPrefixBinding() {
  Handle h = dbRule.openHandle();
  Something original = new Something(0, "Keith");
  assertThat(h
    .createUpdate("insert into something (id, name) values (:my.id, :my.name)")
    .bindBean("my", original)
    .execute())
    .isEqualTo(1);
  assertThat(h
    .select("select * from something where id = ?", original.getId())
    .mapToBean(Something.class)
    .findOnly())
    .isEqualTo(original);
}

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

@Test
public void testFluentApiWithNesting() {
  jdbi.useHandle(h -> {
    h.execute("create table bean (id serial primary key, nested1 json, nested2 json)");
    assertThat(h.createUpdate("insert into bean(id, nested1, nested2) values (:id, :nested1, :nested2)")
      .bindBean(new NestedJsonBean(42, 64, "quux"))
      .execute()).isEqualTo(1);
    NestedJsonBean beany = h.createQuery("select * from bean")
      .mapToBean(NestedJsonBean.class)
      .findOnly();
    assertThat(beany.getId()).isEqualTo(42);
    assertThat(beany.getNested1().getA()).isEqualTo(64);
    assertThat(beany.getNested2().getA()).isEqualTo("quux");
  });
}

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

@Test
public void testBeanPropertyBinding() {
  Handle h = dbRule.openHandle();
  Something original = new Something(0, "Keith");
  assertThat(h
    .createUpdate("insert into something (id, name) values (:id, :name)")
    .bindBean(original)
    .execute())
    .isEqualTo(1);
  assertThat(h
    .select("select * from something where id = ?", original.getId())
    .mapToBean(Something.class)
    .findOnly())
    .isEqualTo(original);
}

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

@Test
public void testBeanPropertyNestedBinding() {
  Handle h = dbRule.openHandle();
  Something thing = new Something(0, "Keith");
  assertThat(h
    .createUpdate("insert into something (id, name) values (:my.nested.id, :my.nested.name)")
    .bindBean("my", new NestsSomething(thing))
    .execute()).isEqualTo(1);
  assertThat(h
    .select("select * from something where id = ?", thing.getId())
    .mapToBean(Something.class)
    .findOnly())
    .isEqualTo(thing);
}

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

@Test
public void bindBeanQualifiedSetter() {
  dbRule.getJdbi()
    .registerArgument(new ReversedStringArgumentFactory())
    .useHandle(handle -> {
      handle.createUpdate("INSERT INTO something (id, name) VALUES (:id, :name)")
        .bindBean(new QualifiedSetterThing(1, "abc"))
        .execute();
      assertThat(handle.select("SELECT name FROM something")
        .mapTo(String.class)
        .findOnly())
        .isEqualTo("cba");
    });
}

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

@Test
public void bindBeanQualifiedGetter() {
  dbRule.getJdbi()
    .registerArgument(new ReversedStringArgumentFactory())
    .useHandle(handle -> {
      handle.createUpdate("INSERT INTO something (id, name) VALUES (:id, :name)")
        .bindBean(new QualifiedGetterThing(1, "abc"))
        .execute();
      assertThat(handle.select("SELECT name FROM something")
        .mapTo(String.class)
        .findOnly())
        .isEqualTo("cba");
    });
}

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

@Test
public void bindBeanQualifiedSetterParam() {
  dbRule.getJdbi()
    .registerArgument(new ReversedStringArgumentFactory())
    .useHandle(handle -> {
      handle.createUpdate("INSERT INTO something (id, name) VALUES (:id, :name)")
        .bindBean(new QualifiedSetterParamThing(1, "abc"))
        .execute();
      assertThat(handle.select("SELECT name FROM something")
        .mapTo(String.class)
        .findOnly())
        .isEqualTo("cba");
    });
}

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

@Test
public void testUsefulArgumentOutputForDebug() {
  expectedException.expect(StatementException.class);
  expectedException.expectMessage("arguments:{positional:{7:8}, named:{name:brian}, finder:[{one=two},{lazy bean property arguments \"java.lang.Object");
  h.createUpdate("insert into something (id, name) values (:id, :name)")
      .bind("name", "brian")
      .bind(7, 8)
      .bindMap(new HandyMapThing<String>().add("one", "two"))
      .bindBean(new Object())
      .execute();
}

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

.bindBean(new User(3, "David"))
.execute();

代码示例来源:origin: de.digitalcollections.cudami/dc-cudami-server-backend-jdbi

@Override
public A save(A article) {
 entityRepository.save(article);
 dbi.withHandle(h -> h.createUpdate("INSERT INTO articles(uuid, text) VALUES (:uuid, :text::JSONB)")
     .bindBean(article)
     .execute());
 return findOne(article.getUuid());
}

代码示例来源:origin: de.digitalcollections.cudami/dc-cudami-server-backend-jdbi

@Override
public W save(W website) {
 entityRepository.save(website);
 dbi.withHandle(h -> h.createUpdate("INSERT INTO websites(url, registration_date, uuid) VALUES (:url, :registrationDate, :uuid)")
     .bindBean(website)
     .execute());
 return findOne(website.getUuid());
}

代码示例来源:origin: de.digitalcollections.cudami/dc-cudami-server-backend-jdbi

@Override
public C save(C contentNode) {
 identifiableRepository.save(contentNode);
 dbi.withHandle(h -> h.createUpdate("INSERT INTO contentnodes(uuid) VALUES (:uuid)")
     .bindBean(contentNode)
     .execute());
 return findOne(contentNode.getUuid());
}

代码示例来源:origin: de.digitalcollections.cudami/dc-cudami-server-backend-jdbi

@Override
public W update(W webpage) {
 identifiableRepository.update(webpage);
 dbi.withHandle(h -> h.createUpdate("UPDATE webpages SET text=:text::JSONB WHERE uuid=:uuid")
     .bindBean(webpage)
     .execute());
 return findOne(webpage.getUuid());
}

代码示例来源:origin: de.digitalcollections.cudami/dc-cudami-server-backend-jdbi

@Override
public A update(A article) {
 entityRepository.update(article);
 dbi.withHandle(h -> h.createUpdate("UPDATE articles SET text=:text::JSONB WHERE uuid=:uuid")
     .bindBean(article)
     .execute());
 return findOne(article.getUuid());
}

代码示例来源:origin: de.digitalcollections.cudami/dc-cudami-server-backend-jdbi

@Override
 public W update(W website) {
  entityRepository.update(website);
  // do not update/left out from statement: created, uuid
  dbi.withHandle(h -> h.createUpdate("UPDATE websites SET url=:url, registration_date=:registrationDate WHERE uuid=:uuid")
      .bindBean(website)
      .execute());
  return findOne(website.getUuid());
 }
}

代码示例来源:origin: de.digitalcollections.cudami/dc-cudami-server-backend-jdbi

@Override
public W save(W webpage) {
 identifiableRepository.save(webpage);
 dbi.withHandle(h -> h.createUpdate("INSERT INTO webpages(uuid, text) VALUES (:uuid, :text::JSONB)")
     .bindBean(webpage)
     .execute());
 return findOne(webpage.getUuid());
}

代码示例来源:origin: de.digitalcollections.cudami/dc-cudami-server-backend-jdbi

@Override
 public E update(E entity) {
  identifiableRepository.update(entity);
  // do not update/left out from statement: created, uuid
  dbi.withHandle(h -> h.createUpdate("UPDATE entities SET entity_type=:entityType WHERE uuid=:uuid")
      .bindBean(entity)
      .execute());
  return findOne(entity.getUuid());
 }
}

相关文章