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


001:        /*
002:
003:           Derby - Class org.apache.derbyTesting.functionTests.tests.store.TestRoutines
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, software
015:           distributed under the License is distributed on an "AS IS" BASIS,
016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:           See the License for the specific language governing permissions and
018:           limitations under the License.
019:
020:         */
021:
022:        package org.apache.derbyTesting.functionTests.util;
023:
024:        import java.security.AccessController;
025:        import java.security.PrivilegedAction;
026:        import java.security.PrivilegedActionException;
027:        import java.security.PrivilegedExceptionAction;
028:        import java.sql.*;
029:        import java.io.*;
030:
031:        import org.apache.derby.iapi.reference.JDBC30Translation;
032:
033:        /**
034:         Utility methods for tests routines, in order to bring some consistency to test output.
035:         Any routines added here should be general purpose in nature, not specific to
036:         a single test.
037:
038:         Add a public static method for the test and then add its creation as a procedure
039:         or function in installRoutines.
040:         */
041:        public class TestRoutines {
042:
043:            /**
044:            	A single procedure to create all the routines in this file.
045:            	The script to run this is in testRoutines.sql
046:             */
047:            public static void installRoutines() throws SQLException {
048:
049:                Connection conn = DriverManager
050:                        .getConnection("jdbc:default:connection");
051:
052:                TestRoutines.installRoutines(conn);
053:
054:            }
055:
056:            /**
057:            	Easy way to install all the routines from a Java test program.
058:            	Just call with a valid connection.
059:            	org.apache.derbyTesting.functionTests.util.TestRoutines.installRoutines(conn);
060:             */
061:            public static void installRoutines(Connection conn)
062:                    throws SQLException {
063:
064:                Statement s = conn.createStatement();
065:
066:                // setSystemProperty
067:                s
068:                        .execute("CREATE PROCEDURE TESTROUTINE.SET_SYSTEM_PROPERTY(IN PROPERTY_KEY VARCHAR(32000), IN PROPERTY_VALUE VARCHAR(32000)) NO SQL EXTERNAL NAME 'org.apache.derbyTesting.functionTests.util.TestRoutines.setSystemProperty' language java parameter style java");
069:
070:                // sleep
071:                s
072:                        .execute("CREATE PROCEDURE TESTROUTINE.SLEEP(IN SLEEP_TIME_MS BIGINT) NO SQL EXTERNAL NAME 'org.apache.derbyTesting.functionTests.util.TestRoutines.sleep' language java parameter style java");
073:
074:                s
075:                        .execute("CREATE FUNCTION TESTROUTINE.HAS_SECURITY_MANAGER() RETURNS INT NO SQL EXTERNAL NAME 'org.apache.derbyTesting.functionTests.util.TestRoutines.hasSecurityManager' language java parameter style java");
076:
077:                s
078:                        .execute("CREATE FUNCTION TESTROUTINE.READ_FILE(FILE_NAME VARCHAR(60), ENCODING VARCHAR(60)) RETURNS VARCHAR(32000) NO SQL EXTERNAL NAME 'org.apache.derbyTesting.functionTests.util.TestRoutines.readFile' language java parameter style java");
079:                s.close();
080:            }
081:
082:            /**
083:            	TESTROUTINE.SET_SYSTEM_PROPERTY(IN PROPERTY_KEY VARCHAR(32000), IN PROPERTY_VALUE VARCHAR(32000))
084:            	Set a system property
085:             */
086:            public static void setSystemProperty(final String key,
087:                    final String value) {
088:
089:                // needs to run in a privileged block as it will be
090:                // called through a SQL statement and thus a generated
091:                // class. The generated class on the stack has no permissions
092:                // granted to it.
093:                AccessController.doPrivileged(new PrivilegedAction() {
094:                    public Object run() {
095:                        System.setProperty(key, value);
096:                        return null; // nothing to return
097:                    }
098:                });
099:
100:            }
101:
102:            /**
103:            	TESTROUTINE.SLEEP(IN TIME_MS BIGINT)
104:            	Sleep for a number of milli-seconds.
105:             */
106:            public static void sleep(long ms) throws InterruptedException {
107:
108:                Thread.sleep(ms);
109:            }
110:
111:            /**
112:             * TESTROUTINE.HAS_SECURITY_MANAGER()
113:             * Return 0 is no security manager is installed, 1 if one is.
114:             * @return
115:             */
116:            public static int hasSecurityManager() {
117:                return System.getSecurityManager() == null ? 0 : 1;
118:            }
119:
120:            /**
121:            TESTROUTINE.READ_FILE(FILE_NAME VARCHAR(60), ENCODING VARCHAR(60)) RETURNS VARCHAR(32000)
122:            Read a file using the passed in encoding display its contents
123:            as ASCII with unicode esacpes..
124:             * @throws PrivilegedActionException 
125:             * @throws IOException 
126:             */
127:            public static String readFile(final String fileName,
128:                    final String encoding) throws PrivilegedActionException,
129:                    IOException {
130:
131:                // needs to run in a privileged block as it will be
132:                // called through a SQL statement and thus a generated
133:                // class. The generated class on the stack has no permissions
134:                // granted to it.
135:                FileInputStream fin = (FileInputStream) AccessController
136:                        .doPrivileged(new PrivilegedExceptionAction() {
137:                            public Object run() throws FileNotFoundException {
138:                                return new FileInputStream(fileName); // nothing to return
139:                            }
140:                        });
141:
142:                InputStreamReader isr = new InputStreamReader(
143:                        new BufferedInputStream(fin, 32 * 1024), encoding);
144:
145:                StringBuffer sb = new StringBuffer();
146:                for (;;) {
147:                    int ci = isr.read();
148:                    if (ci < 0)
149:                        break;
150:
151:                    if (ci <= 0x7f) {
152:                        sb.append((char) ci);
153:                    } else {
154:                        sb.append("\\u");
155:                        String hex = Integer.toHexString(ci);
156:
157:                        switch (hex.length()) {
158:                        case 2:
159:                            sb.append("00");
160:                            break;
161:                        case 3:
162:                            sb.append("0");
163:                            break;
164:                        }
165:                        sb.append(hex);
166:                    }
167:                }
168:
169:                return sb.toString();
170:            }
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.