mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-16 10:16:16 +01:00
Use copy on write in JAXB store implementations
This commit is contained in:
@@ -317,8 +317,9 @@ public class JAXBConfigurationEntryStore<V> implements ConfigurationEntryStore<V
|
|||||||
{
|
{
|
||||||
logger.debug("store configuration to {}", file);
|
logger.debug("store configuration to {}", file);
|
||||||
|
|
||||||
try (IndentXMLStreamWriter writer = XmlStreams.createWriter(file))
|
CopyOnWrite.withTemporaryFile(
|
||||||
{
|
temp -> {
|
||||||
|
try (IndentXMLStreamWriter writer = XmlStreams.createWriter(temp)) {
|
||||||
writer.writeStartDocument();
|
writer.writeStartDocument();
|
||||||
|
|
||||||
// configuration start
|
// configuration start
|
||||||
@@ -328,8 +329,7 @@ public class JAXBConfigurationEntryStore<V> implements ConfigurationEntryStore<V
|
|||||||
|
|
||||||
m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
|
m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
|
||||||
|
|
||||||
for (Entry<String, V> e : entries.entrySet())
|
for (Entry<String, V> e : entries.entrySet()) {
|
||||||
{
|
|
||||||
|
|
||||||
// entry start
|
// entry start
|
||||||
writer.writeStartElement(TAG_ENTRY);
|
writer.writeStartElement(TAG_ENTRY);
|
||||||
@@ -342,7 +342,7 @@ public class JAXBConfigurationEntryStore<V> implements ConfigurationEntryStore<V
|
|||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
|
|
||||||
// value
|
// value
|
||||||
JAXBElement<V> je = new JAXBElement<V>(QName.valueOf(TAG_VALUE), type,
|
JAXBElement<V> je = new JAXBElement<>(QName.valueOf(TAG_VALUE), type,
|
||||||
e.getValue());
|
e.getValue());
|
||||||
|
|
||||||
m.marshal(je, writer);
|
m.marshal(je, writer);
|
||||||
@@ -355,10 +355,9 @@ public class JAXBConfigurationEntryStore<V> implements ConfigurationEntryStore<V
|
|||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
writer.writeEndDocument();
|
writer.writeEndDocument();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
},
|
||||||
{
|
file.toPath()
|
||||||
throw new StoreException("could not store configuration", ex);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|||||||
@@ -113,7 +113,10 @@ public class JAXBConfigurationStore<T> extends AbstractStore<T> {
|
|||||||
Marshaller marshaller = context.createMarshaller();
|
Marshaller marshaller = context.createMarshaller();
|
||||||
|
|
||||||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
||||||
marshaller.marshal(object, configFile);
|
CopyOnWrite.withTemporaryFile(
|
||||||
|
temp -> marshaller.marshal(object, temp.toFile()),
|
||||||
|
configFile.toPath()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
catch (JAXBException ex) {
|
catch (JAXBException ex) {
|
||||||
throw new StoreException("failed to marshall object", ex);
|
throw new StoreException("failed to marshall object", ex);
|
||||||
|
|||||||
Reference in New Issue
Block a user