@Override public long createRelationship( long node1, long node2, RelationshipType type, Map<String,Object> properties ) { return delegate.createRelationship( node1, node2, type, properties ); }
private void createRelationships( BatchInserter inserter, long node, RelationshipType relType, int out ) { for ( int i = 0; i < out; i++ ) { inserter.createRelationship( node, inserter.createNode( null ), relType, null ); } for ( int i = 0; i < out; i++ ) { inserter.createRelationship( inserter.createNode( null ), node, relType, null ); } for ( int i = 0; i < out; i++ ) { inserter.createRelationship( node, node, relType, null ); } }
@Test public void shouldIgnoreRemovingNonExistentRelationshipProperty() { // given BatchInserter inserter = globalInserter; Map<String,Object> noProperties = Collections.emptyMap(); long nodeId1 = inserter.createNode( noProperties ); long nodeId2 = inserter.createNode( noProperties ); long id = inserter.createRelationship( nodeId1, nodeId2, MyRelTypes.TEST, noProperties ); // when inserter.removeRelationshipProperty( id, "non-existent" ); // then no exception should be thrown, this mimics GraphDatabaseService behaviour }
@Test public void testMore() { BatchInserter graphDb = globalInserter; long startNode = graphDb.createNode( properties ); long[] endNodes = new long[25]; Set<Long> rels = new HashSet<>(); for ( int i = 0; i < 25; i++ ) { endNodes[i] = graphDb.createNode( properties ); rels.add( graphDb.createRelationship( startNode, endNodes[i], relTypeArray[i % 5], properties ) ); } for ( BatchRelationship rel : graphDb.getRelationships( startNode ) ) { assertTrue( rels.contains( rel.getId() ) ); assertEquals( rel.getStartNode(), startNode ); } graphDb.setNodeProperties( startNode, properties ); }
@Test public void createEntitiesWithEmptyPropertiesMap() { BatchInserter inserter = globalInserter; // Assert for node long nodeId = inserter.createNode( map() ); getNodeProperties( inserter, nodeId ); //cp=N U http://www.w3.org/1999/02/22-rdf-syntax-ns#type, c=N // Assert for relationship long anotherNodeId = inserter.createNode( null ); long relId = inserter.createRelationship( nodeId, anotherNodeId, RelTypes.BATCH_TEST, map() ); inserter.getRelationshipProperties( relId ); }
long theRel = inserter.createRelationship( from, to, RelationshipType.withName( "TestingPropsHere" ), MapUtil.map( "foo", "bar" ) );
@Test public void testNodeHasProperty() { BatchInserter inserter = globalInserter; long theNode = inserter.createNode( properties ); long anotherNode = inserter.createNode( Collections.emptyMap() ); long relationship = inserter.createRelationship( theNode, anotherNode, RelationshipType.withName( "foo" ), properties ); for ( String key : properties.keySet() ) { assertTrue( inserter.nodeHasProperty( theNode, key ) ); assertFalse( inserter.nodeHasProperty( theNode, key + "-" ) ); assertTrue( inserter.relationshipHasProperty( relationship, key ) ); assertFalse( inserter.relationshipHasProperty( relationship, key + "-" ) ); } }
@Test public void createBatchNodeAndRelationshipsDeleteAllInEmbedded() throws Exception { /* * ()--[REL_TYPE1]-->(node)--[BATCH_TEST]->() */ BatchInserter inserter = newBatchInserter(); long nodeId = inserter.createNode( null ); inserter.createRelationship( nodeId, inserter.createNode( null ), RelTypes.BATCH_TEST, null ); inserter.createRelationship( inserter.createNode( null ), nodeId, RelTypes.REL_TYPE1, null ); // Delete node and all its relationships GraphDatabaseService db = switchToEmbeddedGraphDatabaseService( inserter ); try ( Transaction tx = db.beginTx() ) { Node node = db.getNodeById( nodeId ); for ( Relationship relationship : node.getRelationships() ) { relationship.delete(); } node.delete(); tx.success(); } db.shutdown(); }
@Test public void mustSplitUpRelationshipChainsWhenCreatingDenseNodes() { BatchInserter inserter = globalInserter; long node1 = inserter.createNode( null ); long node2 = inserter.createNode( null ); for ( int i = 0; i < 1000; i++ ) { for ( MyRelTypes relType : MyRelTypes.values() ) { inserter.createRelationship( node1, node2, relType, null ); } } NeoStores neoStores = getFlushedNeoStores( inserter ); NodeRecord record = getRecord( neoStores.getNodeStore(), node1 ); assertTrue( "Node " + record + " should have been dense", record.isDense() ); }
@Test public void testSimple() { BatchInserter graphDb = globalInserter; long node1 = graphDb.createNode( null ); long node2 = graphDb.createNode( null ); long rel1 = graphDb.createRelationship( node1, node2, RelTypes.BATCH_TEST, null ); BatchRelationship rel = graphDb.getRelationshipById( rel1 ); assertEquals( rel.getStartNode(), node1 ); assertEquals( rel.getEndNode(), node2 ); assertEquals( RelTypes.BATCH_TEST.name(), rel.getType().name() ); }
long relationship = inserter.createRelationship( theNode, anotherNode, RelationshipType.withName( "foo" ), properties );
long startNode = graphDb.createNode( properties ); long otherNode = graphDb.createNode( properties ); long selfRelationship = graphDb.createRelationship( startNode, startNode, relTypeArray[0], properties ); long relationship = graphDb.createRelationship( startNode, otherNode, relTypeArray[0], properties ); for ( BatchRelationship rel : graphDb.getRelationships( startNode ) )
@Override protected void relateNodes(Long src, Long dest) { inserter.createRelationship(src, dest, Neo4jGraphDatabase.RelTypes.SIMILAR, null); } }
/** * {@inheritDoc} */ @Override public long createRelationship(long first, long second, BatchInserter batchInserter) { return batchInserter.createRelationship(first, second, FRIEND_OF, Collections.EMPTY_MAP); } }
@Override public long createRelationship( long node1, long node2, RelationshipType type, Map<String,Object> properties ) { return delegate.createRelationship( node1, node2, type, properties ); }
long relationshipId = inserter.createRelationship(nodeId, targetNodeId, relType, relationshipProperties);
private void createRelationship(long nodeId, String link) { Long linkNodeId = findNodeId(link); if (linkNodeId != null) { inserter.createRelationship(nodeId, linkNodeId, WikiRelationship.Link, null); linkCounter.increment(); } else { badLinkCount++; } }
@Override public long createRelationship(long start, long end, RelationshipType type) { synchronized (graphLock) { if (!relationshipMap.containsKey(start, end, type)) { long relationshipId = inserter.createRelationship(start, end, type, Collections.<String, Object>emptyMap()); relationshipMap.put(start, end, type, relationshipId); } } return relationshipMap.get(start, end, type); }
/** * {@inheritDoc} */ @Override public Relationship createRelationshipTo(Node otherNode, RelationshipType type) { return new BatchInserterRelationship(batchInserter.createRelationship(id, otherNode.getId(), type, Collections.<String, Object>emptyMap()), id, otherNode.getId(), type, batchInserter); }
private static boolean createRelationship(BatchInserter targetDb, BatchInserter sourceDb, BatchRelationship rel, Set<String> ignoreProperties, PrimitiveLongLongMap copiedNodeIds) { long startNodeId = copiedNodeIds.get(rel.getStartNode()); long endNodeId = copiedNodeIds.get(rel.getEndNode()); if (startNodeId == -1L || endNodeId == -1L) return false; final RelationshipType type = rel.getType(); try { Map<String, Object> props = getProperties(sourceDb.getRelationshipProperties(rel.getId()), ignoreProperties); // if (props.isEmpty()) props = Collections.<String,Object>singletonMap("old_id",rel.getId()); else props.put("old_id",rel.getId()); targetDb.createRelationship(startNodeId, endNodeId, type, props); return true; } catch (Exception e) { addLog(rel, "create Relationship: " + startNodeId + "-[:" + type + "]" + "->" + endNodeId, e.getMessage()); return false; } }