]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsImpl.java
Add logging to indexing & replace File-API with NIO Path-API
[simantics/platform.git] / bundles / org.simantics.db.indexing / src / org / simantics / db / indexing / IndexedRelationsImpl.java
index bc9247e37818302ce53b3bdbfd5b35f9c406d21d..1d027a8252c6c4894f9a3b87cc94ceb033f4a536 100644 (file)
@@ -13,6 +13,7 @@ package org.simantics.db.indexing;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Path;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -37,6 +38,8 @@ import org.simantics.db.layer0.genericrelation.IndexedRelations;
 import org.simantics.db.service.QueryControl;
 import org.simantics.db.service.SerialisationSupport;
 import org.simantics.utils.datastructures.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @author Tuukka Lehtonen
@@ -44,6 +47,8 @@ import org.simantics.utils.datastructures.Pair;
  */
 public class IndexedRelationsImpl implements IndexedRelations {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(IndexedRelationsImpl.class);
+    
     Map<Object, RWLock> indexLocks = new WeakHashMap<Object, RWLock>();
 
     static class LockHandle {
@@ -370,7 +375,7 @@ public class IndexedRelationsImpl implements IndexedRelations {
 
     @Override
     public void insert(IProgressMonitor monitor, RequestProcessor processor, GenericRelation relation,  
-            Resource relationResource, Resource input, Collection<Object[]> documents) {
+            Resource relationResource, Resource input, Collection<Object[]> documents) throws IndexException {
 
 //        System.out.println("Inserting to index: " + input + " " + documents);
 
@@ -413,7 +418,7 @@ public class IndexedRelationsImpl implements IndexedRelations {
 
     @Override
     public void remove(IProgressMonitor monitor, RequestProcessor processor, GenericRelation relation,
-            Resource relationResource, Resource input, String key, Collection<Object> keyValues) {
+            Resource relationResource, Resource input, String key, Collection<Object> keyValues) throws IndexException {
 
         if (relation == null)
             throw new IllegalArgumentException("null relation");
@@ -473,7 +478,7 @@ public class IndexedRelationsImpl implements IndexedRelations {
     
     @Override
     public boolean replace(IProgressMonitor monitor, RequestProcessor processor, GenericRelation relation,
-            Resource relationResource, Resource input, String key, Collection<Object> keyValues, Collection<Object[]> documents) {
+            Resource relationResource, Resource input, String key, Collection<Object> keyValues, Collection<Object[]> documents) throws IndexException {
 
         if (relation == null)
             throw new IllegalArgumentException("null relation");
@@ -521,16 +526,15 @@ public class IndexedRelationsImpl implements IndexedRelations {
         IndexedRelationsSearcherBase searcher = makeSearcher(processor, relationResource, input);
 
         LockHandle handle = lock(processor, Pair.make(relationResource, input), true);
-
+        Path path = DatabaseIndexing.getIndexLocation(processor.getSession(), relationResource, input);
         try {
             searcher.changeState(monitor, processor.getSession(), State.NONE);
             if (!searcher.checkState(State.NONE))
                 throw new IndexException("Could not close index for input " + input + " before removing it");
 
-            File path = DatabaseIndexing.getIndexLocation(processor.getSession(), relationResource, input);
             DatabaseIndexing.deleteIndex(path);
-
         } catch (IOException e) {
+            LOGGER.error("Could not delete {}", path.toAbsolutePath(), e);
             throw new IndexException(e);
         } finally {
             handle.unlock();