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
相关推荐
标签:atomikos-transactions-jdbc.jar.zip,atomikos,transactions,jdbc,jar.zip包下载,依赖包
<jdbc-driver-params> <!--driver-name>gov.gfmis.dblistener.ojdbc.... <global-transactions-protocol>OnePhaseCommit</global-transactions-protocol> </jdbc-data-source-params> </jdbc-data-source>
- (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 ...
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 - ...
官方版本,亲测可用
IEEE-Transactions-Word-templates-and-instructions.zip
JAVA分布式事务atomikos atomikos jar 包 transactions-jdbc-4.0.4.jar
完整英文版IEC 62264-5:2016 Enterprise-control system integration - Part 5:Business to manufacturing transactions(企业控制系统集成 - 第 5 部分:企业到制造交易)。IEC 62264-5:2016在执行与3级和4级相关...
VAET: A Visual Analysis Approach for E-transactions Time-Series
django-celery-transactions django-celery-transactions保留Celery任务,直到提交了当前数据库事务为止,避免了Celery 所述的潜在竞争情况。 从信号处理程序发送任务,不用担心!特征如果回滚事务,则将丢弃任务。 ...
ieee模版 用于发表ieee transaction论文的通用latex模版
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...
InnoDB: Starting in background the rollback of uncommitted transactions 2017-11-15 19:23:48 fc8 InnoDB: Rolling back trx with id 275035944, 0 rows to undo 2017-11-15 19:23:48 fc8 InnoDB: Assertion ...
标签:atomikos-transactions-jms.jar.zip,atomikos,transactions,jms,jar.zip包下载,依赖包
标签:atomikos-transactions-jta.jar.zip,atomikos,transactions,jta,jar.zip包下载,依赖包
transactions-essentials-all.jar
kaggle data: transactions-from-a-bakery.tar-数据集
Chapter I: Adaptation and Congestion in a Multi-Agent System to Analyse Empirical Traffic Problems Chapter II: A Multi-Agent Modeling Approach to Simulate Dynamic Activity-Travel Patterns Chapter III:...
Chapter 1:Introduction Part I R and Data Mining Chapter 2: Introduction to R Chapter 3: Introduction to Data Mining Part II Case Studies Chapter 4: Predicting Algae Blooms Chapter 5: Predicting ...