001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-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: package org.geotools.data.hsql.fidmapper;
017:
018: import java.io.IOException;
019: import java.sql.Connection;
020: import java.sql.Statement;
021:
022: import org.geotools.data.jdbc.fidmapper.AbstractFIDMapper;
023: import org.geotools.data.jdbc.fidmapper.FIDMapper;
024: import org.geotools.data.jdbc.fidmapper.TypedFIDMapper;
025: import org.geotools.feature.Feature;
026:
027: /**
028: * This fidmapper just takes another fid mapper aand wraps it! Due
029: * to volatility issues, it seems that without a FIDMapper that isn't
030: * declared to be volatile, some things don't work...the TypedFIDMapper
031: * would've been a good choice except that it makes changes to the FID
032: * in the getID method.
033: *
034: * @author aalam
035: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/hsql/src/main/java/org/geotools/data/hsql/fidmapper/HsqlFIDMapper.java $
036: */
037: public class HsqlFIDMapper extends AbstractFIDMapper {
038: private static final long serialVersionUID = 1L;
039: private String featureTypeName;
040: private FIDMapper wrappedMapper;
041:
042: /**
043: * Creates a new HsqlFIDMapper object.
044: *
045: * @param wrapped
046: * @param featureTypeName
047: *
048: * @throws IllegalArgumentException DOCUMENT ME!
049: */
050: public HsqlFIDMapper(FIDMapper wrapped, String featureTypeName) {
051: if (wrapped == null) {
052: throw new IllegalArgumentException(
053: "The wrapped feature mapper cannot be null");
054: }
055:
056: if (featureTypeName == null) {
057: throw new IllegalArgumentException(
058: "The featureTypeName cannot be null");
059: }
060:
061: this .wrappedMapper = wrapped;
062: this .featureTypeName = featureTypeName;
063: }
064:
065: /**
066: * @see org.geotools.data.jdbc.fidmapper.FIDMapper#getID(java.lang.Object[])
067: */
068: public String getID(Object[] attributes) {
069: // return featureTypeName + "." + wrappedMapper.getID(attributes);
070: return wrappedMapper.getID(attributes);
071: }
072:
073: /**
074: * @see org.geotools.data.jdbc.fidmapper.FIDMapper#getPKAttributes(java.lang.String)
075: */
076: public Object[] getPKAttributes(String FID) throws IOException {
077: //int pos = FID.indexOf(".");
078:
079: return wrappedMapper.getPKAttributes(FID);
080: }
081:
082: /**
083: * @see org.geotools.data.jdbc.fidmapper.FIDMapper#returnFIDColumnsAsAttributes()
084: */
085: public boolean returnFIDColumnsAsAttributes() {
086: return wrappedMapper.returnFIDColumnsAsAttributes();
087: }
088:
089: /**
090: * @see org.geotools.data.jdbc.fidmapper.FIDMapper#getColumnCount()
091: */
092: public int getColumnCount() {
093: return wrappedMapper.getColumnCount();
094: }
095:
096: /**
097: * @see org.geotools.data.jdbc.fidmapper.FIDMapper#getColumnName(int)
098: */
099: public String getColumnName(int colIndex) {
100: return wrappedMapper.getColumnName(colIndex);
101: }
102:
103: /**
104: * @see org.geotools.data.jdbc.fidmapper.FIDMapper#getColumnType(int)
105: */
106: public int getColumnType(int colIndex) {
107: return wrappedMapper.getColumnType(colIndex);
108: }
109:
110: /**
111: * @see org.geotools.data.jdbc.fidmapper.FIDMapper#getColumnSize(int)
112: */
113: public int getColumnSize(int colIndex) {
114: return wrappedMapper.getColumnSize(colIndex);
115: }
116:
117: /**
118: * @see org.geotools.data.jdbc.fidmapper.FIDMapper#getColumnDecimalDigits(int)
119: */
120: public int getColumnDecimalDigits(int colIndex) {
121: return wrappedMapper.getColumnSize(colIndex);
122: }
123:
124: /**
125: * @see org.geotools.data.jdbc.fidmapper.FIDMapper#isAutoIncrement(int)
126: */
127: public boolean isAutoIncrement(int colIndex) {
128: return wrappedMapper.isAutoIncrement(colIndex);
129: }
130:
131: /**
132: * @see java.lang.Object#equals(java.lang.Object)
133: */
134: public boolean equals(Object object) {
135: if (!(object instanceof TypedFIDMapper)) {
136: return false;
137: }
138:
139: HsqlFIDMapper other = (HsqlFIDMapper) object;
140:
141: return other.wrappedMapper.equals(wrappedMapper)
142: && (other.featureTypeName == featureTypeName);
143: }
144:
145: /**
146: * @see org.geotools.data.jdbc.fidmapper.FIDMapper#createID(java.sql.Connection,
147: * org.geotools.feature.Feature, Statement)
148: */
149: public String createID(Connection conn, Feature feature,
150: Statement statement) throws IOException {
151: return featureTypeName + "."
152: + wrappedMapper.createID(conn, feature, statement);
153: }
154:
155: /**
156: * @see org.geotools.data.jdbc.fidmapper.FIDMapper#initSupportStructures()
157: */
158: public void initSupportStructures() {
159: wrappedMapper.initSupportStructures();
160: }
161:
162: /**
163: * Returns the base mapper wrapped by this TypedFIDMapper
164: *
165: */
166: public FIDMapper getWrappedMapper() {
167: return wrappedMapper;
168: }
169: }
|