protected final NodeState unphasedState() { return this._resolver.resolveState(this); }
protected final NodeState unphasedState() { return this._resolver.resolveState(this); }
@Override public final long lastModification() { final NodeState state = this._resolver.resolveState(this); if (state != null) { return state.time(); } else { throw new RuntimeException(Constants.CACHE_MISS_ERROR); } }
@Override public final long timeDephasing() { final NodeState state = this._resolver.resolveState(this); if (state != null) { return (this._time - state.time()); } else { throw new RuntimeException(Constants.CACHE_MISS_ERROR); } }
@Override public final long lastModification() { final NodeState state = this._resolver.resolveState(this); if (state != null) { return state.time(); } else { throw new RuntimeException(Constants.CACHE_MISS_ERROR); } }
@Override public Object getAt(int propIndex) { return _resolver.resolveState(this).get(propIndex); }
@Override public byte typeAt(final int index) { final NodeState resolved = this._resolver.resolveState(this); if (resolved != null) { return resolved.getType(index); } return -1; }
@Override public final long timeDephasing() { final NodeState state = this._resolver.resolveState(this); if (state != null) { return (this._time - state.time()); } else { throw new RuntimeException(Constants.CACHE_MISS_ERROR); } }
@Override public Object getByIndex(long propIndex) { return _resolver.resolveState(this).get(propIndex); }
@Override public byte type(String name) { final NodeState resolved = this._resolver.resolveState(this); if (resolved != null) { return resolved.getType(this._resolver.stringToHash(name, false)); } return -1; }
@Override public byte type(String propertyName) { final NodeState resolved = this._resolver.resolveState(this); if (resolved != null) { return resolved.getType(this._resolver.stringToHash(propertyName, false)); } return -1; }
@Override public Object get(String name) { final NodeState resolved = this._resolver.resolveState(this); if (resolved != null) { return resolved.get(this._resolver.stringToHash(name, false)); } return null; }
@Override public Object get(String propertyName) { final NodeState resolved = this._resolver.resolveState(this); if (resolved != null) { return resolved.get(this._resolver.stringToHash(propertyName, false)); } return null; }
@Override public Node setAt(int index, byte type, Object value) { final NodeState unPhasedState = this._resolver.resolveState(this); boolean isDiff = (type != unPhasedState.getType(index)); if (!isDiff) { isDiff = !isEquals(unPhasedState.get(index), value, type); } if (isDiff) { final NodeState preciseState = this._resolver.alignState(this); if (preciseState != null) { preciseState.set(index, type, value); } else { throw new RuntimeException(Constants.CACHE_MISS_ERROR); } } return this; }
@Override public void setProperty(String propertyName, byte propertyType, Object propertyValue) { //hash the property a single time final long hashed = this._resolver.stringToHash(propertyName, true); final NodeState unPhasedState = this._resolver.resolveState(this); boolean isDiff = (propertyType != unPhasedState.getType(hashed)); if (!isDiff) { isDiff = !isEquals(unPhasedState.get(hashed), propertyValue, propertyType); } if (isDiff) { final NodeState preciseState = this._resolver.alignState(this); if (preciseState != null) { preciseState.set(hashed, propertyType, propertyValue); } else { throw new RuntimeException(Constants.CACHE_MISS_ERROR); } } }
@Override public void unindex(String indexName, org.mwg.Node nodeToIndex, String flatKeyAttributes, Callback<Boolean> callback) { final String[] keyAttributes = flatKeyAttributes.split(Constants.QUERY_SEP + ""); final NodeState currentNodeState = this._resolver.alignState(this); if (currentNodeState == null) { throw new RuntimeException(Constants.CACHE_MISS_ERROR); } LongLongArrayMap indexMap = (LongLongArrayMap) currentNodeState.get(this._resolver.stringToHash(indexName, false)); if (indexMap != null) { Query flatQuery = _graph.newQuery(); final NodeState toIndexNodeState = this._resolver.resolveState(nodeToIndex); for (int i = 0; i < keyAttributes.length; i++) { String attKey = keyAttributes[i]; Object attValue = toIndexNodeState.getFromKey(attKey); if (attValue != null) { flatQuery.add(attKey, attValue.toString()); } else { flatQuery.add(attKey, null); } } //TODO AUTOMATIC UPDATE indexMap.remove(flatQuery.hash(), nodeToIndex.id()); } if (Constants.isDefined(callback)) { callback.on(true); } }
final org.mwg.Node resolvedNode = resolved[i]; if (resolvedNode != null) { final NodeState resolvedState = selfPointer._resolver.resolveState(resolvedNode); boolean exact = true; for (int j = 0; j < query.attributes().length; j++) {
@Override public void findAll(final String indexName, final Callback<Node[]> callback) { final NodeState currentNodeState = this._resolver.resolveState(this); if (currentNodeState == null) { throw new RuntimeException(Constants.CACHE_MISS_ERROR); } final LongLongArrayMap indexMap = (LongLongArrayMap) currentNodeState.get(this._resolver.stringToHash(indexName, false)); if (indexMap != null) { final long[] ids = new long[(int) indexMap.size()]; final int[] idIndex = {0}; indexMap.each(new LongLongArrayMapCallBack() { @Override public void on(final long hash, final long nodeId) { ids[idIndex[0]] = nodeId; idIndex[0]++; } }); _resolver.lookupAll(world(), time(), ids, new Callback<Node[]>() { @Override public void on(Node[] result) { //TODO shrink result callback.on(result); } }); } else { callback.on(new org.mwg.plugin.AbstractNode[0]); } }
private void internal_add_remove(boolean isIndex, Node node, String... attributeNames) { Query flatQuery = node.graph().newQuery(); final NodeState toIndexNodeState = node.graph().resolver().resolveState(node); for (int i = 0; i < attributeNames.length; i++) { final String attKey = attributeNames[i]; final Object attValue = toIndexNodeState.getFromKey(attKey); if (attValue != null) { flatQuery.add(attKey, attValue.toString()); } else { flatQuery.add(attKey, null); } } if (isIndex) { put(flatQuery.hash(), node.id()); } else { delete(flatQuery.hash(), node.id()); } }
@Override public void eval(TaskContext ctx) { final TaskResult previous = ctx.result(); final TaskResult result = ctx.newResult(); for (int i = 0; i < previous.size(); i++) { if (previous.get(i) instanceof BaseNode) { final Node n = (Node) previous.get(i); final NodeState nState = ctx.graph().resolver().resolveState(n); nState.each(new NodeStateCallback() { @Override public void on(int attributeKey, byte elemType, Object elem) { if (_filter == -1 || elemType == _filter) { String retrieved = ctx.graph().resolver().hashToString(attributeKey); if (retrieved != null) { result.add(retrieved); } else { result.add(attributeKey); } } } }); n.free(); } } previous.clear(); ctx.continueWith(result); }