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

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

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

Dao.rollBack介绍

[英]If you have previously set auto-commit to false using #setAutoCommit(DatabaseConnection,boolean) then this will roll-back and flush all changes to the database made from that point up to now on the connection returned by the #startThreadConnection() . None of those changes will be written to the database and are discarded. The connection will continue to stay in the current auto-commit mode.

WARNING: Chances are you should be using the #callBatchTasks(Callable) instead of this method unless you know what you are doing.

NOTE: Depending on your underlying database implementation and whether or not you are working with a single database connection, you may need to synchronize calls to here and calls to #callBatchTasks(Callable), #setAutoCommit(DatabaseConnection,boolean), and #commit(DatabaseConnection).
[中]如果您以前使用#setAutoCommit(DatabaseConnection,boolean)将auto commit设置为false,那么这将回滚并刷新从该点到现在为止在#startThreadConnection()返回的连接上对数据库所做的所有更改。这些更改都不会写入数据库并被丢弃。连接将继续保持当前自动提交模式。
警告:除非您知道自己在做什么,否则您可能应该使用#callBatchTasks(Callable)而不是此方法。
注意:根据基础数据库实现以及是否使用单个数据库连接,您可能需要同步对此处的调用以及对#callBatchTasks(可调用)、setAutoCommit(DatabaseConnection,布尔值)和#commit(DatabaseConnection)的调用。

代码示例

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

/**
 * @see Dao#rollBack(DatabaseConnection)
 */
@Override
public void rollBack(DatabaseConnection connection) {
  try {
    dao.rollBack(connection);
  } catch (SQLException e) {
    logMessage(e, "rollBack(" + connection + ") threw exception");
    throw new RuntimeException(e);
  }
}

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

/**
 * @see Dao#rollBack(DatabaseConnection)
 */
@Override
public void rollBack(DatabaseConnection connection) {
  try {
    dao.rollBack(connection);
  } catch (SQLException e) {
    logMessage(e, "rollBack(" + connection + ") threw exception");
    throw new RuntimeException(e);
  }
}

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

@Test
public void testCallBatchTasksCommitted() throws Exception {
  final Dao<Foo, Integer> dao = createDao(Foo.class, true);
  final Foo foo1 = new Foo();
  DatabaseConnection conn = dao.startThreadConnection();
  try {
    dao.callBatchTasks(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        assertEquals(1, dao.create(foo1));
        assertNotNull(dao.queryForId(foo1.id));
        return null;
      }
    });
    dao.rollBack(conn);
    assertNotNull(dao.queryForId(foo1.id));
  } finally {
    dao.endThreadConnection(conn);
  }
}

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

@Test
public void testConnectionMethods() throws Exception {
  Dao<Foo, Integer> dao = createDao(Foo.class, true);
  DatabaseConnection conn = null;
  try {
    conn = dao.startThreadConnection();
    assertTrue(dao.isAutoCommit(conn));
    dao.setAutoCommit(conn, false);
    assertFalse(dao.isAutoCommit(conn));
    Foo foo = new Foo();
    assertEquals(1, dao.create(foo));
    assertNotNull(dao.queryForId(foo.id));
    dao.rollBack(conn);
    assertNull(dao.queryForId(foo.id));
    foo = new Foo();
    assertEquals(1, dao.create(foo));
    assertNotNull(dao.queryForId(foo.id));
    dao.commit(conn);
    assertNotNull(dao.queryForId(foo.id));
    dao.rollBack(conn);
    assertNotNull(dao.queryForId(foo.id));
  } finally {
    if (conn != null) {
      conn.setAutoCommit(true);
      dao.endThreadConnection(conn);
    }
  }
}

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

assertNotNull(dao.queryForId(foo.id));
dao.rollBack(conn);
assertNull(dao.queryForId(foo.id));
assertNotNull(dao.queryForId(foo.id));
dao.rollBack(conn);
assertNotNull(dao.queryForId(foo.id));

相关文章