Source Code Cross Referenced for MaxIncFIDMapper.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:         * TODO: 26-may-2005 D. Adler Removed returnIDAsAttribute variable and method.
018:         */
019:        /*
020:         * Created on 18-apr-2004
021:         * 26-may-2005 D. Adler Removed returnIDAsAttribute variable and method.
022:         * 12-jul-2006 D. Adler GEOT-728 Refactor FIDMapper classes
023:         */
024:        package org.geotools.data.jdbc.fidmapper;
025:
026:        import org.geotools.data.DataSourceException;
027:        import org.geotools.feature.Feature;
028:        import java.io.IOException;
029:        import java.sql.Connection;
030:        import java.sql.ResultSet;
031:        import java.sql.SQLException;
032:        import java.sql.Statement;
033:        import java.util.logging.Level;
034:        import java.util.logging.Logger;
035:
036:        /**
037:         * A FID mapper that uses a single integer column as the primary key and that
038:         * does a <code>SELECT MAX(fixColumn) + 1</code> to generate new ones. This is
039:         * a fragile generation strategy, better use a sequence or a serial to get
040:         * reliable results.
041:         *
042:         * @author aaime
043:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/jdbc/src/main/java/org/geotools/data/jdbc/fidmapper/MaxIncFIDMapper.java $
044:         */
045:        public class MaxIncFIDMapper extends AbstractFIDMapper {
046:            private static final long serialVersionUID = 5719859796485477701L;
047:
048:            /** A logger */
049:            private static final Logger LOGGER = org.geotools.util.logging.Logging
050:                    .getLogger("org.geotools.data.jdbc.fidmapper");
051:
052:            /**
053:             * Creates a new MaxIncFIDMapper object.
054:             *
055:             * @param tableName the table name
056:             * @param FIDColumn the name of the FID column
057:             * @param FIDColumnType The SQL type of the column - must be a numeric type
058:             */
059:            public MaxIncFIDMapper(String tableName, String FIDColumn,
060:                    int FIDColumnType) {
061:                this (null, tableName, FIDColumn, FIDColumnType, false);
062:            }
063:
064:            /**
065:             * Creates a new MaxIncFIDMapper object that will return the FID columns as
066:             * business attributes.
067:             *
068:             * @param tableSchemaName the schema of this table
069:             * @param tableName the table name
070:             * @param FIDColumn the name of the FID column
071:             * @param FIDColumnType The SQL type of the column - must be a numeric type
072:             * @param returnFIDColumnsAsAttributes true to return FID columns as
073:             *        attributes.
074:             */
075:            public MaxIncFIDMapper(String tableSchemaName, String tableName,
076:                    String FIDColumn, int FIDColumnType,
077:                    boolean returnFIDColumnsAsAttributes) {
078:                super (tableSchemaName, tableName);
079:                this .returnFIDColumnsAsAttributes = returnFIDColumnsAsAttributes;
080:                setInfo(FIDColumn, FIDColumnType, 0, 0, false);
081:            }
082:
083:            /**
084:             * @see org.geotools.data.jdbc.fidmapper.FIDMapper#getID(java.lang.Object[])
085:             */
086:            public String getID(Object[] attributes) {
087:                return String.valueOf(attributes[0]);
088:            }
089:
090:            /**
091:             * @see org.geotools.data.jdbc.fidmapper.FIDMapper#getPKAttributes(java.lang.String)
092:             */
093:            public Object[] getPKAttributes(String FID) {
094:                try {
095:                    return new Object[] { new Long(Long.parseLong(FID)) };
096:                } catch (NumberFormatException e) {
097:                    return new Object[] { new Long(-1) };
098:                }
099:            }
100:
101:            /**
102:             * @see java.lang.Object#equals(java.lang.Object)
103:             */
104:            public boolean equals(Object object) {
105:                if (!(object instanceof  TypedFIDMapper)) {
106:                    return false;
107:                }
108:
109:                MaxIncFIDMapper other = (MaxIncFIDMapper) object;
110:
111:                return (other.getColumnName() == this .getColumnName())
112:                        && (other.getColumnType() == this .getColumnType())
113:                        && (other.returnFIDColumnsAsAttributes == this .returnFIDColumnsAsAttributes);
114:            }
115:
116:            /**
117:             * @see org.geotools.data.jdbc.fidmapper.FIDMapper#createID(java.sql.Connection,
118:             *      Feature, Statement)
119:             */
120:            public String createID(Connection conn, Feature feature,
121:                    Statement statement) throws IOException {
122:                Statement stmt = null;
123:                ResultSet rs = null;
124:                try {
125:                    stmt = conn.createStatement();
126:                    rs = stmt.executeQuery("Select MAX(" + getColumnName()
127:                            + ") from " + tableName);
128:
129:                    if (rs.next()) {
130:                        long maxFid = rs.getLong(1);
131:
132:                        return String.valueOf(maxFid + 1);
133:                    } else {
134:                        throw new DataSourceException("Could not get MAX for "
135:                                + tableName + "." + getColumnName()
136:                                + ": No result returned from query");
137:                    }
138:                } catch (SQLException e) {
139:                    throw new DataSourceException(
140:                            "An sql problem occurred. Are the table and the fid column there?",
141:                            e);
142:                } finally {
143:                    if (stmt != null) {
144:                        try {
145:                            stmt.close();
146:                        } catch (SQLException e) {
147:                            LOGGER.log(Level.WARNING,
148:                                    "MaxIncFidMapper could not close statement:"
149:                                            + e, e);
150:                        }
151:                    }
152:                    if (rs != null) {
153:                        try {
154:                            rs.close();
155:                        } catch (SQLException e) {
156:                            LOGGER.log(Level.WARNING,
157:                                    "MaxIncFidMapper could not close resultset:"
158:                                            + e, e);
159:                        }
160:                    }
161:                }
162:            }
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.