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

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

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

Dao.endThreadConnection介绍

[英]WARNING: This method is for advanced users only. It is only to support the #setAutoCommit(DatabaseConnection,boolean) and other methods below. Chances are you should be using the #callBatchTasks(Callable) instead of this method unless you know what you are doing.

This method is used to free the connection returned by the #startThreadConnection() above.
[中]警告:此方法仅适用于高级用户。它仅支持#setAutoCommit(DatabaseConnection,boolean)和下面的其他方法。除非您知道自己在做什么,否则您应该使用#callBatchTasks(Callable)而不是此方法。
此方法用于释放上面的#startThreadConnection()返回的连接。

代码示例

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

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

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

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

代码示例来源:origin: ikidou/Retrofit2Demo

blogDao.create(blog);
blogDao.endThreadConnection(databaseConnection);
blogDao.commit(databaseConnection);
databaseConnection.setAutoCommit(autoCommit);

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

@Override
  public void run() {
    try {
      DatabaseConnection conn2 = dao.startThreadConnection();
      try {
        assertNotNull(dao.queryForId(foo.id));
      } finally {
        if (conn2 != null) {
          dao.endThreadConnection(conn2);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}).start();

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

@Test
public void testAutoCommitClose() throws Exception {
  Dao<Foo, Integer> dao = createDao(Foo.class, true);
  DatabaseConnection conn = null;
  try {
    conn = dao.startThreadConnection();
    dao.setAutoCommit(conn, false);
    Foo foo = new Foo();
    assertEquals(1, dao.create(foo));
    List<Foo> results = dao.queryForAll();
    assertEquals(1, results.size());
    dao.endThreadConnection(conn);
    conn = null;
    after();
    DaoManager.clearCache();
    before();
    dao = createDao(Foo.class, true);
    results = dao.queryForAll();
    // we expect there to be no results because we closed the connection to the database before a commit
    // happened
    assertEquals(0, results.size());
  } finally {
    if (conn != null) {
      dao.endThreadConnection(conn);
    }
  }
}

代码示例来源: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: com.j256.ormlite/ormlite-jdbc

@Test
public void testConnectionRollback() throws Exception {
  JdbcPooledConnectionSource pooled = new JdbcPooledConnectionSource(DEFAULT_DATABASE_URL);
  Dao<Foo, Integer> dao = null;
  DatabaseConnection conn = null;
  try {
    TableUtils.createTable(pooled, Foo.class);
    dao = DaoManager.createDao(pooled, Foo.class);
    conn = dao.startThreadConnection();
    dao.setAutoCommit(conn, false);
    Foo foo = new Foo();
    assertEquals(1, dao.create(foo));
    assertNotNull(dao.queryForId(foo.id));
    dao.endThreadConnection(conn);
    assertNull(dao.queryForId(foo.id));
  } finally {
    TableUtils.dropTable(pooled, Foo.class, true);
    if (dao != null) {
      dao.endThreadConnection(conn);
    }
    pooled.close();
  }
}

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

@Test
public void testAutoCommitClose() throws Exception {
  Dao<Foo, Integer> dao = createDao(Foo.class, true);
  DatabaseConnection conn = null;
  try {
    conn = dao.startThreadConnection();
    dao.setAutoCommit(conn, false);
    Foo foo = new Foo();
    assertEquals(1, dao.create(foo));
    List<Foo> results = dao.queryForAll();
    assertEquals(1, results.size());
    try {
      closeConnectionSource();
    } catch (SQLException e) {
      // ignore any exceptions (stupid derby)
    }
    conn = null;
    DaoManager.clearCache();
    openConnectionSource();
    dao = createDao(Foo.class, true);
    results = dao.queryForAll();
    // we expect there to be no results because we closed the connection to the database before a commit
    // happened
    assertEquals(0, results.size());
  } finally {
    dao.endThreadConnection(conn);
  }
}

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

if (conn1 != null) {
  dao.setAutoCommit(conn1, true);
  dao.endThreadConnection(conn1);

代码示例来源: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

if (conn != null) {
  dao.setAutoCommit(conn, true);
  dao.endThreadConnection(conn);

相关文章