/*
  * It will remove a property from an embedded node if it exists.
  * After deleting the property, if the node does not have any more properties and relationships (except for an incoming one),
  * it will delete the embedded node as well.
  */
 private void removePropertyForEmbedded(Node embeddedNode, String[] embeddedColumnSplit, int i) {
   if (i == embeddedColumnSplit.length - 1) {
     // Property
     String property = embeddedColumnSplit[embeddedColumnSplit.length - 1];
     if (embeddedNode.hasProperty(property)) {
       embeddedNode.removeProperty(property);
     }
   } else {
     Iterator<Relationship> iterator =
         embeddedNode
             .getRelationships(Direction.OUTGOING, withName(embeddedColumnSplit[i]))
             .iterator();
     if (iterator.hasNext()) {
       removePropertyForEmbedded(iterator.next().getEndNode(), embeddedColumnSplit, i + 1);
     }
   }
   if (!embeddedNode.getPropertyKeys().iterator().hasNext()) {
     // Node without properties
     Iterator<Relationship> iterator = embeddedNode.getRelationships().iterator();
     if (iterator.hasNext()) {
       Relationship relationship = iterator.next();
       if (!iterator.hasNext()) {
         // Node with only one relationship and no properties,
         // we can remove it:
         // It means we have removed all the properties from the embedded node
         // and it is NOT an intermediate node like
         // (entity) --> (embedded1) --> (embedded2)
         relationship.delete();
         embeddedNode.delete();
       }
     }
   }
 }
Esempio n. 2
0
  @Test
  public void testIntType() {
    int time = (int) System.currentTimeMillis();
    Integer iValue = new Integer(time);
    String key = "testing";
    node1.setProperty(key, iValue);
    newTransaction();

    clearCache();
    Integer propertyValue = null;
    propertyValue = (Integer) node1.getProperty(key);
    assertEquals(iValue, propertyValue);

    iValue = new Integer((int) System.currentTimeMillis());
    node1.setProperty(key, iValue);
    newTransaction();

    clearCache();
    propertyValue = (Integer) node1.getProperty(key);
    assertEquals(iValue, propertyValue);

    node1.removeProperty(key);
    newTransaction();

    clearCache();
    assertTrue(!node1.hasProperty(key));

    node1.setProperty("other", 123L);
    assertEquals(123L, node1.getProperty("other"));
    newTransaction();
    clearCache();
    assertEquals(123L, node1.getProperty("other"));
  }
Esempio n. 3
0
  @Test
  public void testLongArray() {
    long[] array1 = new long[] {1, 2, 3, 4, 5};
    Long[] array2 = new Long[] {6l, 7l, 8l};
    String key = "testlongarray";
    node1.setProperty(key, array1);
    newTransaction();

    clearCache();
    long[] propertyValue = null;
    propertyValue = (long[]) node1.getProperty(key);
    assertEquals(array1.length, propertyValue.length);
    for (int i = 0; i < array1.length; i++) {
      assertEquals(array1[i], propertyValue[i]);
    }

    node1.setProperty(key, array2);
    newTransaction();

    clearCache();
    propertyValue = (long[]) node1.getProperty(key);
    assertEquals(array2.length, propertyValue.length);
    for (int i = 0; i < array2.length; i++) {
      assertEquals(array2[i], new Long(propertyValue[i]));
    }

    node1.removeProperty(key);
    newTransaction();

    clearCache();
    assertTrue(!node1.hasProperty(key));
  }
