mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 22:15:45 +01:00
improve performance
This commit is contained in:
@@ -46,6 +46,7 @@ import sonia.scm.ConfigurationException;
|
||||
import sonia.scm.HandlerEvent;
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.StoreException;
|
||||
import sonia.scm.Type;
|
||||
import sonia.scm.repository.AbstractRepositoryManager;
|
||||
import sonia.scm.repository.PermissionType;
|
||||
@@ -73,7 +74,10 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXB;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -114,6 +118,19 @@ public class XmlRepositoryManager extends AbstractRepositoryManager
|
||||
{
|
||||
addHandler(handler);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
JAXBContext context =
|
||||
JAXBContext.newInstance(XmlRepositoryDatabase.class);
|
||||
|
||||
marshaller = context.createMarshaller();
|
||||
unmarshaller = context.createUnmarshaller();
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
throw new StoreException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -497,8 +514,15 @@ public class XmlRepositoryManager extends AbstractRepositoryManager
|
||||
*/
|
||||
private void loadDB()
|
||||
{
|
||||
repositoryDB = JAXB.unmarshal(repositoryDBFile,
|
||||
XmlRepositoryDatabase.class);
|
||||
try
|
||||
{
|
||||
repositoryDB =
|
||||
(XmlRepositoryDatabase) unmarshaller.unmarshal(repositoryDBFile);
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
throw new StoreException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -506,9 +530,16 @@ public class XmlRepositoryManager extends AbstractRepositoryManager
|
||||
*
|
||||
*/
|
||||
private void storeDB()
|
||||
{
|
||||
try
|
||||
{
|
||||
repositoryDB.setLastModified(System.currentTimeMillis());
|
||||
JAXB.marshal(repositoryDB, repositoryDBFile);
|
||||
marshaller.marshal(repositoryDB, repositoryDBFile);
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
throw new StoreException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
@@ -581,6 +612,9 @@ public class XmlRepositoryManager extends AbstractRepositoryManager
|
||||
/** Field description */
|
||||
private Map<String, RepositoryHandler> handlerMap;
|
||||
|
||||
/** Field description */
|
||||
private Marshaller marshaller;
|
||||
|
||||
/** Field description */
|
||||
private XmlRepositoryDatabase repositoryDB;
|
||||
|
||||
@@ -592,4 +626,7 @@ public class XmlRepositoryManager extends AbstractRepositoryManager
|
||||
|
||||
/** Field description */
|
||||
private Set<Type> types;
|
||||
|
||||
/** Field description */
|
||||
private Unmarshaller unmarshaller;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.StoreException;
|
||||
import sonia.scm.security.ScmSecurityException;
|
||||
import sonia.scm.security.SecurityContext;
|
||||
import sonia.scm.user.AbstractUserManager;
|
||||
@@ -63,6 +64,10 @@ import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import javax.xml.bind.JAXB;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -98,6 +103,18 @@ public class XmlUserManager extends AbstractUserManager
|
||||
public XmlUserManager(Provider<SecurityContext> scurityContextProvider)
|
||||
{
|
||||
this.scurityContextProvider = scurityContextProvider;
|
||||
|
||||
try
|
||||
{
|
||||
JAXBContext context = JAXBContext.newInstance(XmlUserDatabase.class);
|
||||
|
||||
marshaller = context.createMarshaller();
|
||||
unmarshaller = context.createUnmarshaller();
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
throw new StoreException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -384,7 +401,14 @@ public class XmlUserManager extends AbstractUserManager
|
||||
*/
|
||||
private void loadDB()
|
||||
{
|
||||
userDB = JAXB.unmarshal(userDBFile, XmlUserDatabase.class);
|
||||
try
|
||||
{
|
||||
userDB = (XmlUserDatabase) unmarshaller.unmarshal(userDBFile);
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
throw new StoreException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -392,16 +416,29 @@ public class XmlUserManager extends AbstractUserManager
|
||||
*
|
||||
*/
|
||||
private void storeDB()
|
||||
{
|
||||
try
|
||||
{
|
||||
userDB.setLastModified(System.currentTimeMillis());
|
||||
JAXB.marshal(userDB, userDBFile);
|
||||
marshaller.marshal(userDB, userDBFile);
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
throw new StoreException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private Marshaller marshaller;
|
||||
|
||||
/** Field description */
|
||||
private Provider<SecurityContext> scurityContextProvider;
|
||||
|
||||
/** Field description */
|
||||
private Unmarshaller unmarshaller;
|
||||
|
||||
/** Field description */
|
||||
private XmlUserDatabase userDB;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user