]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcherBase.java
Removed contact application support prints
[simantics/platform.git] / bundles / org.simantics.db.indexing / src / org / simantics / db / indexing / IndexedRelationsSearcherBase.java
index 136a7bcf643d689f1d5f7e6cc04206ea5aee001f..82f4abdd905d570600a9a10871e4d7f7e43cb414 100644 (file)
@@ -64,6 +64,7 @@ import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.indexing.internal.IndexingJob;
 import org.simantics.db.layer0.adapter.GenericRelation;
+import org.simantics.db.layer0.genericrelation.IndexException;
 import org.simantics.db.request.Read;
 import org.simantics.db.service.CollectionSupport;
 import org.simantics.db.service.SerialisationSupport;
@@ -115,14 +116,18 @@ abstract public class IndexedRelationsSearcherBase {
        this.state = State.READY;
     }
     
+    public State state() {
+       return state;
+    }
+    
     protected boolean checkState(State state) {
        return this.state == state;
     }
     
-    protected void assertState(State state) throws AssertionError {
-
-       if(this.state != state) throw new AssertionError("Illegal state, expected " + state.name() + " but was in " + this.state.name());
-       
+    protected void assertState(State state) throws IndexException {
+        State s = this.state;
+        if (s != state)
+            throw new IndexException("Illegal index searcher state, expected " + state.name() + " but state was " + s.name());
     }
     
     public void changeState(IProgressMonitor monitor, Session session, State state) {
@@ -624,7 +629,7 @@ abstract public class IndexedRelationsSearcherBase {
                     mon.subTask("Erasing previous index");
                     if (getLogger().isDebugEnabled())
                         getLogger().debug("Erasing previous index {}", indexPath.toAbsolutePath());
-                    FileUtils.delete(indexPath);
+                    FileUtils.emptyDirectory(indexPath);
                 }
             }
     
@@ -633,7 +638,7 @@ abstract public class IndexedRelationsSearcherBase {
     
             try {
                 mon.subTask("Start index write");
-                createDirectory(indexPath);
+                Files.createDirectories(indexPath);
     
                 directory.set(FSDirectory.open(indexPath.toFile()));
                 IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_4_9, Queries.getAnalyzer()).setOpenMode(OpenMode.CREATE);
@@ -992,20 +997,14 @@ abstract public class IndexedRelationsSearcherBase {
         return path;
     }
 
-    private static void createDirectory(Path path) throws IOException {
-        if (Files.exists(path) && !Files.isDirectory(path))
-            throw new IOException("Could not create index directory " + path + ", a file by that name already exists");
-        Files.createDirectories(path);
-    }
-
     Path getIndexPath() {
         return indexPath;
     }
 
     boolean isIndexAvailable() {
-        return (Files.exists(indexPath) && Files.isDirectory(indexPath));
+        return Files.isDirectory(indexPath);
     }
-    
+
     abstract Throwable bestEffortClear(IProgressMonitor monitor, Session session);
 
     /*