01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: /*
17: * 17-Jul-2006 D. Adler GEOT-728 Refactor FIDMapper classes
18: */
19: package org.geotools.data.jdbc.fidmapper;
20:
21: import org.geotools.feature.Feature;
22: import java.io.IOException;
23: import java.rmi.server.UID;
24: import java.sql.Connection;
25: import java.sql.Statement;
26:
27: /**
28: * Last resort fid mapper for tables that does not have a primary key. It
29: * allows reading the table getting unique FIDs by using the same mechanism
30: * used by DefaultFeature, but the same Feature will receive a different FID
31: * each time it is loaded from the datastore.
32: *
33: * @author wolf
34: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/jdbc/src/main/java/org/geotools/data/jdbc/fidmapper/NullFIDMapper.java $
35: */
36: public class NullFIDMapper extends AbstractFIDMapper {
37: private static final long serialVersionUID = 1L;
38: private static final String ARRAY_OUT_OF_BOUND_MESSAGE = "There are no columns in this FIDMapper";
39:
40: public NullFIDMapper() {
41: super (null, null);
42: }
43:
44: /**
45: * Constructor to set schema and table name for Null mapper.
46: *
47: * @param tableSchemaName
48: * @param tableName
49: */
50: public NullFIDMapper(String tableSchemaName, String tableName) {
51: super (tableSchemaName, tableName);
52: }
53:
54: /**
55: * @see org.geotools.data.jdbc.fidmapper.FIDMapper#getID(java.lang.Object[])
56: */
57: public String getID(Object[] attributes) {
58: // optimization, since the UID toString uses only ":" and converts long and integers
59: // to strings for the rest, so the only non word character is really ":"
60: return "nfm-" + new UID().toString().replace(':', '_');
61: }
62:
63: /**
64: * @see org.geotools.data.jdbc.fidmapper.FIDMapper#getPKAttributes(java.lang.String)
65: */
66: public Object[] getPKAttributes(String FID) throws IOException {
67: return new Object[0];
68: }
69:
70: /**
71: * @see org.geotools.data.jdbc.fidmapper.FIDMapper#createID(java.sql.Connection,
72: * org.geotools.feature.Feature, Statement)
73: */
74: public String createID(Connection conn, Feature feature,
75: Statement statement) throws IOException {
76: return getID(null);
77: }
78:
79: /**
80: * This FID mappers generates unique IDs out of the blue using {@link UID
81: * UID}
82: *
83: * @see org.geotools.data.jdbc.fidmapper.FIDMapper#isVolatile()
84: */
85: public boolean isVolatile() {
86: return true;
87: }
88: }
|