org.neo4j.graphdb.Node.removeProperty()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(168)

本文整理了Java中org.neo4j.graphdb.Node.removeProperty()方法的一些代码示例,展示了Node.removeProperty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.removeProperty()方法的具体详情如下:
包路径:org.neo4j.graphdb.Node
类名称:Node
方法名:removeProperty

Node.removeProperty介绍

暂无

代码示例

代码示例来源:origin: neo4j/neo4j

  1. @Test
  2. public void shouldHandleRemovePropertyConcurrentlyWithIndexDrop() throws Throwable
  3. {
  4. shouldHandleIndexDropConcurrentlyWithOperation( nodeId -> db.getNodeById( nodeId ).removeProperty( KEY ) );
  5. }

代码示例来源:origin: neo4j/neo4j

  1. @SuppressWarnings( "boxing" )
  2. @Override
  3. public Void beforeCommit( TransactionData data )
  4. {
  5. if ( Iterables.count( data.createdRelationships() ) == 0 )
  6. {
  7. return null;
  8. }
  9. node.setProperty( "counter", ((Long) node.removeProperty( "counter" )) + 1 );
  10. return null;
  11. }

代码示例来源:origin: neo4j/neo4j

  1. @Test
  2. public void largeTx()
  3. {
  4. Node node = getGraphDb().createNode();
  5. node.setProperty( "anchor", "hi" );
  6. for ( int i = 0; i < 255; i++ )
  7. {
  8. node.setProperty( "foo", 1 );
  9. node.removeProperty( "foo" );
  10. }
  11. commit();
  12. }

代码示例来源:origin: neo4j/neo4j

  1. @Test
  2. public void addAndRemovePropertiesWithinOneTransaction()
  3. {
  4. Node node = getGraphDb().createNode();
  5. node.setProperty( "name", "oscar" );
  6. node.setProperty( "favourite_numbers", new Long[] { 1L, 2L, 3L } );
  7. node.setProperty( "favourite_colors", new String[] { "blue", "red" } );
  8. node.removeProperty( "favourite_colors" );
  9. newTransaction();
  10. assertNotNull( node.getProperty( "favourite_numbers", null ) );
  11. }

代码示例来源:origin: neo4j/neo4j

  1. @Test
  2. public void testNodeRemoveProperty()
  3. {
  4. Node node1 = getGraphDb().getNodeById( node1Id );
  5. Node node2 = getGraphDb().getNodeById( node2Id );
  6. Relationship rel = node1.getSingleRelationship( MyRelTypes.TEST,
  7. Direction.BOTH );
  8. // test remove property
  9. assertEquals( 1, node1.removeProperty( key1 ) );
  10. assertEquals( 2, node2.removeProperty( key1 ) );
  11. assertEquals( 1, rel.removeProperty( key1 ) );
  12. assertEquals( string1, node1.removeProperty( key2 ) );
  13. assertEquals( string2, node2.removeProperty( key2 ) );
  14. assertEquals( string1, rel.removeProperty( key2 ) );
  15. assertNotNull( node1.removeProperty( arrayKey ) );
  16. assertNotNull( node2.removeProperty( arrayKey ) );
  17. assertNotNull( rel.removeProperty( arrayKey ) );
  18. }

代码示例来源:origin: neo4j/neo4j

  1. private void setAndRemoveSomeProperties( GraphDatabaseService graphDatabaseService, Object value )
  2. {
  3. Node commonNode;
  4. try ( Transaction transaction = graphDatabaseService.beginTx() )
  5. {
  6. commonNode = graphDatabaseService.createNode();
  7. for ( int i = 0; i < 10; i++ )
  8. {
  9. commonNode.setProperty( "key" + i, value );
  10. }
  11. transaction.success();
  12. }
  13. try ( Transaction transaction = graphDatabaseService.beginTx() )
  14. {
  15. for ( int i = 0; i < 10; i++ )
  16. {
  17. commonNode.removeProperty( "key" + i );
  18. }
  19. transaction.success();
  20. }
  21. }
  22. }

代码示例来源:origin: neo4j/neo4j

  1. @Test
  2. public void removingPropertyDoesNotBreakPreviouslyCreatedNodePropertyKeysIterator()
  3. {
  4. // GIVEN
  5. GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
  6. try ( Transaction tx = db.beginTx() )
  7. {
  8. Node node = db.createNode();
  9. node.setProperty( "name", "Horst" );
  10. node.setProperty( "age", "72" );
  11. Iterator<String> iterator = node.getPropertyKeys().iterator();
  12. while ( iterator.hasNext() )
  13. {
  14. node.removeProperty( iterator.next() );
  15. }
  16. tx.success();
  17. }
  18. }

