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

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

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

Dao.commit介绍

[英]If you have previously set auto-commit to false using #setAutoCommit(DatabaseConnection,boolean) then this will commit all changes to the database made from that point up to now on the connection returned by the #startThreadConnection(). The changes will be written to the database and 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 #rollBack(DatabaseConnection).
[中]如果以前使用#setAutoCommit(DatabaseConnection,boolean)将auto commit设置为false,则这将提交从该点到现在为止对#startThreadConnection()返回的连接所做的所有数据库更改。更改将写入数据库并被丢弃。连接将继续保持当前自动提交模式。
警告:除非您知道自己在做什么,否则您可能应该使用#callBatchTasks(Callable)而不是此方法。
注意:根据基础数据库实现以及是否使用单个数据库连接,您可能需要同步对此处的调用以及对#callBatchTasks(可调用)、setAutoCommit(DatabaseConnection,布尔值)和#rollBack(DatabaseConnection)的调用。

代码示例

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

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

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

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

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

  1. blogDao.commit(databaseConnection);
  2. databaseConnection.setAutoCommit(autoCommit);

代码示例来源: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. assertNotNull(dao.queryForId(foo.id));
  2. dao.commit(conn);
  3. assertNotNull(dao.queryForId(foo.id));

相关文章