do not read stored objects on every get method call

This commit is contained in:
Sebastian Sdorra
2012-05-19 11:02:50 +02:00
parent caa0206202
commit a8d5e677de
3 changed files with 75 additions and 23 deletions

View File

@@ -52,6 +52,22 @@ import java.util.Set;
public abstract class AbstractListenableStore<T> implements ListenableStore<T> 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 * Method description
* *
@@ -88,6 +104,43 @@ public abstract class AbstractListenableStore<T> implements ListenableStore<T>
listeners.remove(listener); 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 * Method description
* *
@@ -105,5 +158,8 @@ public abstract class AbstractListenableStore<T> implements ListenableStore<T>
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** Field description */ /** Field description */
private Set<ConfigChangedListener<T>> listeners = Sets.newHashSet(); protected Set<ConfigChangedListener<T>> listeners = Sets.newHashSet();
/** Field description */
protected T storeObject;
} }

View File

@@ -45,7 +45,6 @@ import org.slf4j.LoggerFactory;
import sonia.scm.orientdb.OrientDBUtil; import sonia.scm.orientdb.OrientDBUtil;
import sonia.scm.store.AbstractListenableStore; import sonia.scm.store.AbstractListenableStore;
import sonia.scm.store.Store;
import sonia.scm.util.Util; import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------ //~--- JDK imports ------------------------------------------------------------
@@ -110,7 +109,7 @@ public class OrientDBStore<T> extends AbstractListenableStore<T>
this.name = name; this.name = name;
} }
//~--- get methods ---------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**
* Method description * Method description
@@ -119,7 +118,7 @@ public class OrientDBStore<T> extends AbstractListenableStore<T>
* @return * @return
*/ */
@Override @Override
public T get() protected T readObject()
{ {
T result = null; T result = null;
ODatabaseDocumentTx connection = connectionProvider.get(); ODatabaseDocumentTx connection = connectionProvider.get();
@@ -152,8 +151,6 @@ public class OrientDBStore<T> extends AbstractListenableStore<T>
return result; return result;
} }
//~--- set methods ----------------------------------------------------------
/** /**
* Method description * Method description
* *
@@ -161,7 +158,7 @@ public class OrientDBStore<T> extends AbstractListenableStore<T>
* @param t * @param t
*/ */
@Override @Override
public void set(T t) protected void writeObject(T t)
{ {
ODatabaseDocumentTx connection = connectionProvider.get(); ODatabaseDocumentTx connection = connectionProvider.get();

View File

@@ -84,6 +84,19 @@ public class JAXBStore<T> extends AbstractListenableStore<T>
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public Class<T> getType()
{
return type;
}
//~--- methods --------------------------------------------------------------
/** /**
* Method description * Method description
* *
@@ -91,7 +104,7 @@ public class JAXBStore<T> extends AbstractListenableStore<T>
* @return * @return
*/ */
@Override @Override
public T get() protected T readObject()
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
@@ -115,19 +128,6 @@ public class JAXBStore<T> extends AbstractListenableStore<T>
return result; return result;
} }
/**
* Method description
*
*
* @return
*/
public Class<T> getType()
{
return type;
}
//~--- set methods ----------------------------------------------------------
/** /**
* Method description * Method description
* *
@@ -135,7 +135,7 @@ public class JAXBStore<T> extends AbstractListenableStore<T>
* @param object * @param object
*/ */
@Override @Override
public void set(T object) protected void writeObject(T object)
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
@@ -149,7 +149,6 @@ public class JAXBStore<T> extends AbstractListenableStore<T>
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(object, configFile); marshaller.marshal(object, configFile);
fireEvent(object); fireEvent(object);
} }
catch (JAXBException ex) catch (JAXBException ex)