Esempio n. 4
0
  @Test
  public void testChangesAreVisibleInTransaction() {
    AutoIndexer<Node> autoIndexer = graphDb.index().getNodeAutoIndexer();
    autoIndexer.startAutoIndexingProperty("nodeProp");
    autoIndexer.setEnabled(true);

    newTransaction();

    Node node1 = graphDb.createNode();
    node1.setProperty("nodeProp", "nodePropValue");
    node1.setProperty("nodePropNonIndexable", "valueWhatever");
    ReadableIndex<Node> nodeIndex = autoIndexer.getAutoIndex();
    assertEquals(node1, nodeIndex.get("nodeProp", "nodePropValue").getSingle());

    newTransaction();

    Node node2 = graphDb.createNode();
    node2.setProperty("nodeProp", "nodePropValue2");
    assertEquals(node2, nodeIndex.get("nodeProp", "nodePropValue2").getSingle());
    node2.setProperty("nodeProp", "nodePropValue3");
    assertEquals(node2, nodeIndex.get("nodeProp", "nodePropValue3").getSingle());
    node2.removeProperty("nodeProp");
    assertFalse(nodeIndex.get("nodeProp", "nodePropValue2").hasNext());
    assertFalse(nodeIndex.get("nodeProp", "nodePropValue3").hasNext());

    newTransaction();

    assertEquals(node1, nodeIndex.get("nodeProp", "nodePropValue").getSingle());
    assertFalse(nodeIndex.get("nodeProp", "nodePropValue2").hasNext());
    assertFalse(nodeIndex.get("nodeProp", "nodePropValue3").hasNext());
  }
Esempio n. 5
0
  @Test
  public void testFloatType() {
    Float fValue = new Float(45.678f);
    String key = "testfloat";
    node1.setProperty(key, fValue);
    newTransaction();

    clearCache();
    Float propertyValue = null;
    propertyValue = (Float) node1.getProperty(key);
    assertEquals(fValue, propertyValue);

    fValue = new Float(5684.3243f);
    node1.setProperty(key, fValue);
    newTransaction();

    clearCache();
    propertyValue = (Float) node1.getProperty(key);
    assertEquals(fValue, propertyValue);

    node1.removeProperty(key);
    newTransaction();

    clearCache();
    assertTrue(!node1.hasProperty(key));
  }
Esempio n. 6
0
  @Test
  public void testLongType() {
    long time = System.currentTimeMillis();
    Long lValue = new Long(time);
    String key = "testlong";
    node1.setProperty(key, lValue);
    newTransaction();

    clearCache();
    Long propertyValue = null;
    propertyValue = (Long) node1.getProperty(key);
    assertEquals(lValue, propertyValue);

    lValue = new Long(System.currentTimeMillis());
    node1.setProperty(key, lValue);
    newTransaction();

    clearCache();
    propertyValue = (Long) node1.getProperty(key);
    assertEquals(lValue, propertyValue);

    node1.removeProperty(key);
    newTransaction();

    clearCache();
    assertTrue(!node1.hasProperty(key));

    node1.setProperty("other", 123L);
    assertEquals(123L, node1.getProperty("other"));
    newTransaction();
    clearCache();
    assertEquals(123L, node1.getProperty("other"));
  }
  private void removeTupleOperation(
      EntityKey entityKey,
      Node node,
      TupleOperation operation,
      TupleContext tupleContext,
      Set<String> processedAssociationRoles) {
    if (!tupleContext.getTupleTypeContext().isPartOfAssociation(operation.getColumn())) {
      if (isPartOfRegularEmbedded(entityKey.getColumnNames(), operation.getColumn())) {
        // Embedded node
        String[] split = split(operation.getColumn());
        removePropertyForEmbedded(node, split, 0);
      } else if (node.hasProperty(operation.getColumn())) {
        node.removeProperty(operation.getColumn());
      }
    }
    // if the column represents a to-one association, remove the relationship
    else {
      String associationRole = tupleContext.getTupleTypeContext().getRole(operation.getColumn());
      if (!processedAssociationRoles.contains(associationRole)) {

        Iterator<Relationship> relationships =
            node.getRelationships(withName(associationRole)).iterator();

        if (relationships.hasNext()) {
          relationships.next().delete();
        }
      }
    }
  }
Esempio n. 8
0
  @Test
  public void testCharArray() {
    char[] array1 = new char[] {'1', '2', '3', '4', '5'};
    Character[] array2 = new Character[] {'6', '7', '8'};
    String key = "testchararray";
    node1.setProperty(key, array1);
    newTransaction();

    clearCache();
    char[] propertyValue = null;
    propertyValue = (char[]) node1.getProperty(key);
    assertEquals(array1.length, propertyValue.length);
    for (int i = 0; i < array1.length; i++) {
      assertEquals(array1[i], propertyValue[i]);
    }

    node1.setProperty(key, array2);
    newTransaction();

    clearCache();
    propertyValue = (char[]) node1.getProperty(key);
    assertEquals(array2.length, propertyValue.length);
    for (int i = 0; i < array2.length; i++) {
      assertEquals(array2[i], new Character(propertyValue[i]));
    }

    node1.removeProperty(key);
    newTransaction();

    clearCache();
    assertTrue(!node1.hasProperty(key));
  }
