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

@@ -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");