Source Code Cross Referenced for DB2SQLBuilderTest.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-2007. 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.vividsolutions.jts.geom.Point;
020:        import org.geotools.data.DefaultQuery;
021:        import org.geotools.data.FeatureSource;
022:
023:        import org.geotools.data.db2.filter.SQLEncoderDB2;
024:        import org.geotools.factory.CommonFactoryFinder;
025:        import org.geotools.feature.AttributeType;
026:        import org.geotools.feature.AttributeTypeFactory;
027:        import org.geotools.feature.FeatureType;
028:        import org.geotools.filter.SQLEncoderException;
029:
030:        import org.opengis.filter.Filter;
031:        import org.opengis.filter.FilterFactory;
032:        import org.opengis.filter.Id;
033:        import org.opengis.filter.PropertyIsEqualTo;
034:        import org.opengis.filter.PropertyIsLike;
035:        import org.opengis.filter.expression.Literal;
036:        import org.opengis.filter.expression.PropertyName;
037:        import org.opengis.filter.identity.FeatureId;
038:
039:        import java.io.IOException;
040:        import java.util.HashSet;
041:        import java.util.Set;
042:
043:        /**
044:         * Exercise DB2SQLBuilder.
045:         * 
046:         * @author David Adler - IBM Corporation
047:         * @source $URL:
048:         *         http://svn.geotools.org/geotools/trunk/gt/modules/unsupported/db2/src/test/java/org/geotools/data/db2/DB2SQLBuilderTest.java $
049:         */
050:        public class DB2SQLBuilderTest extends DB2TestCase {
051:            private DB2SQLBuilder sqlBuilder = null;
052:
053:            private DB2DataStore dataStore = null;
054:
055:            /**
056:             * Setup creates an encoder and SQLBuilder
057:             * 
058:             * @throws Exception
059:             */
060:            public void setUp() throws Exception {
061:                super .setUp();
062:                this .dataStore = getDataStore();
063:
064:                SQLEncoderDB2 encoder = new SQLEncoderDB2();
065:                encoder.setSqlNameEscape("\"");
066:                sqlBuilder = (DB2SQLBuilder) dataStore.getSqlBuilder("Places");
067:            }
068:
069:            public void testFidFilter() throws SQLEncoderException, IOException {
070:                String typeName = "Places";
071:                FeatureSource fs = dataStore.getFeatureSource("Places");
072:                FeatureType ft = fs.getSchema();
073:                FilterFactory ff2 = CommonFactoryFinder.getFilterFactory(null);
074:
075:                Set ids = new HashSet();
076:
077:                FeatureId fid1 = ff2.featureId("1");
078:                ids.add(fid1);
079:                Id ff3 = CommonFactoryFinder.getFilterFactory(null).id(ids);
080:                sqlBuilder = (DB2SQLBuilder) dataStore.getSqlBuilder("Places");
081:                DefaultQuery query = new DefaultQuery("Places", ff3);
082:                Filter preFilter = sqlBuilder.getPreQueryFilter(query
083:                        .getFilter());
084:                Filter postFilter = sqlBuilder.getPostQueryFilter(query
085:                        .getFilter());
086:                String[] attrNames = new String[ft.getAttributeCount()];
087:                AttributeType[] attrTypes = new AttributeType[ft
088:                        .getAttributeCount()];
089:
090:                for (int i = 0; i < ft.getAttributeCount(); i++) {
091:                    attrNames[i] = ft.getAttributeType(i).getName();
092:                    attrTypes[i] = ft.getAttributeType(i);
093:                }
094:
095:                String fidQuery = this .sqlBuilder.buildSQLQuery("Places",
096:                        this .dataStore.getFIDMapper("Places"), attrTypes,
097:                        preFilter);
098:                assertEquals(
099:                        "FID encoding failed",
100:                        "SELECT \"Id\", \"Name\", DB2GSE.ST_AsText(\"Geom\") FROM \"Test\".\"Places\" WHERE (\"Id\" = 1)",
101:                        fidQuery);
102:
103:                FeatureId fid2 = ff2.featureId("2");
104:                ids.add(fid2);
105:                ff3 = CommonFactoryFinder.getFilterFactory(null).id(ids);
106:
107:                query = new DefaultQuery("Places", ff3);
108:                preFilter = sqlBuilder.getPreQueryFilter(query.getFilter());
109:                fidQuery = this .sqlBuilder.buildSQLQuery("Places",
110:                        this .dataStore.getFIDMapper("Places"), attrTypes,
111:                        preFilter);
112:                assertEquals(
113:                        "FID encoding failed",
114:                        "SELECT \"Id\", \"Name\", DB2GSE.ST_AsText(\"Geom\") FROM \"Test\".\"Places\" WHERE (\"Id\" = 2) OR (\"Id\" = 1)",
115:                        fidQuery);
116:            }
117:
118:            public void testCompareFilter() throws SQLEncoderException,
119:                    IOException {
120:                String typeName = "Places";
121:                FeatureSource fs = dataStore.getFeatureSource("Places");
122:                FeatureType ft = fs.getSchema();
123:                org.opengis.filter.FilterFactory ff = CommonFactoryFinder
124:                        .getFilterFactory(null);
125:
126:                PropertyName column = ff.property("Name");
127:                Literal compareValue = ff.literal("Zena");
128:                PropertyIsEqualTo filter = ff.equals(column, compareValue);
129:
130:                String[] attrNames = new String[ft.getAttributeCount()];
131:                AttributeType[] attrTypes = new AttributeType[ft
132:                        .getAttributeCount()];
133:
134:                for (int i = 0; i < ft.getAttributeCount(); i++) {
135:                    attrNames[i] = ft.getAttributeType(i).getName();
136:                    attrTypes[i] = ft.getAttributeType(i);
137:                }
138:                sqlBuilder = (DB2SQLBuilder) dataStore.getSqlBuilder("Places");
139:                DefaultQuery query = new DefaultQuery("Places", filter);
140:                Filter preFilter = sqlBuilder.getPreQueryFilter(query
141:                        .getFilter());
142:                Filter postFilter = sqlBuilder.getPostQueryFilter(query
143:                        .getFilter());
144:                String compareQuery = this .sqlBuilder.buildSQLQuery("Places",
145:                        this .dataStore.getFIDMapper("Places"), attrTypes,
146:                        preFilter);
147:                assertEquals(
148:                        "compare encoding failed",
149:                        "SELECT \"Id\", \"Name\", DB2GSE.ST_AsText(\"Geom\") FROM \"Test\".\"Places\" WHERE \"Name\" = 'Zena'",
150:                        compareQuery);
151:
152:                sqlBuilder = (DB2SQLBuilder) dataStore.getSqlBuilder("Roads");
153:                column = ff.property("Length");
154:                compareValue = ff.literal(2.5);
155:                filter = ff.equals(column, compareValue);
156:                query = new DefaultQuery("Roads", filter);
157:                preFilter = sqlBuilder.getPreQueryFilter(query.getFilter());
158:                postFilter = sqlBuilder.getPostQueryFilter(query.getFilter());
159:                compareQuery = this .sqlBuilder.buildSQLQuery("Roads",
160:                        this .dataStore.getFIDMapper("Roads"), attrTypes,
161:                        preFilter);
162:                assertEquals(
163:                        "compare encoding failed",
164:                        "SELECT \"ID\", \"Name\", DB2GSE.ST_AsText(\"Geom\") FROM \"Test\".\"Roads\" WHERE \"Length\" = 2.5",
165:                        compareQuery);
166:            }
167:
168:            public void testLikeFilter() throws SQLEncoderException,
169:                    IOException {
170:                String typeName = "Places";
171:                FeatureSource fs = dataStore.getFeatureSource("Places");
172:                FeatureType ft = fs.getSchema();
173:
174:                org.opengis.filter.FilterFactory ff = CommonFactoryFinder
175:                        .getFilterFactory(null);
176:                PropertyName column = ff.property("Name");
177:                Literal compareValue = ff.literal("Zena");
178:                PropertyIsEqualTo filter = ff.equals(column, compareValue);
179:
180:                String pattern = "s_met*s";
181:                PropertyIsLike lf = ff.like(column, pattern);
182:                sqlBuilder = (DB2SQLBuilder) dataStore.getSqlBuilder("Places");
183:                DefaultQuery query = new DefaultQuery("Places", lf);
184:                Filter preFilter = sqlBuilder.getPreQueryFilter(query
185:                        .getFilter());
186:                Filter postFilter = sqlBuilder.getPostQueryFilter(query
187:                        .getFilter());
188:                String[] attrNames = new String[ft.getAttributeCount()];
189:                AttributeType[] attrTypes = new AttributeType[ft
190:                        .getAttributeCount()];
191:
192:                for (int i = 0; i < ft.getAttributeCount(); i++) {
193:                    attrNames[i] = ft.getAttributeType(i).getName();
194:                    attrTypes[i] = ft.getAttributeType(i);
195:                }
196:
197:                String likeQuery = this .sqlBuilder.buildSQLQuery("Places",
198:                        this .dataStore.getFIDMapper("Places"), attrTypes,
199:                        preFilter);
200:                assertEquals(
201:                        "LIKE encoding failed",
202:                        "SELECT \"Id\", \"Name\", DB2GSE.ST_AsText(\"Geom\") FROM \"Test\".\"Places\" WHERE \"Name\" LIKE 's_met%s' ",
203:                        likeQuery);
204:            }
205:
206:            public void testSqlFrom() {
207:                StringBuffer sb;
208:                sb = new StringBuffer();
209:                sqlBuilder.sqlFrom(sb, "Test");
210:                assertEquals("Encoding didn't match",
211:                        " FROM \"Test\".\"Test\"", sb.toString());
212:            }
213:
214:            public void testSqlGeometryColumn() {
215:                String columnName = "Geom";
216:                Class geomClass = Point.class;
217:                AttributeType geomAttr = AttributeTypeFactory.newAttributeType(
218:                        columnName, geomClass);
219:
220:                StringBuffer sb = new StringBuffer();
221:                this .sqlBuilder.sqlGeometryColumn(sb, geomAttr);
222:                assertEquals("Encoding didn't match",
223:                        "DB2GSE.ST_AsText(\"Geom\")", sb.toString());
224:            }
225:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.