Esempio n. 9
0
  @Test
  public void testByteType() {
    byte b = (byte) 177;
    Byte bValue = new Byte(b);
    String key = "testbyte";
    node1.setProperty(key, bValue);
    newTransaction();

    clearCache();
    Byte propertyValue = null;
    propertyValue = (Byte) node1.getProperty(key);
    assertEquals(bValue, propertyValue);

    bValue = new Byte((byte) 200);
    node1.setProperty(key, bValue);
    newTransaction();

    clearCache();
    propertyValue = (Byte) node1.getProperty(key);
    assertEquals(bValue, propertyValue);

    node1.removeProperty(key);
    newTransaction();

    clearCache();
    assertTrue(!node1.hasProperty(key));
  }
Esempio n. 10
0
  @Test
  public void testBooleanType() {
    boolean value = true;
    Boolean bValue = new Boolean(value);
    String key = "testbool";
    node1.setProperty(key, bValue);
    newTransaction();

    clearCache();
    Boolean propertyValue = null;
    propertyValue = (Boolean) node1.getProperty(key);
    assertEquals(bValue, propertyValue);

    bValue = new Boolean(false);
    node1.setProperty(key, bValue);
    newTransaction();

    clearCache();
    propertyValue = (Boolean) node1.getProperty(key);
    assertEquals(bValue, propertyValue);

    node1.removeProperty(key);
    newTransaction();

    clearCache();
    assertTrue(!node1.hasProperty(key));
  }
Esempio n. 11
0
  @Test
  public void testDoubleArray() {
    double[] array1 = new double[] {1.0, 2.0, 3.0, 4.0, 5.0};
    Double[] array2 = new Double[] {6.0, 7.0, 8.0};
    String key = "testdoublearray";
    node1.setProperty(key, array1);
    newTransaction();

    clearCache();
    double propertyValue[] = null;
    propertyValue = (double[]) node1.getProperty(key);
    assertEquals(array1.length, propertyValue.length);
    for (int i = 0; i < array1.length; i++) {
      assertEquals(array1[i], propertyValue[i], 0.0);
    }

    node1.setProperty(key, array2);
    newTransaction();

    clearCache();
    propertyValue = (double[]) node1.getProperty(key);
    assertEquals(array2.length, propertyValue.length);
    for (int i = 0; i < array2.length; i++) {
      assertEquals(array2[i], new Double(propertyValue[i]));
    }

    node1.removeProperty(key);
    newTransaction();

    clearCache();
    assertTrue(!node1.hasProperty(key));
  }
Esempio n. 12
0
  @Test
  public void testFloatArray() {
    float[] array1 = new float[] {1.0f, 2.0f, 3.0f, 4.0f, 5.0f};
    Float[] array2 = new Float[] {6.0f, 7.0f, 8.0f};
    String key = "testfloatarray";
    node1.setProperty(key, array1);
    newTransaction();

    clearCache();
    float propertyValue[] = null;
    propertyValue = (float[]) node1.getProperty(key);
    assertEquals(array1.length, propertyValue.length);
    for (int i = 0; i < array1.length; i++) {
      assertEquals(array1[i], propertyValue[i], 0.0);
    }

    node1.setProperty(key, array2);
    newTransaction();

    clearCache();
    propertyValue = (float[]) node1.getProperty(key);
    assertEquals(array2.length, propertyValue.length);
    for (int i = 0; i < array2.length; i++) {
      assertEquals(array2[i], new Float(propertyValue[i]));
    }

    node1.removeProperty(key);
    newTransaction();

    clearCache();
    assertTrue(!node1.hasProperty(key));
  }
