Source Code Cross Referenced for ConcurrencyTest.java in  » Database-ORM » jaxor-3.5 » net » sourceforge » jaxor » example » tests » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » jaxor 3.5 » net.sourceforge.jaxor.example.tests 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * User: Michael Rettig
003:         * Date: Aug 13, 2002
004:         * Time: 3:51:15 PM
005:         */
006:        package net.sourceforge.jaxor.example.tests;
007:
008:        import net.sourceforge.jaxor.ConcurrencyException;
009:        import net.sourceforge.jaxor.JaxorContextImpl;
010:        import net.sourceforge.jaxor.QueryParams;
011:        import net.sourceforge.jaxor.api.JaxorContext;
012:        import net.sourceforge.jaxor.example.domain.*;
013:        import net.sourceforge.jaxor.example.simple.*;
014:
015:        import java.util.ArrayList;
016:        import java.util.List;
017:
018:        public class ConcurrencyTest extends MultiTableTestCase {
019:
020:            protected List getRows() {
021:                List all = new ArrayList();
022:                all.add(new AddressMetaRow());
023:                all.add(new ContactMetaRow());
024:                return all;
025:            }
026:
027:            public void testOptimisticConcurrency() {
028:                //Mckoi doesn't support this level of transaction isolation
029:                if (!isMckoiTest()) {
030:                    AddressEntity address = ObjectFactory.createAddress();
031:                    commit();
032:                    AddressEntity first = AddressFinder
033:                            .selectByPrimaryKey(address.getAddressId());
034:                    commit();
035:                    AddressEntity second = AddressFinder
036:                            .selectByPrimaryKey(address.getAddressId());
037:                    first.setCity("new city");
038:                    second.setCity("second city");
039:                    first.update();
040:                    try {
041:                        second.update();
042:                        fail("Should fail with an optimistic locking exception");
043:                    } catch (ConcurrencyException expected) {
044:                    }
045:                }
046:            }
047:
048:            public void testOptimisticConcurrencyWithConnections() {
049:                AddressEntity address = ObjectFactory.createAddress();
050:                commit();
051:                JaxorContext conn1 = new JaxorContextImpl(this .getTransaction());
052:                AddressFinderBase finder = new AddressFinderBase(conn1);
053:                AddressEntity first = finder.selectByPrimaryKey(address
054:                        .getAddressId());
055:                AddressEntity second = AddressFinder.selectByPrimaryKey(address
056:                        .getAddressId());
057:                first.setCity("new city");
058:                second.setCity("second city");
059:                conn1.flush();
060:                try {
061:                    getJaxor().flush();
062:                    fail("Should fail with an optimistic locking exception");
063:                } catch (ConcurrencyException expected) {
064:                }
065:            }
066:
067:            public void testOptimisticConcurrencyUponDeleteWithConnections() {
068:                AddressEntity address = ObjectFactory.createAddress();
069:                commit();
070:                JaxorContext conn1 = new JaxorContextImpl(this .getTransaction());
071:                AddressFinderBase firstFinder = new AddressFinderBase(conn1);
072:                AddressEntity first = firstFinder.selectByPrimaryKey(address
073:                        .getAddressId());
074:                AddressEntity second = AddressFinder.selectByPrimaryKey(address
075:                        .getAddressId());
076:                first.delete();
077:                conn1.flush();
078:                second.setCity("second city");
079:                try {
080:                    second.update();
081:                    fail("Should fail with an optimistic locking exception");
082:                } catch (ConcurrencyException expected) {
083:                }
084:            }
085:
086:            public void testOptimisticConcurrencyUponDelete() {
087:                //Mckoi doesn't support this level of transaction isolation
088:                if (!isMckoiTest()) {
089:                    AddressEntity address = ObjectFactory.createAddress();
090:                    commit();
091:                    AddressEntity first = AddressFinder
092:                            .selectByPrimaryKey(address.getAddressId());
093:                    commit();
094:                    AddressEntity second = AddressFinder
095:                            .selectByPrimaryKey(address.getAddressId());
096:                    first.delete();
097:                    second.setCity("second city");
098:                    try {
099:                        second.update();
100:                        fail("Should fail with an optimistic locking exception");
101:                    } catch (ConcurrencyException expected) {
102:                    }
103:                }
104:            }
105:
106:            public void testCodeFordocs() {
107:                ContactFinderBase finder = new ContactFinderBase(getJaxor());
108:                ContactEntity contact = ContactFactory.createContact(new Long(
109:                        12345));
110:                commit();
111:                finder.selectByPrimaryKey(new Long(12345));
112:                finder.selectByContactId(new Long(12345));
113:                finder.findUnique("where contact_id=12345", false);
114:                finder.queryUnique(
115:                        "select * from Contact where contact_id=12345", false);
116:                QueryParams params = new QueryParams();
117:                params.addLong(new Long(12345));
118:                finder.findUnique("where contact_id=?", params, false);
119:            }
120:
121:            public void testConcurrencyWithOnlyPrimaryKey() {
122:                ContactEntity contact = ContactFactory.createContact();
123:                commit();
124:                contact = ContactFinder.selectByPrimaryKey(contact
125:                        .getContactId());
126:                commit();
127:                ContactEntity second = ContactFinder.selectByPrimaryKey(contact
128:                        .getContactId());
129:                second.setEmail("email@mail.com");
130:                second.update();
131:                second = ContactFinder
132:                        .selectByPrimaryKey(second.getContactId());
133:                assertEquals("Didn't match" + second.getEmail(),
134:                        "email@mail.com", second.getEmail());
135:                second.setEmail("newEmail@mail.com");
136:                second.update();
137:                second = ContactFinder.selectByPrimaryKey(contact
138:                        .getContactId());
139:                assertEquals("newEmail@mail.com", second.getEmail());
140:            }
141:
142:            public void testContactResultSet() {
143:                ContactEntity contact = ContactFactory.createContact();
144:                commit();
145:                ContactResultSet contactRs = ContactFinder
146:                        .selectByEmailResultSet(contact.getEmail());
147:                try {
148:                    while (contactRs.hasNext())
149:                        contactRs.next();
150:                    assertEquals(1, contactRs.getEntityResultSet().count());
151:                } finally {
152:                    contactRs.close();
153:                }
154:            }
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.