polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [3/7] zest-java git commit: jdbm-entitystore: remove last usage of core/io
Date Fri, 09 Dec 2016 16:28:34 GMT
jdbm-entitystore: remove last usage of core/io


Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/888e4292
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/888e4292
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/888e4292

Branch: refs/heads/develop
Commit: 888e429210844c4245db0c72e952762ce415e6a7
Parents: ee1d1ab
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Fri Dec 9 09:46:28 2016 +0100
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Fri Dec 9 09:46:28 2016 +0100

----------------------------------------------------------------------
 .../entitystore/jdbm/JdbmEntityStoreMixin.java  | 39 +++++++++++++++++++-
 1 file changed, 37 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/888e4292/extensions/entitystore-jdbm/src/main/java/org/apache/zest/entitystore/jdbm/JdbmEntityStoreMixin.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jdbm/src/main/java/org/apache/zest/entitystore/jdbm/JdbmEntityStoreMixin.java
b/extensions/entitystore-jdbm/src/main/java/org/apache/zest/entitystore/jdbm/JdbmEntityStoreMixin.java
index 19c2b7d..5d3d069 100644
--- a/extensions/entitystore-jdbm/src/main/java/org/apache/zest/entitystore/jdbm/JdbmEntityStoreMixin.java
+++ b/extensions/entitystore-jdbm/src/main/java/org/apache/zest/entitystore/jdbm/JdbmEntityStoreMixin.java
@@ -26,6 +26,7 @@ import java.io.StringReader;
 import java.io.StringWriter;
 import java.io.UncheckedIOException;
 import java.io.Writer;
+import java.nio.file.Files;
 import java.util.Properties;
 import java.util.Spliterator;
 import java.util.Spliterators;
@@ -54,7 +55,6 @@ import org.apache.zest.api.injection.scope.Service;
 import org.apache.zest.api.injection.scope.This;
 import org.apache.zest.api.injection.scope.Uses;
 import org.apache.zest.api.service.ServiceDescriptor;
-import org.apache.zest.io.Files;
 import org.apache.zest.library.fileconfig.FileConfiguration;
 import org.apache.zest.library.locking.ReadLock;
 import org.apache.zest.library.locking.WriteLock;
@@ -82,6 +82,7 @@ public class JdbmEntityStoreMixin
     private RecordManager recordManager;
     private BTree index;
     private Serializer serializer;
+    private File tempDirectory;
 
     @This
     ReadWriteLock lock;
@@ -278,7 +279,7 @@ public class JdbmEntityStoreMixin
         File lgFile = new File( getDatabaseName() + ".lg" );
 
         // Create temporary store
-        File tempDatabase = Files.createTemporayFileOf( dbFile );
+        File tempDatabase = createTemporaryDatabase();
         final RecordManager recordManager;
         final BTree index;
         try
@@ -401,6 +402,40 @@ public class JdbmEntityStoreMixin
         return name;
     }
 
+    private File createTemporaryDatabase()
+    {
+        try
+        {
+            File tempDatabase = Files.createTempFile( getTemporaryDirectory().toPath(),
+                                                      descriptor.identity().toString(),
+                                                      "write" ).toFile();
+            tempDatabase.deleteOnExit();
+            return tempDatabase;
+        }
+        catch( IOException ex )
+        {
+            throw new UncheckedIOException( ex );
+        }
+    }
+
+    private File getTemporaryDirectory() throws IOException
+    {
+        if( tempDirectory != null )
+        {
+            return tempDirectory;
+        }
+        String storeId = descriptor.identity().toString();
+        tempDirectory = fileConfiguration != null
+                        ? new File( fileConfiguration.temporaryDirectory(), storeId )
+                        : new File( new File( System.getProperty( "java.io.tmpdir" ) ),
+                                    storeId );
+        if( !tempDirectory.exists() )
+        {
+            java.nio.file.Files.createDirectories( tempDirectory.toPath() );
+        }
+        return tempDirectory;
+    }
+
     private Properties getProperties()
     {
         JdbmConfiguration config = this.config.get();


Mime
View raw message