Esempio n. 13
0
  @Test
  public void testStringArray() {
    String[] array1 = new String[] {"a", "b", "c", "d", "e"};
    String[] array2 = new String[] {"ff", "gg", "hh"};
    String key = "teststringarray";
    node1.setProperty(key, array1);
    newTransaction();

    clearCache();
    String propertyValue[] = null;
    propertyValue = (String[]) node1.getProperty(key);
    assertEquals(array1.length, propertyValue.length);
    for (int i = 0; i < array1.length; i++) {
      assertEquals(array1[i], propertyValue[i]);
    }

    node1.setProperty(key, array2);
    newTransaction();

    clearCache();
    propertyValue = (String[]) node1.getProperty(key);
    assertEquals(array2.length, propertyValue.length);
    for (int i = 0; i < array2.length; i++) {
      assertEquals(array2[i], propertyValue[i]);
    }

    node1.removeProperty(key);
    newTransaction();

    clearCache();
    assertTrue(!node1.hasProperty(key));
  }
Esempio n. 14
0
  @Test
  public void testBooleanArray() {
    boolean[] array1 = new boolean[] {true, false, true, false, true};
    Boolean[] array2 = new Boolean[] {false, true, false};
    String key = "testboolarray";
    node1.setProperty(key, array1);
    newTransaction();

    clearCache();
    boolean propertyValue[] = null;
    propertyValue = (boolean[]) node1.getProperty(key);
    assertEquals(array1.length, propertyValue.length);
    for (int i = 0; i < array1.length; i++) {
      assertEquals(array1[i], propertyValue[i]);
    }

    node1.setProperty(key, array2);
    newTransaction();

    clearCache();
    propertyValue = (boolean[]) node1.getProperty(key);
    assertEquals(array2.length, propertyValue.length);
    for (int i = 0; i < array2.length; i++) {
      assertEquals(array2[i], new Boolean(propertyValue[i]));
    }

    node1.removeProperty(key);
    newTransaction();

    clearCache();
    assertTrue(!node1.hasProperty(key));
  }
Esempio n. 15
0
  @Test
  public void testCharType() {
    char c = 'c';
    Character cValue = new Character(c);
    String key = "testchar";
    node1.setProperty(key, cValue);
    newTransaction();

    clearCache();
    Character propertyValue = null;
    propertyValue = (Character) node1.getProperty(key);
    assertEquals(cValue, propertyValue);

    cValue = new Character('d');
    node1.setProperty(key, cValue);
    newTransaction();

    clearCache();
    propertyValue = (Character) node1.getProperty(key);
    assertEquals(cValue, propertyValue);

    node1.removeProperty(key);
    newTransaction();

    clearCache();
    assertTrue(!node1.hasProperty(key));
  }
Esempio n. 16
0
  @Test
  public void testIntArray() {
    int[] array1 = new int[] {1, 2, 3, 4, 5};
    Integer[] array2 = new Integer[] {6, 7, 8};
    String key = "testintarray";
    node1.setProperty(key, array1);
    newTransaction();

    clearCache();
    int propertyValue[] = null;
    propertyValue = (int[]) node1.getProperty(key);
    assertEquals(array1.length, propertyValue.length);
    for (int i = 0; i < array1.length; i++) {
      assertEquals(array1[i], propertyValue[i]);
    }

    node1.setProperty(key, array2);
    newTransaction();

    clearCache();
    propertyValue = (int[]) node1.getProperty(key);
    assertEquals(array2.length, propertyValue.length);
    for (int i = 0; i < array2.length; i++) {
      assertEquals(array2[i], new Integer(propertyValue[i]));
    }

    node1.removeProperty(key);
    newTransaction();

    clearCache();
    assertTrue(!node1.hasProperty(key));
  }
Esempio n. 17
0
  @Test
  public void testShortType() {
    short value = 453;
    Short sValue = new Short(value);
    String key = "testshort";
    node1.setProperty(key, sValue);
    newTransaction();

    clearCache();
    Short propertyValue = null;
    propertyValue = (Short) node1.getProperty(key);
    assertEquals(sValue, propertyValue);

    sValue = new Short((short) 5335);
    node1.setProperty(key, sValue);
    newTransaction();

    clearCache();
    propertyValue = (Short) node1.getProperty(key);
    assertEquals(sValue, propertyValue);

    node1.removeProperty(key);
    newTransaction();

    clearCache();
    assertTrue(!node1.hasProperty(key));
  }
