zborowskib

Unable to release shapefile lock when inserting data...

Discussion created by zborowskib on Sep 26, 2012
Hi Guys,

I'm writing a SOE for ArcGIS Server 10.1 and I cannot get this method to release a damn lock when updating a shapefile.  Can anyone have a look at this and see what I'm missing because I've tried everything?

inFeatureClass is a MapService layer in an SOE.

private String convertToShp(IFeatureClass inFeatureClass, String outputPath, String outputFilename, IQueryFilter filter) 
  throws Exception {
  ShapefileWorkspaceFactory outWorkspaceFactory = new ShapefileWorkspaceFactory();
  Workspace outWorkspace = null;
  IFeatureCursor inFeatureCursor = null;
  IFeature inFeature = null;
  FeatureClass outFeatureClass = null;
  
  try {
     
   //step 1:  create shapefile.
   String guid = createFlowpathShapefile(inFeatureClass, outputPath, outputFilename);
   
   //step 2:  open and add data.
   //get the workspace.
   outWorkspaceFactory = new ShapefileWorkspaceFactory();
   outWorkspace = new Workspace(outWorkspaceFactory.openFromFile(outputPath + File.separator + guid, 0));
  
   outFeatureClass = new FeatureClass(outWorkspace.openFeatureClass(outputFilename));
   
   //Start/open an edit session for creating output feature.
   outWorkspace.startEditing(true);
   outWorkspace.startEditOperation();
   
   //determine input feature class indeces.
   int stream_length_idx = inFeatureClass.findField(FlowpathConstants.NHN_ATT_STREAM_LENGTH);
   int dwn_seg_idx = inFeatureClass.findField(FlowpathConstants.NHN_ATT_DOWSNTREAM_SEGMENT_NUMBER);
   int elevation_idx = inFeatureClass.findField(FlowpathConstants.NHN_ATT_ELEVATION);
   int shape_len_idx = inFeatureClass.findField(FlowpathConstants.NHN_ATT_SHAPE_LENGTH);
 
   inFeatureCursor = inFeatureClass.search(filter, false);
   while ((inFeature = inFeatureCursor.nextFeature()) != null){
    
    //Create a new feature and add the polyline geometry to it.
    Feature outFeature = (Feature)outFeatureClass.createFeature();
    outFeature.setShapeByRef(inFeature.getShape());
    
    /*
     * Add in the attribute data and store in the shapefile.
     */
    double streamLength = new Double(inFeature.getValue(stream_length_idx).toString());
    outFeature.setValue(2, streamLength);
    
    int downstreamSegment = new Integer(inFeature.getValue(dwn_seg_idx).toString());
    outFeature.setValue(3, downstreamSegment);
    
    double elevation = new Double(inFeature.getValue(elevation_idx).toString());
    outFeature.setValue(4, elevation);
    
    double shapeLength = new Double(inFeature.getValue(shape_len_idx).toString());
    outFeature.setValue(5, shapeLength);
        
    outFeature.store();
    
   }
   
   //close the edit session.
   outWorkspace.stopEditOperation();
   outWorkspace.stopEditing(true);
   
   //release arcobjects.
   Cleaner.release(inFeatureCursor);
   Cleaner.release(outFeatureClass);
   return guid;
  } catch (Exception ex) {
   throw new Exception(ex);
  } finally {
   Cleaner.release(outFeatureClass);
   outFeatureClass = null;
  }
 }


[ATTACH=CONFIG]18004[/ATTACH]

Attachments

Outcomes