Source Code Cross Referenced for MultiTableTestCase.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 10, 2002
004:         * Time: 3:02:04 PM
005:         */
006:        package net.sourceforge.jaxor.example.tests;
007:
008:        import net.sourceforge.jaxor.JaxorSession;
009:        import net.sourceforge.jaxor.MetaRow;
010:        import net.sourceforge.jaxor.api.JaxorContext;
011:        import net.sourceforge.jaxor.api.JaxorTransaction;
012:        import net.sourceforge.jaxor.example.db.*;
013:
014:        import java.sql.Connection;
015:        import java.util.Iterator;
016:        import java.util.List;
017:
018:        /**
019:         * This is base test cases for testing against an in-memory hypersonic database.
020:         * The test case creates and drops the tables in setup/teardown.
021:         * Also a JaxorContext is created and registered to JaxorSession for convenience.
022:         */
023:        public abstract class MultiTableTestCase extends JaxorTestCase {
024:
025:            public static JaxorContextTestingFactory JAXOR_Factory;
026:
027:            public MultiTableTestCase() {
028:                this (new HypersonicContextTestingFactory());
029:            }
030:
031:            public MultiTableTestCase(JaxorContextTestingFactory context) {
032:                JAXOR_Factory = context;
033:            }
034:
035:            public JaxorContextTestingFactory getTestingContext() {
036:                return JAXOR_Factory;
037:            }
038:
039:            protected abstract List getRows();
040:
041:            /**
042:             * Commits the context and begins a new session
043:             */
044:            protected void commit() {
045:                JaxorSession.commit();
046:                beginSession();
047:            }
048:
049:            private void beginSession() {
050:                createSession(getNewContext());
051:            }
052:
053:            /**
054:             * The version of sqlserver used for integration testing does not support
055:             * certain transaction isolation levels. i.e. insert and delete in of the same
056:             * row in the same transactions.
057:             * @return
058:             */
059:            public boolean isSqlServerTest() {
060:                return JAXOR_Factory.getClass() == SqlServerContextTestingFactory.class;
061:            }
062:
063:            public boolean isMckoiTest() {
064:                return JAXOR_Factory.getClass().equals(
065:                        MckoiContextTestingFactory.class);
066:            }
067:
068:            public JaxorContext getNewContext() {
069:                JaxorContext context = JAXOR_Factory.create();
070:                context.setUser(getClass().getName());
071:                return context;
072:            }
073:
074:            private void createSession(JaxorContext conn) {
075:                JaxorSession.setJaxorContext(conn);
076:            }
077:
078:            protected final void setUp() throws Exception {
079:                beginSession();
080:                try {
081:                    List allRows = getRows();
082:                    Connection connection = JaxorSession.getJaxorContext()
083:                            .getConnection();
084:                    for (Iterator iterator = allRows.iterator(); iterator
085:                            .hasNext();) {
086:                        MetaRow entityRow = (MetaRow) iterator.next();
087:                        try {
088:                            TableMaker.dropTable(entityRow.getTableName(),
089:                                    connection);
090:                        } catch (Exception e) {
091:                            //e.printStackTrace();
092:                        }
093:                        JaxorSession.getJaxorContext().commit();
094:                    }
095:                    for (Iterator iterator = allRows.iterator(); iterator
096:                            .hasNext();) {
097:                        MetaRow metaRow = (MetaRow) iterator.next();
098:                        TableMaker.createTable(metaRow, connection,
099:                                JAXOR_Factory);
100:                    }
101:                    JaxorSession.getJaxorContext().commit();
102:                } catch (Exception exc) {
103:                    JaxorSession.getJaxorContext().getTransaction().rollback(
104:                            exc);
105:                    JaxorSession.getJaxorContext().end();
106:                    throw exc;
107:                }
108:                prep();
109:            }
110:
111:            public JaxorContext getJaxor() {
112:                return JaxorSession.getJaxorContext();
113:            }
114:
115:            protected void prep() throws Exception {
116:            }
117:
118:            protected Connection getConnection() {
119:                return getTransaction().getConnection();
120:            }
121:
122:            protected JaxorTransaction getTransaction() {
123:                return JaxorSession.getJaxorContext().getTransaction();
124:            }
125:
126:            protected final void tearDown() throws Exception {
127:                try {
128:                    cleanUp();
129:                } finally {
130:                    JaxorSession.end();
131:                }
132:                JAXOR_Factory.cleanupTest();
133:            }
134:
135:            protected void cleanUp() throws Exception {
136:
137:            }
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.