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


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2004-2006, GeoTools Project Managment Committee (PMC)
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:         *    Created on 18-apr-2004
017:         */
018:        /*
019:         * Created on 18-apr-2004
020:         * 12-jul-2006 D. Adler GEOT-728 Refactor FIDMapper classes
021:         */
022:        package org.geotools.data.jdbc.fidmapper;
023:
024:        import org.geotools.data.DataSourceException;
025:        import org.geotools.feature.Feature;
026:        import java.io.IOException;
027:        import java.io.UnsupportedEncodingException;
028:        import java.net.URLDecoder;
029:        import java.net.URLEncoder;
030:        import java.sql.Connection;
031:        import java.sql.Statement;
032:
033:        /**
034:         * A simple implementation of FIDMapper for multi column primary keys
035:         *
036:         * @author wolf
037:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/jdbc/src/main/java/org/geotools/data/jdbc/fidmapper/MultiColumnFIDMapper.java $
038:         */
039:        public class MultiColumnFIDMapper extends AbstractFIDMapper {
040:            private static final long serialVersionUID = 1L;
041:            private static final String UTF8 = "UTF-8";
042:
043:            /**
044:             * Builds a new instance of the MultiColumnFIDMapper
045:             *
046:             * @param tableSchemaName
047:             * @param tableName
048:             * @param colNames - column names
049:             * @param colTypes - column types, see {@link java.sql.Types}
050:             * @param colSizes - column sizes
051:             * @param colDecimalDigits - column decimals
052:             * @param autoIncrement - flags for auto-increment tests
053:             *
054:             * @throws IllegalArgumentException
055:             */
056:            public MultiColumnFIDMapper(String tableSchemaName,
057:                    String tableName, String[] colNames, int[] colTypes,
058:                    int[] colSizes, int[] colDecimalDigits,
059:                    boolean[] autoIncrement) {
060:                super (tableSchemaName, tableName);
061:                if ((colNames == null) || (colTypes == null)
062:                        || (autoIncrement == null)) {
063:                    throw new IllegalArgumentException(
064:                            "Column description arrays must be not null");
065:                }
066:
067:                if (colNames.length == 0) {
068:                    throw new IllegalArgumentException(
069:                            "Column description arrays must be not empty");
070:                }
071:
072:                if ((colNames.length != colTypes.length)
073:                        || (colNames.length != autoIncrement.length)) {
074:                    throw new IllegalArgumentException(
075:                            "Column description arrays must have the same size");
076:                }
077:
078:                this .colNames = colNames;
079:                this .colTypes = colTypes;
080:                this .colSizes = colSizes;
081:                this .colDecimalDigits = colDecimalDigits;
082:                this .autoIncrement = autoIncrement;
083:                this .returnFIDColumnsAsAttributes = true;
084:            }
085:
086:            /**
087:             * Builds a new instance of the MultiColumnFIDMapper
088:             *
089:             * @param colNames - column names
090:             * @param colTypes - column types, see {@link java.sql.Types}
091:             * @param colSizes - column sizes
092:             * @param colDecimalDigits - column decimals
093:             * @param autoIncrement - flags for auto-increment tests
094:             *
095:             * @throws IllegalArgumentException
096:             */
097:            public MultiColumnFIDMapper(String[] colNames, int[] colTypes,
098:                    int[] colSizes, int[] colDecimalDigits,
099:                    boolean[] autoIncrement) {
100:                this (null, null, colNames, colTypes, colSizes,
101:                        colDecimalDigits, autoIncrement);
102:            }
103:
104:            /**
105:             * @see org.geotools.data.jdbc.fidmapper.FIDMapper#getID(java.lang.Object[])
106:             */
107:            public String getID(Object[] attributes) {
108:                StringBuffer sb = new StringBuffer();
109:
110:                try {
111:                    for (int i = 0; i < attributes.length; i++) {
112:                        sb.append(URLEncoder.encode(attributes[i].toString(),
113:                                UTF8));
114:
115:                        if (i < (attributes.length - 1)) {
116:                            sb.append("&");
117:                        }
118:                    }
119:                } catch (UnsupportedEncodingException e) {
120:                    // c'mon, don't tell me UTF-8 is not supported ;-)
121:                }
122:
123:                return sb.toString();
124:            }
125:
126:            /**
127:             * @see org.geotools.data.jdbc.fidmapper.FIDMapper#getPKAttributes(java.lang.String)
128:             */
129:            public Object[] getPKAttributes(String FID) throws IOException {
130:                String[] attributes = FID.split("&");
131:
132:                if (attributes.length != colNames.length) {
133:                    throw new DataSourceException(
134:                            "The FID is not compatible with MultiColumnFIDMapper, was expecting "
135:                                    + colNames.length
136:                                    + " URL-encoded columns and got "
137:                                    + attributes.length + " columns");
138:                }
139:
140:                for (int i = 0; i < attributes.length; i++) {
141:                    attributes[i] = URLDecoder.decode(attributes[i], UTF8);
142:                }
143:
144:                return attributes;
145:            }
146:
147:            /**
148:             * @see org.geotools.data.jdbc.fidmapper.FIDMapper#createID(java.sql.Connection,
149:             *      org.geotools.feature.Feature, Statement)
150:             */
151:            public String createID(Connection conn, Feature feature,
152:                    Statement statement) throws IOException {
153:                String[] attValues = new String[colNames.length];
154:
155:                for (int i = 0; i < colNames.length; i++) {
156:                    attValues[i] = feature.getAttribute(colNames[i]).toString();
157:                }
158:
159:                return getID(attValues);
160:            }
161:
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.