mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
simplified structure of store builders
This commit is contained in:
@@ -21,10 +21,8 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package sonia.scm.store;
|
|
||||||
|
|
||||||
import sonia.scm.repository.Repository;
|
package sonia.scm.store;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The BlobStoreFactory can be used to create a new or get an existing {@link BlobStore}s.
|
* The BlobStoreFactory can be used to create a new or get an existing {@link BlobStore}s.
|
||||||
@@ -46,7 +44,7 @@ import sonia.scm.repository.Repository;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
* @since 1.23
|
* @since 1.23
|
||||||
*
|
*
|
||||||
* @apiviz.landmark
|
* @apiviz.landmark
|
||||||
* @apiviz.uses sonia.scm.store.BlobStore
|
* @apiviz.uses sonia.scm.store.BlobStore
|
||||||
*/
|
*/
|
||||||
@@ -66,66 +64,7 @@ public interface BlobStoreFactory {
|
|||||||
* @param name The name for the {@link BlobStore}.
|
* @param name The name for the {@link BlobStore}.
|
||||||
* @return Floating API to either specify a repository or directly build a global {@link BlobStore}.
|
* @return Floating API to either specify a repository or directly build a global {@link BlobStore}.
|
||||||
*/
|
*/
|
||||||
default FloatingStoreParameters.Builder withName(String name) {
|
default StoreParametersBuilder<BlobStore> withName(String name) {
|
||||||
return new FloatingStoreParameters(this).new Builder(name);
|
return new StoreParametersBuilder<>(name, this::getStore);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final class FloatingStoreParameters implements StoreParameters {
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
private String repositoryId;
|
|
||||||
|
|
||||||
private final BlobStoreFactory factory;
|
|
||||||
|
|
||||||
FloatingStoreParameters(BlobStoreFactory factory) {
|
|
||||||
this.factory = factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getRepositoryId() {
|
|
||||||
return repositoryId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Builder {
|
|
||||||
|
|
||||||
Builder(String name) {
|
|
||||||
FloatingStoreParameters.this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this to create or get a {@link BlobStore} for a specific repository. This step is optional. If you want to
|
|
||||||
* have a global {@link BlobStore}, omit this.
|
|
||||||
* @param repository The optional repository for the {@link BlobStore}.
|
|
||||||
* @return Floating API to finish the call.
|
|
||||||
*/
|
|
||||||
public FloatingStoreParameters.Builder forRepository(Repository repository) {
|
|
||||||
FloatingStoreParameters.this.repositoryId = repository.getId();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this to create or get a {@link BlobStore} for a specific repository. This step is optional. If you want to
|
|
||||||
* have a global {@link BlobStore}, omit this.
|
|
||||||
* @param repositoryId The id of the optional repository for the {@link BlobStore}.
|
|
||||||
* @return Floating API to finish the call.
|
|
||||||
*/
|
|
||||||
public FloatingStoreParameters.Builder forRepository(String repositoryId) {
|
|
||||||
FloatingStoreParameters.this.repositoryId = repositoryId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates or gets the {@link BlobStore} with the given name and (if specified) the given repository. If no
|
|
||||||
* repository is given, the {@link BlobStore} will be global.
|
|
||||||
*/
|
|
||||||
public BlobStore build(){
|
|
||||||
return factory.getStore(FloatingStoreParameters.this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,8 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package sonia.scm.store;
|
|
||||||
|
|
||||||
import sonia.scm.repository.Repository;
|
package sonia.scm.store;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ConfigurationEntryStoreFactory can be used to create new or get existing {@link ConfigurationEntryStore}s.
|
* The ConfigurationEntryStoreFactory can be used to create new or get existing {@link ConfigurationEntryStore}s.
|
||||||
@@ -51,7 +49,7 @@ import sonia.scm.repository.Repository;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
* @since 1.31
|
* @since 1.31
|
||||||
*
|
*
|
||||||
* @apiviz.landmark
|
* @apiviz.landmark
|
||||||
* @apiviz.uses sonia.scm.store.ConfigurationEntryStore
|
* @apiviz.uses sonia.scm.store.ConfigurationEntryStore
|
||||||
*/
|
*/
|
||||||
@@ -72,67 +70,7 @@ public interface ConfigurationEntryStoreFactory {
|
|||||||
* @return Floating API to set the name and either specify a repository or directly build a global
|
* @return Floating API to set the name and either specify a repository or directly build a global
|
||||||
* {@link ConfigurationEntryStore}.
|
* {@link ConfigurationEntryStore}.
|
||||||
*/
|
*/
|
||||||
default <T> TypedFloatingConfigurationEntryStoreParameters<T>.Builder withType(Class<T> type) {
|
default <T> TypedStoreParametersBuilder<T, ConfigurationEntryStore<T>> withType(Class<T> type) {
|
||||||
return new TypedFloatingConfigurationEntryStoreParameters<T>(this).new Builder(type);
|
return new TypedStoreParametersBuilder<>(type, this::getStore);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final class TypedFloatingConfigurationEntryStoreParameters<T> {
|
|
||||||
|
|
||||||
private final TypedStoreParametersImpl<T> parameters = new TypedStoreParametersImpl<>();
|
|
||||||
private final ConfigurationEntryStoreFactory factory;
|
|
||||||
|
|
||||||
TypedFloatingConfigurationEntryStoreParameters(ConfigurationEntryStoreFactory factory) {
|
|
||||||
this.factory = factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Builder {
|
|
||||||
|
|
||||||
Builder(Class<T> type) {
|
|
||||||
parameters.setType(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this to set the name for the {@link ConfigurationEntryStore}.
|
|
||||||
* @param name The name for the {@link ConfigurationEntryStore}.
|
|
||||||
* @return Floating API to either specify a repository or directly build a global {@link ConfigurationEntryStore}.
|
|
||||||
*/
|
|
||||||
public OptionalRepositoryBuilder withName(String name) {
|
|
||||||
parameters.setName(name);
|
|
||||||
return new OptionalRepositoryBuilder();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class OptionalRepositoryBuilder {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this to create or get a {@link ConfigurationEntryStore} for a specific repository. This step is optional. If
|
|
||||||
* you want to have a global {@link ConfigurationEntryStore}, omit this.
|
|
||||||
* @param repository The optional repository for the {@link ConfigurationEntryStore}.
|
|
||||||
* @return Floating API to finish the call.
|
|
||||||
*/
|
|
||||||
public OptionalRepositoryBuilder forRepository(Repository repository) {
|
|
||||||
parameters.setRepositoryId(repository.getId());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this to create or get a {@link ConfigurationEntryStore} for a specific repository. This step is optional. If
|
|
||||||
* you want to have a global {@link ConfigurationEntryStore}, omit this.
|
|
||||||
* @param repositoryId The id of the optional repository for the {@link ConfigurationEntryStore}.
|
|
||||||
* @return Floating API to finish the call.
|
|
||||||
*/
|
|
||||||
public OptionalRepositoryBuilder forRepository(String repositoryId) {
|
|
||||||
parameters.setRepositoryId(repositoryId);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates or gets the {@link ConfigurationEntryStore} with the given name and (if specified) the given repository.
|
|
||||||
* If no repository is given, the {@link ConfigurationEntryStore} will be global.
|
|
||||||
*/
|
|
||||||
public ConfigurationEntryStore<T> build(){
|
|
||||||
return factory.getStore(parameters);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,12 +21,10 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package sonia.scm.store;
|
package sonia.scm.store;
|
||||||
|
|
||||||
|
|
||||||
import sonia.scm.repository.Repository;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ConfigurationStoreFactory can be used to create new or get existing {@link ConfigurationStore} objects.
|
* The ConfigurationStoreFactory can be used to create new or get existing {@link ConfigurationStore} objects.
|
||||||
* <br>
|
* <br>
|
||||||
@@ -51,7 +49,7 @@ import sonia.scm.repository.Repository;
|
|||||||
* </pre></code>
|
* </pre></code>
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*
|
*
|
||||||
* @apiviz.landmark
|
* @apiviz.landmark
|
||||||
* @apiviz.uses sonia.scm.store.ConfigurationStore
|
* @apiviz.uses sonia.scm.store.ConfigurationStore
|
||||||
*/
|
*/
|
||||||
@@ -72,67 +70,7 @@ public interface ConfigurationStoreFactory {
|
|||||||
* @return Floating API to set the name and either specify a repository or directly build a global
|
* @return Floating API to set the name and either specify a repository or directly build a global
|
||||||
* {@link ConfigurationStore}.
|
* {@link ConfigurationStore}.
|
||||||
*/
|
*/
|
||||||
default <T> TypedFloatingConfigurationStoreParameters<T>.Builder withType(Class<T> type) {
|
default <T> TypedStoreParametersBuilder<T,ConfigurationStore<T>> withType(Class<T> type) {
|
||||||
return new TypedFloatingConfigurationStoreParameters<T>(this).new Builder(type);
|
return new TypedStoreParametersBuilder<>(type, this::getStore);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final class TypedFloatingConfigurationStoreParameters<T> {
|
|
||||||
|
|
||||||
private final TypedStoreParametersImpl<T> parameters = new TypedStoreParametersImpl<>();
|
|
||||||
private final ConfigurationStoreFactory factory;
|
|
||||||
|
|
||||||
TypedFloatingConfigurationStoreParameters(ConfigurationStoreFactory factory) {
|
|
||||||
this.factory = factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Builder {
|
|
||||||
|
|
||||||
Builder(Class<T> type) {
|
|
||||||
parameters.setType(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this to set the name for the {@link ConfigurationStore}.
|
|
||||||
* @param name The name for the {@link ConfigurationStore}.
|
|
||||||
* @return Floating API to either specify a repository or directly build a global {@link ConfigurationStore}.
|
|
||||||
*/
|
|
||||||
public OptionalRepositoryBuilder withName(String name) {
|
|
||||||
parameters.setName(name);
|
|
||||||
return new OptionalRepositoryBuilder();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class OptionalRepositoryBuilder {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this to create or get a {@link ConfigurationStore} for a specific repository. This step is optional. If you
|
|
||||||
* want to have a global {@link ConfigurationStore}, omit this.
|
|
||||||
* @param repository The optional repository for the {@link ConfigurationStore}.
|
|
||||||
* @return Floating API to finish the call.
|
|
||||||
*/
|
|
||||||
public OptionalRepositoryBuilder forRepository(Repository repository) {
|
|
||||||
parameters.setRepositoryId(repository.getId());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this to create or get a {@link ConfigurationStore} for a specific repository. This step is optional. If you
|
|
||||||
* want to have a global {@link ConfigurationStore}, omit this.
|
|
||||||
* @param repositoryId The id of the optional repository for the {@link ConfigurationStore}.
|
|
||||||
* @return Floating API to finish the call.
|
|
||||||
*/
|
|
||||||
public OptionalRepositoryBuilder forRepository(String repositoryId) {
|
|
||||||
parameters.setRepositoryId(repositoryId);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates or gets the {@link ConfigurationStore} with the given name and (if specified) the given repository. If no
|
|
||||||
* repository is given, the {@link ConfigurationStore} will be global.
|
|
||||||
*/
|
|
||||||
public ConfigurationStore<T> build(){
|
|
||||||
return factory.getStore(parameters);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,8 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package sonia.scm.store;
|
|
||||||
|
|
||||||
import sonia.scm.repository.Repository;
|
package sonia.scm.store;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The DataStoreFactory can be used to create new or get existing {@link DataStore}s.
|
* The DataStoreFactory can be used to create new or get existing {@link DataStore}s.
|
||||||
@@ -48,7 +46,7 @@ import sonia.scm.repository.Repository;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
* @since 1.23
|
* @since 1.23
|
||||||
*
|
*
|
||||||
* @apiviz.landmark
|
* @apiviz.landmark
|
||||||
* @apiviz.uses sonia.scm.store.DataStore
|
* @apiviz.uses sonia.scm.store.DataStore
|
||||||
*/
|
*/
|
||||||
@@ -69,67 +67,7 @@ public interface DataStoreFactory {
|
|||||||
* @return Floating API to set the name and either specify a repository or directly build a global
|
* @return Floating API to set the name and either specify a repository or directly build a global
|
||||||
* {@link DataStore}.
|
* {@link DataStore}.
|
||||||
*/
|
*/
|
||||||
default <T> TypedFloatingDataStoreParameters<T>.Builder withType(Class<T> type) {
|
default <T> TypedStoreParametersBuilder<T, DataStore<T>> withType(Class<T> type) {
|
||||||
return new TypedFloatingDataStoreParameters<T>(this).new Builder(type);
|
return new TypedStoreParametersBuilder<>(type, this::getStore);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final class TypedFloatingDataStoreParameters<T> {
|
|
||||||
|
|
||||||
private final TypedStoreParametersImpl<T> parameters = new TypedStoreParametersImpl<>();
|
|
||||||
private final DataStoreFactory factory;
|
|
||||||
|
|
||||||
TypedFloatingDataStoreParameters(DataStoreFactory factory) {
|
|
||||||
this.factory = factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Builder {
|
|
||||||
|
|
||||||
Builder(Class<T> type) {
|
|
||||||
parameters.setType(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this to set the name for the {@link DataStore}.
|
|
||||||
* @param name The name for the {@link DataStore}.
|
|
||||||
* @return Floating API to either specify a repository or directly build a global {@link DataStore}.
|
|
||||||
*/
|
|
||||||
public OptionalRepositoryBuilder withName(String name) {
|
|
||||||
parameters.setName(name);
|
|
||||||
return new OptionalRepositoryBuilder();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class OptionalRepositoryBuilder {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this to create or get a {@link DataStore} for a specific repository. This step is optional. If you
|
|
||||||
* want to have a global {@link DataStore}, omit this.
|
|
||||||
* @param repository The optional repository for the {@link DataStore}.
|
|
||||||
* @return Floating API to finish the call.
|
|
||||||
*/
|
|
||||||
public OptionalRepositoryBuilder forRepository(Repository repository) {
|
|
||||||
parameters.setRepositoryId(repository.getId());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this to create or get a {@link DataStore} for a specific repository. This step is optional. If you
|
|
||||||
* want to have a global {@link DataStore}, omit this.
|
|
||||||
* @param repositoryId The id of the optional repository for the {@link DataStore}.
|
|
||||||
* @return Floating API to finish the call.
|
|
||||||
*/
|
|
||||||
public OptionalRepositoryBuilder forRepository(String repositoryId) {
|
|
||||||
parameters.setRepositoryId(repositoryId);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates or gets the {@link DataStore} with the given name and (if specified) the given repository. If no
|
|
||||||
* repository is given, the {@link DataStore} will be global.
|
|
||||||
*/
|
|
||||||
public DataStore<T> build(){
|
|
||||||
return factory.getStore(parameters);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,8 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package sonia.scm.store;
|
|
||||||
|
|
||||||
import sonia.scm.repository.Repository;
|
package sonia.scm.store;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The fields of the {@link StoreParameters} are used from the {@link BlobStoreFactory} to create a store.
|
* The fields of the {@link StoreParameters} are used from the {@link BlobStoreFactory} to create a store.
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package sonia.scm.store;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import sonia.scm.repository.Repository;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder for {@link StoreParameters}.
|
||||||
|
*
|
||||||
|
* @param <S> type of store
|
||||||
|
*/
|
||||||
|
public final class StoreParametersBuilder<S> {
|
||||||
|
|
||||||
|
private final StoreParametersImpl parameters;
|
||||||
|
private final Function<StoreParameters, S> factory;
|
||||||
|
|
||||||
|
StoreParametersBuilder(String name, Function<StoreParameters, S> factory) {
|
||||||
|
this.parameters = new StoreParametersImpl(name);
|
||||||
|
this.factory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter(AccessLevel.PRIVATE)
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
private static class StoreParametersImpl implements StoreParameters {
|
||||||
|
private final String name;
|
||||||
|
private String repositoryId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this to create or get a store for a specific repository. This step is optional. If you want to
|
||||||
|
* have a global store, omit this.
|
||||||
|
*
|
||||||
|
* @param repository The optional repository for the store.
|
||||||
|
* @return Floating API to finish the call.
|
||||||
|
*/
|
||||||
|
public StoreParametersBuilder<S> forRepository(Repository repository) {
|
||||||
|
parameters.repositoryId = repository.getId();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this to create or get a store for a specific repository. This step is optional. If you want to
|
||||||
|
* have a global store, omit this.
|
||||||
|
*
|
||||||
|
* @param repositoryId The id of the optional repository for the store.
|
||||||
|
* @return Floating API to finish the call.
|
||||||
|
*/
|
||||||
|
public StoreParametersBuilder<S> forRepository(String repositoryId) {
|
||||||
|
parameters.repositoryId = repositoryId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates or gets the store with the given name and (if specified) the given repository. If no
|
||||||
|
* repository is given, the store will be global.
|
||||||
|
*/
|
||||||
|
public S build() {
|
||||||
|
return factory.apply(parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,10 +21,8 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package sonia.scm.store;
|
|
||||||
|
|
||||||
import sonia.scm.repository.Repository;
|
package sonia.scm.store;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The fields of the {@link TypedStoreParameters} are used from the {@link ConfigurationStoreFactory},
|
* The fields of the {@link TypedStoreParameters} are used from the {@link ConfigurationStoreFactory},
|
||||||
@@ -33,11 +31,8 @@ import sonia.scm.repository.Repository;
|
|||||||
* @author Mohamed Karray
|
* @author Mohamed Karray
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public interface TypedStoreParameters<T> {
|
public interface TypedStoreParameters<T> extends StoreParameters {
|
||||||
|
|
||||||
Class<T> getType();
|
Class<T> getType();
|
||||||
|
|
||||||
String getName();
|
|
||||||
|
|
||||||
String getRepositoryId();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package sonia.scm.store;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import sonia.scm.repository.Repository;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder for {@link TypedStoreParameters}.
|
||||||
|
*
|
||||||
|
* @param <T> type of data
|
||||||
|
* @param <S> type of store
|
||||||
|
*/
|
||||||
|
public final class TypedStoreParametersBuilder<T,S> {
|
||||||
|
|
||||||
|
private final TypedStoreParametersImpl<T> parameters;
|
||||||
|
private final Function<TypedStoreParameters<T>, S> factory;
|
||||||
|
|
||||||
|
TypedStoreParametersBuilder(Class<T> type, Function<TypedStoreParameters<T>, S> factory) {
|
||||||
|
this.factory = factory;
|
||||||
|
this.parameters = new TypedStoreParametersImpl<>(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this to set the name for the store.
|
||||||
|
* @param name The name for the store.
|
||||||
|
* @return Floating API to either specify a repository or directly build a global store.
|
||||||
|
*/
|
||||||
|
public OptionalRepositoryBuilder withName(String name) {
|
||||||
|
parameters.setName(name);
|
||||||
|
return new OptionalRepositoryBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter(AccessLevel.PRIVATE)
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
private static class TypedStoreParametersImpl<T> implements TypedStoreParameters<T> {
|
||||||
|
private final Class<T> type;
|
||||||
|
private String name;
|
||||||
|
private String repositoryId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class OptionalRepositoryBuilder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this to create or get a store for a specific repository. This step is optional. If you
|
||||||
|
* want to have a global store, omit this.
|
||||||
|
* @param repository The optional repository for the store.
|
||||||
|
* @return Floating API to finish the call.
|
||||||
|
*/
|
||||||
|
public OptionalRepositoryBuilder forRepository(Repository repository) {
|
||||||
|
parameters.setRepositoryId(repository.getId());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this to create or get a store for a specific repository. This step is optional. If you
|
||||||
|
* want to have a global store, omit this.
|
||||||
|
* @param repositoryId The id of the optional repository for the store.
|
||||||
|
* @return Floating API to finish the call.
|
||||||
|
*/
|
||||||
|
public OptionalRepositoryBuilder forRepository(String repositoryId) {
|
||||||
|
parameters.setRepositoryId(repositoryId);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates or gets the store with the given name and (if specified) the given repository. If no
|
||||||
|
* repository is given, the store will be global.
|
||||||
|
*/
|
||||||
|
public S build(){
|
||||||
|
return factory.apply(parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package sonia.scm.store;
|
|
||||||
|
|
||||||
class TypedStoreParametersImpl<T> implements TypedStoreParameters<T> {
|
|
||||||
private Class<T> type;
|
|
||||||
private String name;
|
|
||||||
private String repositoryId;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<T> getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setType(Class<T> type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getRepositoryId() {
|
|
||||||
return repositoryId;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setRepositoryId(String repositoryId) {
|
|
||||||
this.repositoryId = repositoryId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package sonia.scm.store;
|
package sonia.scm.store;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
@@ -52,7 +52,7 @@ public class JAXBDataStoreTest extends DataStoreTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DataStore getDataStore(Class type, Repository repository) {
|
protected <T> DataStore<T> getDataStore(Class<T> type, Repository repository) {
|
||||||
return createDataStoreFactory()
|
return createDataStoreFactory()
|
||||||
.withType(type)
|
.withType(type)
|
||||||
.withName("test")
|
.withName("test")
|
||||||
@@ -61,7 +61,7 @@ public class JAXBDataStoreTest extends DataStoreTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DataStore getDataStore(Class type) {
|
protected <T> DataStore<T> getDataStore(Class<T> type) {
|
||||||
return createDataStoreFactory()
|
return createDataStoreFactory()
|
||||||
.withType(type)
|
.withType(type)
|
||||||
.withName("test")
|
.withName("test")
|
||||||
|
|||||||
@@ -21,13 +21,12 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package sonia.scm.store;
|
package sonia.scm.store;
|
||||||
|
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public abstract class ConfigurationEntryStoreTestBase extends KeyValueStoreTestBase {
|
public abstract class ConfigurationEntryStoreTestBase extends KeyValueStoreTestBase {
|
||||||
@@ -35,26 +34,25 @@ public abstract class ConfigurationEntryStoreTestBase extends KeyValueStoreTestB
|
|||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected abstract ConfigurationEntryStoreFactory createConfigurationStoreFactory();
|
protected abstract ConfigurationEntryStoreFactory createConfigurationStoreFactory();
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
@Override
|
@Override
|
||||||
protected ConfigurationEntryStore getDataStore(Class type) {
|
protected <T> ConfigurationEntryStore<T> getDataStore(Class<T> type) {
|
||||||
return this.createConfigurationStoreFactory()
|
return this.createConfigurationStoreFactory()
|
||||||
.withType(type)
|
.withType(type)
|
||||||
.withName(storeName)
|
.withName(storeName)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ConfigurationEntryStore getDataStore(Class type, Repository repository) {
|
protected <T> ConfigurationEntryStore<T> getDataStore(Class<T> type, Repository repository) {
|
||||||
return this.createConfigurationStoreFactory()
|
return this.createConfigurationStoreFactory()
|
||||||
.withType(type)
|
.withType(type)
|
||||||
.withName(repoStoreName)
|
.withName(repoStoreName)
|
||||||
.forRepository(repository)
|
.forRepository(repository)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user