Source Code Cross Referenced for DB2TestCase.java in  » GIS » GeoTools-2.4.1 » org » geotools » data » db2 » 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 » GIS » GeoTools 2.4.1 » org.geotools.data.db2 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) Copyright IBM Corporation, 2005. All rights reserved.
005:         *
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation;
009:         *    version 2.1 of the License.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         *
016:         */
017:        package org.geotools.data.db2;
018:
019:        import com.ibm.db2.jcc.DB2ConnectionPoolDataSource;
020:        import junit.framework.TestCase;
021:        import org.geotools.data.db2.DB2ConnectionFactory;
022:        import org.geotools.data.jdbc.ConnectionPool;
023:        import org.geotools.data.jdbc.JDBCDataStoreConfig;
024:        import org.geotools.data.jdbc.datasource.DataSourceUtil;
025:        import org.geotools.data.jdbc.datasource.ManageableDataSource;
026:
027:        import java.io.IOException;
028:        import java.sql.Connection;
029:        import java.sql.SQLException;
030:        import java.util.HashMap;
031:        import java.util.Iterator;
032:        import java.util.Map;
033:        import java.util.PropertyResourceBundle;
034:        import java.util.Set;
035:
036:        import javax.sql.DataSource;
037:        import javax.sql.PooledConnection;
038:
039:        /**
040:         * Provide common functionality for DB2 plug-in testcases.
041:         *
042:         * @author David Adler - IBM Corporation
043:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/db2/src/test/java/org/geotools/data/db2/DB2TestCase.java $
044:         */
045:        public class DB2TestCase extends TestCase {
046:            protected static final String DB2_URL_PREFIX = "jdbc:db2://";
047:            protected Map allParams = null;
048:            protected String dbname = null;
049:            protected String user = null;
050:            protected String pw = null;
051:            protected String host = null;
052:            protected int portnum = 50000;
053:            protected String tabSchema = null;
054:            protected String dbURL = null;
055:            protected boolean mock = false;
056:            protected ManageableDataSource pool = null;
057:
058:            protected void setUp() throws Exception {
059:                super .setUp();
060:                setPropertyValues();
061:                setAllParamValues();
062:            }
063:
064:            protected void tearDown() throws Exception {
065:                if (pool != null)
066:                    pool.close();
067:                super .tearDown();
068:            }
069:
070:            protected String getDbURL() {
071:                return DB2_URL_PREFIX + host + ":" + portnum + "/" + dbname;
072:            }
073:
074:            /**
075:             * Sets local values used in testing from a properties file
076:             *
077:             * @throws IOException
078:             * @throws SQLException
079:             */
080:            protected void setPropertyValues() throws IOException, SQLException {
081:                String propertyFile = "db2test.properties";
082:                PropertyResourceBundle resource = new PropertyResourceBundle(
083:                        this .getClass().getResourceAsStream(propertyFile));
084:                host = resource.getString("host");
085:                portnum = Integer.parseInt(resource.getString("portnum"));
086:                dbname = resource.getString("dbname");
087:                user = resource.getString("user");
088:                pw = resource.getString("password");
089:                tabSchema = resource.getString("tabschema");
090:
091:                if (resource.getString("mock").equals("1")) {
092:                    mock = true;
093:                } else {
094:                    mock = false;
095:                }
096:            }
097:
098:            protected void setAllParamValues() {
099:                allParams = new HashMap();
100:                allParams.put("database", dbname);
101:                allParams.put("dbtype", "db2");
102:                allParams.put("host", host);
103:                allParams.put("port", String.valueOf(portnum));
104:                allParams.put("user", user);
105:                allParams.put("passwd", pw);
106:                allParams.put("tabschema", tabSchema);
107:            }
108:
109:            /**
110:             * Common local method to get a Connection for testing
111:             *
112:             *
113:             * @throws Exception
114:             */
115:            protected Connection getLocalConnection() throws Exception {
116:                DB2ConnectionPoolDataSource poolDataSource;
117:                poolDataSource = new DB2ConnectionPoolDataSource();
118:                poolDataSource.setDatabaseName(dbname);
119:                poolDataSource.setUser(user);
120:                poolDataSource.setPassword(pw);
121:                poolDataSource.setPortNumber(portnum);
122:                poolDataSource.setServerName(host);
123:                poolDataSource.setDriverType(4);
124:
125:                PooledConnection pc = poolDataSource.getPooledConnection();
126:                Connection conn = pc.getConnection();
127:
128:                return conn;
129:            }
130:
131:            /**
132:             * Common local method to get a ConnectionPool for testing
133:             *
134:             *
135:             * @throws Exception
136:             */
137:            protected ManageableDataSource getLocalConnectionPool()
138:                    throws Exception {
139:                String url = DB2DataStoreFactory.getJDBCUrl(host, portnum,
140:                        dbname);
141:                return DB2DataStoreFactory.getDefaultDataSource(url, user, pw,
142:                        10, 2, false);
143:            }
144:
145:            /**
146:             * Local utility method to make a copy of a Map object.
147:             * 
148:             * <p>
149:             * Used to make copies of a HashMap of Param objects but should work for
150:             * any Map.
151:             * </p>
152:             *
153:             * @param params an arbitrary Map object
154:             *
155:             * @return a copy of the input Map object
156:             */
157:            protected Map copyParams(Map params) {
158:                Map p2 = new HashMap();
159:                Set keys = params.keySet();
160:                Iterator it = keys.iterator();
161:
162:                while (it.hasNext()) {
163:                    String key = (String) it.next();
164:                    p2.put(key, params.get(key));
165:                }
166:
167:                return p2;
168:            }
169:
170:            protected DB2DataStore getDataStore() throws Exception {
171:                JDBCDataStoreConfig config = new JDBCDataStoreConfig(tabSchema,
172:                        tabSchema, 100000);
173:
174:                if (pool == null) {
175:                    pool = getLocalConnectionPool();
176:                }
177:
178:                return new DB2DataStore(pool, config, getDbURL());
179:            }
180:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.