diff --git a/scm-core/src/main/java/sonia/scm/store/DataStore.java b/scm-core/src/main/java/sonia/scm/store/DataStore.java index 2b6e199407..d19ce05f66 100644 --- a/scm-core/src/main/java/sonia/scm/store/DataStore.java +++ b/scm-core/src/main/java/sonia/scm/store/DataStore.java @@ -31,6 +31,10 @@ package sonia.scm.store; +//~--- JDK imports ------------------------------------------------------------ + +import java.util.Map; + /** * * @author Sebastian Sdorra @@ -85,4 +89,12 @@ public interface DataStore * @return */ public T get(String id); + + /** + * Method description + * + * + * @return + */ + public Map getAll(); } 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 3d3e1ecff9..8327409a51 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 @@ -35,6 +35,9 @@ package sonia.scm.store; 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; @@ -45,6 +48,8 @@ import sonia.scm.security.KeyGenerator; import java.io.File; +import java.util.Map; + import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; @@ -169,27 +174,63 @@ public class JAXBDataStore extends AbstractDataStore { logger.trace("try to retrieve item with id {}", id); - T item = null; File file = getFile(id); + return read(file); + } + + /** + * Method description + * + * + * @return + */ + @Override + public Map getAll() + { + logger.trace("get all items from data store"); + + Builder builder = ImmutableMap.builder(); + + for (File file : directory.listFiles()) + { + builder.put(getId(file), read(file)); + } + + return builder.build(); + } + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param file + * + * @return + */ + private T read(File file) + { + T item = null; + if (file.exists()) { + logger.trace("try to read {}", file); try { item = (T) context.createUnmarshaller().unmarshal(file); } catch (JAXBException ex) { - throw new StoreException("could not read object with id ".concat(id), - ex); + throw new StoreException( + "could not read object ".concat(file.getPath()), ex); } } return item; } - //~--- methods -------------------------------------------------------------- - /** * Method description * @@ -225,6 +266,21 @@ public class JAXBDataStore extends AbstractDataStore 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 */