Select to view content in your preferred language

SR locak on gdb is not releasing in SOE

2468
0
11-09-2015 08:04 PM
HaiderAli
Deactivated User

My problem is sr lock is not releasing on gdb , also please see that code can be improved?

Below is my code  

    public String exportGDB(String whereClause,IServerObjectHelper serverObjectHelper)  // returns the path of GDB

    {

    String tempPath = System.getProperty("java.io.tmpdir");

    SOEHelper soeHelper = new SOEHelper();

    String fileName = System.currentTimeMillis() + ".gdb";

   

    try

    {

    // Create a FileGDB workspace factory

    IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();

  

  

   

    // Create a new File geodatabase

    IWorkspaceName workspaceName = workspaceFactory.create(tempPath,fileName , null, 0);

   

    IName wsName = (IName) workspaceName;

  

    IWorkspace workspace = new IWorkspaceProxy(wsName.open());

   

    IFeatureWorkspace featureWorkspace = new IFeatureWorkspaceProxy(workspace);

   

    IMapLayerInfos layerInfos = soeHelper.getLayerInfo(serverObjectHelper);

  

    IQueryFilter qf = new QueryFilter();

    qf.setWhereClause(whereClause);

  

  

  

    IFeatureClass fc = null;

    IMapLayerInfo layerInfo = null;

    IFeatureClass gdbFeatureClass = null;

    IFeature newFeature = null;

    IFeature feature = null;

    IFeatureCursor  featureCursor = null;

   

   

    for (int i=0; i < layerInfos.getCount(); i++)

    {

    layerInfo = layerInfos.getElement(i);

   

    fc = soeHelper.getFeatureClass(layerInfo.getID(), serverObjectHelper);

    //

    // IWorkspaceName fcwsName = (IWorkspaceName)fc.getFeatureDataset().getWorkspace();

    //

    IFeatureClassDescription fcDesc = new FeatureClassDescription();

    IObjectClassDescription ocDesc = (IObjectClassDescription) fcDesc;

    //

    //

    gdbFeatureClass = new FeatureClass(featureWorkspace.createFeatureClass(layerInfo.getName(), layerInfo.getFields(),

    ocDesc.getInstanceCLSID(), ocDesc.getClassExtensionCLSID(), esriFeatureType.esriFTSimple, "SHAPE", ""));

    // IFeatureClassName sourceFeatureClassName = new FeatureClassName();

    //

    // IFeatureDataConverter2 featureDataConverter = new FeatureDataConverter();

    //

    // IEnumInvalidObject enumInvalidObject = featureDataConverter.convertFeatureClass((IDatasetName)fcwsName,

    // qf, null,(IFeatureDatasetName)workspaceName, sourceFeatureClassName,

    // soeHelper.getGeomRef(fc),

    // layerInfo.getFields(), "", 1000, 0);

    //

    //

    // // Check for errors.

    // IInvalidObjectInfo invalidObjectInfo = null;

    // enumInvalidObject.reset();

    // while ((invalidObjectInfo = enumInvalidObject.next()) != null){

    // // Handle the errors in a way appropriate to the application.

    // System.out.println("Errors occurred for the following feature: " +

    // invalidObjectInfo.getInvalidObjectID());

    // }

  

    featureCursor = fc.search(qf, true);

  

    feature =  featureCursor.nextFeature();

    

    while(feature != null)

    {

    newFeature = gdbFeatureClass.createFeature();

  

    for (int j = 0; j < featureCursor.getFields().getFieldCount(); j++)

    {

   

    if(featureCursor.getFields().getField(j).getType() ==  esriFieldType.esriFieldTypeOID)

    { // skip

    continue;

    }

  

    newFeature.setValue(newFeature.getFields().findField(featureCursor.getFields().getField(j).getName()), feature.getValue(j));

    }

  

    newFeature.store();

    feature =  featureCursor.nextFeature();

    Cleaner.release(newFeature);

    }

  

    Cleaner.release(gdbFeatureClass);

    Cleaner.release(featureCursor);

    }

  

    // Cleaner.releaseAllInCurrentThread();

  

    // Cleaner.release(gdbFeatureClass);

    // Cleaner.release(featureCursor);

    //

    soeHelper.releaseSilently(workspaceName);

    soeHelper.releaseSilently(wsName);

    soeHelper.releaseSilently(layerInfos);

  

    Cleaner.release(featureWorkspace);

    Cleaner.release(workspace);

    Cleaner.release(workspaceFactory);

  

    qf = null;

    workspace = null;

    featureWorkspace = null;

    workspaceFactory = null;

    fc = null;

    layerInfo = null;

    gdbFeatureClass = null;

    newFeature = null;

    feature = null;

    featureCursor = null;

  

    return fileName;

   

    } catch (Exception e) {

    e.printStackTrace();

    return null;

    }

   

   

    }

Tags (3)
0 Kudos
0 Replies