代码示例来源:origin: neo4j/neo4j

  1. private void changeRandomNode( GraphDatabaseService db, int nodeCount, RandomValues random )
  2. {
  3. try ( Transaction tx = db.beginTx() )
  4. {
  5. long nodeId = random.nextInt( nodeCount );
  6. Node node = db.getNodeById( nodeId );
  7. Object[] keys = Iterables.asCollection( node.getPropertyKeys() ).toArray();
  8. String key = (String) random.among( keys );
  9. if ( random.nextFloat() < 0.1 )
  10. { // REMOVE
  11. node.removeProperty( key );
  12. }
  13. else
  14. { // CHANGE
  15. node.setProperty( key, random.nextValue().asObject() );
  16. }
  17. tx.success();
  18. }
  19. catch ( NotFoundException e )
  20. { // It's OK, it happens if some other thread deleted that property in between us reading it and
  21. // removing or setting it
  22. }
  23. }

代码示例来源:origin: neo4j/neo4j

  1. @Test
  2. public void removeOneOfThree()
  3. {
  4. Node node = getGraphDb().createNode();
  5. node.setProperty( "1", 1 );
  6. node.setProperty( "2", 2 );
  7. node.setProperty( "3", 3 );
  8. newTransaction();
  9. node.removeProperty( "2" );
  10. newTransaction();
  11. assertNull( node.getProperty( "2", null ) );
  12. }

代码示例来源:origin: neo4j/neo4j

  1. node.setProperty( key, random.nextValueAsObject() );
  2. random.among( nodes, node -> node.setProperty( random.among( keys ), random.nextValueAsObject() ) );
  3. random.among( nodes, node -> node.removeProperty( random.among( keys ) ) );

代码示例来源:origin: neo4j/neo4j

  1. @Test
  2. public void testNodeChangeProperty2()
  3. {
  4. String key1 = "key1";
  5. Integer int1 = 1;
  6. Integer int2 = 2;
  7. String string1 = "1";
  8. String string2 = "2";
  9. Boolean bool1 = Boolean.TRUE;
  10. Boolean bool2 = Boolean.FALSE;
  11. Node node1 = getGraphDb().createNode();
  12. node1.setProperty( key1, int1 );
  13. node1.setProperty( key1, int2 );
  14. assertEquals( int2, node1.getProperty( key1 ) );
  15. node1.removeProperty( key1 );
  16. node1.setProperty( key1, string1 );
  17. node1.setProperty( key1, string2 );
  18. assertEquals( string2, node1.getProperty( key1 ) );
  19. node1.removeProperty( key1 );
  20. node1.setProperty( key1, bool1 );
  21. node1.setProperty( key1, bool2 );
  22. assertEquals( bool2, node1.getProperty( key1 ) );
  23. node1.removeProperty( key1 );
  24. node1.delete();
  25. }

代码示例来源:origin: neo4j/neo4j

  1. if ( random.nextBoolean() )
  2. node.setProperty( randomKey(), random.nextValueAsObject() );
  3. random.among( nodes, node -> node.setProperty( randomKey(), random.nextValueAsObject() ) );
  4. random.among( nodes, node -> node.removeProperty( randomKey() ) );

