Commits

Sebastian Sdorra committed 5d8c4ba

implement new blob store api

Comments (0)

Files changed (7)

scm-dao-xml/src/main/java/sonia/scm/store/FileBasedStore.java

+/**
+ * Copyright (c) 2010, Sebastian Sdorra All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. 2. Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. 3. Neither the name of SCM-Manager;
+ * nor the names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://bitbucket.org/sdorra/scm-manager
+ *
+ */
+
+
+
+package sonia.scm.store;
+
+//~--- non-JDK imports --------------------------------------------------------
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+//~--- JDK imports ------------------------------------------------------------
+
+import java.io.File;
+
+/**
+ *
+ * @author Sebastian Sdorra
+ *
+ * @param <T>
+ */
+public abstract class FileBasedStore<T> implements StoreBase<T>
+{
+
+  /**
+   * the logger for FileBasedStore
+   */
+  private static final Logger logger =
+    LoggerFactory.getLogger(FileBasedStore.class);
+
+  //~--- constructors ---------------------------------------------------------
+
+  /**
+   * Constructs ...
+   *
+   *
+   * @param directory
+   * @param suffix
+   */
+  public FileBasedStore(File directory, String suffix)
+  {
+    this.directory = directory;
+    this.suffix = suffix;
+  }
+
+  //~--- methods --------------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @param file
+   *
+   * @return
+   */
+  protected abstract T read(File file);
+
+  /**
+   * Method description
+   *
+   */
+  @Override
+  public void clear()
+  {
+    logger.debug("clear store");
+
+    for (File file : directory.listFiles())
+    {
+      remove(file);
+    }
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @param id
+   */
+  @Override
+  public void remove(String id)
+  {
+    File file = getFile(id);
+
+    remove(file);
+  }
+
+  //~--- get methods ----------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @param id
+   *
+   * @return
+   */
+  @Override
+  public T get(String id)
+  {
+    logger.trace("try to retrieve item with id {}", id);
+
+    File file = getFile(id);
+
+    return read(file);
+  }
+
+  //~--- methods --------------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @param file
+   */
+  protected void remove(File file)
+  {
+    if (file.exists() &&!file.delete())
+    {
+      logger.debug("delete store entry {}", file);
+
+      throw new StoreException(
+        "could not delete store entry ".concat(file.getPath()));
+    }
+  }
+
+  //~--- get methods ----------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @param id
+   *
+   * @return
+   */
+  protected File getFile(String id)
+  {
+    Preconditions.checkArgument(!Strings.isNullOrEmpty(id),
+      "id argument is required");
+
+    return new File(directory, id.concat(suffix));
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @param file
+   *
+   * @return
+   */
+  protected String getId(File file)
+  {
+    String name = file.getName();
+
+    return name.substring(0, name.length() - suffix.length());
+  }
+
+  //~--- fields ---------------------------------------------------------------
+
+  /** Field description */
+  protected File directory;
+
+  /** Field description */
+  private String suffix;
+}

scm-dao-xml/src/main/java/sonia/scm/store/FileBasedStoreFactory.java

+/**
+ * Copyright (c) 2010, Sebastian Sdorra All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. 2. Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. 3. Neither the name of SCM-Manager;
+ * nor the names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://bitbucket.org/sdorra/scm-manager
+ *
+ */
+
+
+
+package sonia.scm.store;
+
+//~--- non-JDK imports --------------------------------------------------------
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import sonia.scm.SCMContextProvider;
+import sonia.scm.util.IOUtil;
+
+//~--- JDK imports ------------------------------------------------------------
+
+import java.io.File;
+
+/**
+ *
+ * @author Sebastian Sdorra
+ */
+public class FileBasedStoreFactory
+{
+
+  /** Field description */
+  private static final String BASE_DIRECTORY = "var";
+
+  /**
+   * the logger for FileBasedStoreFactory
+   */
+  private static final Logger logger =
+    LoggerFactory.getLogger(FileBasedStoreFactory.class);
+
+  //~--- constructors ---------------------------------------------------------
+
+  /**
+   * Constructs ...
+   *
+   *
+   * @param context
+   * @param dataDirectoryName
+   */
+  public FileBasedStoreFactory(SCMContextProvider context,
+    String dataDirectoryName)
+  {
+    this.context = context;
+    this.dataDirectoryName = dataDirectoryName;
+  }
+
+  //~--- get methods ----------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @param name
+   *
+   * @return
+   */
+  protected File getDirectory(String name)
+  {
+    if (dataDirectory == null)
+    {
+      dataDirectory = new File(context.getBaseDirectory(),
+        BASE_DIRECTORY.concat(File.separator).concat(dataDirectoryName));
+      logger.debug("create data directory {}", dataDirectory);
+    }
+
+    File storeDirectory = new File(dataDirectory, name);
+
+    IOUtil.mkdirs(storeDirectory);
+
+    return storeDirectory;
+  }
+
+  //~--- fields ---------------------------------------------------------------
+
+  /** Field description */
+  private SCMContextProvider context;
+
+  /** Field description */
+  private File dataDirectory;
+
+  /** Field description */
+  private String dataDirectoryName;
+}

scm-dao-xml/src/main/java/sonia/scm/store/FileBlob.java

+/**
+ * Copyright (c) 2010, Sebastian Sdorra All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. 2. Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. 3. Neither the name of SCM-Manager;
+ * nor the names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://bitbucket.org/sdorra/scm-manager
+ *
+ */
+
+
+
+package sonia.scm.store;
+
+//~--- JDK imports ------------------------------------------------------------
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ *
+ * @author Sebastian Sdorra
+ */
+public class FileBlob implements Blob
+{
+
+  /**
+   * Constructs ...
+   *
+   *
+   * @param id
+   * @param file
+   */
+  public FileBlob(String id, File file)
+  {
+    this.id = id;
+    this.file = file;
+  }
+
+  //~--- get methods ----------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @return
+   */
+  @Override
+  public String getId()
+  {
+    return id;
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @return
+   *
+   * @throws FileNotFoundException
+   */
+  @Override
+  public InputStream getInputStream() throws FileNotFoundException
+  {
+    return new FileInputStream(file);
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @return
+   *
+   * @throws IOException
+   */
+  @Override
+  public OutputStream getOutputStream() throws IOException
+  {
+    return new FileOutputStream(file);
+  }
+
+  //~--- fields ---------------------------------------------------------------
+
+  /** Field description */
+  private File file;
+
+  /** Field description */
+  private String id;
+}

scm-dao-xml/src/main/java/sonia/scm/store/FileBlobStore.java

+/**
+ * Copyright (c) 2010, Sebastian Sdorra All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. 2. Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. 3. Neither the name of SCM-Manager;
+ * nor the names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://bitbucket.org/sdorra/scm-manager
+ *
+ */
+
+
+
+package sonia.scm.store;
+
+//~--- non-JDK imports --------------------------------------------------------
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import sonia.scm.security.KeyGenerator;
+
+//~--- JDK imports ------------------------------------------------------------
+
+import java.io.File;
+
+import java.util.List;
+
+/**
+ *
+ * @author Sebastian Sdorra
+ */
+public class FileBlobStore extends FileBasedStore<Blob> implements BlobStore
+{
+
+  /** Field description */
+  private static final String SUFFIX = ".blob";
+
+  /**
+   * the logger for FileBlobStore
+   */
+  private static final Logger logger =
+    LoggerFactory.getLogger(FileBlobStore.class);
+
+  //~--- constructors ---------------------------------------------------------
+
+  /**
+   * Constructs ...
+   *
+   *
+   * @param keyGenerator
+   * @param directory
+   */
+  public FileBlobStore(KeyGenerator keyGenerator, File directory)
+  {
+    super(directory, SUFFIX);
+  }
+
+  //~--- methods --------------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @return
+   */
+  @Override
+  public Blob create()
+  {
+    return create(keyGenerator.createKey());
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @param id
+   *
+   * @return
+   */
+  @Override
+  public Blob create(String id)
+  {
+    return new FileBlob(id, getFile(id));
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @param blob
+   */
+  @Override
+  public void remove(Blob blob)
+  {
+    remove(blob.getId());
+  }
+
+  //~--- get methods ----------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @return
+   */
+  @Override
+  public List<Blob> getAll()
+  {
+    logger.trace("get all items from data store");
+
+    Builder<Blob> builder = ImmutableList.builder();
+
+    for (File file : directory.listFiles())
+    {
+      builder.add(read(file));
+    }
+
+    return builder.build();
+  }
+
+  //~--- methods --------------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @param file
+   *
+   * @return
+   */
+  @Override
+  protected FileBlob read(File file)
+  {
+    String id = getId(file);
+
+    return new FileBlob(id, file);
+  }
+
+  //~--- fields ---------------------------------------------------------------
+
+  /** Field description */
+  private KeyGenerator keyGenerator;
+}

scm-dao-xml/src/main/java/sonia/scm/store/FileBlobStoreFactory.java

+/**
+ * Copyright (c) 2010, Sebastian Sdorra All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. 2. Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. 3. Neither the name of SCM-Manager;
+ * nor the names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://bitbucket.org/sdorra/scm-manager
+ *
+ */
+
+
+
+package sonia.scm.store;
+
+//~--- non-JDK imports --------------------------------------------------------
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import sonia.scm.SCMContextProvider;
+import sonia.scm.security.KeyGenerator;
+
+/**
+ *
+ * @author Sebastian Sdorra
+ */
+@Singleton
+public class FileBlobStoreFactory extends FileBasedStoreFactory
+  implements BlobStoreFactory
+{
+
+  /** Field description */
+  private static final String DIRECTORY_NAME = "blob";
+
+  /**
+   * the logger for FileBlobStoreFactory
+   */
+  private static final Logger logger =
+    LoggerFactory.getLogger(FileBlobStoreFactory.class);
+
+  //~--- constructors ---------------------------------------------------------
+
+  /**
+   * Constructs ...
+   *
+   *
+   * @param context
+   * @param keyGenerator
+   */
+  @Inject
+  public FileBlobStoreFactory(SCMContextProvider context,
+    KeyGenerator keyGenerator)
+  {
+    super(context, DIRECTORY_NAME);
+    this.keyGenerator = keyGenerator;
+  }
+
+  //~--- get methods ----------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @param name
+   *
+   * @return
+   */
+  @Override
+  public BlobStore getBlobStore(String name)
+  {
+    logger.debug("create new blob with name {}", name);
+
+    return new FileBlobStore(keyGenerator, getDirectory(name));
+  }
+
+  //~--- fields ---------------------------------------------------------------
+
+  /** Field description */
+  private KeyGenerator keyGenerator;
+}

scm-dao-xml/src/main/java/sonia/scm/store/JAXBDataStore.java

 
 //~--- non-JDK imports --------------------------------------------------------
 
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMap.Builder;
-import com.google.common.collect.Maps;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
  *
  * @param <T>
  */
-public class JAXBDataStore<T> extends AbstractDataStore<T>
+public class JAXBDataStore<T> extends FileBasedStore<T> implements DataStore<T>
 {
 
   /** Field description */
    */
   public JAXBDataStore(KeyGenerator keyGenerator, Class<T> type, File directory)
   {
-    super(keyGenerator);
+    super(directory, SUFFIX);
+    this.keyGenerator = keyGenerator;
 
     try
     {
   /**
    * Method description
    *
-   */
-  @Override
-  public void clear()
-  {
-    logger.debug("clear store");
-
-    for (File file : directory.listFiles())
-    {
-      remove(file);
-    }
-  }
-
-  /**
-   * Method description
-   *
    *
    * @param id
    * @param item
    * Method description
    *
    *
-   * @param id
-   */
-  @Override
-  public void remove(String id)
-  {
-    File file = getFile(id);
-
-    remove(file);
-  }
-
-  //~--- get methods ----------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @param id
+   * @param item
    *
    * @return
    */
   @Override
-  public T get(String id)
+  public String put(T item)
   {
-    logger.trace("try to retrieve item with id {}", id);
+    String key = keyGenerator.createKey();
 
-    File file = getFile(id);
+    put(key, item);
 
-    return read(file);
+    return key;
   }
 
+  //~--- get methods ----------------------------------------------------------
+
   /**
    * Method description
    *
    *
    * @return
    */
-  private T read(File file)
+  @Override
+  protected T read(File file)
   {
     T item = null;
 
     if (file.exists())
     {
       logger.trace("try to read {}", file);
+
       try
       {
         item = (T) context.createUnmarshaller().unmarshal(file);
     return item;
   }
 
-  /**
-   * Method description
-   *
-   *
-   * @param file
-   */
-  private void remove(File file)
-  {
-    if (file.exists() &&!file.delete())
-    {
-      logger.debug("delete store entry {}", file);
-
-      throw new StoreException(
-        "could not delete store entry ".concat(file.getPath()));
-    }
-  }
-
-  //~--- get methods ----------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @param id
-   *
-   * @return
-   */
-  private File getFile(String id)
-  {
-    Preconditions.checkArgument(!Strings.isNullOrEmpty(id),
-      "id argument is required");
-
-    return new File(directory, id.concat(SUFFIX));
-  }
-
-  /**
-   * Method description
-   *
-   *
-   * @param file
-   *
-   * @return
-   */
-  private String getId(File file)
-  {
-    String name = file.getName();
-
-    return name.substring(0, name.length() - SUFFIX.length());
-  }
-
   //~--- fields ---------------------------------------------------------------
 
   /** Field description */
   private JAXBContext context;
 
   /** Field description */
-  private File directory;
+  private KeyGenerator keyGenerator;
 }

scm-dao-xml/src/main/java/sonia/scm/store/JAXBDataStoreFactory.java

 
 import sonia.scm.SCMContextProvider;
 import sonia.scm.security.KeyGenerator;
-import sonia.scm.util.IOUtil;
-
-//~--- JDK imports ------------------------------------------------------------
-
-import java.io.File;
 
 /**
  *
  * @author Sebastian Sdorra
  */
 @Singleton
-public class JAXBDataStoreFactory implements DataStoreFactory
+public class JAXBDataStoreFactory extends FileBasedStoreFactory
+  implements DataStoreFactory
 {
 
+  /** Field description */
+  private static final String DIRECTORY_NAME = "data";
+
   /**
    * the logger for JAXBDataStoreFactory
    */
   public JAXBDataStoreFactory(SCMContextProvider context,
     KeyGenerator keyGenerator)
   {
-    this.context = context;
+    super(context, DIRECTORY_NAME);
     this.keyGenerator = keyGenerator;
   }
 
     return new JAXBDataStore<T>(keyGenerator, type, getDirectory(name));
   }
 
-  /**
-   * Method description
-   *
-   *
-   * @param name
-   *
-   * @return
-   */
-  private File getDirectory(String name)
-  {
-    if (dataDirectory == null)
-    {
-      dataDirectory = new File(context.getBaseDirectory(), "var");
-    }
-
-    File storeDirectory = new File(dataDirectory, name);
-
-    IOUtil.mkdirs(storeDirectory);
-
-    return storeDirectory;
-  }
-
   //~--- fields ---------------------------------------------------------------
 
   /** Field description */
-  private SCMContextProvider context;
-
-  /** Field description */
-  private File dataDirectory;
-
-  /** Field description */
   private KeyGenerator keyGenerator;
 }