From a504ddf5435e2085f7c0dcf1bf0adbe8ac27783e Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Thu, 20 Jun 2013 18:33:24 +0200 Subject: [PATCH 1/3] use reader instead of xmlsource to read configuration entry stores --- .../store/JAXBConfigurationEntryStore.java | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationEntryStore.java b/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationEntryStore.java index a4cfd6f454..96e0e1ad63 100644 --- a/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationEntryStore.java +++ b/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationEntryStore.java @@ -30,10 +30,12 @@ */ + package sonia.scm.store; //~--- non-JDK imports -------------------------------------------------------- +import com.google.common.base.Charsets; import com.google.common.base.Predicate; import com.google.common.collect.Collections2; import com.google.common.collect.Maps; @@ -47,7 +49,13 @@ import sonia.scm.xml.IndentXMLStreamWriter; //~--- JDK imports ------------------------------------------------------------ import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.Writer; import java.util.Collection; import java.util.Collections; @@ -65,7 +73,6 @@ import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; -import javax.xml.transform.stream.StreamSource; /** * @@ -294,6 +301,32 @@ public class JAXBConfigurationEntryStore } } + /** + * Method description + * + * + * @return + * + * @throws FileNotFoundException + */ + private Reader createReader() throws FileNotFoundException + { + return new InputStreamReader(new FileInputStream(file), Charsets.UTF_8); + } + + /** + * Method description + * + * + * @return + * + * @throws FileNotFoundException + */ + private Writer createWriter() throws FileNotFoundException + { + return new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8); + } + /** * Method description * @@ -312,7 +345,7 @@ public class JAXBConfigurationEntryStore { Unmarshaller u = context.createUnmarshaller(); - reader = xmlInputFactory.createXMLStreamReader(new StreamSource(file)); + reader = xmlInputFactory.createXMLStreamReader(createReader()); reader.nextTag(); reader.nextTag(); @@ -357,7 +390,7 @@ public class JAXBConfigurationEntryStore //J- writer = new IndentXMLStreamWriter( XMLOutputFactory.newFactory().createXMLStreamWriter( - new FileOutputStream(file) + createWriter() ) ); //J+ From 76217dc0efdc3179778d250053f4362801de1244 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Thu, 20 Jun 2013 18:36:51 +0200 Subject: [PATCH 2/3] do not synchronize over all configuration entry stores --- .../store/JAXBConfigurationEntryStore.java | 19 ++++++++----------- .../JAXBConfigurationEntryStoreFactory.java | 10 ++++++++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationEntryStore.java b/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationEntryStore.java index 96e0e1ad63..0d5bcc2540 100644 --- a/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationEntryStore.java +++ b/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationEntryStore.java @@ -84,9 +84,6 @@ public class JAXBConfigurationEntryStore implements ConfigurationEntryStore { - /** Field description */ - private static final Object LOCK = new Object(); - /** Field description */ private static final String TAG_CONFIGURATION = "configuration"; @@ -116,11 +113,11 @@ public class JAXBConfigurationEntryStore * @param file * @param type */ - JAXBConfigurationEntryStore(KeyGenerator keyGenerator, File file, + JAXBConfigurationEntryStore(File file, KeyGenerator keyGenerator, Class type) { - this.keyGenerator = keyGenerator; this.file = file; + this.keyGenerator = keyGenerator; this.type = type; try @@ -149,7 +146,7 @@ public class JAXBConfigurationEntryStore { logger.debug("clear configuration store"); - synchronized (LOCK) + synchronized (file) { entries.clear(); store(); @@ -186,7 +183,7 @@ public class JAXBConfigurationEntryStore { logger.debug("put item {} to configuration store", id); - synchronized (LOCK) + synchronized (file) { entries.put(id, item); store(); @@ -204,7 +201,7 @@ public class JAXBConfigurationEntryStore { logger.debug("remove item {} from configuration store", id); - synchronized (LOCK) + synchronized (file) { entries.remove(id); store(); @@ -429,15 +426,15 @@ public class JAXBConfigurationEntryStore //~--- fields --------------------------------------------------------------- + /** Field description */ + private final File file; + /** Field description */ private JAXBContext context; /** Field description */ private Map entries = Maps.newHashMap(); - /** Field description */ - private File file; - /** Field description */ private KeyGenerator keyGenerator; diff --git a/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationEntryStoreFactory.java b/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationEntryStoreFactory.java index c203452010..bf5dae720f 100644 --- a/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationEntryStoreFactory.java +++ b/scm-dao-xml/src/main/java/sonia/scm/store/JAXBConfigurationEntryStoreFactory.java @@ -30,6 +30,7 @@ */ + package sonia.scm.store; //~--- non-JDK imports -------------------------------------------------------- @@ -100,8 +101,13 @@ public class JAXBConfigurationEntryStoreFactory logger.debug("create new configuration store for type {} with name {}", type, name); - return new JAXBConfigurationEntryStore(keyGenerator, - new File(directory, name.concat(StoreConstants.FILE_EXTENSION)), type); + //J- + return new JAXBConfigurationEntryStore( + new File(directory,name.concat(StoreConstants.FILE_EXTENSION)), + keyGenerator, + type + ); + //J+ } //~--- fields --------------------------------------------------------------- From 9fbb031dab0a4b4ea611263e3f6376d30621284c Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 23 Jun 2013 18:44:55 +0200 Subject: [PATCH 3/3] close branch issue-405