com.j256.ormlite.dao.Dao.updateId()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(131)

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

Dao.updateId介绍

[英]Update the data parameter in the database to change its id to the newId parameter. The data must have its current (old) id set. If the id field has already changed then it cannot be updated. After the id has been updated in the database, the id field of the data parameter will also be changed.

NOTE: Depending on the database type and the id type, you may be unable to change the id of the field.
[中]更新数据库中的数据参数,将其id更改为newId参数。数据必须设置其当前(旧)id。如果id字段已更改,则无法更新。在数据库中更新id后,数据参数的id字段也将更改。
注意:根据数据库类型和id类型,您可能无法更改字段的id。

代码示例

代码示例来源:origin: j256/ormlite-core

/**
 * A call through to the {@link Dao#updateId(Object, Object)}.
 */
public int updateId(ID newId) throws SQLException {
  checkForDao();
  @SuppressWarnings("unchecked")
  T t = (T) this;
  return dao.updateId(t, newId);
}

代码示例来源:origin: j256/ormlite-core

/**
 * @see Dao#updateId(Object, Object)
 */
@Override
public int updateId(T data, ID newId) {
  try {
    return dao.updateId(data, newId);
  } catch (SQLException e) {
    logMessage(e, "updateId threw exception on: " + data);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: org.mycontroller.standalone/mycontroller-core

public void updateId(Tdao tdao, Tid tid) {
  try {
    Integer count = this.getDao().updateId(tdao, tid);
    _logger.debug("Updated item:[{}, id:{}], Update count:{}", tdao, tid, count);
  } catch (SQLException ex) {
    _logger.error("unable to update item:[{}]", tdao, ex);
  }
}

代码示例来源:origin: com.j256.ormlite/ormlite-core

/**
 * A call through to the {@link Dao#updateId(Object, Object)}.
 */
public int updateId(ID newId) throws SQLException {
  checkForDao();
  @SuppressWarnings("unchecked")
  T t = (T) this;
  return dao.updateId(t, newId);
}

代码示例来源:origin: com.j256.ormlite/ormlite-core

/**
 * @see Dao#updateId(Object, Object)
 */
@Override
public int updateId(T data, ID newId) {
  try {
    return dao.updateId(data, newId);
  } catch (SQLException e) {
    logMessage(e, "updateId threw exception on: " + data);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: mycontroller-org/mycontroller

public void updateId(Tdao tdao, Tid tid) {
  try {
    Integer count = this.getDao().updateId(tdao, tid);
    _logger.debug("Updated item:[{}, id:{}], Update count:{}", tdao, tid, count);
  } catch (SQLException ex) {
    _logger.error("unable to update item:[{}]", tdao, ex);
    throw new McDatabaseException(ex);
  }
}

代码示例来源:origin: j256/ormlite-core

@Test(expected = RuntimeException.class)
public void testUpdateIdThrow() throws Exception {
  @SuppressWarnings("unchecked")
  Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
  RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
  expect(dao.updateId(null, null)).andThrow(new SQLException("Testing catch"));
  replay(dao);
  rtDao.updateId(null, null);
  verify(dao);
}

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

@Test
public void testUpdateIdNull() throws Exception {
  Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
  assertEquals(0, fooDao.updateId(null, null));
}

代码示例来源:origin: j256/ormlite-core

@Test(expected = SQLException.class)
public void testUpdateIdNoId() throws Exception {
  Dao<NoId, Object> noIdDao = createDao(NoId.class, true);
  NoId noId = new NoId();
  noId.stuff = "1";
  assertEquals(1, noIdDao.create(noId));
  noIdDao.updateId(noId, "something else");
}

代码示例来源:origin: j256/ormlite-core

@Test(expected = SQLException.class)
public void testUpdateIdThrow() throws Exception {
  Dao<Foo, Integer> dao = createDao(Foo.class, true);
  Foo foo = new Foo();
  assertEquals(1, dao.create(foo));
  DatabaseConnection conn = connectionSource.getReadWriteConnection(FOO_TABLE_NAME);
  try {
    // close connection
    conn.close();
    dao.updateId(foo, foo.id + 1);
  } finally {
    connectionSource.releaseConnection(conn);
  }
}

代码示例来源:origin: j256/ormlite-core

@Test
public void testUpdateId() throws Exception {
  Dao<Foo, Integer> dao = createDao(Foo.class, true);
  Foo foo = new Foo();
  assertEquals(1, dao.create(foo));
  int id = foo.id;
  assertNotNull(dao.queryForId(id));
  assertNull(dao.queryForId(id + 1));
  assertEquals(1, dao.updateId(foo, id + 1));
  assertNull(dao.queryForId(id));
  assertNotNull(dao.queryForId(id + 1));
}

代码示例来源:origin: j256/ormlite-core

@Test
public void testUpdateId() throws Exception {
  Dao<Foo, Integer> dao = createDao(Foo.class, true);
  enableCache(dao);
  Foo foo = new Foo();
  int val = 12312321;
  foo.val = val;
  assertEquals(1, dao.create(foo));
  Foo result = dao.queryForId(foo.id);
  assertSame(foo, result);
  // updateId behind the back
  Foo foo2 = new Foo();
  foo2.id = foo.id;
  int val2 = 1312341412;
  foo2.val = val2;
  int id2 = foo.id + 1;
  assertEquals(1, dao.updateId(foo2, id2));
  // the result should _not_ have the same value
  assertNotSame(foo, foo2);
  // but the id should be the same
  assertEquals(id2, foo.id);
}

代码示例来源:origin: j256/ormlite-core

@Test
public void testUpdateIdNotInCache() throws Exception {
  Dao<Foo, Integer> dao = createDao(Foo.class, true);
  Foo foo1 = new Foo();
  int val = 12312321;
  foo1.val = val;
  assertEquals(1, dao.create(foo1));
  int id1 = foo1.id;
  Foo result = dao.queryForId(foo1.id);
  assertNotSame(foo1, result);
  // we enable the cache _after_ Foo was created
  ObjectCache cache = enableCache(dao);
  // updateId behind the back
  Foo foo2 = new Foo();
  foo2.id = foo1.id;
  int val2 = 1312341412;
  foo2.val = val2;
  int id2 = foo1.id + 1;
  assertEquals(1, dao.updateId(foo2, id2));
  // the result should _not_ have the same value
  assertNotSame(foo1, foo2);
  // and the id should be the old one and not the new one
  assertEquals(id1, foo1.id);
  assertEquals(0, cache.size(Foo.class));
}

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

assertEquals(1, dao.updateId(data2, id2));

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

@Test
public void testJustIdUpdateId() throws Exception {
  Dao<JustId, Object> justIdDao = createDao(JustId.class, true);
  String id = "just-id-update-1";
  JustId justId = new JustId();
  justId.id = id;
  assertEquals(1, justIdDao.create(justId));
  JustId justId2 = justIdDao.queryForId(id);
  assertNotNull(justId2);
  assertEquals(id, justId2.id);
  String id2 = "just-id-update-2";
  // change the id
  assertEquals(1, justIdDao.updateId(justId2, id2));
  assertNull(justIdDao.queryForId(id));
  JustId justId3 = justIdDao.queryForId(id2);
  assertNotNull(justId3);
  assertEquals(id2, justId3.id);
  assertEquals(1, justIdDao.delete(justId3));
  assertNull(justIdDao.queryForId(id));
  assertNull(justIdDao.queryForId(id2));
}

代码示例来源:origin: j256/ormlite-core

assertEquals(1, accountDao.updateId(accountResult, newId));
accountResult = accountDao.queryForId(newId);
assertNotNull(accountResult);

相关文章