Esempio n. 18
0
  @Test
  public void testRemoveUnloadedHeavyProperty() {
    /*
     * Checks a bug where removing non-cached heavy properties
     * would cause NPE in auto indexer.
     */
    graphDb.index().getNodeAutoIndexer().setEnabled(true);
    graphDb.index().getNodeAutoIndexer().startAutoIndexingProperty("nodeProp");

    newTransaction();

    Node node1 = graphDb.createNode();
    // Large array, needed for making sure this is a heavy property
    node1.setProperty("nodeProp", new int[] {-1, 2, 3, 4, 5, 6, 1, 1, 1, 1});

    newTransaction();

    // clear the caches
    NeoStoreXaDataSource dataSource =
        graphDb.getDependencyResolver().resolveDependency(NeoStoreXaDataSource.class);
    dataSource.getNodeCache().clear();
    dataSource.getRelationshipCache().clear();

    node1.removeProperty("nodeProp");
    newTransaction();
    assertFalse(node1.hasProperty("nodeProp"));
  }
Esempio n. 19
0
  @Test
  public void testByteArray() {
    byte[] array1 = new byte[] {1, 2, 3, 4, 5};
    Byte[] array2 = new Byte[] {6, 7, 8};
    String key = "testbytearray";
    node1.setProperty(key, array1);
    newTransaction();

    clearCache();
    byte[] propertyValue = null;
    propertyValue = (byte[]) node1.getProperty(key);
    assertEquals(array1.length, propertyValue.length);
    for (int i = 0; i < array1.length; i++) {
      assertEquals(array1[i], propertyValue[i]);
    }

    node1.setProperty(key, array2);
    newTransaction();

    clearCache();
    propertyValue = (byte[]) node1.getProperty(key);
    assertEquals(array2.length, propertyValue.length);
    for (int i = 0; i < array2.length; i++) {
      assertEquals(array2[i], new Byte(propertyValue[i]));
    }

    node1.removeProperty(key);
    newTransaction();

    clearCache();
    assertTrue(!node1.hasProperty(key));
  }
 @Test
 public void testNodeMultiRemoveProperty() {
   Node node = getGraphDb().createNode();
   node.setProperty("key0", "0");
   node.setProperty("key1", "1");
   node.setProperty("key2", "2");
   node.setProperty("key3", "3");
   node.setProperty("key4", "4");
   newTransaction();
   node.removeProperty("key3");
   node.removeProperty("key2");
   node.removeProperty("key3");
   newTransaction();
   getNodeManager().clearCache();
   assertEquals("0", node.getProperty("key0"));
   assertEquals("1", node.getProperty("key1"));
   assertEquals("4", node.getProperty("key4"));
   assertTrue(!node.hasProperty("key2"));
   assertTrue(!node.hasProperty("key3"));
   node.delete();
 }
Esempio n. 21
0
 public void removeNodeProperty(long nodeId, String key)
     throws NodeNotFoundException, NoSuchPropertyException {
   Node node = node(nodeId);
   Transaction tx = graphDb.beginTx();
   try {
     if (node.removeProperty(key) == null) {
       throw new NoSuchPropertyException(node, key);
     }
     tx.success();
   } finally {
     tx.finish();
   }
 }
  @Test
  public void shouldAllowRemoveAndAddConflictingDataInOneTransaction_RemoveProperty()
      throws Exception {
    // given
    Node node = constrainedNode("Label1", "key1", "value1");

    newTransaction();

    // when
    node.removeProperty("key1");
    db.createNode(label("Label1")).setProperty("key1", "value1");
    commit();
  }
  @Test
  public void canRemoveShortStringProperty() throws Exception {
    long recordCount = dynamicRecordsInUse();
    long propCount = propertyRecordsInUse();
    GraphDatabaseService db = graphdb.getGraphDatabaseService();
    Node node = db.createNode();
    node.setProperty("key", "value");
    newTx();

    assertEquals(recordCount, dynamicRecordsInUse());
    assertEquals(propCount + 1, propertyRecordsInUse());
    assertEquals("value", node.getProperty("key"));

    node.removeProperty("key");
    commit();

    assertEquals(recordCount, dynamicRecordsInUse());
    assertEquals(propCount, propertyRecordsInUse());
    assertThat(node, inTx(db, not(hasProperty("key"))));
  }
