1. Characteristic of Transaction:
1) A (Atomicity) --> All the operations in one transaction should be regarded as a whole. They cannot be seperated.
2) C (Consistency) -->
3) I (Isolation) --> One transaction should not interrupt or affect another transaction.
4) D (Durability) --> All the changes that one transaction made to the DB should be persisted and cannot be rollback.
Comments: The characteristics of transaction are realized by DBMS.
2. JDBC Transaction Isolation levels:
1) TRANSACTION_NONE
2) TRANSACTION_READ_UNCOMMITTED
3) TRANSACTION_READ_COMMITTED
4) TRANSACTION_REPEATABLE_READ
5) TRANSACTION_SERIALIZABLE
TRANSACTION_NONE |
Not supported | Not applicable | Not applicable | Not applicable |
TRANSACTION_READ_COMMITTED |
Supported | Prevented | Allowed | Allowed |
TRANSACTION_READ_UNCOMMITTED |
Supported | Allowed | Allowed | Allowed |
TRANSACTION_REPEATABLE_READ |
Supported | Prevented | Prevented | Allowed |
TRANSACTION_SERIALIZABLE |
Supported | Prevented | Prevented | Prevented |
Comments:
Usually, you do not need to do anything about the transaction isolation level, you can use the default one for your DBMS.
The default transaction isolation level depends on your DBMS.
JDBC allows you to find out what transaction isolation level your DBMS is set to.
connection.getTransactionIsolation();
3. Problems may occur during transaction:
1) Dirty Reads: --> That means we should not make changes to DB during transaction unless it is committed.
Accessing an updated value that has not been committed is considered dirty-reads.
Because it is possible for that value to be rolled back to its previous value.
If you read a value that is later rolled back, you will have read an invalid value.
2) Non-Repeatable Reads: --> That means we should lock a single ROW.
Non-repeatable reads occurs when transaction A retrieves a row, transaction B subsequently updates the row.
And transaction A later retrieves the same row again. <Remeber that right now transaction A hasn't finished yet.>
Transaction A retrieves the same row twice but sees different data.
3) Phantom Reads: --> That means we should lock a single TABLE.
Phantom-reads occurs when transaction A retrieves a set of row satisfying a given condition,
Transaction B subsequently insert/delete/update a row such that the row now meets the condition in transaction A.
Transaction A later repeats the conditional retrieval, transaction A now sees a different result set compared with the previous one.
4. JDBC Transaction Usage
1) Set transaction isolation level:
connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
2) Disable auto-commit:
JDBC connections start out with auto-commit mode enabled, where each SQL statement is implicitly demarcated with a transaction.
User who wish to execute multiple statements per transaction must turn auto-commit mode off.
connection.setAutoCommit(false);
3) Commit transaction:
connection.commit();
4) Roll back transaction when exception occurs during transaction operation:
conn.rollback();
5) Restore auto-commit:
conn.setAutoCommit(true);
6) Restore transaction isolation level if necessary
int level = conn.getTransactionIsolation(); connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); ... connection.setTransaxtionIsolation(level);
Reference Links:
1) http://docs.oracle.com/javase/tutorial/jdbc/basics/transactions.html Oracle official docs
2) http://www.java2s.com/Tutorial/Java/0340__Database/JDBCTransactionIsolationLevels.htm Listed transaction isolation level in details
相关推荐
《IEEE Transactions LaTeX2e 模板与指南》 在学术界,尤其是在计算机科学与信息技术领域,IEEE Transactions 杂志是极具权威的出版物之一。它提供了高质量的研究成果展示平台,而使用正确的论文格式是提交论文的第...
要在项目中使用Atomikos Transactions JDBC,首先需要将`atomikos-transactions-jdbc.jar`添加到项目的类路径中。然后,根据项目需求配置Atomikos的事务管理器,包括设置事务超时时间、日志位置等参数。 5. **使用...
<jdbc-driver-params> <!--driver-name>gov.gfmis.dblistener.ojdbc.... <global-transactions-protocol>OnePhaseCommit</global-transactions-protocol> </jdbc-data-source-params> </jdbc-data-source>
完整英文版 BS EN 62264-5:2016 Enterprise-control system integration - Part 5:Business to manufacturing transactions(企业控制系统集成 - 第 5 部分:企业到制造交易)。BS EN 62264-5:2016在执行与3级和4...
- (void) paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions; - (void) purchasedTransaction: (SKPaymentTransaction *)transaction; - (void) completeTransaction: ...
5, IEC 62264-5:2016 Enterprise-control system integration - Part 5:Business to manufacturing transactions(企业控制系统集成 - 第 5 部分:企业到制造交易)。 6, IEC 62264-6:2020 Enterprise-control ...
5, BS EN 62264-5:2016 Enterprise-control system integration - Part 5:Business to manufacturing transactions(企业控制系统集成 - 第 5 部分:企业到制造交易)。6, BS EN 62264-6:2020 Enterprise-...
Chapter 6 - An Introduction to SQL Chapter 7 - SQL Recipes Chapter 8 - InnoDB Tables and Transactions Chapter 9 - Security Chapter 10 - Administration and Server Configuration Part III - ...
官方版本,亲测可用
JAVA分布式事务atomikos atomikos jar 包 transactions-jdbc-4.0.4.jar
这个压缩包"IEEE-Transactions-Word-templates-and-instructions.zip"包含了用于撰写和提交论文的官方Microsoft Word模板和指南,对于需要在该期刊发表论文的IT专业人士至关重要。下面我们将详细探讨使用这些模板和...
完整英文版IEC 62264-5:2016 Enterprise-control system integration - Part 5:Business to manufacturing transactions(企业控制系统集成 - 第 5 部分:企业到制造交易)。IEC 62264-5:2016在执行与3级和4级相关...
33. **《南京航空航天大学学报》** *(Transactions of Nanjing University of Aeronautics and Astronautics)* - **ISSN:** 1005--1120 - **领域:** 航空航天工程与机械制造。 34. **《中国有色金属学会学报》*...
django-celery-transactions django-celery-transactions保留Celery任务,直到提交了当前数据库事务为止,避免了Celery 所述的潜在竞争情况。 从信号处理程序发送任务,不用担心!特征如果回滚事务,则将丢弃任务。 ...
PART IV: MASTERING NOSQL CHAPTER 14: CHOOSING AMONG NOSQL FLAVORS 271 CHAPTER 15: COEXISTENCE 285 CHAPTER 16: PERFORMANCE TUNING 301 CHAPTER 17: TOOLS AND UTILITIES 311 APPENDIX: INSTALLATION AND...
#### ORA-00037: Unable to switch between different transactions - **解释**: 无法在不同的事务之间切换。 - **解决方案**: 确认事务管理配置,并确保所有事务都按预期运行。 #### ORA-00038: Unable to start ...
transactions-essentials-all.jar
这个库被封装在名为"atomikos-transactions-jms.jar"的JAR文件中,通常作为开发人员在构建支持分布式事务的应用程序时的一个依赖组件。 在Java应用程序中,特别是那些需要跨多个数据源进行操作的系统,分布式事务...
完整英文版 ANSI/ISA-95.00.06-2014 Enterprise-Control System Integration Part 6:Messaging Service Model(企业控制系统集成第六部分:消息服务模型)。ISA-95 的这一部分定义了一组消息传递服务模型,用于跨级别...
标题中的“gt-jdbc-2.6.5.jar”是一个Java数据库连接(JDBC)驱动程序,用于连接Oracle数据库,并且是Geotools项目的一部分。Geotools是一个开源的Java库,专门用于处理地理空间数据,它提供了丰富的API来操作和展示...