/*
 * The MIT License
 *
 * Copyright (c) 2010 Fabrice Medio
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package net.rhapso.koa.storage;

import net.rhapso.koa.StorageFactory;
import net.rhapso.koa.storage.block.Cache;
import net.rhapso.koa.tree.StoreName;

import java.io.File;

public class FileStorageFactory extends StorageFactory {
    private File dataDir;

    public FileStorageFactory(File dataDir) {
        super();
        this.dataDir = dataDir;
    }

    protected Addressable createAddressable(StoreName storeName, Cache cache) {
        File file = new File(dataDir, storeName.getName());
        return new Addressable(new FileStorage(file), cache);
    }

    @Override
    public boolean physicallyExists(StoreName storeName) {
        return new File(dataDir, storeName.getName()).exists();
    }
}

@@ -1,11 +1,10 @@
 /*
-%0D
 %0A * The 
@@ -14,21 +14,19 @@
  License
-%0D
 %0A *
-%0D
 %0A * Copy
@@ -53,21 +53,19 @@
 ce Medio
-%0D
 %0A *
-%0D
 %0A * Perm
@@ -136,17 +136,16 @@
 g a copy
-%0D
 %0A * of t
@@ -217,17 +217,16 @@
  to deal
-%0D
 %0A * in t
@@ -297,17 +297,16 @@
 e rights
-%0D
 %0A * to u
@@ -374,17 +374,16 @@
 /or sell
-%0D
 %0A * copi
@@ -447,17 +447,16 @@
 tware is
-%0D
 %0A * furn
@@ -507,21 +507,19 @@
 ditions:
-%0D
 %0A *
-%0D
 %0A * The 
@@ -588,17 +588,16 @@
 luded in
-%0D
 %0A * all 
@@ -647,13 +647,11 @@
 are.
-%0D
 %0A *
-%0D
 %0A * 
@@ -724,17 +724,16 @@
 PRESS OR
-%0D
 %0A * IMPL
@@ -800,17 +800,16 @@
 ABILITY,
-%0D
 %0A * FITN
@@ -879,17 +879,16 @@
 HALL THE
-%0D
 %0A * AUTH
@@ -953,17 +953,16 @@
 OR OTHER
-%0D
 %0A * LIAB
@@ -1034,17 +1034,16 @@
 NG FROM,
-%0D
 %0A * OUT 
@@ -1111,17 +1111,16 @@
 LINGS IN
-%0D
 %0A * THE 
@@ -1132,16 +1132,13 @@
 ARE.
-%0D
 %0A */
-%0D%0A%0D
+%0A
 %0Apac
@@ -1165,19 +1165,17 @@
 storage;
-%0D%0A%0D
+%0A
 %0Aimport 
@@ -1204,17 +1204,16 @@
 Factory;
-%0D
 %0Aimport 
@@ -1247,17 +1247,16 @@
 k.Cache;
-%0D
 %0Aimport 
@@ -1285,19 +1285,17 @@
 oreName;
-%0D%0A%0D
+%0A
 %0Aimport 
@@ -1307,19 +1307,17 @@
 io.File;
-%0D%0A%0D
+%0A
 %0Apublic 
@@ -1365,17 +1365,16 @@
 actory %7B
-%0D
 %0A    pri
@@ -1391,19 +1391,17 @@
 dataDir;
-%0D%0A%0D
+%0A
 %0A    pub
@@ -1438,17 +1438,16 @@
 taDir) %7B
-%0D
 %0A       
@@ -1455,17 +1455,16 @@
 super();
-%0D
 %0A       
@@ -1487,26 +1487,23 @@
 dataDir;
-%0D
 %0A    %7D
-%0D%0A%0D
+%0A
 %0A    pro
@@ -1570,25 +1570,97 @@
 che cache) %7B
-%0D
+%0A        if (!dataDir.exists()) %7B%0A            dataDir.mkdirs();%0A        %7D
 %0A        Fil
@@ -1707,17 +1707,16 @@
 Name());
-%0D
 %0A       
@@ -1773,18 +1773,15 @@
 he);
-%0D
 %0A    %7D
-%0D%0A%0D
+%0A
 %0A   
@@ -1790,17 +1790,16 @@
 Override
-%0D
 %0A    pub
@@ -1849,17 +1849,16 @@
 eName) %7B
-%0D
 %0A       
@@ -1917,16 +1917,13 @@
 s();
-%0D
 %0A    %7D
-%0D
 %0A%7D
-%0D
 %0A

Create missing dirs