mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-12-23 08:49:48 +01:00
Add delete method for configuration store (#1814)
Add method to delete configuration stores completely.
This commit is contained in:
@@ -29,10 +29,9 @@ import java.util.function.BooleanSupplier;
|
||||
/**
|
||||
* Base class for {@link ConfigurationStore}.
|
||||
*
|
||||
* @param <T> type of store objects
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.16
|
||||
*
|
||||
* @param <T> type of store objects
|
||||
*/
|
||||
public abstract class AbstractStore<T> implements ConfigurationStore<T> {
|
||||
|
||||
@@ -64,10 +63,19 @@ public abstract class AbstractStore<T> implements ConfigurationStore<T> {
|
||||
this.storeObject = object;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
if (readOnly.getAsBoolean()) {
|
||||
throw new StoreReadOnlyException();
|
||||
}
|
||||
deleteObject();
|
||||
this.storeObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the stored object.
|
||||
*
|
||||
*
|
||||
* @return stored object
|
||||
*/
|
||||
protected abstract T readObject();
|
||||
@@ -75,8 +83,14 @@ public abstract class AbstractStore<T> implements ConfigurationStore<T> {
|
||||
/**
|
||||
* Write object to the store.
|
||||
*
|
||||
*
|
||||
* @param object object to write
|
||||
*/
|
||||
protected abstract void writeObject(T object);
|
||||
|
||||
/**
|
||||
* Deletes store object.
|
||||
*
|
||||
* @since 2.24.0
|
||||
*/
|
||||
protected abstract void deleteObject();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.store;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -32,17 +32,14 @@ import static java.util.Optional.ofNullable;
|
||||
* ConfigurationStore for configuration objects. <strong>Note:</strong> the default
|
||||
* implementation use JAXB to marshall the configuration objects.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*
|
||||
* @param <T> type of the configuration objects
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public interface ConfigurationStore<T>
|
||||
{
|
||||
public interface ConfigurationStore<T> {
|
||||
|
||||
/**
|
||||
* Returns the configuration object from store.
|
||||
*
|
||||
*
|
||||
* @return configuration object from store
|
||||
*/
|
||||
T get();
|
||||
@@ -50,20 +47,24 @@ public interface ConfigurationStore<T>
|
||||
/**
|
||||
* Returns the configuration object from store.
|
||||
*
|
||||
*
|
||||
* @return configuration object from store
|
||||
*/
|
||||
default Optional<T> getOptional() {
|
||||
return ofNullable(get());
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Stores the given configuration object to the store.
|
||||
*
|
||||
*
|
||||
* @param object configuration object to store
|
||||
*/
|
||||
void set(T object);
|
||||
|
||||
/**
|
||||
* Deletes the configuration.
|
||||
* @since 2.24.0
|
||||
*/
|
||||
default void delete() {
|
||||
throw new StoreException("Delete operation is not implemented by the store");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,11 @@ public class StoreReadOnlyException extends ExceptionWithContext {
|
||||
LOG.error(getMessage());
|
||||
}
|
||||
|
||||
public StoreReadOnlyException() {
|
||||
super(noContext(), "Store is read only, could not delete store");
|
||||
LOG.error(getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode () {
|
||||
return CODE;
|
||||
|
||||
Reference in New Issue
Block a user