Partly move setProperty functionality into AccumuloElement

This commit is contained in:
Michael Lieberman
2014-12-31 11:51:53 -05:00
parent 439dc7ae93
commit fec6fdc522
2 changed files with 11 additions and 12 deletions

View File

@@ -79,7 +79,11 @@ public abstract class AccumuloElement implements Element {
@Override
public void setProperty(String key, Object value) {
makeCache();
globals.getGraph().setProperty(type, this, key, value);
globals.getGraph().setPropertyForIndexes(type, this, key, value);
// MDL 31 Dec 2014: The above calls getProperty, so this
// order is important (for now).
globals.getElementWrapper(type).writeProperty(this, key, value);
globals.getGraph().checkedFlush();
propertyCache.put(key, value);
}

View File

@@ -838,7 +838,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
}
}
private void checkedFlush() {
void checkedFlush() {
if (config.getAutoFlush()) {
flush();
}
@@ -858,30 +858,25 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
* @param key
* @param val
*/
void setProperty(Class<? extends Element> type, Element element, String key, Object val) {
void setPropertyForIndexes(Class<? extends Element> type, Element element, String key, Object val) {
checkProperty(key, val);
try {
byte[] newByteVal = AccumuloByteSerializer.serialize(val);
Mutation m = null;
if (config.getAutoIndex() || getIndexedKeys(type).contains(key)) {
byte[] newByteVal = AccumuloByteSerializer.serialize(val);
BatchWriter bw = getIndexBatchWriter(type);
Object old = element.getProperty(key);
if (old != null) {
byte[] oldByteVal = AccumuloByteSerializer.serialize(old);
m = new Mutation(oldByteVal);
Mutation m = new Mutation(oldByteVal);
m.putDelete(key, element.getId().toString());
bw.addMutation(m);
}
m = new Mutation(newByteVal);
Mutation m = new Mutation(newByteVal);
m.put(key.getBytes(), element.getId().toString().getBytes(), EMPTY);
bw.addMutation(m);
checkedFlush();
}
getElementTableWrapper(type).writeProperty(element, key, val);
checkedFlush();
} catch (MutationsRejectedException e) {
e.printStackTrace();
}