From 8c97e817eb7cb0ac39c06197e109c399c01f5a0c Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Fri, 7 Dec 2012 11:55:03 +0100 Subject: [PATCH] implement new blob store api --- .../java/sonia/scm/store/FileBasedStore.java | 196 ++++++++++++++++++ .../scm/store/FileBasedStoreFactory.java | 114 ++++++++++ .../main/java/sonia/scm/store/FileBlob.java | 113 ++++++++++ .../java/sonia/scm/store/FileBlobStore.java | 165 +++++++++++++++ .../sonia/scm/store/FileBlobStoreFactory.java | 102 +++++++++ .../java/sonia/scm/store/JAXBDataStore.java | 107 ++-------- .../sonia/scm/store/JAXBDataStoreFactory.java | 41 +--- 7 files changed, 710 insertions(+), 128 deletions(-) create mode 100644 scm-dao-xml/src/main/java/sonia/scm/store/FileBasedStore.java create mode 100644 scm-dao-xml/src/main/java/sonia/scm/store/FileBasedStoreFactory.java create mode 100644 scm-dao-xml/src/main/java/sonia/scm/store/FileBlob.java create mode 100644 scm-dao-xml/src/main/java/sonia/scm/store/FileBlobStore.java create mode 100644 scm-dao-xml/src/main/java/sonia/scm/store/FileBlobStoreFactory.java diff --git a/scm-dao-xml/src/main/java/sonia/scm/store/FileBasedStore.java b/scm-dao-xml/src/main/java/sonia/scm/store/FileBasedStore.java new file mode 100644 index 0000000000..940a065747 --- /dev/null +++ b/scm-dao-xml/src/main/java/sonia/scm/store/FileBasedStore.java @@ -0,0 +1,196 @@ +/** + * 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 + */ +public abstract class FileBasedStore implements StoreBase +{ + + /** + * 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; +} diff --git a/scm-dao-xml/src/main/java/sonia/scm/store/FileBasedStoreFactory.java b/scm-dao-xml/src/main/java/sonia/scm/store/FileBasedStoreFactory.java new file mode 100644 index 0000000000..e70482b108 --- /dev/null +++ b/scm-dao-xml/src/main/java/sonia/scm/store/FileBasedStoreFactory.java @@ -0,0 +1,114 @@ +/** + * 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; +} diff --git a/scm-dao-xml/src/main/java/sonia/scm/store/FileBlob.java b/scm-dao-xml/src/main/java/sonia/scm/store/FileBlob.java new file mode 100644 index 0000000000..98ac600180 --- /dev/null +++ b/scm-dao-xml/src/main/java/sonia/scm/store/FileBlob.java @@ -0,0 +1,113 @@ +/** + * 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; +} diff --git a/scm-dao-xml/src/main/java/sonia/scm/store/FileBlobStore.java b/scm-dao-xml/src/main/java/sonia/scm/store/FileBlobStore.java new file mode 100644 index 0000000000..142c2f4758 --- /dev/null +++ b/scm-dao-xml/src/main/java/sonia/scm/store/FileBlobStore.java @@ -0,0 +1,165 @@ +/** + * 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 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 getAll() + { + logger.trace("get all items from data store"); + + Builder 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; +} diff --git a/scm-dao-xml/src/main/java/sonia/scm/store/FileBlobStoreFactory.java b/scm-dao-xml/src/main/java/sonia/scm/store/FileBlobStoreFactory.java new file mode 100644 index 0000000000..661b70eef9 --- /dev/null +++ b/scm-dao-xml/src/main/java/sonia/scm/store/FileBlobStoreFactory.java @@ -0,0 +1,102 @@ +/** + * 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; +} diff --git a/scm-dao-xml/src/main/java/sonia/scm/store/JAXBDataStore.java b/scm-dao-xml/src/main/java/sonia/scm/store/JAXBDataStore.java index 8327409a51..21c32f5e84 100644 --- a/scm-dao-xml/src/main/java/sonia/scm/store/JAXBDataStore.java +++ b/scm-dao-xml/src/main/java/sonia/scm/store/JAXBDataStore.java @@ -33,11 +33,8 @@ package sonia.scm.store; //~--- 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; @@ -60,7 +57,7 @@ import javax.xml.bind.Marshaller; * * @param */ -public class JAXBDataStore extends AbstractDataStore +public class JAXBDataStore extends FileBasedStore implements DataStore { /** Field description */ @@ -84,7 +81,8 @@ public class JAXBDataStore extends AbstractDataStore */ public JAXBDataStore(KeyGenerator keyGenerator, Class type, File directory) { - super(keyGenerator); + super(directory, SUFFIX); + this.keyGenerator = keyGenerator; try { @@ -99,21 +97,6 @@ public class JAXBDataStore extends AbstractDataStore //~--- methods -------------------------------------------------------------- - /** - * Method description - * - */ - @Override - public void clear() - { - logger.debug("clear store"); - - for (File file : directory.listFiles()) - { - remove(file); - } - } - /** * Method description * @@ -149,36 +132,22 @@ public class JAXBDataStore extends AbstractDataStore * 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 * @@ -210,13 +179,15 @@ public class JAXBDataStore extends AbstractDataStore * * @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); @@ -231,61 +202,11 @@ public class JAXBDataStore extends AbstractDataStore 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; } diff --git a/scm-dao-xml/src/main/java/sonia/scm/store/JAXBDataStoreFactory.java b/scm-dao-xml/src/main/java/sonia/scm/store/JAXBDataStoreFactory.java index d84434616c..5fd3b9675d 100644 --- a/scm-dao-xml/src/main/java/sonia/scm/store/JAXBDataStoreFactory.java +++ b/scm-dao-xml/src/main/java/sonia/scm/store/JAXBDataStoreFactory.java @@ -41,20 +41,19 @@ import org.slf4j.LoggerFactory; 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 */ @@ -74,7 +73,7 @@ public class JAXBDataStoreFactory implements DataStoreFactory public JAXBDataStoreFactory(SCMContextProvider context, KeyGenerator keyGenerator) { - this.context = context; + super(context, DIRECTORY_NAME); this.keyGenerator = keyGenerator; } @@ -98,36 +97,8 @@ public class JAXBDataStoreFactory implements DataStoreFactory return new JAXBDataStore(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; }