Le 04/05/2013 08:45, Michael Spreng a écrit : >> If it is the recommended way, I can take a look at osmosis code source, >> and see if this version increase is something easy to do. > In my opinion yes, this is the only sane way to handle this. Just take > care that you won't break creation of diffs from the api-db.
I'm including a patch for this, that only impacts the ChangeDeriver class. I have tested it on a country, and the generated diff was correct - the only difference with the current osmosis version is the version on deleted elements. I haven't tested on the api-db. If you prefer that I send the patch to trac, or github, please ask me. -- Jocelyn
>From cf8404bc826bf742616d7f7aab5f8dc926f4b70c Mon Sep 17 00:00:00 2001 From: Jocelyn Jaubert <[email protected]> Date: Tue, 7 May 2013 23:42:37 +0200 Subject: [PATCH] Increment version in ChangeDeriver when an object is deleted When an object is deleted, we increase the version. This is not always the same version than on the API (if the object was modified several time between the two compared file), but is slighty better than not incrementing the version. This fixes a bug when merging several diffs generated by osmosis, as this makes sure that we will never have the same object with the same version in different diffs. --- .../core/change/v0_6/impl/VersionSetter.java | 38 ++++++++++++++++++++ .../osmosis/set/v0_6/ChangeDeriver.java | 9 +++-- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 osmosis-core/src/main/java/org/openstreetmap/osmosis/core/change/v0_6/impl/VersionSetter.java diff --git a/osmosis-core/src/main/java/org/openstreetmap/osmosis/core/change/v0_6/impl/VersionSetter.java b/osmosis-core/src/main/java/org/openstreetmap/osmosis/core/change/v0_6/impl/VersionSetter.java new file mode 100644 index 0000000..594be8e --- /dev/null +++ b/osmosis-core/src/main/java/org/openstreetmap/osmosis/core/change/v0_6/impl/VersionSetter.java @@ -0,0 +1,38 @@ +// This software is released into the Public Domain. See copying.txt for details. +package org.openstreetmap.osmosis.core.change.v0_6.impl; + +import org.openstreetmap.osmosis.core.container.v0_6.EntityContainer; + + +/** + * Updates the current version on to entities. + */ +public class VersionSetter { + + /** + * Creates a new instance. + */ + public VersionSetter() { + } + + + /** + * Increment the version on the supplied entity. + * + * @param entityContainer + * The container holding the entity to be modified. + * @return A container holding an updated entity. + */ + public EntityContainer incrementVersion(EntityContainer entityContainer) { + EntityContainer resultContainer; + int version; + + version = entityContainer.getEntity().getVersion(); + version = version + 1; + + resultContainer = entityContainer.getWriteableInstance(); + resultContainer.getEntity().setVersion(version); + + return resultContainer; + } +} diff --git a/osmosis-set/src/main/java/org/openstreetmap/osmosis/set/v0_6/ChangeDeriver.java b/osmosis-set/src/main/java/org/openstreetmap/osmosis/set/v0_6/ChangeDeriver.java index 007f483..8953814 100644 --- a/osmosis-set/src/main/java/org/openstreetmap/osmosis/set/v0_6/ChangeDeriver.java +++ b/osmosis-set/src/main/java/org/openstreetmap/osmosis/set/v0_6/ChangeDeriver.java @@ -5,6 +5,7 @@ import java.util.Collections; import org.openstreetmap.osmosis.core.OsmosisRuntimeException; import org.openstreetmap.osmosis.core.change.v0_6.impl.TimestampSetter; +import org.openstreetmap.osmosis.core.change.v0_6.impl.VersionSetter; import org.openstreetmap.osmosis.core.container.v0_6.ChangeContainer; import org.openstreetmap.osmosis.core.container.v0_6.EntityContainer; import org.openstreetmap.osmosis.core.sort.v0_6.EntityByTypeThenIdComparator; @@ -88,12 +89,16 @@ public class ChangeDeriver implements MultiSinkRunnableChangeSource { EntityContainer fromEntityContainer = null; EntityContainer toEntityContainer = null; TimestampSetter timestampSetter; + VersionSetter versionSetter; // Create a comparator for comparing two entities by type and identifier. comparator = new EntityContainerComparator(new EntityByTypeThenIdComparator()); // Create an object for setting the current timestamp on entities being deleted. timestampSetter = new TimestampSetter(); + + // Create an object for setting the version on entities being deleted. + versionSetter = new VersionSetter(); // We can't get meaningful data from the initialize data on the // input streams, so pass empty meta data to the sink and discard @@ -125,7 +130,7 @@ public class ChangeDeriver implements MultiSinkRunnableChangeSource { // deleted so set the delete time to the current time. changeSink.process( new ChangeContainer( - timestampSetter.updateTimestamp(fromEntityContainer), + versionSetter.incrementVersion(timestampSetter.updateTimestamp(fromEntityContainer)), ChangeAction.Delete)); fromEntityContainer = null; } else if (comparisonResult > 0) { @@ -157,7 +162,7 @@ public class ChangeDeriver implements MultiSinkRunnableChangeSource { // deleted so set the delete time to the current time. changeSink.process( new ChangeContainer( - timestampSetter.updateTimestamp(fromEntityContainer), + versionSetter.incrementVersion(timestampSetter.updateTimestamp(fromEntityContainer)), ChangeAction.Delete)); fromEntityContainer = null; } -- 1.7.10.4
_______________________________________________ osmosis-dev mailing list [email protected] http://lists.openstreetmap.org/listinfo/osmosis-dev
