refactor store api

This commit is contained in:
Sebastian Sdorra
2016-12-11 21:31:05 +01:00
parent 837df4b87c
commit 5332ac2466
47 changed files with 323 additions and 802 deletions

View File

@@ -41,13 +41,13 @@ import org.slf4j.LoggerFactory;
import sonia.scm.NotSupportedFeatuerException;
import sonia.scm.SCMContextProvider;
import sonia.scm.event.ScmEventBus;
import sonia.scm.store.Store;
import sonia.scm.store.StoreFactory;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.io.IOException;
import sonia.scm.store.ConfigurationStore;
import sonia.scm.store.ConfigurationStoreFactory;
/**
@@ -72,7 +72,7 @@ public abstract class AbstractRepositoryHandler<C extends SimpleRepositoryConfig
*
* @param storeFactory
*/
protected AbstractRepositoryHandler(StoreFactory storeFactory)
protected AbstractRepositoryHandler(ConfigurationStoreFactory storeFactory)
{
this.store = storeFactory.getStore(getConfigClass(), getType().getName());
}
@@ -221,5 +221,5 @@ public abstract class AbstractRepositoryHandler<C extends SimpleRepositoryConfig
protected C config;
/** Field description */
protected Store<C> store;
protected ConfigurationStore<C> store;
}

View File