Esempio n. 24
0
  @Test
  public void testDoubleType() {
    Double dValue = new Double(45.678d);
    String key = "testdouble";
    node1.setProperty(key, dValue);
    newTransaction();
    clearCache();
    Double propertyValue = null;
    propertyValue = (Double) node1.getProperty(key);
    assertEquals(dValue, propertyValue);
    dValue = new Double(56784.3243d);
    node1.setProperty(key, dValue);
    newTransaction();
    clearCache();
    propertyValue = (Double) node1.getProperty(key);
    assertEquals(dValue, propertyValue);

    node1.removeProperty(key);
    newTransaction();
    clearCache();
    assertTrue(!node1.hasProperty(key));
  }
  @Test
  public void testNodeRemoveProperty() {
    Node node1 = getGraphDb().getNodeById(node1Id);
    Node node2 = getGraphDb().getNodeById(node2Id);
    Relationship rel = node1.getSingleRelationship(MyRelTypes.TEST, Direction.BOTH);

    // test remove property
    assertEquals(1, node1.removeProperty(key1));
    assertEquals(2, node2.removeProperty(key1));
    assertEquals(1, rel.removeProperty(key1));
    assertEquals(string1, node1.removeProperty(key2));
    assertEquals(string2, node2.removeProperty(key2));
    assertEquals(string1, rel.removeProperty(key2));
    assertTrue(node1.removeProperty(arrayKey) != null);
    assertTrue(node2.removeProperty(arrayKey) != null);
    assertTrue(rel.removeProperty(arrayKey) != null);
  }
  @Test
  public void shouldGetCorrectTransactionDataUponCommit() {
    // Create new data, nothing modified, just added/created
    ExpectedTransactionData expectedData = new ExpectedTransactionData();
    VerifyingTransactionEventHandler handler = new VerifyingTransactionEventHandler(expectedData);
    GraphDatabaseService db = dbRule.getGraphDatabaseService();
    db.registerTransactionEventHandler(handler);
    Node node1 = null, node2, node3 = null;
    Relationship rel1 = null, rel2 = null;
    try {
      try (Transaction tx = db.beginTx()) {
        node1 = db.createNode();
        expectedData.expectedCreatedNodes.add(node1);

        node2 = db.createNode();
        expectedData.expectedCreatedNodes.add(node2);

        rel1 = node1.createRelationshipTo(node2, RelTypes.TXEVENT);
        expectedData.expectedCreatedRelationships.add(rel1);

        node1.setProperty("name", "Mattias");
        expectedData.assignedProperty(node1, "name", "Mattias", null);

        node1.setProperty("last name", "Persson");
        expectedData.assignedProperty(node1, "last name", "Persson", null);

        node1.setProperty("counter", 10);
        expectedData.assignedProperty(node1, "counter", 10, null);

        rel1.setProperty("description", "A description");
        expectedData.assignedProperty(rel1, "description", "A description", null);

        rel1.setProperty("number", 4.5D);
        expectedData.assignedProperty(rel1, "number", 4.5D, null);

        node3 = db.createNode();
        expectedData.expectedCreatedNodes.add(node3);
        rel2 = node3.createRelationshipTo(node2, RelTypes.TXEVENT);
        expectedData.expectedCreatedRelationships.add(rel2);

        node3.setProperty("name", "Node 3");
        expectedData.assignedProperty(node3, "name", "Node 3", null);
        tx.success();
      }

      assertTrue("Should have been invoked", handler.hasBeenCalled());
      if (handler.failure() != null) {
        throw new RuntimeException(handler.failure());
      }
    } finally {
      db.unregisterTransactionEventHandler(handler);
    }

    // Use the above data and modify it, change properties, delete stuff
    expectedData = new ExpectedTransactionData();
    handler = new VerifyingTransactionEventHandler(expectedData);
    db.registerTransactionEventHandler(handler);
    try {
      try (Transaction tx = db.beginTx()) {
        Node newNode = db.createNode();
        expectedData.expectedCreatedNodes.add(newNode);

        Node tempNode = db.createNode();
        Relationship tempRel = tempNode.createRelationshipTo(node1, RelTypes.TXEVENT);
        tempNode.setProperty("something", "Some value");
        tempRel.setProperty("someproperty", 101010);
        tempNode.removeProperty("nothing");

        node3.setProperty("test", "hello");
        node3.setProperty("name", "No name");
        node3.delete();
        expectedData.expectedDeletedNodes.add(node3);
        expectedData.removedProperty(node3, "name", null, "Node 3");

        node1.setProperty("new name", "A name");
        node1.setProperty("new name", "A better name");
        expectedData.assignedProperty(node1, "new name", "A better name", null);
        node1.setProperty("name", "Nothing");
        node1.setProperty("name", "Mattias Persson");
        expectedData.assignedProperty(node1, "name", "Mattias Persson", "Mattias");
        node1.removeProperty("counter");
        expectedData.removedProperty(node1, "counter", null, 10);
        node1.removeProperty("last name");
        node1.setProperty("last name", "Hi");
        expectedData.assignedProperty(node1, "last name", "Hi", "Persson");

        rel2.delete();
        expectedData.expectedDeletedRelationships.add(rel2);

        rel1.removeProperty("number");
        expectedData.removedProperty(rel1, "number", null, 4.5D);
        rel1.setProperty("description", "Ignored");
        rel1.setProperty("description", "New");
        expectedData.assignedProperty(rel1, "description", "New", "A description");

        tempRel.delete();
        tempNode.delete();
        tx.success();
      }

      assertTrue("Should have been invoked", handler.hasBeenCalled());
      if (handler.failure() != null) {
        throw new RuntimeException(handler.failure());
      }
    } finally {
      db.unregisterTransactionEventHandler(handler);
    }
  }
 @BreakpointTrigger
 void removeProperty(Node node, String key) {
   node.removeProperty(key);
 }
