private void changeName(long nodeId, String propertyKeyName, Object newValue) throws KernelException { try (Transaction tx = db.beginTx()) { Statement statement = bridge.instance(); int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName(propertyKeyName); statement .dataWriteOperations() .nodeSetProperty(nodeId, Property.property(propertyKeyId, newValue)); tx.success(); } }
private long createNode( Statement statement, String labelName, String propertyKeyName, Object value) throws KernelException { int labelId = statement.tokenWriteOperations().labelGetOrCreateForName(labelName); int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName(propertyKeyName); long nodeId = statement.dataWriteOperations().nodeCreate(); statement.dataWriteOperations().nodeAddLabel(nodeId, labelId); statement .dataWriteOperations() .nodeSetProperty(nodeId, Property.property(propertyKeyId, value)); return nodeId; }
@Override public void commitPropertyMaps( PrimitiveIntObjectMap<DefinedProperty> cowPropertyAddMap, Iterator<Integer> removed) { synchronized (this) { // Dereference the volatile once to avoid multiple barriers DefinedProperty[] newArray = properties; if (newArray == null) { return; } /* * add map will definitely be added in the properties array - all properties * added and later removed in the same tx are removed from there as well. * The remove map will not necessarily be removed, since it may hold a prop that was * added in this tx. So the difference in size is all the keys that are common * between properties and remove map subtracted by the add map size. */ int extraLength = 0; if (cowPropertyAddMap != null) { extraLength += cowPropertyAddMap.size(); } int newArraySize = newArray.length; // make sure that we don't make inplace modifications to the existing array // TODO: Refactor this to guarantee only one copy, // currently it can do two copies in the clone() case if it also compacts if (extraLength > 0) { DefinedProperty[] oldArray = newArray; newArray = new DefinedProperty[oldArray.length + extraLength]; System.arraycopy(oldArray, 0, newArray, 0, oldArray.length); } else { newArray = newArray.clone(); } if (removed != null) { while (removed.hasNext()) { int key = removed.next(); for (int i = 0; i < newArraySize; i++) { Property existingProperty = newArray[i]; if (existingProperty.propertyKeyId() == key) { int swapWith = --newArraySize; newArray[i] = newArray[swapWith]; newArray[swapWith] = null; break; } } } } if (cowPropertyAddMap != null) { PrimitiveIntIterator keyIterator = cowPropertyAddMap.iterator(); while (keyIterator.hasNext()) { int key = keyIterator.next(); DefinedProperty addedProperty = cowPropertyAddMap.get(key); for (int i = 0; i < newArray.length; i++) { Property existingProperty = newArray[i]; if (existingProperty == null || addedProperty.propertyKeyId() == existingProperty.propertyKeyId()) { newArray[i] = Property.property(addedProperty.propertyKeyId(), addedProperty.value()); if (existingProperty == null) { newArraySize++; } break; } } } } // these size changes are updated from lock releaser if (newArraySize < newArray.length) { DefinedProperty[] compactedNewArray = new DefinedProperty[newArraySize]; System.arraycopy(newArray, 0, compactedNewArray, 0, newArraySize); sort(compactedNewArray); properties = compactedNewArray; } else { sort(newArray); properties = newArray; } } }