Source Code Cross Referenced for DatabasePropertyTestSetup.java in  » Database-DBMS » db-derby-10.2 » org » apache » derbyTesting » junit » 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 DBMS » db derby 10.2 » org.apache.derbyTesting.junit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         * Derby - Class org.apache.derbyTesting.functionTests.util.DatabasePropertyTestSetup
004:         *
005:         * Licensed to the Apache Software Foundation (ASF) under one or more
006:         * contributor license agreements.  See the NOTICE file distributed with
007:         * this work for additional information regarding copyright ownership.
008:         * The ASF licenses this file to You under the Apache License, Version 2.0
009:         * (the "License"); you may not use this file except in compliance with
010:         * the License.  You may obtain a copy of the License at
011:         *
012:         *    http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing, 
015:         * software distributed under the License is distributed on an 
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
017:         * either express or implied. See the License for the specific 
018:         * language governing permissions and limitations under the License.
019:         */
020:        package org.apache.derbyTesting.junit;
021:
022:        import java.sql.CallableStatement;
023:        import java.sql.Connection;
024:        import java.sql.PreparedStatement;
025:        import java.sql.ResultSet;
026:        import java.sql.SQLException;
027:        import java.util.Enumeration;
028:        import java.util.Properties;
029:
030:        import junit.framework.Test;
031:
032:        import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
033:
034:        /**
035:         * Test decorator to set a set of database properties on setUp
036:         * and restore them to the previous values on tearDown.
037:         *
038:         */
039:        public class DatabasePropertyTestSetup extends BaseJDBCTestSetup {
040:
041:            private Properties newValues;
042:            private Properties oldValues;
043:
044:            /**
045:             * Create a test decorator that sets and restores the passed
046:             * in properties. Assumption is that the contents of
047:             * properties and values will not change during execution.
048:             * @param test test to be decorated
049:             * @param newValues properties to be set
050:             */
051:            public DatabasePropertyTestSetup(Test test, Properties newValues) {
052:                super (test);
053:                this .newValues = newValues;
054:                this .oldValues = new Properties();
055:            }
056:
057:            /**
058:             * For each property store the current value and
059:             * replace it with the new value, unless there is no change.
060:             */
061:            protected void setUp() throws java.lang.Exception {
062:                setProperties(newValues);
063:            }
064:
065:            /**
066:             * Revert the properties to their values prior to the setUp call.
067:             */
068:            protected void tearDown() throws java.lang.Exception {
069:                Connection conn = getConnection();
070:                conn.setAutoCommit(false);
071:                CallableStatement setDBP = conn
072:                        .prepareCall("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(?, NULL)");
073:                // Clear all the system properties set by the new set
074:                // that will not be reset by the old set. Ignore any 
075:                // invalid property values.
076:                try {
077:                    for (Enumeration e = newValues.propertyNames(); e
078:                            .hasMoreElements();) {
079:                        String key = (String) e.nextElement();
080:                        if (oldValues.getProperty(key) == null) {
081:                            setDBP.setString(1, key);
082:                            setDBP.executeUpdate();
083:                        }
084:                    }
085:                } catch (SQLException sqle) {
086:                    if (!sqle.getSQLState().equals(
087:                            SQLStateConstants.PROPERTY_UNSUPPORTED_CHANGE))
088:                        throw sqle;
089:                }
090:                // and then reset nay old values which will cause the commit.
091:                setProperties(oldValues);
092:                super .tearDown();
093:                newValues = null;
094:                oldValues = null;
095:            }
096:
097:            private void setProperties(Properties values) throws SQLException {
098:                Connection conn = getConnection();
099:                conn.setAutoCommit(false);
100:
101:                PreparedStatement getDBP = conn
102:                        .prepareStatement("VALUES SYSCS_UTIL.SYSCS_GET_DATABASE_PROPERTY(?)");
103:                CallableStatement setDBP = conn
104:                        .prepareCall("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(?, ?)");
105:
106:                for (Enumeration e = values.propertyNames(); e
107:                        .hasMoreElements();) {
108:                    final String key = (String) e.nextElement();
109:                    final String value = values.getProperty(key);
110:
111:                    getDBP.setString(1, key);
112:                    ResultSet rs = getDBP.executeQuery();
113:                    rs.next();
114:                    String old = rs.getString(1);
115:                    rs.close();
116:
117:                    boolean change;
118:                    if (old != null) {
119:                        // set, might need to be changed.
120:                        change = !old.equals(value);
121:
122:                        // If we are not processing the oldValues
123:                        // then store in the oldValues. Reference equality is ok here.
124:                        if (change && (values != oldValues))
125:                            oldValues.setProperty(key, old);
126:                    } else {
127:                        // notset, needs to be set
128:                        change = true;
129:                    }
130:
131:                    if (change) {
132:                        setDBP.setString(1, key);
133:                        setDBP.setString(2, value);
134:                        setDBP.executeUpdate();
135:                    }
136:                }
137:                conn.commit();
138:                getDBP.close();
139:                setDBP.close();
140:                conn.close();
141:            }
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.