mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 06:25:45 +01:00
do not read stored objects on every get method call
This commit is contained in:
@@ -52,6 +52,22 @@ import java.util.Set;
|
||||
public abstract class AbstractListenableStore<T> implements ListenableStore<T>
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract T readObject();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param object
|
||||
*/
|
||||
protected abstract void writeObject(T object);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -88,6 +104,43 @@ public abstract class AbstractListenableStore<T> implements ListenableStore<T>
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public T get()
|
||||
{
|
||||
if (storeObject == null)
|
||||
{
|
||||
storeObject = readObject();
|
||||
}
|
||||
|
||||
return storeObject;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param obejct
|
||||
*/
|
||||
@Override
|
||||
public void set(T obejct)
|
||||
{
|
||||
writeObject(obejct);
|
||||
this.storeObject = obejct;
|
||||
fireEvent(obejct);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -105,5 +158,8 @@ public abstract class AbstractListenableStore<T> implements ListenableStore<T>
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private Set<ConfigChangedListener<T>> listeners = Sets.newHashSet();
|
||||
protected Set<ConfigChangedListener<T>> listeners = Sets.newHashSet();
|
||||
|
||||
/** Field description */
|
||||
protected T storeObject;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.orientdb.OrientDBUtil;
|
||||
import sonia.scm.store.AbstractListenableStore;
|
||||
import sonia.scm.store.Store;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
@@ -110,7 +109,7 @@ public class OrientDBStore<T> extends AbstractListenableStore<T>
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
@@ -119,7 +118,7 @@ public class OrientDBStore<T> extends AbstractListenableStore<T>
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public T get()
|
||||
protected T readObject()
|
||||
{
|
||||
T result = null;
|
||||
ODatabaseDocumentTx connection = connectionProvider.get();
|
||||
@@ -152,8 +151,6 @@ public class OrientDBStore<T> extends AbstractListenableStore<T>
|
||||
return result;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -161,7 +158,7 @@ public class OrientDBStore<T> extends AbstractListenableStore<T>
|
||||
* @param t
|
||||
*/
|
||||
@Override
|
||||
public void set(T t)
|
||||
protected void writeObject(T t)
|
||||
{
|
||||
ODatabaseDocumentTx connection = connectionProvider.get();
|
||||
|
||||
|
||||
@@ -84,6 +84,19 @@ public class JAXBStore<T> extends AbstractListenableStore<T>
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Class<T> getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -91,7 +104,7 @@ public class JAXBStore<T> extends AbstractListenableStore<T>
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public T get()
|
||||
protected T readObject()
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
@@ -115,19 +128,6 @@ public class JAXBStore<T> extends AbstractListenableStore<T>
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Class<T> getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -135,7 +135,7 @@ public class JAXBStore<T> extends AbstractListenableStore<T>
|
||||
* @param object
|
||||
*/
|
||||
@Override
|
||||
public void set(T object)
|
||||
protected void writeObject(T object)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
@@ -149,7 +149,6 @@ public class JAXBStore<T> extends AbstractListenableStore<T>
|
||||
|
||||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
||||
marshaller.marshal(object, configFile);
|
||||
|
||||
fireEvent(object);
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
|
||||
Reference in New Issue
Block a user