Source Code Cross Referenced for DB2FIDMapperFactory.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 org.geotools.data.jdbc.JDBCUtils;
020:        import org.geotools.data.jdbc.fidmapper.BasicFIDMapper;
021:        import org.geotools.data.jdbc.fidmapper.DefaultFIDMapperFactory;
022:        import org.geotools.data.jdbc.fidmapper.FIDMapper;
023:        import org.geotools.data.jdbc.fidmapper.MaxIncFIDMapper;
024:        import org.geotools.data.jdbc.fidmapper.TypedFIDMapper;
025:        import java.io.IOException;
026:        import java.sql.Connection;
027:        import java.sql.ResultSet;
028:        import java.sql.SQLException;
029:        import java.sql.Statement;
030:        import java.util.logging.Logger;
031:
032:        /**
033:         * Overrides DefaultFIDMapperFactory methods for DB2-specific handling.
034:         *
035:         * @author David Adler - IBM Corporation
036:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/db2/src/main/java/org/geotools/data/db2/DB2FIDMapperFactory.java $
037:         */
038:        public class DB2FIDMapperFactory extends DefaultFIDMapperFactory {
039:            private static final Logger LOGGER = org.geotools.util.logging.Logging
040:                    .getLogger("org.geotools.data.db2");
041:            private String databaseSchemaName = null;
042:
043:            /**
044:             * Default constructor will cause FID columns to be returned as business
045:             * attributes.
046:             */
047:            public DB2FIDMapperFactory(String databaseSchemaName) {
048:                super (true);
049:                this .databaseSchemaName = databaseSchemaName;
050:            }
051:
052:            /**
053:             * Constructs a DB2FIDMapperFactory with user specification of whether to
054:             * return FID columns as business attributes.
055:             *
056:             * @param returnFIDColumnsAsAttributes true if FID columns should be
057:             *        returned as business attributes.
058:             */
059:            public DB2FIDMapperFactory(boolean returnFIDColumnsAsAttributes) {
060:                super (returnFIDColumnsAsAttributes);
061:            }
062:
063:            /**
064:             * Gets the appropriate FIDMapper for the specified table.
065:             *
066:             * @param catalog
067:             * @param schema
068:             * @param tableName
069:             * @param connection the active database connection to get table key
070:             *        information
071:             *
072:             * @return the appropriate FIDMapper for the specified table.
073:             *
074:             * @throws IOException if any error occurs.
075:             */
076:            public FIDMapper getMapper(String catalog, String schema,
077:                    String tableName, Connection connection) throws IOException {
078:                FIDMapper fm = super .getMapper(catalog, schema, tableName,
079:                        connection);
080:                LOGGER.fine(toString(fm));
081:
082:                return fm;
083:            }
084:
085:            /**
086:             * Determine whether this column is autoincrement.  An open connection to
087:             * the database must be provided.
088:             *
089:             * @param catalog not used
090:             * @param schema not used
091:             * @param tableName the table name
092:             * @param conn an open database connection
093:             * @param tableInfo not used
094:             * @param columnName the FID column name
095:             * @param dataType not used
096:             *
097:             * @return true if this is an autoincrement column
098:             *
099:             * @throws SQLException
100:             */
101:            protected boolean isAutoIncrement(String catalog, String schema,
102:                    String tableName, Connection conn, ResultSet tableInfo,
103:                    String columnName, int dataType) throws SQLException {
104:                // if it's not an integer type it can't be an auto increment type
105:                if (!isIntegralType(dataType)) {
106:                    return false;
107:                }
108:
109:                // It seems like there should be a better way to get this directly from the catalog
110:                boolean autoIncrement = false;
111:                Statement statement = null;
112:                ResultSet rs = null;
113:
114:                try {
115:                    statement = conn.createStatement();
116:
117:                    String stmtString = "SELECT IDENTITY, GENERATED FROM SYSCAT.COLUMNS "
118:                            + "WHERE TABSCHEMA = '"
119:                            + tableInfo.getString("TABLE_SCHEM")
120:                            + "' "
121:                            + "AND TABNAME = '"
122:                            + tableName
123:                            + "' "
124:                            + "AND COLNAME = '" + columnName + "'";
125:
126:                    rs = statement.executeQuery(stmtString);
127:
128:                    if (rs.next()) {
129:                        if (rs.getString(1).equals("Y")
130:                                && rs.getString(2).equals("A")) {
131:                            autoIncrement = true;
132:                        }
133:                    }
134:                } finally {
135:                    JDBCUtils.close(statement);
136:                    JDBCUtils.close(rs);
137:                }
138:
139:                return autoIncrement;
140:            }
141:
142:            /**
143:             * Returns a DB2NullFIDMapper when there is no primary key.
144:             *
145:             * @param schema ignored.
146:             * @param tableName ignored.
147:             * @param connection ignored.
148:             *
149:             * @return a DB2NullFIDMapper.
150:             */
151:            protected FIDMapper buildNoPKMapper(String schema,
152:                    String tableName, Connection connection) {
153:                FIDMapper mapper;
154:                mapper = new DB2NullFIDMapper(schema, tableName);
155:
156:                return mapper;
157:            }
158:
159:            /**
160:             * Builds a FID mapper based on a single column primary key. Default
161:             * version tries the auto-increment way, then a mapping on an {@link
162:             * MaxIncFIDMapper} type for numeric columns, and a plain {@link
163:             * BasicFIDMapper} of text based columns.
164:             *
165:             * @param schema
166:             * @param tableName
167:             * @param connection not used
168:             * @param ci the column information
169:             *
170:             * @return a FIDMapper
171:             */
172:            protected FIDMapper buildSingleColumnFidMapper(String schema,
173:                    String tableName, Connection connection, ColumnInfo ci) {
174:
175:                if (ci.isAutoIncrement()) {
176:                    return new DB2AutoIncrementFIDMapper(databaseSchemaName,
177:                            tableName, ci.getColName(), ci.getDataType());
178:                } else if (isIntegralType(ci.getDataType())) {
179:                    return new MaxIncFIDMapper(databaseSchemaName, tableName,
180:                            ci.getColName(), ci.getDataType(), true);
181:                } else {
182:                    return new BasicFIDMapper(databaseSchemaName, tableName, ci
183:                            .getColName(), ci.getSize(), true);
184:                }
185:            }
186:
187:            /**
188:             * Create a nice string representation of a FID Mapper
189:             *
190:             * @param fm the FID Mapper
191:             *
192:             * @return the String representation
193:             */
194:            String toString(FIDMapper fm) {
195:                String mapperName = ((TypedFIDMapper) fm).getWrappedMapper()
196:                        .getClass().toString();
197:                String colInfo = "";
198:
199:                if (fm.getColumnCount() > 0) {
200:                    colInfo = fm.getColumnName(0) + ":" + fm.getColumnType(0)
201:                            + ":" + fm.getColumnSize(0) + ":"
202:                            + fm.getColumnDecimalDigits(0);
203:                }
204:
205:                String s = mapperName + ":" + fm.getColumnCount() + ":"
206:                        + colInfo + ":" + fm.returnFIDColumnsAsAttributes()
207:                        + ":" + fm.hasAutoIncrementColumns() + ":" + "";
208:
209:                return s;
210:            }
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.