/* (non-Javadoc)
   * @see org.geotools.data.DataStore#getFeatureWriterAppend(java.lang.String, org.geotools.data.Transaction)
   *
   */
  public FeatureWriter<SimpleFeatureType, SimpleFeature> getFeatureWriterAppend(
      String typeName, Transaction transaction) throws IOException {
    FeatureWriter<SimpleFeatureType, SimpleFeature> writer =
        getFeatureWriter(typeName, transaction);

    while (writer.hasNext()) {
      writer.next(); // Hmmm this would be a use for skip() then?
    }

    return writer;
  }
  /**
   * Provides a wrapper on the provided writer that checks locks.
   *
   * @param writer FeatureWriter requiring access control
   * @param transaction Transaction being used
   * @return FeatureWriter with lock checking
   */
  public FeatureWriter<SimpleFeatureType, SimpleFeature> checkedWriter(
      final FeatureWriter<SimpleFeatureType, SimpleFeature> writer, final Transaction transaction) {
    SimpleFeatureType featureType = writer.getFeatureType();
    final String typeName = featureType.getTypeName();

    return new DelegatingFeatureWriter<SimpleFeatureType, SimpleFeature>() {
      SimpleFeature live = null;

      public FeatureWriter<SimpleFeatureType, SimpleFeature> getDelegate() {
        return writer;
      }

      public SimpleFeatureType getFeatureType() {
        return writer.getFeatureType();
      }

      public SimpleFeature next() throws IOException {
        live = writer.next();

        return live;
      }

      public void remove() throws IOException {
        if (live != null) {
          assertAccess(typeName, live.getID(), transaction);
        }

        writer.remove();
        live = null;
      }

      public void write() throws IOException {
        if (live != null) {
          assertAccess(typeName, live.getID(), transaction);
        }

        writer.write();
        live = null;
      }

      public boolean hasNext() throws IOException {
        live = null;

        return writer.hasNext();
      }

      public void close() throws IOException {
        live = null;
        if (writer != null) writer.close();
      }
    };
  }