什么是q发问题Q假设有q么一家书吧,֮可以到那里喝茶读书。顾客拿着选好要读的图书到柜台登记Q然后找个地方去阅读Q走时图书归q店家。有一天,一个顾客相中了一本书后正要拿ȝ讎ͼ另一个顾客的手也抓住了这仅有的一本书Qƈ发问题出C。两个顾客要d一本书Q互不相让,q让店主伤透了脑筋。这个案例仅仅是众多q发问题中的一个微部分,但从中我们可以看出ƈ发问题主要出现在多个用户Ҏ限资源进行访问的时候,如果解决不好会直接媄响系l的有效、正常运行。数据库是一个共享的资源Qƈ发问题的出现是必不可免的Q如何识别ƈ发类型ƈ加以控制是这一章重点要讲述的内宏V?/p>
本章分成两大部分,一部分主要讲Visual FoxPro中ƈ发控制机制。VFP中ƈ发控制相对简单,数据加锁的Ş式比较单一Q非帔R合作ؓ初步了解q发问题的切入点。第二部分以SQL Server 2000、ADO.NET以及C#Z要工P深入了解q发一致性问题、封锁协议、事务隔ȝ内容Q难度相对较深。象一些更为深入的q发控制手段Q例如多_度锁和意象锁{内容在本章中将不做深入讨论Q感兴趣可以参考相关书c?/p>
[实在不好意思COPY别h的成果,不过q篇文章出奇的精彩,ƈ发操作的来龙去脉说的清清楚楚Q也是我正要扄Q比JAVAEYE上面所谓的专家叫嚷着什?悲观??乐观?而不解是原因要强的多Q值得收藏]
java代码: ![]() |
1 Session session = ...; 2 Transaction tx = ...; 3 4 Parent parent = (Parent) session.load(Parent.class, id); 5 6 Child child = new Child(); 7 child.setParent(parent); 8 child.setName("sun"); 9 10 parent.addChild(child); 11 s.update(parent); 12 13 s.flush(); 14 tx.commit(); 15 s.close(); |
java代码: ![]() |
1 Session session = ...; 2 Transaction tx = ...; 3 4 Parent parent = (Parent) session.load(Parent.class, id); 5 Child child = (Child) session.load(Child.class, childId); 6 7 child.setParent(parent); 8 child.setName("sun"); 9 10 parent.addChild(child); 11 s.update(parent); 12 13 s.flush(); 14 tx.commit(); 15 s.close(); |
java代码: ![]() |
1 <class name="Child" table="child"> 2 <id column="id" name="id" type="integer" unsaved-value="null"> 3 <generator class="identity"/> 4 </id> 5 ... 6 </class> |
java代码: ![]() |
1 unsaved-null="0" |
java代码: ![]() |
1 Foo foo=sess.load(Foo.class,id); 2 foo.setXXX(xxx); 3 sess.flush(); 4 sess.commit(); |
java代码: ![]() |
1 // in the first session 2 Cat cat = (Cat) firstSession.load(Cat.class, catId); 3 Cat potentialMate = new Cat(); 4 firstSession.save(potentialMate); 5 6 // in a higher tier of the application 7 cat.setMate(potentialMate); 8 9 // later, in a new session 10 secondSession.update(cat); // update cat 11 secondSession.update(mate); // update mate 12 |
java代码: ![]() |
![]() ...}
2 Session session = ...; 3 Transacton tx = ...; 4 session.update(cat); 5 cat.addMate(mate); 6 tx.commit(); 7 session.close(); 8 }; |
java代码: ![]() |
1 Cat cat = new Cat(); 2 cat.setXXX(); 3 daoimpl.addMate(cat,mate); |
java代码: ![]() |
1 Cat cat = new Cat(); 2 cat.setXXX(); 3 daoimpl.addCat(cat); 4 daoimpl.addMate(cat, mate); |
java代码: ![]() |
![]() ...}
2 Session session = ...; 3 Transacton tx = ...; 4 session.saveOrUpdate(cat); 5 cat.addMate(mate); 6 tx.commit(); 7 session.close(); 8 }; |