Esempio n. 28
0
  private Node quadraticSplit(Node indexNode, RelationshipType relationshipType) {
    List<Node> entries = new ArrayList<Node>();

    Iterable<Relationship> relationships =
        indexNode.getRelationships(relationshipType, Direction.OUTGOING);
    for (Relationship relationship : relationships) {
      entries.add(relationship.getEndNode());
      relationship.delete();
    }

    // pick two seed entries such that the dead space is maximal
    Node seed1 = null;
    Node seed2 = null;
    double worst = Double.NEGATIVE_INFINITY;
    for (int i = 0; i < entries.size(); ++i) {
      Node e = entries.get(i);
      Envelope eEnvelope = getChildNodeEnvelope(e, relationshipType);
      for (int j = i + 1; j < entries.size(); ++j) {
        Node e1 = entries.get(j);
        Envelope e1Envelope = getChildNodeEnvelope(e1, relationshipType);
        double deadSpace =
            getArea(createEnvelope(eEnvelope, e1Envelope))
                - getArea(eEnvelope)
                - getArea(e1Envelope);
        if (deadSpace > worst) {
          worst = deadSpace;
          seed1 = e;
          seed2 = e1;
        }
      }
    }

    List<Node> group1 = new ArrayList<Node>();
    group1.add(seed1);
    Envelope group1envelope = getChildNodeEnvelope(seed1, relationshipType);

    List<Node> group2 = new ArrayList<Node>();
    group2.add(seed2);
    Envelope group2envelope = getChildNodeEnvelope(seed2, relationshipType);

    entries.remove(seed1);
    entries.remove(seed2);
    while (entries.size() > 0) {
      // compute the cost of inserting each entry
      List<Node> bestGroup = null;
      Envelope bestGroupEnvelope = null;
      Node bestEntry = null;
      double expansionMin = Double.POSITIVE_INFINITY;
      for (Node e : entries) {
        Envelope nodeEnvelope = getChildNodeEnvelope(e, relationshipType);
        double expansion1 =
            getArea(createEnvelope(nodeEnvelope, group1envelope)) - getArea(group1envelope);
        double expansion2 =
            getArea(createEnvelope(nodeEnvelope, group2envelope)) - getArea(group2envelope);

        if (expansion1 < expansion2 && expansion1 < expansionMin) {
          bestGroup = group1;
          bestGroupEnvelope = group1envelope;
          bestEntry = e;
          expansionMin = expansion1;
        } else if (expansion2 < expansion1 && expansion2 < expansionMin) {
          bestGroup = group2;
          bestGroupEnvelope = group2envelope;
          bestEntry = e;
          expansionMin = expansion2;
        } else if (expansion1 == expansion2 && expansion1 < expansionMin) {
          // in case of equality choose the group with the smallest area
          if (getArea(group1envelope) < getArea(group2envelope)) {
            bestGroup = group1;
            bestGroupEnvelope = group1envelope;
          } else {
            bestGroup = group2;
            bestGroupEnvelope = group2envelope;
          }
          bestEntry = e;
          expansionMin = expansion1;
        }
      }

      // insert the best candidate entry in the best group
      bestGroup.add(bestEntry);
      bestGroupEnvelope.expandToInclude(getChildNodeEnvelope(bestEntry, relationshipType));

      entries.remove(bestEntry);
    }

    // reset bounding box and add new children
    indexNode.removeProperty(INDEX_PROP_BBOX);
    for (Node node : group1) {
      addChild(indexNode, relationshipType, node);
    }

    // create new node from split
    Node newIndexNode = database.createNode();
    for (Node node : group2) {
      addChild(newIndexNode, relationshipType, node);
    }

    return newIndexNode;
  }
 @Override
 protected void doSomething() throws Throwable {
   Pair<Integer, Node> pair = getNode(random, false);
   Node node = pair.other();
   node.removeProperty(randomPropertyKey(random));
 }
