Split up store parameters into typed and untyped

This commit is contained in:
René Pfeuffer
2018-12-04 09:23:12 +01:00
parent 3021bea65a
commit 8952e755df
11 changed files with 50 additions and 26 deletions

View File

@@ -64,14 +64,12 @@ final class FloatingStoreParameters implements StoreParameters {
this.factory = factory;
}
public Class getType() {
return null;
}
@Override
public String getName() {
return name;
}
@Override
public Repository getRepository() {
return repository;
}

View File

@@ -48,14 +48,14 @@ import sonia.scm.repository.Repository;
* @apiviz.uses sonia.scm.store.ConfigurationEntryStore
*/
public interface ConfigurationEntryStoreFactory {
<T> ConfigurationEntryStore<T> getStore(final StoreParameters storeParameters);
<T> ConfigurationEntryStore<T> getStore(final TypedStoreParameters<T> storeParameters);
default <T> TypedFloatingConfigurationEntryStoreParameters<T>.Builder withType(Class<T> type) {
return new TypedFloatingConfigurationEntryStoreParameters<T>(this).new Builder(type);
}
}
final class TypedFloatingConfigurationEntryStoreParameters<T> implements StoreParameters {
final class TypedFloatingConfigurationEntryStoreParameters<T> implements TypedStoreParameters<T> {
private Class<T> type;
private String name;
@@ -67,14 +67,17 @@ final class TypedFloatingConfigurationEntryStoreParameters<T> implements StorePa
this.factory = factory;
}
@Override
public Class<T> getType() {
return type;
}
@Override
public String getName() {
return name;
}
@Override
public Repository getRepository() {
return repository;
}

View File

@@ -48,14 +48,14 @@ import sonia.scm.repository.Repository;
* @apiviz.uses sonia.scm.store.ConfigurationStore
*/
public interface ConfigurationStoreFactory {
<T> ConfigurationStore<T> getStore(final StoreParameters storeParameters);
<T> ConfigurationStore<T> getStore(final TypedStoreParameters<T> storeParameters);
default <T> TypedFloatingConfigurationStoreParameters<T>.Builder withType(Class<T> type) {
return new TypedFloatingConfigurationStoreParameters<T>(this).new Builder(type);
}
}
final class TypedFloatingConfigurationStoreParameters<T> implements StoreParameters {
final class TypedFloatingConfigurationStoreParameters<T> implements TypedStoreParameters<T> {
private Class<T> type;
private String name;
@@ -67,14 +67,17 @@ final class TypedFloatingConfigurationStoreParameters<T> implements StoreParamet
this.factory = factory;
}
@Override
public Class<T> getType() {
return type;
}
@Override
public String getName() {
return name;
}
@Override
public Repository getRepository() {
return repository;
}

View File

@@ -45,14 +45,14 @@ import sonia.scm.repository.Repository;
* @apiviz.uses sonia.scm.store.DataStore
*/
public interface DataStoreFactory {
<T> DataStore<T> getStore(final StoreParameters storeParameters);
<T> DataStore<T> getStore(final TypedStoreParameters<T> storeParameters);
default <T> TypedFloatingDataStoreParameters<T>.Builder withType(Class<T> type) {
return new TypedFloatingDataStoreParameters<T>(this).new Builder(type);
}
}
final class TypedFloatingDataStoreParameters<T> implements StoreParameters {
final class TypedFloatingDataStoreParameters<T> implements TypedStoreParameters<T> {
private Class<T> type;
private String name;
@@ -64,14 +64,17 @@ final class TypedFloatingDataStoreParameters<T> implements StoreParameters {
this.factory = factory;
}
@Override
public Class<T> getType() {
return type;
}
@Override
public String getName() {
return name;
}
@Override
public Repository getRepository() {
return repository;
}

View File

@@ -3,14 +3,12 @@ package sonia.scm.store;
import sonia.scm.repository.Repository;
/**
* The fields of the {@link StoreParameters} are used from the {@link StoreFactory} to create a store.
* The fields of the {@link StoreParameters} are used from the {@link BlobStoreFactory} to create a store.
*
* @author Mohamed Karray
* @since 2.0.0
*/
public interface StoreParameters<T> {
Class<T> getType();
public interface StoreParameters {
String getName();

View File

@@ -0,0 +1,19 @@
package sonia.scm.store;
import sonia.scm.repository.Repository;
/**
* The fields of the {@link TypedStoreParameters} are used from the {@link ConfigurationStoreFactory},
* {@link ConfigurationEntryStoreFactory} and {@link DataStoreFactory} to create a type safe store.
*
* @author Mohamed Karray
* @since 2.0.0
*/
public interface TypedStoreParameters<T> {
Class<T> getType();
String getName();
Repository getRepository();
}

View File

@@ -67,6 +67,10 @@ public abstract class FileBasedStoreFactory {
}
protected File getStoreLocation(StoreParameters storeParameters) {
return getStoreLocation(storeParameters.getName(), null, storeParameters.getRepository());
}
protected File getStoreLocation(TypedStoreParameters storeParameters) {
return getStoreLocation(storeParameters.getName(), storeParameters.getType(), storeParameters.getRepository());
}

View File

@@ -58,9 +58,8 @@ public class JAXBConfigurationEntryStoreFactory extends FileBasedStoreFactory
}
@Override
@SuppressWarnings("unchecked")
public ConfigurationEntryStore getStore(StoreParameters storeParameters) {
return new JAXBConfigurationEntryStore(getStoreLocation(storeParameters.getName().concat(StoreConstants.FILE_EXTENSION), storeParameters.getType(), storeParameters.getRepository()), keyGenerator, storeParameters.getType());
public <T> ConfigurationEntryStore<T> getStore(TypedStoreParameters<T> storeParameters) {
return new JAXBConfigurationEntryStore<>(getStoreLocation(storeParameters.getName().concat(StoreConstants.FILE_EXTENSION), storeParameters.getType(), storeParameters.getRepository()), keyGenerator, storeParameters.getType());
}
}

View File

@@ -36,7 +36,7 @@ import sonia.scm.SCMContextProvider;
import sonia.scm.repository.RepositoryLocationResolver;
/**
* JAXB implementation of {@link StoreFactory}.
* JAXB implementation of {@link ConfigurationStoreFactory}.
*
* @author Sebastian Sdorra
*/
@@ -54,8 +54,7 @@ public class JAXBConfigurationStoreFactory extends FileBasedStoreFactory impleme
}
@Override
@SuppressWarnings("unchecked")
public JAXBConfigurationStore getStore(StoreParameters storeParameters) {
return new JAXBConfigurationStore(storeParameters.getType(), getStoreLocation(storeParameters.getName().concat(StoreConstants.FILE_EXTENSION), storeParameters.getType(), storeParameters.getRepository()));
public <T> JAXBConfigurationStore<T> getStore(TypedStoreParameters<T> storeParameters) {
return new JAXBConfigurationStore<>(storeParameters.getType(), getStoreLocation(storeParameters.getName().concat(StoreConstants.FILE_EXTENSION), storeParameters.getType(), storeParameters.getRepository()));
}
}

View File

@@ -55,7 +55,6 @@ import java.io.File;
public class JAXBDataStoreFactory extends FileBasedStoreFactory
implements DataStoreFactory {
private static final Logger logger = LoggerFactory.getLogger(JAXBDataStoreFactory.class);
private KeyGenerator keyGenerator;
@Inject
@@ -65,10 +64,9 @@ public class JAXBDataStoreFactory extends FileBasedStoreFactory
}
@Override
@SuppressWarnings("unchecked")
public DataStore getStore(StoreParameters storeParameters) {
public <T> DataStore<T> getStore(TypedStoreParameters<T> storeParameters) {
File storeLocation = getStoreLocation(storeParameters);
IOUtil.mkdirs(storeLocation);
return new JAXBDataStore(keyGenerator, storeParameters.getType(), storeLocation);
return new JAXBDataStore<>(keyGenerator, storeParameters.getType(), storeLocation);
}
}

View File

@@ -43,7 +43,7 @@ package sonia.scm.store;
public class InMemoryConfigurationStoreFactory implements ConfigurationStoreFactory {
@Override
public ConfigurationStore getStore(StoreParameters storeParameters) {
public ConfigurationStore getStore(TypedStoreParameters storeParameters) {
return new InMemoryConfigurationStore<>();
}
}