代码示例来源:origin: neo4j/neo4j

  1. @Test
  2. public void removeAndAddSameProperty()
  3. {
  4. Node node = getGraphDb().createNode();
  5. node.setProperty( "foo", "bar" );
  6. newTransaction();
  7. node.removeProperty( "foo" );
  8. node.setProperty( "foo", "bar" );
  9. newTransaction();
  10. assertEquals( "bar", node.getProperty( "foo" ) );
  11. node.setProperty( "foo", "bar" );
  12. node.removeProperty( "foo" );
  13. newTransaction();
  14. assertNull( node.getProperty( "foo", null ) );
  15. }

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

  1. Object catValue = cat.getProperty(copiedKey, null);
  2. if (catValue == null) {
  3. cat.setProperty(copiedKey, copiedValue);
  4. node.removeProperty(copiedKey);
  5. } else if (copiedValue.equals(catValue)) {
  6. node.removeProperty(copiedKey);
  7. node.removeProperty(sourceKey);

代码示例来源:origin: neo4j/neo4j

  1. @Test
  2. public void testChangeProperty()
  3. {
  4. Node node = getGraphDb().createNode();
  5. node.setProperty( "test", "test1" );
  6. tx.success();
  7. tx.begin();
  8. node.setProperty( "test", "test2" );
  9. node.removeProperty( "test" );
  10. node.setProperty( "test", "test3" );
  11. assertEquals( "test3", node.getProperty( "test" ) );
  12. node.removeProperty( "test" );
  13. node.setProperty( "test", "test4" );
  14. tx.success();
  15. tx.begin();
  16. assertEquals( "test4", node.getProperty( "test" ) );
  17. }

代码示例来源:origin: SciGraph/SciGraph

  1. public void dropIndex() {
  2. if (indexExists()) {
  3. Transaction tx = graphDb.beginTx();
  4. // ...cleanup the index.
  5. int counter = 0;
  6. for (Node n : graphDb.getAllNodes()) {
  7. n.removeProperty(IN_LIST_PROPERTY);
  8. n.removeProperty(OUT_LIST_PROPERTY);
  9. tx = batchTransactions(tx, counter++);
  10. }
  11. // reset the flag.
  12. metaDataNode.setProperty(INDEX_EXISTS_PROPERTY, false);
  13. tx.success();
  14. tx.close();
  15. logger.info("Reachability index dropped.");
  16. } else {
  17. logger.warning("There was no reachability index to drop.");
  18. }
  19. }

代码示例来源:origin: neo4j/neo4j

  1. @Test
  2. public void testNodeRemoveProperty()
  3. if ( node1.removeProperty( key1 ) != null )
  4. node1.removeProperty( null );
  5. fail( "Remove null property should throw exception." );
  6. node1.setProperty( key1, int1 );
  7. node2.setProperty( key1, string1 );
  8. node1.setProperty( key2, string2 );
  9. node2.setProperty( key2, int2 );
  10. try
  11. node1.removeProperty( null );
  12. fail( "Null argument should result in exception." );
  13. assertEquals( int1, node1.removeProperty( key1 ) );
  14. assertEquals( string1, node2.removeProperty( key1 ) );
  15. if ( node2.removeProperty( key1 ) != null )

代码示例来源:origin: neo4j/neo4j

  1. @Test
  2. public void addAndRemovePropertiesWithinOneTransaction2()
  3. {
  4. Node node = getGraphDb().createNode();
  5. node.setProperty( "foo", "bar" );
  6. newTransaction();
  7. node.setProperty( "foo2", "bar" );
  8. node.removeProperty( "foo" );
  9. newTransaction();
  10. try
  11. {
  12. node.getProperty( "foo" );
  13. fail( "property should not exist" );
  14. }
  15. catch ( NotFoundException e )
  16. {
  17. // good
  18. }
  19. }

代码示例来源:origin: neo4j/neo4j

  1. @Test
  2. public void testNodeMultiRemoveProperty()
  3. {
  4. Node node = getGraphDb().createNode();
  5. node.setProperty( "key0", "0" );
  6. node.setProperty( "key1", "1" );
  7. node.setProperty( "key2", "2" );
  8. node.setProperty( "key3", "3" );
  9. node.setProperty( "key4", "4" );
  10. newTransaction();
  11. node.removeProperty( "key3" );
  12. node.removeProperty( "key2" );
  13. node.removeProperty( "key3" );
  14. newTransaction();
  15. assertEquals( "0", node.getProperty( "key0" ) );
  16. assertEquals( "1", node.getProperty( "key1" ) );
  17. assertEquals( "4", node.getProperty( "key4" ) );
  18. assertTrue( !node.hasProperty( "key2" ) );
  19. assertTrue( !node.hasProperty( "key3" ) );
  20. node.delete();
  21. }

代码示例来源:origin: neo4j/neo4j

  1. @Test
  2. public void testAdditionHappensInTheMiddleIfItFits()
  3. {
  4. Node node = getGraphDb().createNode();
  5. long recordsInUseAtStart = propertyRecordsInUse();
  6. node.setProperty( "int1", 1 );
  7. node.setProperty( "double1", 1.0 );
  8. node.setProperty( "int2", 2 );
  9. int stuffedShortStrings = 0;
  10. for ( ; stuffedShortStrings < PropertyType.getPayloadSizeLongs(); stuffedShortStrings++ )
  11. {
  12. node.setProperty( "shortString" + stuffedShortStrings, String.valueOf( stuffedShortStrings ) );
  13. }
  14. newTransaction();
  15. assertEquals( recordsInUseAtStart + 2, propertyRecordsInUse() );
  16. node.removeProperty( "shortString" + 1 );
  17. node.setProperty( "int3", 3 );
  18. newTransaction();
  19. assertEquals( recordsInUseAtStart + 2, propertyRecordsInUse() );
  20. }

相关文章