mysql测试spring事务是否生效
2015-10-15 15:59
471 查看
同时对三张表进行插入操作,事务保证完整性。下面进行简单测试:
1. 锁定表
锁定用户表
查看表是否锁定:
显示被锁定的表。
2. 验证在同一session下是否可以插入操作
可以操作成功。
3. 启动spring应用,执行插入操作,不能成功。
4,解锁
查看被锁定的表:
上述表不在锁定中。
5. 调用spring应用,执行插入操作,操作可以成功。
所以,应用spring的@transactional进行事务管理是ok的。
附录:
[LIKE '
[/code]
The
The database containing the table.
The table name.
The number of table locks or lock requests there are for the table. For example, if one client acquires a lock for a table using
Whether the table name is locked. Name locking is used for operations such as dropping or renaming tables.
1. 锁定表
锁定用户表
LOCK TABLES user WRITE;
查看表是否锁定:
show OPEN TABLES where In_use > 0;
显示被锁定的表。
2. 验证在同一session下是否可以插入操作
insert into user(userId,ip,type,terminal) values(10002,'127.0.0.1',7,'pc');
可以操作成功。
3. 启动spring应用,执行插入操作,不能成功。
4,解锁
UNLOCK TABLES;
查看被锁定的表:
show OPEN TABLES where In_use > 0;
上述表不在锁定中。
5. 调用spring应用,执行插入操作,操作可以成功。
所以,应用spring的@transactional进行事务管理是ok的。
附录:
SHOW OPEN TABLES Syntax:https://dev.mysql.com/doc/refman/5.0/en/show-open-tables.html
SHOW OPEN TABLES [{FROM | IN} [code]db_name]
[LIKE '
pattern' | WHERE
expr]
[/code]
SHOW OPEN TABLESlists the non-
TEMPORARYtables that are currently open in the table cache. SeeSection 8.4.3.1, “How MySQL Opens and Closes Tables”. The
WHEREclause can be given to select rows using more general conditions, as discussed in Section 19.18, “Extensions to SHOW Statements”.
The
FROMand
LIKEclauses may be used as of MySQL 5.0.12. The
LIKEclause, if present, indicates which table names to match. The
FROMclause, if present, restricts the tables shown to those present in the
db_namedatabase.
SHOW OPEN TABLESoutput has the following columns:
Database
The database containing the table.
Table
The table name.
In_use
The number of table locks or lock requests there are for the table. For example, if one client acquires a lock for a table using
LOCK TABLE t1 WRITE,
In_usewill be 1. If another client issues
LOCK TABLE t1 WRITEwhile the table remains locked, the client will block waiting for the lock, but the lock request causes
In_useto be 2. If the count is zero, the table is open but not currently being used.
In_useis also increased by the
HANDLER ... OPENstatement and decreased by
HANDLER ... CLOSE.
Name_locked
Whether the table name is locked. Name locking is used for operations such as dropping or renaming tables.
相关文章推荐
- Java读取properties配置文件时,中文乱码解决方法 .
- JAVA获取CLASSPATH路径
- Java CompletionService 理解
- Java编程思想学习笔记
- Java Bean详细的说明
- java 贪吃蛇----z
- java编绎原理
- [Java并发编程]-线程的六种状态及其状态转换
- javaallcompletionproposalcomputer错误
- JAVA-选择排序从控制台输入数组
- [Java并发编程]-线程的六种状态及其状态转换
- Java核心技术第6章(4)
- 从Eclipse中Export Android项目并且安装时的事项
- maven 修改使用jdk版本
- 谈谈Java类型中ParameterizedType,GenericArrayType,TypeVariabl,WildcardType
- with root cause java.lang.NoClassDefFoundError:Could not initialize class com.AlipaySubmit
- with root cause java.lang.NoClassDefFoundError:Could not initialize class com.AlipaySubmit
- with root cause java.lang.NoClassDefFoundError:Could not initialize class com.AlipaySubmit
- with root cause java.lang.NoClassDefFoundError:Could not initialize class com.AlipaySubmit
- with root cause java.lang.NoClassDefFoundError:Could not initialize class com.AlipaySubmit