@Override
 public Property graphRemoveProperty(KernelStatement state, int propertyKeyId) {
   Property existingProperty = graphGetProperty(state, propertyKeyId);
   if (existingProperty.isDefined()) {
     state.txState().graphDoRemoveProperty((DefinedProperty) existingProperty);
   }
   return existingProperty;
 }
 @Override
 public void graphChangeStoreProperty(Property previousProperty, Property property)
     throws PropertyNotFoundException {
   // TODO this should change. We don't have the property record id here, so we PersistenceManager
   // has been changed to only accept the property key and it will find it among the property
   // records
   // on demand. This change was made instead of cramming in record id into the Property objects,
   persistenceManager.graphChangeProperty((int) property.propertyKeyId(), property.value());
 }
 @Override
 public Property nodeRemoveProperty(KernelStatement state, long nodeId, int propertyKeyId)
     throws EntityNotFoundException {
   Property existingProperty = nodeGetProperty(state, nodeId, propertyKeyId);
   if (existingProperty.isDefined()) {
     legacyPropertyTrackers.nodeRemoveStoreProperty(nodeId, (DefinedProperty) existingProperty);
     state.txState().nodeDoRemoveProperty(nodeId, (DefinedProperty) existingProperty);
     indexesUpdateProperty(state, nodeId, propertyKeyId, (DefinedProperty) existingProperty, null);
   }
   return existingProperty;
 }
 @Override
 public Property graphGetProperty(KernelStatement state, int propertyKeyId) {
   Iterator<DefinedProperty> properties = graphGetAllProperties(state);
   while (properties.hasNext()) {
     Property property = properties.next();
     if (property.propertyKeyId() == propertyKeyId) {
       return property;
     }
   }
   return Property.noGraphProperty(propertyKeyId);
 }
 @Override
 public Property relationshipRemoveProperty(
     KernelStatement state, long relationshipId, int propertyKeyId)
     throws EntityNotFoundException {
   Property existingProperty = relationshipGetProperty(state, relationshipId, propertyKeyId);
   if (existingProperty.isDefined()) {
     legacyPropertyTrackers.relationshipRemoveStoreProperty(
         relationshipId, (DefinedProperty) existingProperty);
     state
         .txState()
         .relationshipDoRemoveProperty(relationshipId, (DefinedProperty) existingProperty);
   }
   return existingProperty;
 }
 @Override
 public Property relationshipSetProperty(
     KernelStatement state, long relationshipId, DefinedProperty property)
     throws EntityNotFoundException {
   Property existingProperty =
       relationshipGetProperty(state, relationshipId, property.propertyKeyId());
   if (!existingProperty.isDefined()) {
     legacyPropertyTrackers.relationshipAddStoreProperty(relationshipId, property);
   } else {
     legacyPropertyTrackers.relationshipChangeStoreProperty(
         relationshipId, (DefinedProperty) existingProperty, property);
   }
   state.txState().relationshipDoReplaceProperty(relationshipId, existingProperty, property);
   return existingProperty;
 }
 @Override
 public Property nodeSetProperty(KernelStatement state, long nodeId, DefinedProperty property)
     throws EntityNotFoundException {
   Property existingProperty = nodeGetProperty(state, nodeId, property.propertyKeyId());
   if (!existingProperty.isDefined()) {
     legacyPropertyTrackers.nodeAddStoreProperty(nodeId, property);
   } else {
     legacyPropertyTrackers.nodeChangeStoreProperty(
         nodeId, (DefinedProperty) existingProperty, property);
   }
   state.txState().nodeDoReplaceProperty(nodeId, existingProperty, property);
   indexesUpdateProperty(
       state, nodeId, property.propertyKeyId(), existingProperty.value(null), property.value());
   return existingProperty;
 }
 @Override
 public Property relationshipGetProperty(
     KernelStatement state, long relationshipId, int propertyKeyId)
     throws EntityNotFoundException {
   if (state.hasTxStateWithChanges()) {
     Iterator<DefinedProperty> properties = relationshipGetAllProperties(state, relationshipId);
     while (properties.hasNext()) {
       Property property = properties.next();
       if (property.propertyKeyId() == propertyKeyId) {
         return property;
       }
     }
     return Property.noRelationshipProperty(relationshipId, propertyKeyId);
   }
   return storeLayer.relationshipGetProperty(relationshipId, propertyKeyId);
 }
Example #9
0
 @Override
 public void graphDoRemoveProperty(Property removedProperty) {
   if (!removedProperty.isNoProperty()) {
     graphPropertyDiffSets().remove((SafeProperty) removedProperty);
     legacyState.graphRemoveProperty(removedProperty);
     hasChanges = true;
   }
 }
Example #10
0
 @Override
 public void relationshipDoRemoveProperty(long relationshipId, Property removedProperty) {
   if (!removedProperty.isNoProperty()) {
     relationshipPropertyDiffSets(relationshipId).remove((SafeProperty) removedProperty);
     legacyState.relationshipRemoveProperty(relationshipId, removedProperty);
     hasChanges = true;
   }
 }
