[Fix] Fixed race condition in XmlExportModelCommand
This commit is contained in:
parent
5461d04f4e
commit
9801e8e543
|
@ -24,8 +24,8 @@ import java.nio.file.Files;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.xml.stream.XMLStreamWriter;
|
import javax.xml.stream.XMLStreamWriter;
|
||||||
|
@ -162,7 +162,7 @@ public class XmlExportModelCommand extends Command {
|
||||||
|
|
||||||
if (this.doResources) {
|
if (this.doResources) {
|
||||||
ResourceMap resourceMap = tx().getResourceMap();
|
ResourceMap resourceMap = tx().getResourceMap();
|
||||||
Set<String> resourceTypesToExport = new TreeSet<>(resourceMap.getTypes(tx()));
|
Set<String> resourceTypesToExport = resourceMap.getTypes(tx());
|
||||||
if (!this.resourceTypes.isEmpty())
|
if (!this.resourceTypes.isEmpty())
|
||||||
resourceTypesToExport.retainAll(this.resourceTypes);
|
resourceTypesToExport.retainAll(this.resourceTypes);
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ public class XmlExportModelCommand extends Command {
|
||||||
|
|
||||||
if (this.doOrders) {
|
if (this.doOrders) {
|
||||||
OrderMap orderMap = tx().getOrderMap();
|
OrderMap orderMap = tx().getOrderMap();
|
||||||
Set<String> orderTypesToExport = new TreeSet<>(orderMap.getTypes(tx()));
|
Set<String> orderTypesToExport = orderMap.getTypes(tx());
|
||||||
if (!this.orderTypes.isEmpty())
|
if (!this.orderTypes.isEmpty())
|
||||||
orderTypesToExport.retainAll(this.orderTypes);
|
orderTypesToExport.retainAll(this.orderTypes);
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ public class XmlExportModelCommand extends Command {
|
||||||
|
|
||||||
if (this.doActivities) {
|
if (this.doActivities) {
|
||||||
ActivityMap activityMap = tx().getActivityMap();
|
ActivityMap activityMap = tx().getActivityMap();
|
||||||
Set<String> activityTypesToExport = new TreeSet<>(activityMap.getTypes(tx()));
|
Set<String> activityTypesToExport = activityMap.getTypes(tx());
|
||||||
if (!this.activityTypes.isEmpty())
|
if (!this.activityTypes.isEmpty())
|
||||||
activityTypesToExport.retainAll(this.activityTypes);
|
activityTypesToExport.retainAll(this.activityTypes);
|
||||||
|
|
||||||
|
@ -276,27 +276,18 @@ public class XmlExportModelCommand extends Command {
|
||||||
|
|
||||||
private void writeOrdersByType(XMLStreamWriter writer, OrderMap orderMap, String type) {
|
private void writeOrdersByType(XMLStreamWriter writer, OrderMap orderMap, String type) {
|
||||||
StrolchElementToSaxWriterVisitor visitor = new StrolchElementToSaxWriterVisitor(writer);
|
StrolchElementToSaxWriterVisitor visitor = new StrolchElementToSaxWriterVisitor(writer);
|
||||||
Set<String> keysByType = new TreeSet<>(orderMap.getKeysBy(tx(), type));
|
List<Order> orders = orderMap.getElementsBy(tx(), type);
|
||||||
for (String id : keysByType) {
|
for (Order order : orders) {
|
||||||
Order order = orderMap.getBy(tx(), type, id);
|
|
||||||
order.accept(visitor);
|
order.accept(visitor);
|
||||||
this.statistics.nrOfOrders++;
|
this.statistics.nrOfOrders++;
|
||||||
logElementsWritten();
|
logElementsWritten();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void logElementsWritten() {
|
|
||||||
if (this.nextLogTime < System.currentTimeMillis()) {
|
|
||||||
logger.info("Wrote " + this.statistics.getNrOfElements() + " of " + this.elementsToWrite + " Elements.");
|
|
||||||
this.nextLogTime = System.currentTimeMillis() + LOG_INTERVAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeResourcesByType(XMLStreamWriter writer, ResourceMap resourceMap, String type) {
|
private void writeResourcesByType(XMLStreamWriter writer, ResourceMap resourceMap, String type) {
|
||||||
StrolchElementToSaxWriterVisitor visitor = new StrolchElementToSaxWriterVisitor(writer);
|
StrolchElementToSaxWriterVisitor visitor = new StrolchElementToSaxWriterVisitor(writer);
|
||||||
Set<String> keysByType = new TreeSet<>(resourceMap.getKeysBy(tx(), type));
|
List<Resource> resources = resourceMap.getElementsBy(tx(), type);
|
||||||
for (String id : keysByType) {
|
for (Resource resource : resources) {
|
||||||
Resource resource = resourceMap.getBy(tx(), type, id);
|
|
||||||
resource.accept(visitor);
|
resource.accept(visitor);
|
||||||
this.statistics.nrOfResources++;
|
this.statistics.nrOfResources++;
|
||||||
logElementsWritten();
|
logElementsWritten();
|
||||||
|
@ -305,15 +296,21 @@ public class XmlExportModelCommand extends Command {
|
||||||
|
|
||||||
private void writeActivitiesByType(XMLStreamWriter writer, ActivityMap activityMap, String type) {
|
private void writeActivitiesByType(XMLStreamWriter writer, ActivityMap activityMap, String type) {
|
||||||
StrolchElementToSaxWriterVisitor visitor = new StrolchElementToSaxWriterVisitor(writer);
|
StrolchElementToSaxWriterVisitor visitor = new StrolchElementToSaxWriterVisitor(writer);
|
||||||
Set<String> keysByType = new TreeSet<>(activityMap.getKeysBy(tx(), type));
|
List<Activity> activities = activityMap.getElementsBy(tx(), type);
|
||||||
for (String id : keysByType) {
|
for (Activity activity : activities) {
|
||||||
Activity activity = activityMap.getBy(tx(), type, id);
|
|
||||||
activity.accept(visitor);
|
activity.accept(visitor);
|
||||||
this.statistics.nrOfActivities++;
|
this.statistics.nrOfActivities++;
|
||||||
logElementsWritten();
|
logElementsWritten();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void logElementsWritten() {
|
||||||
|
if (this.nextLogTime < System.currentTimeMillis()) {
|
||||||
|
logger.info("Wrote " + this.statistics.getNrOfElements() + " of " + this.elementsToWrite + " Elements.");
|
||||||
|
this.nextLogTime = System.currentTimeMillis() + LOG_INTERVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param modelFile
|
* @param modelFile
|
||||||
* the modelFile to set
|
* the modelFile to set
|
||||||
|
|
Loading…
Reference in New Issue