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

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

本文整理了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

  1. /**
  2. * @see Dao#endThreadConnection(DatabaseConnection)
  3. */
  4. @Override
  5. public void endThreadConnection(DatabaseConnection connection) {
  6. try {
  7. dao.endThreadConnection(connection);
  8. } catch (SQLException e) {
  9. logMessage(e, "endThreadConnection(" + connection + ") threw exception");
  10. throw new RuntimeException(e);
  11. }
  12. }

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

  1. /**
  2. * @see Dao#endThreadConnection(DatabaseConnection)
  3. */
  4. @Override
  5. public void endThreadConnection(DatabaseConnection connection) {
  6. try {
  7. dao.endThreadConnection(connection);
  8. } catch (SQLException e) {
  9. logMessage(e, "endThreadConnection(" + connection + ") threw exception");
  10. throw new RuntimeException(e);
  11. }
  12. }

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

  1. blogDao.create(blog);
  2. blogDao.endThreadConnection(databaseConnection);
  3. blogDao.commit(databaseConnection);
  4. databaseConnection.setAutoCommit(autoCommit);

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

  1. @Override
  2. public void run() {
  3. try {
  4. DatabaseConnection conn2 = dao.startThreadConnection();
  5. try {
  6. assertNotNull(dao.queryForId(foo.id));
  7. } finally {
  8. if (conn2 != null) {
  9. dao.endThreadConnection(conn2);
  10. }
  11. }
  12. } catch (Exception e) {
  13. e.printStackTrace();
  14. }
  15. }
  16. }).start();

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

  1. @Test
  2. public void testAutoCommitClose() throws Exception {
  3. Dao<Foo, Integer> dao = createDao(Foo.class, true);
  4. DatabaseConnection conn = null;
  5. try {
  6. conn = dao.startThreadConnection();
  7. dao.setAutoCommit(conn, false);
  8. Foo foo = new Foo();
  9. assertEquals(1, dao.create(foo));
  10. List<Foo> results = dao.queryForAll();
  11. assertEquals(1, results.size());
  12. dao.endThreadConnection(conn);
  13. conn = null;
  14. after();
  15. DaoManager.clearCache();
  16. before();
  17. dao = createDao(Foo.class, true);
  18. results = dao.queryForAll();
  19. // we expect there to be no results because we closed the connection to the database before a commit
  20. // happened
  21. assertEquals(0, results.size());
  22. } finally {
  23. if (conn != null) {
  24. dao.endThreadConnection(conn);
  25. }
  26. }
  27. }

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

  1. @Test
  2. public void testCallBatchTasksCommitted() throws Exception {
  3. final Dao<Foo, Integer> dao = createDao(Foo.class, true);
  4. final Foo foo1 = new Foo();
  5. DatabaseConnection conn = dao.startThreadConnection();
  6. try {
  7. dao.callBatchTasks(new Callable<Void>() {
  8. @Override
  9. public Void call() throws Exception {
  10. assertEquals(1, dao.create(foo1));
  11. assertNotNull(dao.queryForId(foo1.id));
  12. return null;
  13. }
  14. });
  15. dao.rollBack(conn);
  16. assertNotNull(dao.queryForId(foo1.id));
  17. } finally {
  18. dao.endThreadConnection(conn);
  19. }
  20. }

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

  1. @Test
  2. public void testConnectionRollback() throws Exception {
  3. JdbcPooledConnectionSource pooled = new JdbcPooledConnectionSource(DEFAULT_DATABASE_URL);
  4. Dao<Foo, Integer> dao = null;
  5. DatabaseConnection conn = null;
  6. try {
  7. TableUtils.createTable(pooled, Foo.class);
  8. dao = DaoManager.createDao(pooled, Foo.class);
  9. conn = dao.startThreadConnection();
  10. dao.setAutoCommit(conn, false);
  11. Foo foo = new Foo();
  12. assertEquals(1, dao.create(foo));
  13. assertNotNull(dao.queryForId(foo.id));
  14. dao.endThreadConnection(conn);
  15. assertNull(dao.queryForId(foo.id));
  16. } finally {
  17. TableUtils.dropTable(pooled, Foo.class, true);
  18. if (dao != null) {
  19. dao.endThreadConnection(conn);
  20. }
  21. pooled.close();
  22. }
  23. }

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

  1. @Test
  2. public void testAutoCommitClose() throws Exception {
  3. Dao<Foo, Integer> dao = createDao(Foo.class, true);
  4. DatabaseConnection conn = null;
  5. try {
  6. conn = dao.startThreadConnection();
  7. dao.setAutoCommit(conn, false);
  8. Foo foo = new Foo();
  9. assertEquals(1, dao.create(foo));
  10. List<Foo> results = dao.queryForAll();
  11. assertEquals(1, results.size());
  12. try {
  13. closeConnectionSource();
  14. } catch (SQLException e) {
  15. // ignore any exceptions (stupid derby)
  16. }
  17. conn = null;
  18. DaoManager.clearCache();
  19. openConnectionSource();
  20. dao = createDao(Foo.class, true);
  21. results = dao.queryForAll();
  22. // we expect there to be no results because we closed the connection to the database before a commit
  23. // happened
  24. assertEquals(0, results.size());
  25. } finally {
  26. dao.endThreadConnection(conn);
  27. }
  28. }

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

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

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

  1. @Test
  2. public void testConnectionMethods() throws Exception {
  3. Dao<Foo, Integer> dao = createDao(Foo.class, true);
  4. DatabaseConnection conn = null;
  5. try {
  6. conn = dao.startThreadConnection();
  7. assertTrue(dao.isAutoCommit(conn));
  8. dao.setAutoCommit(conn, false);
  9. assertFalse(dao.isAutoCommit(conn));
  10. Foo foo = new Foo();
  11. assertEquals(1, dao.create(foo));
  12. assertNotNull(dao.queryForId(foo.id));
  13. dao.rollBack(conn);
  14. assertNull(dao.queryForId(foo.id));
  15. foo = new Foo();
  16. assertEquals(1, dao.create(foo));
  17. assertNotNull(dao.queryForId(foo.id));
  18. dao.commit(conn);
  19. assertNotNull(dao.queryForId(foo.id));
  20. dao.rollBack(conn);
  21. assertNotNull(dao.queryForId(foo.id));
  22. } finally {
  23. if (conn != null) {
  24. conn.setAutoCommit(true);
  25. dao.endThreadConnection(conn);
  26. }
  27. }
  28. }

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

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

相关文章