Example #11
0
 @Override
 public void nodeDoRemoveProperty(long nodeId, Property removedProperty) {
   if (!removedProperty.isNoProperty()) {
     nodePropertyDiffSets(nodeId).remove((SafeProperty) removedProperty);
     legacyState.nodeRemoveProperty(nodeId, removedProperty);
     hasChanges = true;
   }
 }
 @Override
 public void relationshipRemoveStoreProperty(long relationshipId, Property property) {
   // TODO this should change. We don't have the property record id here, so we PersistenceManager
   // has been changed to only accept the property key and it will find it among the property
   // records
   // on demand. This change was made instead of cramming in record id into the Property objects,
   persistenceManager.relRemoveProperty(relationshipId, (int) property.propertyKeyId());
 }
 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();
   }
 }
Example #14
0
 @Override
 public void graphDoReplaceProperty(Property replacedProperty, SafeProperty newProperty) {
   if (!newProperty.isNoProperty()) {
     DiffSets<SafeProperty> diffSets = graphPropertyDiffSets();
     if (!replacedProperty.isNoProperty()) {
       diffSets.remove((SafeProperty) replacedProperty);
     }
     diffSets.add(newProperty);
     legacyState.graphSetProperty(newProperty.asPropertyDataJustForIntegration());
     hasChanges = true;
   }
 }
 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;
 }
Example #16
0
 @Override
 public void nodeDoReplaceProperty(
     long nodeId, Property replacedProperty, SafeProperty newProperty) {
   if (!newProperty.isNoProperty()) {
     DiffSets<SafeProperty> diffSets = nodePropertyDiffSets(nodeId);
     if (!replacedProperty.isNoProperty()) {
       diffSets.remove((SafeProperty) replacedProperty);
     }
     diffSets.add(newProperty);
     legacyState.nodeSetProperty(nodeId, newProperty.asPropertyDataJustForIntegration());
     hasChanges = true;
   }
 }
  @Test
  public void showsRemovedRelationships() throws Exception {
    // Given
    state.relationshipDoDelete(1l, 1, 1l, 2l);
    state.relationshipDoDelete(2l, 1, 1l, 1l);

    when(ops.relationshipGetAllProperties(1l))
        .thenReturn(IteratorUtil.<DefinedProperty>emptyIterator());
    when(ops.relationshipGetAllProperties(2l))
        .thenReturn(asList(Property.stringProperty(1, "p")).iterator());
    when(ops.propertyKeyGetName(1)).thenReturn("key");

    // When & Then
    TxStateTransactionDataSnapshot snapshot = snapshot();
    assertThat(idList(snapshot.deletedRelationships()), equalTo(asList(1l, 2l)));
    assertThat(single(snapshot.removedRelationshipProperties()).key(), equalTo("key"));
  }
  @Test
  public void showsDeletedNodes() throws Exception {
    // Given
    state.nodeDoDelete(1l);
    state.nodeDoDelete(2l);
    when(ops.nodeGetAllProperties(1l)).thenReturn(IteratorUtil.<DefinedProperty>emptyIterator());
    when(ops.nodeGetAllProperties(2l))
        .thenReturn(asList(Property.stringProperty(1, "p")).iterator());
    when(ops.nodeGetLabels(1l)).thenReturn(PrimitiveIntCollections.emptyIterator());
    when(ops.nodeGetLabels(2l)).thenReturn(PrimitiveIntCollections.iterator(15));
    when(ops.propertyKeyGetName(1)).thenReturn("key");
    when(ops.labelGetName(15)).thenReturn("label");

    // When & Then
    TxStateTransactionDataSnapshot snapshot = snapshot();
    assertThat(idList(snapshot.deletedNodes()), equalTo(asList(1l, 2l)));
    assertThat(single(snapshot.removedLabels()).label().name(), equalTo("label"));
    assertThat(single(snapshot.removedNodeProperties()).key(), equalTo("key"));
  }
Example #19
0
 @Override
 public int compare(Property o1, Property o2) {
   return o1.propertyKeyId() - o2.propertyKeyId();
 }
Example #20
0
  @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;
      }
    }
  }
  @Override
  public void nodeAddStoreProperty(long nodeId, Property property)
      throws PropertyNotFoundException {

    persistenceManager.nodeAddProperty(nodeId, (int) property.propertyKeyId(), property.value());
  }
 @Override
 public void relationshipAddStoreProperty(long relationshipId, Property property)
     throws PropertyNotFoundException {
   persistenceManager.relAddProperty(
       relationshipId, (int) property.propertyKeyId(), property.value());
 }
 @Override
 public void graphAddStoreProperty(Property property) throws PropertyNotFoundException {
   persistenceManager.graphAddProperty((int) property.propertyKeyId(), property.value());
 }