Source Code Cross Referenced for DerbyTestDatabase.java in  » J2EE » openejb3 » org » apache » openejb » test » 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 » J2EE » openejb3 » org.apache.openejb.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.openejb.test;
017:
018:        import org.apache.openejb.test.beans.Database;
019:        import org.apache.openejb.test.beans.DatabaseHome;
020:
021:        import javax.naming.InitialContext;
022:        import java.rmi.RemoteException;
023:        import java.util.Properties;
024:
025:        /**
026:         * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
027:         *
028:         * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 $ 
029:         */
030:        public class DerbyTestDatabase implements  TestDatabase {
031:
032:            protected Database database;
033:            protected InitialContext initialContext;
034:
035:            private static String _createAccount = "CREATE TABLE account ( ssn VARCHAR(25), first_name VARCHAR(256), last_name VARCHAR(256), balance integer)";
036:
037:            private static String _dropAccount = "DROP TABLE account";
038:
039:            private static String _createEntity = "CREATE TABLE entity ( id integer GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), first_name VARCHAR(256), last_name VARCHAR(256) )";
040:
041:            private static String _dropEntity = "DROP TABLE entity";
042:
043:            static {
044:                System.setProperty("noBanner", "true");
045:            }
046:
047:            public void createEntityTable() throws java.sql.SQLException {
048:                try {
049:                    try {
050:                        database.execute(DerbyTestDatabase._dropEntity);
051:                    } catch (Exception e) {
052:                        // not concerned
053:                    }
054:                    database.execute(DerbyTestDatabase._createEntity);
055:                } catch (RemoteException re) {
056:                    if (re.detail != null
057:                            && re.detail instanceof  java.sql.SQLException) {
058:                        throw (java.sql.SQLException) re.detail;
059:                    } else {
060:                        throw new java.sql.SQLException(
061:                                "Cannot create entity table: "
062:                                        + re.getMessage(),
063:                                DerbyTestDatabase._createEntity);
064:                    }
065:                }
066:            }
067:
068:            public void dropEntityTable() throws java.sql.SQLException {
069:                try {
070:                    database.execute(DerbyTestDatabase._dropEntity);
071:                } catch (RemoteException re) {
072:                    if (re.detail != null
073:                            && re.detail instanceof  java.sql.SQLException) {
074:                        throw (java.sql.SQLException) re.detail;
075:                    } else {
076:                        throw new java.sql.SQLException(
077:                                "Unable to drop entity table: "
078:                                        + re.getMessage(),
079:                                DerbyTestDatabase._dropEntity);
080:                    }
081:                }
082:            }
083:
084:            public void createAccountTable() throws java.sql.SQLException {
085:                try {
086:                    try {
087:                        database.execute(DerbyTestDatabase._dropAccount);
088:                    } catch (Exception e) {
089:                        // not concerned
090:                    }
091:                    database.execute(DerbyTestDatabase._createAccount);
092:                } catch (RemoteException re) {
093:                    if (re.detail != null
094:                            && re.detail instanceof  java.sql.SQLException) {
095:                        throw (java.sql.SQLException) re.detail;
096:                    } else {
097:                        throw new java.sql.SQLException(
098:                                "Cannot create account table: "
099:                                        + re.getMessage(),
100:                                DerbyTestDatabase._createAccount);
101:                    }
102:                }
103:            }
104:
105:            public void dropAccountTable() throws java.sql.SQLException {
106:                try {
107:                    database.execute(DerbyTestDatabase._dropAccount);
108:                } catch (RemoteException re) {
109:                    if (re.detail != null
110:                            && re.detail instanceof  java.sql.SQLException) {
111:                        throw (java.sql.SQLException) re.detail;
112:                    } else {
113:                        throw new java.sql.SQLException(
114:                                "Cannot drop account table: " + re.getMessage(),
115:                                DerbyTestDatabase._dropAccount);
116:                    }
117:                }
118:            }
119:
120:            public void start() throws IllegalStateException {
121:                try {
122:                    Properties properties = TestManager.getServer()
123:                            .getContextEnvironment();
124:                    initialContext = new InitialContext(properties);
125:                } catch (Exception e) {
126:                    throw (IllegalStateException) new IllegalStateException(
127:                            "Cannot create initial context: "
128:                                    + e.getClass().getName() + " "
129:                                    + e.getMessage()).initCause(e);
130:                }
131:
132:                Object obj = null;
133:                DatabaseHome databaseHome = null;
134:                try {
135:                    /* Create database */
136:                    obj = initialContext.lookup("client/tools/DatabaseHome");
137:                    databaseHome = (DatabaseHome) javax.rmi.PortableRemoteObject
138:                            .narrow(obj, DatabaseHome.class);
139:                } catch (Exception e) {
140:                    throw new IllegalStateException(
141:                            "Cannot find 'client/tools/DatabaseHome': "
142:                                    + e.getClass().getName() + " "
143:                                    + e.getMessage());
144:                }
145:                try {
146:                    database = databaseHome.create();
147:                } catch (Exception e) {
148:                    throw new IllegalStateException("Cannot start database: "
149:                            + e.getClass().getName() + " " + e.getMessage());
150:                }
151:            }
152:
153:            public void stop() throws IllegalStateException {
154:            }
155:
156:            public void init(Properties props) throws IllegalStateException {
157:            }
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.