@Override public final Object getOrCreate(String propertyName, byte propertyType) { final NodeState preciseState = this._resolver.alignState(this); if (preciseState != null) { return preciseState.getOrCreate(this._resolver.stringToHash(propertyName, true), propertyType); } else { throw new RuntimeException(Constants.CACHE_MISS_ERROR); } }
@Override public final void free() { this._resolver.freeNode(this); }
private void internal_index(long world, long time, String name, boolean ifExists, Callback<NodeIndex> callback) { final CoreGraph selfPointer = this; final long indexNameCoded = this._resolver.stringToHash(name, true); this._resolver.lookup(world, time, CoreConstants.END_OF_TIME, new Callback<org.mwg.Node>() { @Override public void on(org.mwg.Node globalIndexNodeUnsafe) {
@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 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 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]); } }
@Override public Node set(String name, byte type, Object value) { //hash the property a single time final int hashed = this._resolver.stringToHash(name, true); return setAt(hashed, type, value); }
protected final NodeState unphasedState() { return this._resolver.resolveState(this); }
@Override public final Node rephase() { this._resolver.alignState(this); return this; }
return; final NodeState resolved = this._resolver.resolveState(this); if (resolved != null) { final Relationship relationArray = (Relationship) resolved.get(relationIndex); ids[i] = relationArray.get(i); this._resolver.lookupAll(_world, _time, ids, new Callback<Node[]>() { @Override public void on(Node[] result) {
@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 final <A extends Node> void travelInTime(final long targetTime, final Callback<A> callback) { _resolver.lookup(_world, targetTime, _id, callback); }
@Override public void on(long attributeKey, byte elemType, Object elem) { if (elem != null) { String resolveName = _resolver.hashToString(attributeKey); if (resolveName == null) { resolveName = attributeKey + "";
@Override public org.mwg.Node newTypedNode(long world, long time, String nodeType) { if (nodeType == null) { throw new RuntimeException("nodeType should not be null"); } if (!_isConnected.get()) { throw new RuntimeException(CoreConstants.DISCONNECTED_ERROR); } final int extraCode = _resolver.stringToHash(nodeType, false); final NodeFactory resolvedFactory = factoryByCode(extraCode); BaseNode newNode; if (resolvedFactory == null) { System.out.println("WARNING: UnKnow NodeType " + nodeType + ", missing plugin configuration in the builder ? Using generic node as a fallback"); newNode = new BaseNode(world, time, this._nodeKeyCalculator.newKey(), this); } else { newNode = (BaseNode) resolvedFactory.create(world, time, this._nodeKeyCalculator.newKey(), this); } this._resolver.initNode(newNode, extraCode); return newNode; }
if (globalIndexNodeUnsafe == null) { globalIndexNodeUnsafe = new BaseNode(world, time, CoreConstants.END_OF_TIME, selfPointer); selfPointer._resolver.initNode(globalIndexNodeUnsafe, CoreConstants.NULL_LONG); globalIndexContent = (LongLongMap) globalIndexNodeUnsafe.getOrCreate(CoreConstants.INDEX_ATTRIBUTE, Type.LONG_TO_LONG_MAP); } else { selfPointer._resolver.lookup(world, time, indexId, callback);
@Override public final void timepoints(final long beginningOfSearch, final long endOfSearch, final Callback<long[]> callback) { this._resolver.resolveTimepoints(this, beginningOfSearch, endOfSearch, callback); }
@Override public void lookupAll(long world, long time, long[] ids, Callback<Node[]> callback) { if (!_isConnected.get()) { throw new RuntimeException(CoreConstants.DISCONNECTED_ERROR); } this._resolver.lookupAll(world, time, ids, callback); }
protected final NodeState newState(long time) { return this._resolver.newState(this, _world, time); }
Object o = toLock.get(j); if (o instanceof BaseNode) { resolver.externalLock((Node) o);
@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); } }