@@ -46,7 +46,6 @@ import sonia.scm.ConfigurationException;
import sonia.scm.io.CommandResult;
import sonia.scm.io.ExtendedCommand;
import sonia.scm.io.FileSystem;
import sonia.scm.store.StoreFactory;
import sonia.scm.util.IOUtil;
//~--- JDK imports ------------------------------------------------------------
@@ -55,6 +54,7 @@ import java.io.File;
import java.io.IOException;
import java.net.URL;
import sonia.scm.store.ConfigurationStoreFactory;
/**
*
@@ -89,7 +89,7 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
* @param storeFactory
* @param fileSystem
*/
public AbstractSimpleRepositoryHandler(StoreFactory storeFactory,
public AbstractSimpleRepositoryHandler(ConfigurationStoreFactory storeFactory,
FileSystem fileSystem)
{
super(storeFactory);

View File

@@ -33,18 +33,35 @@
package sonia.scm.store;
//~--- non-JDK imports --------------------------------------------------------
/**
* Base class for {@link Store}.
* Base class for {@link ConfigurationStore}.
*
* @author Sebastian Sdorra
* @since 1.16
*
* @param <T> type of store objects
*/
public abstract class AbstractStore<T> implements Store<T>
{
public abstract class AbstractStore<T> implements ConfigurationStore<T> {
/**
* stored object
*/
protected T storeObject;
@Override
public T get() {
if (storeObject == null) {
storeObject = readObject();
}
return storeObject;
}
@Override
public void set(T obejct) {
writeObject(obejct);
this.storeObject = obejct;
}
/**
* Read the stored object.
@@ -61,43 +78,4 @@ public abstract class AbstractStore<T> implements Store<T>
* @param object object to write
*/
protected abstract void writeObject(T object);
//~--- get methods ----------------------------------------------------------
/**
* {@inheritDoc}
*
*
* @return
*/
@Override
public T get()
{
if (storeObject == null)
{
storeObject = readObject();
}
return storeObject;
}
//~--- set methods ----------------------------------------------------------
/**
* {@inheritDoc}
*
*
* @param obejct
*/
@Override
public void set(T obejct)
{
writeObject(obejct);
this.storeObject = obejct;
}
//~--- fields ---------------------------------------------------------------
/** stored object */
protected T storeObject;
}

View File

@@ -44,7 +44,7 @@ import java.util.List;
*
* @apiviz.uses sonia.scm.store.Blob
*/
public interface BlobStore extends StoreBase<Blob>
public interface BlobStore extends MultiEntryStore<Blob>
{
/**

View File

@@ -42,8 +42,7 @@ package sonia.scm.store;
* @apiviz.landmark
* @apiviz.uses sonia.scm.store.BlobStore
*/
public interface BlobStoreFactory
{
public interface BlobStoreFactory {
/**
* Returns a {@link BlobStore} with the given name, if the {@link BlobStore}

View File

@@ -50,8 +50,7 @@ import java.util.Collection;
* @param <V> store value type
* @since 1.31
*/
public interface ConfigurationEntryStore<V> extends DataStore<V>
{
public interface ConfigurationEntryStore<V> extends DataStore<V> {
/**
* Return all values matching the given {@link Predicate}.

View File

@@ -34,16 +34,14 @@
package sonia.scm.store;
/**
* Store for configuration objects. <strong>Note:</strong> the default
* ConfigurationStore for configuration objects. <strong>Note:</strong> the default
* implementation use JAXB to marshall the configuration objects.
*
* TODO for 2.0 rename to ConfigurationStore
*
* @author Sebastian Sdorra
*
* @param <T> type of the configuration objects
*/
public interface Store<T>
public interface ConfigurationStore<T>
{
/**

View File

@@ -30,38 +30,30 @@
*/
package sonia.scm.store;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.Initable;
//~--- JDK imports ------------------------------------------------------------
import java.io.Closeable;
/**
* The StoreFactory can be used to create new or get existing
* {@link Store}s.
* The ConfigurationStoreFactory can be used to create new or get existing
* {@link ConfigurationStore} objects.
*
* @author Sebastian Sdorra
*
* @apiviz.landmark
* @apiviz.uses sonia.scm.store.Store
* @apiviz.uses sonia.scm.store.ConfigurationStore
*/
public interface StoreFactory extends Initable, Closeable
public interface ConfigurationStoreFactory
{
/**
* Get an existing {@link Store} or create a new one.
* Get an existing {@link ConfigurationStore} or create a new one.
*
*
* @param type type of the store objects
* @param name name of the store
* @param <T> type of the store objects
*
* @return {@link Store} of the given type and name
* @return {@link ConfigurationStore} of the given type and name
*/
public <T> Store<T> getStore(Class<T> type, String name);
public <T> ConfigurationStore<T> getStore(Class<T> type, String name);
}

View File

@@ -45,8 +45,7 @@ import java.util.Map;
*
* @param <T> type of store items
*/
public interface DataStore<T> extends StoreBase<T>
{
public interface DataStore<T> extends MultiEntryStore<T> {
/**
* Put a item with automatically generated id to the store.

View File

@@ -42,8 +42,7 @@ package sonia.scm.store;
* @apiviz.landmark
* @apiviz.uses sonia.scm.store.DataStore
*/
public interface DataStoreFactory
{
public interface DataStoreFactory {
/**
* Get an existing {@link DataStore} or create a new one.

View File

@@ -39,10 +39,8 @@ package sonia.scm.store;
* @author Sebastian Sdorra
* @since 1.23
*/
public class EntryAlreadyExistsStoreException extends StoreException
{
public class EntryAlreadyExistsStoreException extends StoreException {
/** Field description */
private static final long serialVersionUID = 7016781091599951287L;
//~--- constructors ---------------------------------------------------------
@@ -50,11 +48,9 @@ public class EntryAlreadyExistsStoreException extends StoreException
/**
* Constructs new EntryAllreadyExistsStoreException.
*
*
* @param message message for the exception
*/
public EntryAlreadyExistsStoreException(String message)
{
public EntryAlreadyExistsStoreException(String message) {
super(message);
}
}

View File

@@ -40,8 +40,7 @@ package sonia.scm.store;
*
* @param <T> Type of the stored objects
*/
public interface StoreBase<T>
{
public interface MultiEntryStore<T> {
/**
* Remove all items from the store.

View File

@@ -34,11 +34,11 @@
package sonia.scm.store;
/**
* The store exception can be used by a store implementation.
*
* @author Sebastian Sdorra
*/
public class StoreException extends RuntimeException
{
public class StoreException extends RuntimeException {
/** Field description */
private static final long serialVersionUID = 6974469896007155294L;
@@ -46,45 +46,21 @@ public class StoreException extends RuntimeException
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
* Constructs a new instance.
*
* @param message exception message
*/
public StoreException()
{
super();
}
/**
* Constructs ...
*
*
* @param message
*/
public StoreException(String message)
{
public StoreException(String message) {
super(message);
}
/**
* Constructs ...
* Constructs a new instance.
*
*
* @param cause
* @param message exception message
* @param cause exception cause
*/
public StoreException(Throwable cause)
{
super(cause);
}
/**
* Constructs ...
*
*
* @param message
* @param cause
*/
public StoreException(String message, Throwable cause)
{
public StoreException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -39,9 +39,10 @@ import com.google.inject.Singleton;
import sonia.scm.group.Group;
import sonia.scm.group.GroupDAO;
import sonia.scm.store.StoreFactory;
import sonia.scm.xml.AbstractXmlDAO;
import sonia.scm.store.ConfigurationStoreFactory;
/**
*
* @author Sebastian Sdorra
@@ -63,7 +64,7 @@ public class XmlGroupDAO extends AbstractXmlDAO<Group, XmlGroupDatabase>
* @param storeFactory
*/
@Inject
public XmlGroupDAO(StoreFactory storeFactory)
public XmlGroupDAO(ConfigurationStoreFactory storeFactory)
{
super(storeFactory.getStore(XmlGroupDatabase.class, STORE_NAME));
}

View File

@@ -39,8 +39,8 @@ import com.google.inject.Singleton;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryDAO;
import sonia.scm.store.StoreFactory;
import sonia.scm.xml.AbstractXmlDAO;
import sonia.scm.store.ConfigurationStoreFactory;
/**
*
@@ -64,7 +64,7 @@ public class XmlRepositoryDAO
* @param storeFactory
*/
@Inject
public XmlRepositoryDAO(StoreFactory storeFactory)
public XmlRepositoryDAO(ConfigurationStoreFactory storeFactory)
{
super(storeFactory.getStore(XmlRepositoryDatabase.class, STORE_NAME));
}

View File

@@ -50,7 +50,7 @@ import java.io.File;
*
* @param <T>
*/
public abstract class FileBasedStore<T> implements StoreBase<T>
public abstract class FileBasedStore<T> implements MultiEntryStore<T>
{
/**

View File

@@ -28,12 +28,9 @@
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.store;
//~--- non-JDK imports --------------------------------------------------------
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,75 +38,52 @@ import sonia.scm.SCMContextProvider;
import sonia.scm.util.IOUtil;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
/**
* Abstract store factory for file based stores.
*
* @author Sebastian Sdorra
*/
public class FileBasedStoreFactory
{
/** Field description */
private static final String BASE_DIRECTORY = "var";
public abstract class FileBasedStoreFactory {
/**
* the logger for FileBasedStoreFactory
*/
private static final Logger logger =
LoggerFactory.getLogger(FileBasedStoreFactory.class);
private static final Logger LOG = LoggerFactory.getLogger(FileBasedStoreFactory.class);
//~--- constructors ---------------------------------------------------------
private static final String BASE_DIRECTORY = "var";
/**
* Constructs ...
*
*
* @param context
* @param dataDirectoryName
*/
public FileBasedStoreFactory(SCMContextProvider context,
String dataDirectoryName)
{
private final SCMContextProvider context;
private final String dataDirectoryName;
private File dataDirectory;
protected FileBasedStoreFactory(SCMContextProvider context,
String dataDirectoryName) {
this.context = context;
this.dataDirectoryName = dataDirectoryName;
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
* Returns data directory for given name.
*
* @param name name of data directory
*
* @param name
*
* @return
* @return data directory
*/
protected File getDirectory(String name)
{
if (dataDirectory == null)
{
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);
LOG.debug("create data directory {}", dataDirectory);
}
File storeDirectory = new File(dataDirectory, name);
IOUtil.mkdirs(storeDirectory);
return storeDirectory;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private final SCMContextProvider context;
/** Field description */
private File dataDirectory;
/** Field description */
private final String dataDirectoryName;
}

View File

@@ -28,12 +28,9 @@
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.store;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -43,87 +40,39 @@ import java.io.InputStream;
import java.io.OutputStream;
/**
* File base implementation of {@link Blob}.
*
* @author Sebastian Sdorra
*/
public final class FileBlob implements Blob
{
public final class FileBlob implements Blob {
/**
* Constructs ...
*
*
* @param id
* @param file
*/
public FileBlob(String id, File file)
{
private final String id;
private final File file;
FileBlob(String id, File file) {
this.id = id;
this.file = file;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @throws IOException
*/
@Override
public void commit() throws IOException
{
public void commit() throws IOException {
// nothing todo
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public String getId()
{
public String getId() {
return id;
}
/**
* Method description
*
*
* @return
*
* @throws FileNotFoundException
*/
@Override
public InputStream getInputStream() throws FileNotFoundException
{
public InputStream getInputStream() throws FileNotFoundException {
return new FileInputStream(file);
}
/**
* Method description
*
*
* @return
*
* @throws IOException
*/
@Override
public OutputStream getOutputStream() throws IOException
{
public OutputStream getOutputStream() throws IOException {
return new FileOutputStream(file);
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private final File file;
/** Field description */
private final String id;
}

View File

@@ -28,12 +28,9 @@
* 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 com.google.common.collect.ImmutableList;
@@ -45,147 +42,86 @@ import org.slf4j.LoggerFactory;
import sonia.scm.security.KeyGenerator;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
* File based implementation of {@link BlobStore}.
*
* @author Sebastian Sdorra
*/
public class FileBlobStore extends FileBasedStore<Blob> implements BlobStore
{
/** Field description */
private static final String SUFFIX = ".blob";
public class FileBlobStore extends FileBasedStore<Blob> implements BlobStore {
/**
* the logger for FileBlobStore
*/
private static final Logger logger =
LoggerFactory.getLogger(FileBlobStore.class);
private static final Logger LOG
= LoggerFactory.getLogger(FileBlobStore.class);
//~--- constructors ---------------------------------------------------------
private static final String SUFFIX = ".blob";
/**
* Constructs ...
*
*
* @param keyGenerator
* @param directory
*/
public FileBlobStore(KeyGenerator keyGenerator, File directory)
{
private final KeyGenerator keyGenerator;
FileBlobStore(KeyGenerator keyGenerator, File directory) {
super(directory, SUFFIX);
this.keyGenerator = keyGenerator;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public Blob create()
{
public Blob create() {
return create(keyGenerator.createKey());
}
/**
* Method description
*
*
* @param id
*
* @return
*/
@Override
public Blob create(String id)
{
public Blob create(String id) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(id),
"id argument is required");
logger.debug("create new blob with id {}", id);
LOG.debug("create new blob with id {}", id);
File file = getFile(id);
try
{
if (file.exists())
{
try {
if (file.exists()) {
throw new EntryAlreadyExistsStoreException(
"blob with id ".concat(id).concat(" allready exists"));
}
else if (!file.createNewFile())
{
else if (!file.createNewFile()) {
throw new StoreException("could not create blob for id ".concat(id));
}
}
catch (IOException ex)
{
catch (IOException ex) {
throw new StoreException("could not create blob for id ".concat(id), ex);
}
return new FileBlob(id, file);
}
/**
* Method description
*
*
* @param blob
*/
@Override
public void remove(Blob blob)
{
public void remove(Blob blob) {
Preconditions.checkNotNull(blob, "blob argument is required");
remove(blob.getId());
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public List<Blob> getAll()
{
logger.trace("get all items from data store");
public List<Blob> getAll() {
LOG.trace("get all items from data store");
Builder<Blob> builder = ImmutableList.builder();
for (File file : directory.listFiles())
{
for (File file : directory.listFiles()) {
builder.add(read(file));
}
return builder.build();
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param file
*
* @return
*/
@Override
protected FileBlob read(File file)
{
protected FileBlob read(File file) {
FileBlob blob = null;
if (file.exists())
{
if (file.exists()) {
String id = getId(file);
blob = new FileBlob(id, file);
@@ -194,8 +130,4 @@ public class FileBlobStore extends FileBasedStore<Blob> implements BlobStore
return blob;
}
//~--- fields ---------------------------------------------------------------
/** key generator */
private final KeyGenerator keyGenerator;
}

View File

@@ -28,12 +28,9 @@
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.store;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -44,60 +41,40 @@ import sonia.scm.SCMContextProvider;
import sonia.scm.security.KeyGenerator;
/**
* File based store factory.
*
* @author Sebastian Sdorra
*/
@Singleton
public class FileBlobStoreFactory extends FileBasedStoreFactory
implements BlobStoreFactory
{
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);
private static final Logger LOG = LoggerFactory.getLogger(FileBlobStoreFactory.class);
//~--- constructors ---------------------------------------------------------
private final KeyGenerator keyGenerator;
/**
* Constructs ...
* Constructs a new instance.
*
*
* @param context
* @param keyGenerator
* @param context scm context
* @param keyGenerator key generator
*/
@Inject
public FileBlobStoreFactory(SCMContextProvider context,
KeyGenerator keyGenerator)
{
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);
public BlobStore getBlobStore(String name) {
LOG.debug("create new blob with name {}", name);
return new FileBlobStore(keyGenerator, getDirectory(name));
}
//~--- fields ---------------------------------------------------------------
/** key generator */
private final KeyGenerator keyGenerator;
}

View File

@@ -80,8 +80,7 @@ import javax.xml.stream.XMLStreamWriter;
*
* @param <V>
*/
public class JAXBConfigurationEntryStore<V>
implements ConfigurationEntryStore<V>
public class JAXBConfigurationEntryStore<V> implements ConfigurationEntryStore<V>
{
/** Field description */

View File

@@ -28,18 +28,13 @@
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.store;
//~--- non-JDK imports --------------------------------------------------------
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import javax.xml.bind.JAXBContext;
@@ -47,121 +42,81 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
/**
* JAXB implementation of {@link ConfigurationStore}.
*
* @author Sebastian Sdorra
*
* @param <T>
*/
public class JAXBStore<T> extends AbstractStore<T>
{
/** the logger for JAXBStore */
private static final Logger logger = LoggerFactory.getLogger(JAXBStore.class);
//~--- constructors ---------------------------------------------------------
public class JAXBConfigurationStore<T> extends AbstractStore<T> {
/**
* Constructs ...
*
*
* @param type
* @param configFile
* the logger for JAXBConfigurationStore
*/
public JAXBStore(Class<T> type, File configFile)
{
private static final Logger LOG = LoggerFactory.getLogger(JAXBConfigurationStore.class);
private Class<T> type;
private File configFile;
private JAXBContext context;
JAXBConfigurationStore(Class<T> type, File configFile) {
this.type = type;
try
{
try {
context = JAXBContext.newInstance(type);
this.configFile = configFile;
}
catch (JAXBException ex)
{
throw new StoreException(ex);
catch (JAXBException ex) {
throw new StoreException("failed to create jaxb context", ex);
}
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
* Returns type of stored object.
*
*
* @return
* @return type
*/
public Class<T> getType()
{
public Class<T> getType() {
return type;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
@SuppressWarnings("unchecked")
protected T readObject()
{
logger.debug("load {} from store {}", type, configFile);
protected T readObject() {
LOG.debug("load {} from store {}", type, configFile);
T result = null;
if (configFile.exists())
{
try
{
if (configFile.exists()) {
try {
result = (T) context.createUnmarshaller().unmarshal(configFile);
}
catch (JAXBException ex)
{
throw new StoreException(ex);
catch (JAXBException ex) {
throw new StoreException("failed to unmarshall object", ex);
}
}
return result;
}
/**
* Method description
*
*
* @param object
*/
@Override
protected void writeObject(T object)
{
if (logger.isDebugEnabled())
{
logger.debug("store {} to {}", object.getClass().getName(),
protected void writeObject(T object) {
if (LOG.isDebugEnabled()) {
LOG.debug("store {} to {}", object.getClass().getName(),
configFile.getPath());
}
try
{
try {
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(object, configFile);
}
catch (JAXBException ex)
{
throw new StoreException(ex);
catch (JAXBException ex) {
throw new StoreException("failed to marshall object", ex);
}
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private File configFile;
/** Field description */
private JAXBContext context;
/** Field description */
private Class<T> type;
}

View File

@@ -28,67 +28,59 @@
* 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.util.IOUtil;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.io.File;
/**
* JAXB implementation of {@link JAXBConfigurationStoreFactory}.
*
* @author Sebastian Sdorra
*/
public class MemoryStoreFactory implements StoreFactory
{
@Singleton
public class JAXBConfigurationStoreFactory implements ConfigurationStoreFactory {
/**
* Method description
*
*
* @throws IOException
* the logger for JAXBConfigurationStoreFactory
*/
@Override
public void close() throws IOException
{
private static final Logger LOG = LoggerFactory.getLogger(JAXBConfigurationStoreFactory.class);
// do nothing
}
private final File configDirectory;
/**
* Method description
* Constructs a new instance.
*
*
* @param context
* @param context scm context
*/
@Inject
public JAXBConfigurationStoreFactory(SCMContextProvider context) {
configDirectory = new File(context.getBaseDirectory(), StoreConstants.CONFIGDIRECTORY_NAME);
IOUtil.mkdirs(configDirectory);
}
@Override
public void init(SCMContextProvider context)
{
// do nothing
public <T> JAXBConfigurationStore<T> getStore(Class<T> type, String name) {
if (configDirectory == null) {
throw new IllegalStateException("store factory is not initialized");
}
//~--- get methods ----------------------------------------------------------
File configFile = new File(configDirectory, name.concat(StoreConstants.FILE_EXTENSION));
/**
* Method description
*
*
* @param type
* @param name
* @param <T>
*
* @return
*/
@Override
public <T> Store<T> getStore(Class<T> type, String name)
{
return new MemoryStore<T>();
if (LOG.isDebugEnabled()) {
LOG.debug("create store for {} at {}", type.getName(),
configFile.getPath());
}
return new JAXBConfigurationStore<>(type, configFile);
}
}

View File

@@ -28,12 +28,9 @@
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.store;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
@@ -43,7 +40,6 @@ import org.slf4j.LoggerFactory;
import sonia.scm.security.KeyGenerator;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.util.Map;
@@ -53,87 +49,57 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
/**
* Jaxb implementation of {@link DataStore}.
*
* @author Sebastian Sdorra
*
* @param <T>
* @param <T> type of stored data.
*/
public class JAXBDataStore<T> extends FileBasedStore<T> implements DataStore<T>
{
public class JAXBDataStore<T> extends FileBasedStore<T> implements DataStore<T> {
/**
* the logger for JAXBDataStore
*/
private static final Logger logger =
LoggerFactory.getLogger(JAXBDataStore.class);
private static final Logger LOG
= LoggerFactory.getLogger(JAXBDataStore.class);
//~--- constructors ---------------------------------------------------------
private final JAXBContext context;
/**
* Constructs ...
*
*
* @param type
* @param keyGenerator
* @param directory
*/
public JAXBDataStore(KeyGenerator keyGenerator, Class<T> type, File directory)
{
private final KeyGenerator keyGenerator;
JAXBDataStore(KeyGenerator keyGenerator, Class<T> type, File directory) {
super(directory, StoreConstants.FILE_EXTENSION);
this.keyGenerator = keyGenerator;
try
{
try {
context = JAXBContext.newInstance(type);
this.directory = directory;
}
catch (JAXBException ex)
{
throw new StoreException(ex);
catch (JAXBException ex) {
throw new StoreException("failed to create jaxb context", ex);
}
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param id
* @param item
*/
@Override
public void put(String id, T item)
{
logger.debug("put item {} to store", id);
public void put(String id, T item) {
LOG.debug("put item {} to store", id);
File file = getFile(id);
try
{
try {
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(item, file);
}
catch (JAXBException ex)
{
catch (JAXBException ex) {
throw new StoreException("could not write object with id ".concat(id),
ex);
}
}
/**
* Method description
*
*
* @param item
*
* @return
*/
@Override
public String put(T item)
{
public String put(T item) {
String key = keyGenerator.createKey();
put(key, item);
@@ -141,55 +107,31 @@ public class JAXBDataStore<T> extends FileBasedStore<T> implements DataStore<T>
return key;
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public Map<String, T> getAll()
{
logger.trace("get all items from data store");
public Map<String, T> getAll() {
LOG.trace("get all items from data store");
Builder<String, T> builder = ImmutableMap.builder();
for (File file : directory.listFiles())
{
for (File file : directory.listFiles()) {
builder.put(getId(file), read(file));
}
return builder.build();
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param file
*
* @return
*/
@Override
@SuppressWarnings("unchecked")
protected T read(File file)
{
protected T read(File file) {
T item = null;
if (file.exists())
{
logger.trace("try to read {}", file);
if (file.exists()) {
LOG.trace("try to read {}", file);
try
{
try {
item = (T) context.createUnmarshaller().unmarshal(file);
}
catch (JAXBException ex)
{
catch (JAXBException ex) {
throw new StoreException(
"could not read object ".concat(file.getPath()), ex);
}
@@ -197,12 +139,4 @@ public class JAXBDataStore<T> extends FileBasedStore<T> implements DataStore<T>
return item;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private JAXBContext context;
/** Field description */
private final KeyGenerator keyGenerator;
}

View File

@@ -95,7 +95,7 @@ public class JAXBDataStoreFactory extends FileBasedStoreFactory
{
logger.debug("create new store for type {} with name {}", type, name);
return new JAXBDataStore<T>(keyGenerator, type, getDirectory(name));
return new JAXBDataStore<>(keyGenerator, type, getDirectory(name));
}
//~--- fields ---------------------------------------------------------------

View File

@@ -1,128 +0,0 @@
/**
* 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.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.SCMContextProvider;
import sonia.scm.util.IOUtil;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.io.IOException;
/**
*
* @author Sebastian Sdorra
*/
@Singleton
public class JAXBStoreFactory implements StoreFactory
{
/** the logger for JAXBStoreFactory */
private static final Logger logger =
LoggerFactory.getLogger(JAXBStoreFactory.class);
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @throws IOException
*/
@Override
public void close() throws IOException
{
// do nothing
}
/**
* Method description
*
*
* @param context
*/
@Override
public void init(SCMContextProvider context)
{
configDirectory = new File(context.getBaseDirectory(),
StoreConstants.CONFIGDIRECTORY_NAME);
IOUtil.mkdirs(configDirectory);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param type
* @param name
* @param <T>
*
* @return
*/
@Override
public <T> JAXBStore<T> getStore(Class<T> type, String name)
{
if (configDirectory == null)
{
throw new IllegalStateException("store factory is not initialized");
}
File configFile = new File(configDirectory,
name.concat(StoreConstants.FILE_EXTENSION));
if (logger.isDebugEnabled())
{
logger.debug("create store for {} at {}", type.getName(),
configFile.getPath());
}
return new JAXBStore<T>(type, configFile);
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private File configDirectory;
}

View File

@@ -33,6 +33,7 @@
package sonia.scm.store;
/**
* Store constants for xml implementations.
*
* @author Sebastian Sdorra
*/

View File

@@ -37,10 +37,10 @@ package sonia.scm.user.xml;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import sonia.scm.store.StoreFactory;
import sonia.scm.user.User;
import sonia.scm.user.UserDAO;
import sonia.scm.xml.AbstractXmlDAO;
import sonia.scm.store.ConfigurationStoreFactory;
/**
*
@@ -63,7 +63,7 @@ public class XmlUserDAO extends AbstractXmlDAO<User, XmlUserDatabase>
* @param storeFactory
*/
@Inject
public XmlUserDAO(StoreFactory storeFactory)
public XmlUserDAO(ConfigurationStoreFactory storeFactory)
{
super(storeFactory.getStore(XmlUserDatabase.class, STORE_NAME));
}

View File

@@ -41,11 +41,11 @@ import org.slf4j.LoggerFactory;
import sonia.scm.GenericDAO;
import sonia.scm.ModelObject;
import sonia.scm.group.xml.XmlGroupDAO;
import sonia.scm.store.Store;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
import sonia.scm.store.ConfigurationStore;
/**
*
@@ -76,7 +76,7 @@ public abstract class AbstractXmlDAO<I extends ModelObject,
*
* @param store
*/
public AbstractXmlDAO(Store<T> store)
public AbstractXmlDAO(ConfigurationStore<T> store)
{
this.store = store;
db = store.get();
@@ -290,7 +290,7 @@ public abstract class AbstractXmlDAO<I extends ModelObject,
//~--- fields ---------------------------------------------------------------
/** Field description */
private final Store<T> store;
private final ConfigurationStore<T> store;
/** Field description */
protected T db;

View File

@@ -33,25 +33,15 @@
package sonia.scm.store;
/**
* Unit tests for {@link JAXBConfigurationStore}.
*
* @author Sebastian Sdorra
*/
public class JAXBStoreTest extends StoreTestBase
{
public class JAXBConfigurationStoreTest extends StoreTestBase {
/**
* Method description
*
*
* @return
*/
@Override
protected StoreFactory createStoreFactory()
protected ConfigurationStoreFactory createStoreFactory()
{
JAXBStoreFactory factory = new JAXBStoreFactory();
factory.init(contextProvider);
return factory;
return new JAXBConfigurationStoreFactory(contextProvider);
}
}

View File

@@ -44,12 +44,12 @@ import sonia.scm.Type;
import sonia.scm.io.FileSystem;
import sonia.scm.plugin.Extension;
import sonia.scm.repository.spi.GitRepositoryServiceProvider;
import sonia.scm.store.StoreFactory;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.io.IOException;
import sonia.scm.store.ConfigurationStoreFactory;
/**
*
@@ -89,7 +89,7 @@ public class GitRepositoryHandler
* @param fileSystem
*/
@Inject
public GitRepositoryHandler(StoreFactory storeFactory, FileSystem fileSystem)
public GitRepositoryHandler(ConfigurationStoreFactory storeFactory, FileSystem fileSystem)
{
super(storeFactory, fileSystem);
}

View File

@@ -36,13 +36,13 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.io.DefaultFileSystem;
import sonia.scm.store.StoreFactory;
import static org.junit.Assert.*;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import sonia.scm.store.ConfigurationStoreFactory;
/**
*
@@ -86,7 +86,7 @@ public class GitRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
* @return
*/
@Override
protected RepositoryHandler createRepositoryHandler(StoreFactory factory,
protected RepositoryHandler createRepositoryHandler(ConfigurationStoreFactory factory,
File directory)
{
GitRepositoryHandler repositoryHandler = new GitRepositoryHandler(factory,

View File

@@ -56,7 +56,6 @@ import sonia.scm.io.INIConfigurationWriter;
import sonia.scm.io.INISection;
import sonia.scm.plugin.Extension;
import sonia.scm.repository.spi.HgRepositoryServiceProvider;
import sonia.scm.store.StoreFactory;
import sonia.scm.util.IOUtil;
import sonia.scm.util.SystemUtil;
import sonia.scm.util.Util;
@@ -73,6 +72,7 @@ import java.text.MessageFormat;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import sonia.scm.store.ConfigurationStoreFactory;
/**
*
@@ -122,7 +122,7 @@ public class HgRepositoryHandler
* @param hgContextProvider
*/
@Inject
public HgRepositoryHandler(StoreFactory storeFactory, FileSystem fileSystem,
public HgRepositoryHandler(ConfigurationStoreFactory storeFactory, FileSystem fileSystem,
Provider<HgContext> hgContextProvider)
{
super(storeFactory, fileSystem);

View File

@@ -37,13 +37,13 @@ package sonia.scm.repository;
import sonia.scm.io.DefaultFileSystem;
import sonia.scm.store.StoreFactory;
import static org.junit.Assert.*;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import sonia.scm.store.ConfigurationStoreFactory;
/**
*
@@ -83,7 +83,7 @@ public class HgRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
* @return
*/
@Override
protected RepositoryHandler createRepositoryHandler(StoreFactory factory,
protected RepositoryHandler createRepositoryHandler(ConfigurationStoreFactory factory,
File directory)
{
HgRepositoryHandler handler = new HgRepositoryHandler(factory,
@@ -98,3 +98,4 @@ public class HgRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
return handler;
}
}
//~--- non-JDK imports --------------------------------------------------------

View File

@@ -39,7 +39,7 @@ import org.junit.Assume;
import sonia.scm.SCMContext;
import sonia.scm.io.FileSystem;
import sonia.scm.store.MemoryStoreFactory;
import sonia.scm.store.InMemoryConfigurationStoreFactory;
import static org.mockito.Mockito.*;
@@ -105,7 +105,7 @@ public final class HgTestUtil
FileSystem fileSystem = mock(FileSystem.class);
HgRepositoryHandler handler =
new HgRepositoryHandler(new MemoryStoreFactory(), fileSystem,
new HgRepositoryHandler(new InMemoryConfigurationStoreFactory(), fileSystem,
new HgContextProvider());
handler.init(context);

View File

@@ -54,7 +54,6 @@ import sonia.scm.io.FileSystem;
import sonia.scm.logging.SVNKitLogger;
import sonia.scm.plugin.Extension;
import sonia.scm.repository.spi.SvnRepositoryServiceProvider;
import sonia.scm.store.StoreFactory;
import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------
@@ -62,6 +61,7 @@ import sonia.scm.util.Util;
import java.io.File;
import java.io.IOException;
import sonia.scm.repository.spi.HookEventFacade;
import sonia.scm.store.ConfigurationStoreFactory;
/**
*
@@ -106,7 +106,7 @@ public class SvnRepositoryHandler
* @param repositoryManager
*/
@Inject
public SvnRepositoryHandler(StoreFactory storeFactory, FileSystem fileSystem,
public SvnRepositoryHandler(ConfigurationStoreFactory storeFactory, FileSystem fileSystem,
HookEventFacade eventFacade)
{
super(storeFactory, fileSystem);

View File

@@ -36,13 +36,13 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.io.DefaultFileSystem;
import sonia.scm.store.StoreFactory;
import static org.junit.Assert.*;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import sonia.scm.store.ConfigurationStoreFactory;
/**
*
@@ -81,7 +81,7 @@ public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
* @return
*/
@Override
protected RepositoryHandler createRepositoryHandler(StoreFactory factory,
protected RepositoryHandler createRepositoryHandler(ConfigurationStoreFactory factory,
File directory)
{
SvnRepositoryHandler handler = new SvnRepositoryHandler(factory,

View File

@@ -37,12 +37,12 @@ package sonia.scm.repository;
import sonia.scm.Type;
import sonia.scm.io.DefaultFileSystem;
import sonia.scm.store.StoreFactory;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.io.IOException;
import sonia.scm.store.ConfigurationStoreFactory;
/**
*
@@ -69,7 +69,7 @@ public class DummyRepositoryHandler
*
* @param storeFactory
*/
public DummyRepositoryHandler(StoreFactory storeFactory)
public DummyRepositoryHandler(ConfigurationStoreFactory storeFactory)
{
super(storeFactory, new DefaultFileSystem());
}

View File

@@ -38,8 +38,7 @@ package sonia.scm.repository;
import org.junit.Test;
import sonia.scm.AbstractTestBase;
import sonia.scm.store.MemoryStoreFactory;
import sonia.scm.store.StoreFactory;
import sonia.scm.store.InMemoryConfigurationStoreFactory;
import sonia.scm.util.IOUtil;
import static org.junit.Assert.*;
@@ -48,6 +47,7 @@ import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import sonia.scm.store.ConfigurationStoreFactory;
/**
*
@@ -74,7 +74,7 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase
* @return
*/
protected abstract RepositoryHandler createRepositoryHandler(
StoreFactory factory, File directory);
ConfigurationStoreFactory factory, File directory);
/**
* Method description
@@ -150,11 +150,8 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase
@Override
protected void postSetUp() throws Exception
{
MemoryStoreFactory storeFactory = new MemoryStoreFactory();
storeFactory.init(contextProvider);
baseDirectory = new File(contextProvider.getBaseDirectory(),
"repositories");
InMemoryConfigurationStoreFactory storeFactory = new InMemoryConfigurationStoreFactory();
baseDirectory = new File(contextProvider.getBaseDirectory(), "repositories");
IOUtil.mkdirs(baseDirectory);
handler = createRepositoryHandler(storeFactory, baseDirectory);
}

View File

@@ -28,48 +28,27 @@
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.store;
/**
* In memory store implementation of {@link ConfigurationStore}.
*
* @author Sebastian Sdorra
*
* @param <T>
* @param <T> type of stored object
*/
public class MemoryStore<T> implements Store<T>
{
public class InMemoryConfigurationStore<T> implements ConfigurationStore<T> {
private T object;
/**
* Method description
*
*
* @return
*/
@Override
public T get()
{
public T get() {
return object;
}
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param obejct
*/
@Override
public void set(T obejct)
{
public void set(T obejct) {
this.object = obejct;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private T object;
}

View File

@@ -0,0 +1,50 @@
/**
* 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 --------------------------------------------------------
/**
* In memory configuration store factory for testing purposes.
*
* @author Sebastian Sdorra
*/
public class InMemoryConfigurationStoreFactory implements ConfigurationStoreFactory {
@Override
public <T> ConfigurationStore<T> getStore(Class<T> type, String name)
{
return new InMemoryConfigurationStore<>();
}
}

View File

@@ -56,7 +56,7 @@ public abstract class StoreTestBase extends AbstractTestBase
*
* @return
*/
protected abstract StoreFactory createStoreFactory();
protected abstract ConfigurationStoreFactory createStoreFactory();
/**
* Method description
@@ -65,7 +65,7 @@ public abstract class StoreTestBase extends AbstractTestBase
@Test
public void testGet()
{
Store<StoreObject> store = createStoreFactory().getStore(StoreObject.class,
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(StoreObject.class,
"test");
assertNotNull(store);
@@ -82,7 +82,7 @@ public abstract class StoreTestBase extends AbstractTestBase
@Test
public void testSet()
{
Store<StoreObject> store = createStoreFactory().getStore(StoreObject.class,
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(StoreObject.class,
"test");
assertNotNull(store);

View File

@@ -54,7 +54,6 @@ import sonia.scm.plugin.DefaultPluginLoader;
import sonia.scm.plugin.ExtensionProcessor;
import sonia.scm.plugin.PluginWrapper;
import sonia.scm.repository.RepositoryManager;
import sonia.scm.store.StoreFactory;
import sonia.scm.upgrade.UpgradeManager;
import sonia.scm.user.UserManager;
import sonia.scm.util.IOUtil;
@@ -119,9 +118,6 @@ public class ScmContextListener extends GuiceServletContextListener
// close UserManager
IOUtil.close(globalInjector.getInstance(UserManager.class));
// close StoreFactory
IOUtil.close(globalInjector.getInstance(StoreFactory.class));
// close CacheManager
IOUtil.close(globalInjector.getInstance(CacheManager.class));

View File

@@ -91,8 +91,7 @@ import sonia.scm.store.DataStoreFactory;
import sonia.scm.store.FileBlobStoreFactory;
import sonia.scm.store.JAXBConfigurationEntryStoreFactory;
import sonia.scm.store.JAXBDataStoreFactory;
import sonia.scm.store.JAXBStoreFactory;
import sonia.scm.store.StoreFactory;
import sonia.scm.store.JAXBConfigurationStoreFactory;
import sonia.scm.template.MustacheTemplateEngine;
import sonia.scm.template.TemplateEngine;
import sonia.scm.template.TemplateEngineFactory;
@@ -127,6 +126,7 @@ import com.sun.jersey.spi.container.servlet.ServletContainer;
import java.util.Map;
import javax.servlet.ServletContext;
import sonia.scm.store.ConfigurationStoreFactory;
/**
*
@@ -241,9 +241,8 @@ public class ScmServletModule extends JerseyServletModule
bind(ScmEventBus.class).toInstance(ScmEventBus.getInstance());
// bind core
bind(StoreFactory.class, JAXBStoreFactory.class);
bind(ConfigurationEntryStoreFactory.class,
JAXBConfigurationEntryStoreFactory.class);
bind(ConfigurationStoreFactory.class, JAXBConfigurationStoreFactory.class);
bind(ConfigurationEntryStoreFactory.class, JAXBConfigurationEntryStoreFactory.class);
bind(DataStoreFactory.class, JAXBDataStoreFactory.class);
bind(BlobStoreFactory.class, FileBlobStoreFactory.class);
bind(ScmConfiguration.class).toInstance(config);

View File

@@ -53,7 +53,6 @@ import sonia.scm.repository.RepositoryHandler;
import sonia.scm.repository.RepositoryManager;
import sonia.scm.security.Role;
import sonia.scm.security.ScmSecurityException;
import sonia.scm.store.StoreFactory;
import sonia.scm.util.SystemUtil;
//~--- JDK imports ------------------------------------------------------------
@@ -73,6 +72,7 @@ import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import sonia.scm.store.ConfigurationStoreFactory;
/**
*
@@ -105,7 +105,7 @@ public class SupportResource
@Inject
public SupportResource(SCMContextProvider context,
ScmConfiguration configuration, PluginManager pluginManager,
StoreFactory storeFactory, RepositoryManager repositoryManager,
ConfigurationStoreFactory storeFactory, RepositoryManager repositoryManager,
HttpServletRequest request)
{
this.context = context;

View File

@@ -46,8 +46,7 @@ import sonia.scm.repository.api.HookFeature;
import sonia.scm.repository.spi.HookContextProvider;
import sonia.scm.repository.xml.XmlRepositoryDAO;
import sonia.scm.security.DefaultKeyGenerator;
import sonia.scm.store.JAXBStoreFactory;
import sonia.scm.store.StoreFactory;
import sonia.scm.store.JAXBConfigurationStoreFactory;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
@@ -61,6 +60,7 @@ import java.util.HashSet;
import java.util.Set;
import java.util.Stack;
import org.apache.shiro.authz.UnauthorizedException;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.mockito.invocation.InvocationOnMock;
@@ -69,6 +69,7 @@ import sonia.scm.Manager;
import sonia.scm.ManagerTestBase;
import sonia.scm.event.ScmEventBus;
import sonia.scm.security.KeyGenerator;
import sonia.scm.store.ConfigurationStoreFactory;
/**
* Unit tests for {@link DefaultRepositoryManager}.
@@ -282,6 +283,7 @@ public class DefaultRepositoryManagerTest extends ManagerTestBase<Repository, Re
* @throws RepositoryException
*/
@Test
@SuppressWarnings("unchecked")
@SubjectAware(username = "dent")
public void testGetAllWithPermissions() throws RepositoryException, IOException {
// mock key generator
@@ -316,8 +318,7 @@ public class DefaultRepositoryManagerTest extends ManagerTestBase<Repository, Re
// assert returned repositories
Collection<Repository> repositories = repositoryManager.getAll();
assertEquals(2, repositories.size());
assertThat(repositories,
containsInAnyOrder(
assertThat(repositories, containsInAnyOrder(
hasProperty("id", is("p42")),
hasProperty("id", is("hof"))
)
@@ -520,9 +521,7 @@ public class DefaultRepositoryManagerTest extends ManagerTestBase<Repository, Re
private DefaultRepositoryManager createRepositoryManager(boolean archiveEnabled, KeyGenerator keyGenerator) {
Set<RepositoryHandler> handlerSet = new HashSet<>();
StoreFactory factory = new JAXBStoreFactory();
factory.init(contextProvider);
ConfigurationStoreFactory factory = new JAXBConfigurationStoreFactory(contextProvider);
handlerSet.add(new DummyRepositoryHandler(factory));
handlerSet.add(new DummyRepositoryHandler(factory) {
@Override

View File

@@ -42,8 +42,7 @@ import com.google.common.collect.Lists;
import org.junit.Before;
import org.junit.Test;
import sonia.scm.store.JAXBStoreFactory;
import sonia.scm.store.StoreFactory;
import sonia.scm.store.JAXBConfigurationStoreFactory;
import sonia.scm.user.xml.XmlUserDAO;
import sonia.scm.util.MockUtil;
@@ -54,6 +53,7 @@ import static org.mockito.Mockito.*;
import java.util.Collections;
import java.util.List;
import org.junit.Rule;
import sonia.scm.store.ConfigurationStoreFactory;
/**
*
@@ -120,18 +120,7 @@ public class DefaultUserManagerTest extends UserManagerTestBase
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @return
*/
private XmlUserDAO createXmlUserDAO()
{
StoreFactory factory = new JAXBStoreFactory();
factory.init(contextProvider);
return new XmlUserDAO(factory);
private XmlUserDAO createXmlUserDAO() {
return new XmlUserDAO(new JAXBConfigurationStoreFactory(contextProvider));
}
}