Esempio n. 30
0
  @Test
  public void testMutations() throws Exception {
    graphDb.index().getNodeAutoIndexer().startAutoIndexingProperty("nodeProp1");
    graphDb.index().getNodeAutoIndexer().startAutoIndexingProperty("nodeProp2");
    graphDb.index().getNodeAutoIndexer().setEnabled(true);
    Transaction tx = graphDb.beginTx();
    Node node1 = null, node2 = null, node3 = null, node4 = null;
    try {
      // Create the primitives
      node1 = graphDb.createNode();
      node2 = graphDb.createNode();
      node3 = graphDb.createNode();
      node4 = graphDb.createNode();

      // Add indexable and non-indexable properties
      node1.setProperty("nodeProp1", "nodeProp1Value");
      node2.setProperty("nodeProp2", "nodeProp2Value");
      node3.setProperty("nodeProp1", "nodeProp3Value");
      node4.setProperty("nodeProp2", "nodeProp4Value");

      // Make things persistent
      tx.success();
    } finally {
      tx.finish();
    }

    /*
     *  Here both nodes are indexed. To demonstrate removal, we stop
     *  auto-indexing nodeProp1.
     */
    AutoIndexer<Node> nodeAutoIndexer = graphDb.index().getNodeAutoIndexer();
    nodeAutoIndexer.stopAutoIndexingProperty("nodeProp1");

    tx = graphDb.beginTx();
    try {
      /*
       * nodeProp1 is no longer auto indexed. It will be
       * removed regardless. Note that node3 will remain.
       */
      node1.setProperty("nodeProp1", "nodeProp1Value2");
      /*
       * node2 will be auto updated
       */
      node2.setProperty("nodeProp2", "nodeProp2Value2");
      /*
       * remove node4 property nodeProp2 from index.
       */
      node4.removeProperty("nodeProp2");
      // Make things persistent
      tx.success();
    } catch (Exception e) {
      tx.failure();
    } finally {
      tx.finish();
    }

    Transaction transaction = graphDb.beginTx();
    // Verify
    ReadableIndex<Node> nodeAutoIndex = nodeAutoIndexer.getAutoIndex();
    // node1 is completely gone
    assertFalse(nodeAutoIndex.get("nodeProp1", "nodeProp1Value").hasNext());
    assertFalse(nodeAutoIndex.get("nodeProp1", "nodeProp1Value2").hasNext());
    // node2 is updated
    assertFalse(nodeAutoIndex.get("nodeProp2", "nodeProp2Value").hasNext());
    assertEquals(node2, nodeAutoIndex.get("nodeProp2", "nodeProp2Value2").getSingle());
    /*
     * node3 is still there, despite its nodeProp1 property not being monitored
     * any more because it was not touched, contrary to node1.
     */
    assertEquals(node3, nodeAutoIndex.get("nodeProp1", "nodeProp3Value").getSingle());
    // Finally, node4 is removed because the property was removed.
    assertFalse(nodeAutoIndex.get("nodeProp2", "nodeProp4Value").hasNext());
    // END SNIPPET: Mutations
    transaction.finish();
  }