Skip to content

Commit

Permalink
Quick hack to prevent metadata being zapped on item update. TODO: per…
Browse files Browse the repository at this point in the history
…menant fix
  • Loading branch information
mikesname committed Oct 25, 2013
1 parent c5296fd commit 712468e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
public final class BasicGraphManager<T extends IndexableGraph> implements GraphManager {

private static final String INDEX_NAME = "entities";
private static final String METADATA_PREFIX = "_";

private final FramedGraph<T> graph;

Expand Down Expand Up @@ -250,9 +251,11 @@ private <T extends Element> void replaceProperties(Index<T> index, T item,
// remove 'old' properties
for (String key : item.getPropertyKeys()) {
Object value = item.getProperty(key);
item.removeProperty(key);
if (keys == null || keys.contains(key)) {
index.remove(key, value, item);
if (!key.startsWith(METADATA_PREFIX)) {
item.removeProperty(key);
if (keys == null || keys.contains(key)) {
index.remove(key, value, item);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
public final class SingleIndexGraphManager implements GraphManager {

private static final String INDEX_NAME = "entities";
private static final String METADATA_PREFIX = "_";

private final FramedGraph<Neo4jGraph> graph;

Expand Down Expand Up @@ -256,9 +257,11 @@ private <T extends Element> void replaceProperties(Index<T> index, T item,
// remove 'old' properties
for (String key : item.getPropertyKeys()) {
Object value = item.getProperty(key);
item.removeProperty(key);
if (keys == null || keys.contains(key)) {
index.remove(key, value, item);
if (!key.startsWith(METADATA_PREFIX)) {
item.removeProperty(key);
if (keys == null || keys.contains(key)) {
index.remove(key, value, item);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,34 @@ public void testUpdateVertex() throws Exception {
assertEquals(null, vertex.getProperty(TEST_KEY));
}

@Test
public void testUpdateVertexWithMetadata() throws Exception {
@SuppressWarnings("serial")
Map<String, Object> data = new HashMap<String, Object>() {
{
put(TEST_KEY, TEST_VALUE);
}
};

Vertex vertex = manager.createVertex(TEST_ID1, TEST_TYPE, data);

String testMetaKey = "_metakey";
String testMetaValue = "test-value";
vertex.setProperty(testMetaKey, testMetaValue);

String NEW_TEST_KEY = "newTestKey";
String NEW_TEST_VALUE = "newTestValue";

// change a value of existing key
data.put(TEST_KEY, NEW_TEST_VALUE);
manager.updateVertex(TEST_ID1, TEST_TYPE, data);
vertex = manager.getVertex(TEST_ID1);
assertEquals(NEW_TEST_VALUE, vertex.getProperty(TEST_KEY));

// Check the metadata remains unharmed
assertEquals(testMetaValue, vertex.getProperty(testMetaKey));
}

// TODO copy and change the other tests

@SuppressWarnings("serial")
Expand Down

0 comments on commit 712468e

Please sign in to comment.