mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 23:15:43 +01:00
fix repository caching bug
This commit is contained in:
22
scm-core/src/main/java/sonia/scm/ConfigChangedListener.java
Normal file
22
scm-core/src/main/java/sonia/scm/ConfigChangedListener.java
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public interface ConfigChangedListener
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
public void configChanged(Object config);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.ConfigChangedListener;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
@@ -18,6 +19,8 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXB;
|
||||
@@ -42,6 +45,18 @@ public abstract class AbstractRepositoryHandler<C extends BasicRepositoryConfig>
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
@Override
|
||||
public void addListener(ConfigChangedListener listener)
|
||||
{
|
||||
listenerSet.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -84,6 +99,18 @@ public abstract class AbstractRepositoryHandler<C extends BasicRepositoryConfig>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
@Override
|
||||
public void removeListener(ConfigChangedListener listener)
|
||||
{
|
||||
listenerSet.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -132,6 +159,7 @@ public abstract class AbstractRepositoryHandler<C extends BasicRepositoryConfig>
|
||||
public void setConfig(C config)
|
||||
{
|
||||
this.config = config;
|
||||
fireConfigChanged();
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -174,6 +202,18 @@ public abstract class AbstractRepositoryHandler<C extends BasicRepositoryConfig>
|
||||
repository.setCreationDate(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
private void fireConfigChanged()
|
||||
{
|
||||
for (ConfigChangedListener listener : listenerSet)
|
||||
{
|
||||
listener.configChanged(config);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@@ -181,4 +221,8 @@ public abstract class AbstractRepositoryHandler<C extends BasicRepositoryConfig>
|
||||
|
||||
/** Field description */
|
||||
protected File configFile;
|
||||
|
||||
/** Field description */
|
||||
private Set<ConfigChangedListener> listenerSet =
|
||||
new HashSet<ConfigChangedListener>();
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ import javax.xml.bind.JAXB;
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public abstract class AbstractSimpleRepositoryHandler<T extends SimpleRepositoryConfig>
|
||||
extends AbstractRepositoryHandler<T>
|
||||
public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepositoryConfig>
|
||||
extends AbstractRepositoryHandler<C>
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
@@ -343,20 +343,13 @@ public abstract class AbstractSimpleRepositoryHandler<T extends SimpleRepository
|
||||
}
|
||||
else
|
||||
{
|
||||
String url = config.getBaseUrl();
|
||||
String url = buildUrl(repository);
|
||||
|
||||
if (Util.isNotEmpty(url))
|
||||
{
|
||||
if (!url.endsWith("/"))
|
||||
{
|
||||
url = url.concat("/");
|
||||
}
|
||||
|
||||
url = url.concat(repository.getName());
|
||||
}
|
||||
|
||||
repository.setUrl(url);
|
||||
}
|
||||
}
|
||||
|
||||
return repository;
|
||||
}
|
||||
|
||||
@@ -9,14 +9,19 @@ package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.ConfigChangedListener;
|
||||
import sonia.scm.Handler;
|
||||
import sonia.scm.ListenerSupport;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*
|
||||
* @param <C>
|
||||
*/
|
||||
public interface RepositoryHandler
|
||||
extends Handler<Repository, RepositoryException>
|
||||
extends Handler<Repository, RepositoryException>,
|
||||
ListenerSupport<ConfigChangedListener>
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,12 +10,16 @@ package sonia.scm.cache;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.name.Named;
|
||||
|
||||
import sonia.scm.ConfigChangedListener;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.Undecorated;
|
||||
import sonia.scm.repository.AbstractRepositoryManagerDecorator;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.RepositoryHandler;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
import sonia.scm.repository.RepositoryType;
|
||||
import sonia.scm.util.AssertUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
@@ -24,7 +28,6 @@ import sonia.scm.util.Util;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Collection;
|
||||
import sonia.scm.Undecorated;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -32,6 +35,7 @@ import sonia.scm.Undecorated;
|
||||
*/
|
||||
public class CacheRepositoryManagerDecorator
|
||||
extends AbstractRepositoryManagerDecorator
|
||||
implements ConfigChangedListener
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
@@ -51,8 +55,7 @@ public class CacheRepositoryManagerDecorator
|
||||
*/
|
||||
@Inject
|
||||
public CacheRepositoryManagerDecorator(
|
||||
@Undecorated RepositoryManager manager,
|
||||
CacheManager cacheManager)
|
||||
@Undecorated RepositoryManager manager, CacheManager cacheManager)
|
||||
{
|
||||
super(manager);
|
||||
cache = cacheManager.getExtendedCache(String.class, Repository.class,
|
||||
@@ -61,6 +64,31 @@ public class CacheRepositoryManagerDecorator
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param handler
|
||||
*/
|
||||
@Override
|
||||
public void addHandler(RepositoryHandler handler)
|
||||
{
|
||||
super.addHandler(handler);
|
||||
handler.addListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param config
|
||||
*/
|
||||
@Override
|
||||
public void configChanged(Object config)
|
||||
{
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -95,6 +123,23 @@ public class CacheRepositoryManagerDecorator
|
||||
removeFromCache(repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
@Override
|
||||
public void init(SCMContextProvider context)
|
||||
{
|
||||
super.init(context);
|
||||
|
||||
for (RepositoryType type : getTypes())
|
||||
{
|
||||
getHandler(type.getName()).addListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user