mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-03 21:29:18 +01:00
refactor store api
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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}.
|
||||
|
||||
@@ -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>
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user