Source Code Cross Referenced for OneToOneTest.java in  » Database-ORM » db-ojb » org » apache » ojb » odmg » 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 » db ojb » org.apache.ojb.odmg 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.ojb.odmg;
002:
003:        import java.util.List;
004:
005:        import org.apache.ojb.broker.core.proxy.ProxyHelper;
006:        import org.apache.ojb.junit.ODMGTestCase;
007:        import org.apache.ojb.odmg.shared.TestClassA;
008:        import org.apache.ojb.odmg.shared.TestClassAWithBProxy;
009:        import org.apache.ojb.odmg.shared.TestClassB;
010:        import org.apache.ojb.odmg.shared.TestClassBProxy;
011:        import org.apache.ojb.odmg.shared.TestClassBProxyI;
012:        import org.odmg.ODMGException;
013:        import org.odmg.OQLQuery;
014:        import org.odmg.Transaction;
015:
016:        public class OneToOneTest extends ODMGTestCase {
017:            TestClassA m_a;
018:            TestClassB m_b;
019:
020:            public static void main(String[] args) {
021:                String[] arr = { OneToOneTest.class.getName() };
022:                junit.textui.TestRunner.main(arr);
023:            }
024:
025:            /**
026:             * Constructor for OneToOneTest.
027:             * @param arg0
028:             */
029:            public OneToOneTest(String arg0) {
030:                super (arg0);
031:            }
032:
033:            protected void setUp() throws Exception {
034:                super .setUp();
035:
036:                m_a = new TestClassA();
037:                m_b = new TestClassB();
038:
039:                // init a
040:                m_a.setValue1("A.One");
041:                m_a.setValue2("B.Two");
042:                m_a.setValue3(3);
043:                m_a.setB(m_b);
044:
045:                // init b
046:                m_b.setValue1("B.One");
047:                m_b.setA(m_a);
048:            }
049:
050:            public void testSave() {
051:                Transaction tx = odmg.newTransaction();
052:                tx.begin();
053:                database.makePersistent(m_a);
054:                database.makePersistent(m_b);
055:                tx.commit();
056:
057:                assertTrue(m_a.getOid() != null);
058:                assertTrue(m_b.getOid() != null);
059:            }
060:
061:            /**
062:             * This method tests the correct assignment of a foreign
063:             * key field in case that the referenced object is a
064:             * dynamic proxy
065:             */
066:            public void testFKAssignForProxy() {
067:                try {
068:                    Transaction tx = odmg.newTransaction();
069:                    tx.begin();
070:                    //create a TestClassBProxy and persist it
071:                    //so that when loading it again we will
072:                    //get a dynamic proxy object
073:                    TestClassBProxy b = new TestClassBProxy();
074:                    database.makePersistent(b);
075:                    tx.commit();
076:
077:                    //reload the object created in the previous step
078:                    tx = odmg.newTransaction();
079:                    tx.begin();
080:                    OQLQuery query = odmg.newOQLQuery();
081:                    query.create("select bproxies from "
082:                            + TestClassBProxy.class.getName()
083:                            + " where oid = $1");
084:                    query.bind(b.getOid());
085:                    List bList = (List) query.execute();
086:                    assertEquals(1, bList.size());
087:
088:                    TestClassBProxyI bI = (TestClassBProxyI) bList.get(0);
089:
090:                    //bI should now be a dynamic proxy
091:                    assertTrue(ProxyHelper.isProxy(bI));
092:
093:                    TestClassAWithBProxy a = new TestClassAWithBProxy();
094:                    a.setBProxy(bI);
095:                    tx.lock(a, Transaction.WRITE);
096:                    tx.commit();
097:
098:                    //on commit the foreign key in "a" should have been set to
099:                    //bOid
100:                    String aBOid = a.getBoid();
101:
102:                    assertEquals("foreign key should match", b.getOid(), aBOid);
103:
104:                } catch (ODMGException ex) {
105:                    fail("ODMGException" + ex);
106:                }
107:            }
108:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.