001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.vfny.geoserver.global;
006:
007: import org.geotools.data.DataSourceException;
008: import org.geotools.data.FeatureLock;
009: import org.geotools.data.FeatureLocking;
010: import org.geotools.data.Query;
011: import org.geotools.feature.Feature;
012: import org.geotools.feature.FeatureType;
013: import org.opengis.filter.Filter;
014: import org.opengis.referencing.crs.CoordinateReferenceSystem;
015: import java.io.IOException;
016:
017: /**
018: * GeoServer wrapper for backend Geotools2 DataStore.
019: *
020: * <p>
021: * Support FeatureSource decorator for FeatureTypeInfo that takes care of
022: * mapping the FeatureTypeInfo's FeatureSource with the schema and definition
023: * query configured for it.
024: * </p>
025: *
026: * <p>
027: * Because GeoServer requires that attributes always be returned in the same
028: * order we need a way to smoothly inforce this. Could we use this class to do
029: * so? It would need to support writing and locking though.
030: * </p>
031: *
032: * @author Gabriel Rold�n
033: * @version $Id: GeoServerFeatureLocking.java 8032 2007-12-17 21:08:28Z aaime $
034: */
035: public class GeoServerFeatureLocking extends GeoServerFeatureStore
036: implements FeatureLocking {
037: /**
038: * Creates a new DEFQueryFeatureLocking object.
039: *
040: * @param locking GeoTools2 FeatureSource
041: * @param schema DOCUMENT ME!
042: * @param definitionQuery DOCUMENT ME!
043: * @param declaredCRS
044: * @param srsHandling see {@link FeatureTypeInfo#FORCE} & co.
045: */
046: GeoServerFeatureLocking(FeatureLocking locking, FeatureType schema,
047: Filter definitionQuery,
048: CoordinateReferenceSystem declaredCRS, int srsHandling) {
049: super (locking, schema, definitionQuery, declaredCRS,
050: srsHandling);
051: }
052:
053: FeatureLocking locking() {
054: return (FeatureLocking) source;
055: }
056:
057: /**
058: * <p>
059: * Description ...
060: * </p>
061: *
062: * @param lock
063: *
064: * @throws UnsupportedOperationException DOCUMENT ME!
065: *
066: * @see org.vfny.geoserver.global.GeoServerFeatureStore#setFeatureLock(org.geotools.data.FeatureLock)
067: */
068: public void setFeatureLock(FeatureLock lock) {
069: if (source instanceof FeatureLocking) {
070: ((FeatureLocking) source).setFeatureLock(lock);
071: } else {
072: throw new UnsupportedOperationException(
073: "FeatureTypeConfig does not supports locking");
074: }
075: }
076:
077: /**
078: * DOCUMENT ME!
079: *
080: * @param query DOCUMENT ME!
081: *
082: * @return DOCUMENT ME!
083: *
084: * @throws IOException DOCUMENT ME!
085: * @throws DataSourceException DOCUMENT ME!
086: */
087: public int lockFeatures(Query query) throws IOException {
088: if (source instanceof FeatureLocking) {
089: return ((FeatureLocking) source).lockFeatures(query);
090: } else {
091: throw new DataSourceException(
092: "FeatureTypeConfig does not supports locking");
093: }
094: }
095:
096: // /**
097: // * A custom hack for PostgisFeatureLocking?
098: // *
099: // * @param feature DOCUMENT ME!
100: // *
101: // * @return DOCUMENT ME!
102: // *
103: // * @throws IOException DOCUMENT ME!
104: // */
105: // public int lockFeature(Feature feature) throws IOException {
106: // if (source instanceof PostgisFeatureLocking) {
107: // return ((PostgisFeatureLocking) source).lockFeature(feature);
108: // }
109: //
110: // throw new IOException("FeatureTypeConfig does not support single FeatureLock");
111: // }
112:
113: /**
114: * DOCUMENT ME!
115: *
116: * @param filter DOCUMENT ME!
117: *
118: * @return DOCUMENT ME!
119: *
120: * @throws IOException DOCUMENT ME!
121: */
122: public int lockFeatures(Filter filter) throws IOException {
123: filter = makeDefinitionFilter(filter);
124:
125: return locking().lockFeatures(filter);
126: }
127:
128: /**
129: * DOCUMENT ME!
130: *
131: * @return DOCUMENT ME!
132: *
133: * @throws IOException DOCUMENT ME!
134: */
135: public int lockFeatures() throws IOException {
136: return locking().lockFeatures();
137: }
138:
139: /**
140: * DOCUMENT ME!
141: *
142: * @throws IOException DOCUMENT ME!
143: */
144: public void unLockFeatures() throws IOException {
145: locking().lockFeatures();
146: }
147:
148: /**
149: * DOCUMENT ME!
150: *
151: * @param filter DOCUMENT ME!
152: *
153: * @throws IOException DOCUMENT ME!
154: */
155: public void unLockFeatures(Filter filter) throws IOException {
156: filter = makeDefinitionFilter(filter);
157:
158: locking().unLockFeatures(filter);
159: }
160:
161: public void unLockFeatures(Query query) throws IOException {
162: query = makeDefinitionQuery(query, schema);
163:
164: locking().lockFeatures(query);
165: }
166: }
|