Use static method for new StoreParameters instance

This commit is contained in:
René Pfeuffer
2018-12-03 11:28:03 +01:00
parent ab8b3bae42
commit 3638d3520f
16 changed files with 85 additions and 89 deletions

View File

@@ -48,7 +48,8 @@ import java.io.File;
import java.io.IOException;
import sonia.scm.store.ConfigurationStore;
import sonia.scm.store.ConfigurationStoreFactory;
import sonia.scm.store.StoreParameters;
import static sonia.scm.store.StoreParameters.forType;
/**
@@ -74,10 +75,10 @@ public abstract class AbstractRepositoryHandler<C extends RepositoryConfig>
* @param storeFactory
*/
protected AbstractRepositoryHandler(ConfigurationStoreFactory storeFactory) {
this.store = storeFactory.getStore(new StoreParameters()
.withType(getConfigClass())
.withName(getType().getName())
.build()
this.store = storeFactory.getStore(
forType(getConfigClass())
.withName(getType().getName())
.build()
);
}

View File

@@ -26,8 +26,8 @@ public class StoreParameters {
return repository;
}
public WithType withType(Class type){
return new WithType(type);
public static WithType forType(Class type){
return new StoreParameters().new WithType(type);
}
public class WithType {

View File

@@ -39,11 +39,12 @@ import com.google.inject.Singleton;
import sonia.scm.group.Group;
import sonia.scm.group.GroupDAO;
import sonia.scm.store.StoreParameters;
import sonia.scm.xml.AbstractXmlDAO;
import sonia.scm.store.ConfigurationStoreFactory;
import static sonia.scm.store.StoreParameters.forType;
/**
*
* @author Sebastian Sdorra
@@ -66,10 +67,10 @@ public class XmlGroupDAO extends AbstractXmlDAO<Group, XmlGroupDatabase>
*/
@Inject
public XmlGroupDAO(ConfigurationStoreFactory storeFactory) {
super(storeFactory.getStore(new StoreParameters()
.withType(XmlGroupDatabase.class)
.withName(STORE_NAME)
.build()));
super(storeFactory.getStore(
forType(XmlGroupDatabase.class)
.withName(STORE_NAME)
.build()));
}
//~--- methods --------------------------------------------------------------

View File

@@ -73,10 +73,10 @@ public abstract class FileBasedStoreFactory {
protected File getStoreLocation(String name, Class type, Repository repository) {
if (storeDirectory == null) {
if (repository != null) {
LOG.debug("create store with type :{}, name:{} and repository {}", type, name, repository.getNamespaceAndName());
LOG.debug("create store with type: {}, name: {} and repository: {}", type, name, repository.getNamespaceAndName());
storeDirectory = this.getStoreDirectory(store, repository);
} else {
LOG.debug("create store with type :{} and name:{} ", type, name);
LOG.debug("create store with type: {} and name: {} ", type, name);
storeDirectory = this.getStoreDirectory(store);
}
IOUtil.mkdirs(storeDirectory);
@@ -91,7 +91,7 @@ public abstract class FileBasedStoreFactory {
* @return the store directory of a specific repository
*/
private File getStoreDirectory(Store store, Repository repository) {
return new File (repositoryLocationResolver.getPath(repository.getId()).toFile(), store.getRepositoryStoreDirectory());
return new File(repositoryLocationResolver.getPath(repository.getId()).toFile(), store.getRepositoryStoreDirectory());
}
/**

View File

@@ -36,12 +36,12 @@ package sonia.scm.user.xml;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import sonia.scm.store.StoreParameters;
import sonia.scm.store.ConfigurationStoreFactory;
import sonia.scm.user.User;
import sonia.scm.user.UserDAO;
import sonia.scm.xml.AbstractXmlDAO;
import sonia.scm.store.ConfigurationStoreFactory;
import static sonia.scm.store.StoreParameters.forType;
/**
*
@@ -66,10 +66,10 @@ public class XmlUserDAO extends AbstractXmlDAO<User, XmlUserDatabase>
@Inject
public XmlUserDAO(ConfigurationStoreFactory storeFactory)
{
super(storeFactory.getStore(new StoreParameters()
.withType(XmlUserDatabase.class)
.withName(STORE_NAME)
.build()));
super(storeFactory.getStore(
forType(XmlUserDatabase.class)
.withName(STORE_NAME)
.build()));
}
//~--- methods --------------------------------------------------------------

View File

@@ -42,6 +42,7 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static sonia.scm.store.StoreParameters.forType;
/**
*
@@ -65,11 +66,11 @@ public class FileBlobStoreTest extends BlobStoreTestBase
@Test
@SuppressWarnings("unchecked")
public void shouldStoreAndLoadInRepository() {
BlobStore store = createBlobStoreFactory().getStore(new StoreParameters()
.withType(StoreObject.class)
.withName("test")
.forRepository(new Repository("id", "git", "ns", "n"))
.build());
BlobStore store = createBlobStoreFactory().getStore(
forType(StoreObject.class)
.withName("test")
.forRepository(new Repository("id", "git", "ns", "n"))
.build());
Blob createdBlob = store.create("abc");
List<Blob> storedBlobs = store.getAll();

View File

@@ -50,6 +50,7 @@ import java.util.UUID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static sonia.scm.store.StoreParameters.forType;
//~--- JDK imports ------------------------------------------------------------
@@ -132,10 +133,10 @@ public class JAXBConfigurationEntryStoreTest
ConfigurationEntryStore<AssignedPermission> store = createPermissionStore(RESOURCE_FIXED, name);
store.put("a45", new AssignedPermission("tuser4", "repository:create"));
store = createConfigurationStoreFactory().getStore(new StoreParameters()
.withType(AssignedPermission.class)
.withName(name)
.build());
store = createConfigurationStoreFactory().getStore(
forType(AssignedPermission.class)
.withName(name)
.build());
AssignedPermission ap = store.get("a45");
@@ -231,9 +232,9 @@ public class JAXBConfigurationEntryStoreTest
}
copy(resource, name);
return createConfigurationStoreFactory().getStore(new StoreParameters()
.withType(AssignedPermission.class)
.withName(name)
.build());
return createConfigurationStoreFactory().getStore(
forType(AssignedPermission.class)
.withName(name)
.build());
}
}

View File

@@ -39,6 +39,7 @@ import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static sonia.scm.store.StoreParameters.forType;
/**
* Unit tests for {@link JAXBConfigurationStore}.
@@ -58,11 +59,11 @@ public class JAXBConfigurationStoreTest extends StoreTestBase {
@SuppressWarnings("unchecked")
public void shouldStoreAndLoadInRepository() throws IOException
{
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(new StoreParameters()
.withType(StoreObject.class)
.withName("test")
.forRepository(new Repository("id", "git", "ns", "n"))
.build());
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(
forType(StoreObject.class)
.withName("test")
.forRepository(new Repository("id", "git", "ns", "n"))
.build());
store.set(new StoreObject("value"));
StoreObject storeObject = store.get();

View File

@@ -38,10 +38,9 @@ import org.junit.Test;
import sonia.scm.repository.Repository;
import sonia.scm.security.UUIDKeyGenerator;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static sonia.scm.store.StoreParameters.forType;
/**
*
@@ -63,25 +62,21 @@ public class JAXBDataStoreTest extends DataStoreTestBase {
@Override
protected DataStore getDataStore(Class type, Repository repository) {
StoreParameters params = new StoreParameters()
.withType(type)
return createDataStoreFactory().getStore(forType(type)
.withName("test")
.forRepository(repository)
.build();
return createDataStoreFactory().getStore(params);
.build());
}
@Override
protected DataStore getDataStore(Class type) {
StoreParameters params = new StoreParameters()
.withType(type)
return createDataStoreFactory().getStore(forType(type)
.withName("test")
.build();
return createDataStoreFactory().getStore(params);
.build());
}
@Test
public void shouldStoreAndLoadInRepository() throws IOException
public void shouldStoreAndLoadInRepository()
{
repoStore.put("abc", new StoreObject("abc_value"));
StoreObject storeObject = repoStore.get("abc");

View File

@@ -35,10 +35,10 @@ package sonia.scm.web.lfs;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import sonia.scm.repository.Repository;
import sonia.scm.store.Blob;
import sonia.scm.store.BlobStore;
import sonia.scm.store.BlobStoreFactory;
import sonia.scm.store.StoreParameters;
import static sonia.scm.store.StoreParameters.forType;
/**
* Creates {@link BlobStore} objects to store lfs objects.
@@ -78,11 +78,11 @@ public class LfsBlobStoreFactory {
*/
@SuppressWarnings("unchecked")
public BlobStore getLfsBlobStore(Repository repository) {
return blobStoreFactory.getStore(new StoreParameters()
.withType(Blob.class)
.withName(repository.getId() + GIT_LFS_REPOSITORY_POSTFIX)
.forRepository(repository)
.build()
return blobStoreFactory.getStore(
forType(String.class)
.withName(repository.getId() + GIT_LFS_REPOSITORY_POSTFIX)
.forRepository(repository)
.build()
);
}
}

View File

@@ -50,6 +50,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static sonia.scm.store.StoreParameters.forType;
//~--- JDK imports ------------------------------------------------------------
@@ -69,11 +70,11 @@ public abstract class BlobStoreTestBase extends AbstractTestBase
@Before
public void createBlobStore()
{
store = createBlobStoreFactory().getStore(new StoreParameters()
.withType(Blob.class)
.withName("test")
.forRepository(RepositoryTestData.createHeartOfGold())
.build()
store = createBlobStoreFactory().getStore(
forType(Blob.class)
.withName("test")
.forRepository(RepositoryTestData.createHeartOfGold())
.build()
);
store.clear();
}

View File

@@ -34,6 +34,8 @@ package sonia.scm.store;
import sonia.scm.repository.Repository;
import static sonia.scm.store.StoreParameters.forType;
/**
*
* @author Sebastian Sdorra
@@ -51,8 +53,7 @@ public abstract class ConfigurationEntryStoreTestBase extends KeyValueStoreTestB
//~--- get methods ----------------------------------------------------------
@Override
protected ConfigurationEntryStore getDataStore(Class type) {
StoreParameters params = new StoreParameters()
.withType(type)
StoreParameters params = forType(type)
.withName(storeName)
.build();
return this.createConfigurationStoreFactory().getStore(params);
@@ -60,8 +61,7 @@ public abstract class ConfigurationEntryStoreTestBase extends KeyValueStoreTestB
@Override
protected ConfigurationEntryStore getDataStore(Class type, Repository repository) {
StoreParameters params = new StoreParameters()
.withType(type)
StoreParameters params = forType(type)
.withName(repoStoreName)
.forRepository(repository)
.build();

View File

@@ -39,6 +39,7 @@ import sonia.scm.repository.RepositoryTestData;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static sonia.scm.store.StoreParameters.forType;
/**
*
@@ -56,9 +57,8 @@ public abstract class DataStoreTestBase extends KeyValueStoreTestBase
protected abstract DataStoreFactory createDataStoreFactory();
protected StoreParameters getStoreParametersWithRepository(Repository repository) {
return new StoreParameters()
.withType(StoreObject.class)
protected StoreParameters getStoreParametersWithRepository(Repository repository) {
return forType(StoreObject.class)
.withName("test")
.forRepository(repository)
.build();

View File

@@ -36,11 +36,11 @@ package sonia.scm.store;
import org.junit.Test;
import sonia.scm.AbstractTestBase;
import sonia.scm.repository.Repository;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static sonia.scm.store.StoreParameters.forType;
//~--- JDK imports ------------------------------------------------------------
@@ -60,13 +60,6 @@ public abstract class StoreTestBase extends AbstractTestBase
*/
protected abstract ConfigurationStoreFactory createStoreFactory();
protected StoreParameters getStoreParameters() {
return new StoreParameters()
.withType(StoreObject.class)
.withName("test")
.build();
}
/**
* Method description
*
@@ -74,7 +67,7 @@ public abstract class StoreTestBase extends AbstractTestBase
@Test
public void testGet()
{
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(getStoreParameters());
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(forType(StoreObject.class).withName("test").build());
assertNotNull(store);
@@ -90,7 +83,7 @@ public abstract class StoreTestBase extends AbstractTestBase
@Test
public void testSet()
{
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(getStoreParameters());
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(forType(StoreObject.class).withName("test").build());
assertNotNull(store);

View File

@@ -77,6 +77,8 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import static sonia.scm.store.StoreParameters.forType;
/**
* TODO add events
*
@@ -112,10 +114,10 @@ public class DefaultSecuritySystem implements SecuritySystem
@SuppressWarnings("unchecked")
public DefaultSecuritySystem(ConfigurationEntryStoreFactory storeFactory)
{
store = storeFactory.getStore(new StoreParameters()
.withType(AssignedPermission.class)
.withName(NAME)
.build());
store = storeFactory.getStore(
forType(AssignedPermission.class)
.withName(NAME)
.build());
readAvailablePermissions();
}

View File

@@ -45,9 +45,9 @@ import org.slf4j.LoggerFactory;
import sonia.scm.store.ConfigurationEntryStore;
import sonia.scm.store.ConfigurationEntryStoreFactory;
import sonia.scm.store.StoreParameters;
import static com.google.common.base.Preconditions.*;
import static sonia.scm.store.StoreParameters.forType;
//~--- JDK imports ------------------------------------------------------------
@@ -91,10 +91,10 @@ public class SecureKeyResolver extends SigningKeyResolverAdapter
@SuppressWarnings("unchecked")
public SecureKeyResolver(ConfigurationEntryStoreFactory storeFactory)
{
store = storeFactory.getStore(new StoreParameters()
.withType(SecureKey.class)
.withName(STORE_NAME)
.build());
store = storeFactory.getStore(
forType(SecureKey.class)
.withName(STORE_NAME)
.build());
}
//~--- methods --------------------------------------------------------------