当前位置: 首页>>代码示例>>Java>>正文


Java BatchInserter类代码示例

本文整理汇总了Java中org.neo4j.unsafe.batchinsert.BatchInserter的典型用法代码示例。如果您正苦于以下问题:Java BatchInserter类的具体用法?Java BatchInserter怎么用?Java BatchInserter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BatchInserter类属于org.neo4j.unsafe.batchinsert包,在下文中一共展示了BatchInserter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldNotIndexNodesWithWrongLabel

import org.neo4j.unsafe.batchinsert.BatchInserter; //导入依赖的package包/类
@Test
public void shouldNotIndexNodesWithWrongLabel() throws Exception
{
    // Given
    BatchInserter inserter = BatchInserters.inserter( dbRule.getStoreDirAbsolutePath() );

    inserter.createNode( map("name", "Bob"), label( "User" ), label("Admin"));

    inserter.createDeferredSchemaIndex( label( "Banana" ) ).on( "name" ).create();

    // When
    inserter.shutdown();

    // Then
    GraphDatabaseService db = dbRule.getGraphDatabaseService();
    try(Transaction tx = db.beginTx())
    {
        assertThat( count( db.findNodes( label( "Banana" ), "name", "Bob" ) ), equalTo(0) );
    }
    finally
    {
        db.shutdown();
    }

}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:26,代码来源:BatchInsertionIT.java

示例2: shouldBeAbleToMakeRepeatedCallsToSetNodeProperty

import org.neo4j.unsafe.batchinsert.BatchInserter; //导入依赖的package包/类
@Test
public void shouldBeAbleToMakeRepeatedCallsToSetNodeProperty() throws Exception
{
    BatchInserter inserter = BatchInserters.inserter( dbRule.getStoreDirAbsolutePath() );
    long nodeId = inserter.createNode( Collections.<String, Object>emptyMap() );

    final Object finalValue = 87;
    inserter.setNodeProperty( nodeId, "a", "some property value" );
    inserter.setNodeProperty( nodeId, "a", 42 );
    inserter.setNodeProperty( nodeId, "a", 3.14 );
    inserter.setNodeProperty( nodeId, "a", true );
    inserter.setNodeProperty( nodeId, "a", finalValue );
    inserter.shutdown();

    GraphDatabaseService db = dbRule.getGraphDatabaseService();
    try(Transaction ignored = db.beginTx())
    {
        assertThat( db.getNodeById( nodeId ).getProperty( "a" ), equalTo( finalValue ) );
    }
    finally
    {
        db.shutdown();
    }
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:25,代码来源:BatchInsertionIT.java

示例3: testInsertionSpeed

import org.neo4j.unsafe.batchinsert.BatchInserter; //导入依赖的package包/类
@Ignore
@Test
public void testInsertionSpeed() throws Exception
{
    BatchInserter inserter = BatchInserters.inserter( dbRule.getStoreDirAbsolutePath() );
    BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProvider( inserter );
    BatchInserterIndex index = provider.nodeIndex( "yeah", EXACT_CONFIG );
    index.setCacheCapacity( "key", 1000000 );
    long t = currentTimeMillis();
    for ( int i = 0; i < 1000000; i++ )
    {
        Map<String, Object> properties = map( "key", "value" + i );
        long id = inserter.createNode( properties );
        index.add( id, properties );
    }
    System.out.println( "insert:" + ( currentTimeMillis() - t ) );
    index.flush();

    t = currentTimeMillis();
    for ( int i = 0; i < 1000000; i++ )
    {
        count( (Iterator<Long>) index.get( "key", "value" + i ) );
    }
    System.out.println( "get:" + ( currentTimeMillis() - t ) );
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:26,代码来源:BatchInsertionIT.java

示例4: testBatchIndexToAutoIndex

import org.neo4j.unsafe.batchinsert.BatchInserter; //导入依赖的package包/类
@Test
public void testBatchIndexToAutoIndex() throws IOException {
  BatchInserter inserter = BatchInserters.inserter(new File(path));
  BatchInserterIndexProvider indexProvider = new LuceneBatchInserterIndexProvider(inserter);
  BatchInserterIndex index =
      indexProvider.nodeIndex("node_auto_index", MapUtil.stringMap("type", "exact"));
  long node = inserter.createNode(MapUtil.map("foo", "bar"));
  index.add(node, MapUtil.map("foo", "bar"));
  index.flush();
  assertThat("Batch indexed node can be retrieved", index.get("foo", "bar").next(), is(node));
  indexProvider.shutdown();
  inserter.shutdown();
  graphDb = getGraphDb();
  try (Transaction tx = graphDb.beginTx()) {
    assertThat("AutoIndex is not enabled after reopening the graph", graphDb.index()
        .getNodeAutoIndexer().isEnabled(), is(false));
    assertThat("AutoIndexed properties are not maintained after closing the graph", graphDb
        .index().getNodeAutoIndexer().getAutoIndexedProperties(), is(empty()));
    assertThat("Batch index properties are in the index", graphDb.index().getNodeAutoIndexer()
        .getAutoIndex().query("foo", "bar").size(), is(1));
    tx.success();
  }
}
 
开发者ID:SciGraph,项目名称:SciGraph,代码行数:24,代码来源:Neo4jIndexingTest.java

示例5: registerShutdownHook

import org.neo4j.unsafe.batchinsert.BatchInserter; //导入依赖的package包/类
/**
 * 
 * @param graph2
 */
private static void registerShutdownHook(final BatchInserter graph2) {
	if (lastBatchGraph == null) {
		Runtime.getRuntime().addShutdownHook(new Thread() {
			@Override
			public void run() {
				try {
					final long l = System.nanoTime();
					lastBatchGraph.shutdown();
					LOGGER.info("SHUTDOWN HOOK INVOKED: (took ~{}sec to commit changes", (System.nanoTime() - l) / 1_000_000_000);
				} catch (Exception e) {
					LOGGER.error("Error during shutdown hook", e);
				}
			}
		});
	}
	lastBatchGraph = graph2;
}
 
开发者ID:mondo-project,项目名称:mondo-hawk,代码行数:22,代码来源:Neo4JBatchUtil.java

示例6: BatchNeo4jProcessor

import org.neo4j.unsafe.batchinsert.BatchInserter; //导入依赖的package包/类
public BatchNeo4jProcessor(final BatchInserter inserter) throws DMPGraphException {

		this.inserter = inserter;

		BatchNeo4jProcessor.LOG.debug("start writing");

		bnodes = new ObjectLongOpenHashMap<>();
		nodeResourceMap = new LongLongOpenHashMap();

		tempResourcesIndex = new ObjectLongOpenHashMap<>();
		tempResourcesWDataModelIndex = new ObjectLongOpenHashMap<>();
		tempResourceTypes = new ObjectLongOpenHashMap<>();
		//tempStatementHashes = new LongLongOpenHashMap();
		final Tuple<Set<Long>, DB> mapDBTuple = MapDBUtils
				.createOrGetInMemoryLongIndexTreeSetNonTransactional(GraphIndexStatics.TEMP_STATEMENT_HASHES_INDEX_NAME);
		tempStatementHashes = mapDBTuple.v1();
		tempStatementHashesDB = mapDBTuple.v2();

		// TODO: init all indices, when batch inserter should work on a pre-filled database (otherwise, the existing index would
		// utilised in the first run)
		// initIndices();
		initValueIndex();
		initStatementIndex();
	}
 
开发者ID:dswarm,项目名称:dswarm-graph-neo4j,代码行数:25,代码来源:BatchNeo4jProcessor.java

示例7: getOrCreateUserNodeID

import org.neo4j.unsafe.batchinsert.BatchInserter; //导入依赖的package包/类
private static long getOrCreateUserNodeID(final String userid,
                                          final Map<String, Long> usersNodesMap,
                                          final BatchInserterIndex usersIndex,
                                          final BatchInserter inserter,
                                          final Label label) {

    long userNodeID;

    if (usersNodesMap.containsKey(userid)) {
        userNodeID = usersNodesMap.get(userid);
    } else {
        userNodeID = inserter.createNode(MapUtil.map("node_id", userid), label);
        usersNodesMap.put(userid, userNodeID);
        usersIndex.add(userNodeID, MapUtil.map("node_id", userid));
    }

    return userNodeID;

}
 
开发者ID:inveniosoftware-contrib,项目名称:obelix,代码行数:20,代码来源:ObelixBatchImport.java

示例8: getOrCreateItemNodeID

import org.neo4j.unsafe.batchinsert.BatchInserter; //导入依赖的package包/类
private static long getOrCreateItemNodeID(final String itemid,
                                          final Map<String, Long> itemsNodesMap,
                                          final BatchInserterIndex itemsIndex,
                                          final BatchInserter inserter,
                                          final Label label) {

    long itemNodeID;

    if (itemsNodesMap.containsKey(itemid)) {
        itemNodeID = itemsNodesMap.get(itemid);
    } else {
        itemNodeID = inserter.createNode(MapUtil.map("node_id", itemid), label);
        itemsNodesMap.put(itemid, itemNodeID);
        itemsIndex.add(itemNodeID, MapUtil.map("node_id", itemid));
    }

    return itemNodeID;

}
 
开发者ID:inveniosoftware-contrib,项目名称:obelix,代码行数:20,代码来源:ObelixBatchImport.java

示例9: getOrCreateRelatinshipID

import org.neo4j.unsafe.batchinsert.BatchInserter; //导入依赖的package包/类
private static long getOrCreateRelatinshipID(final String timestamp,
                                             final long userNodeid,
                                             final long itemNodeid,
                                             final Map<String, Long> relationshipsMap,
                                             final BatchInserterIndex relationshipIndex,
                                             final BatchInserter inserter,
                                             final RelationshipType relType) {

    long relationID;
    String uniqueRelationID = userNodeid + itemNodeid + timestamp;
    if (relationshipsMap.containsKey(uniqueRelationID)) {
        relationID = relationshipsMap.get(uniqueRelationID);
    } else {

        relationID = inserter.createRelationship(userNodeid, itemNodeid, relType,
                MapUtil.map("timestamp", timestamp));

        relationshipsMap.put(uniqueRelationID, relationID);
        relationshipIndex.add(relationID, MapUtil.map("useritem", uniqueRelationID));
    }

    return relationID;

}
 
开发者ID:inveniosoftware-contrib,项目名称:obelix,代码行数:25,代码来源:ObelixBatchImport.java

示例10: LuceneBatchInserterIndexProviderNewImpl

import org.neo4j.unsafe.batchinsert.BatchInserter; //导入依赖的package包/类
public LuceneBatchInserterIndexProviderNewImpl( final BatchInserter inserter )
{
    this.inserter = inserter;
    this.indexStore = ((BatchInserterImpl) inserter).getIndexStore();
    this.relationshipLookup = new LuceneBatchInserterIndex.RelationshipLookup()
    {
        @Override
        public EntityId lookup( long id )
        {
            // TODO too may objects allocated here
            BatchRelationship rel = inserter.getRelationshipById( id );
            return new RelationshipData( id, rel.getStartNode(), rel.getEndNode() );
        }
    };
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:16,代码来源:LuceneBatchInserterIndexProviderNewImpl.java

示例11: batchInsert

import org.neo4j.unsafe.batchinsert.BatchInserter; //导入依赖的package包/类
@Test
public void batchInsert() throws Exception
{
    Neo4jTestCase.deleteFileOrDirectory( new File(
            "target/neo4jdb-batchinsert" ) );
    // START SNIPPET: batchInsert
    BatchInserter inserter = BatchInserters.inserter( "target/neo4jdb-batchinsert" );
    BatchInserterIndexProvider indexProvider =
            new LuceneBatchInserterIndexProvider( inserter );
    BatchInserterIndex actors =
            indexProvider.nodeIndex( "actors", MapUtil.stringMap( "type", "exact" ) );
    actors.setCacheCapacity( "name", 100000 );

    Map<String, Object> properties = MapUtil.map( "name", "Keanu Reeves" );
    long node = inserter.createNode( properties );
    actors.add( node, properties );

    //make the changes visible for reading, use this sparsely, requires IO!
    actors.flush();

    // Make sure to shut down the index provider as well
    indexProvider.shutdown();
    inserter.shutdown();
    // END SNIPPET: batchInsert

    GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase( "target/neo4jdb-batchinsert" );
    try ( Transaction tx = db.beginTx() )
    {
        Index<Node> index = db.index().forNodes( "actors" );
        Node reeves = index.get( "name", "Keanu Reeves" ).next();
        assertEquals( node, reeves.getId() );
    }
    db.shutdown();
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:35,代码来源:ImdbDocTest.java

示例12: shouldIndexNodesWithMultipleLabels

import org.neo4j.unsafe.batchinsert.BatchInserter; //导入依赖的package包/类
@Test
public void shouldIndexNodesWithMultipleLabels() throws Exception
{
    // Given
    String path = dbRule.getStoreDirAbsolutePath();
    BatchInserter inserter = BatchInserters.inserter( path );

    inserter.createNode( map( "name", "Bob" ), label( "User" ), label( "Admin" ) );

    inserter.createDeferredSchemaIndex( label( "User" ) ).on( "name" ).create();
    inserter.createDeferredSchemaIndex( label( "Admin" ) ).on( "name" ).create();

    // When
    inserter.shutdown();

    // Then
    GraphDatabaseService db = dbRule.getGraphDatabaseService();
    try ( Transaction tx = db.beginTx() )
    {
        assertThat( count( db.findNodes( label( "User" ), "name", "Bob" ) ), equalTo(1) );
        assertThat( count( db.findNodes( label( "Admin" ), "name", "Bob" ) ), equalTo(1) );
    }
    finally
    {
        db.shutdown();
    }

}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:29,代码来源:BatchInsertionIT.java

示例13: shouldBeAbleToMakeRepeatedCallsToSetNodePropertyWithMultiplePropertiesPerBlock

import org.neo4j.unsafe.batchinsert.BatchInserter; //导入依赖的package包/类
@Test
public void shouldBeAbleToMakeRepeatedCallsToSetNodePropertyWithMultiplePropertiesPerBlock() throws Exception
{
    BatchInserter inserter = BatchInserters.inserter( dbRule.getStoreDirAbsolutePath() );
    long nodeId = inserter.createNode( Collections.<String, Object>emptyMap() );

    final Object finalValue1 = 87;
    final Object finalValue2 = 3.14;
    inserter.setNodeProperty( nodeId, "a", "some property value" );
    inserter.setNodeProperty( nodeId, "a", 42 );
    inserter.setNodeProperty( nodeId, "b", finalValue2 );
    inserter.setNodeProperty( nodeId, "a", finalValue2 );
    inserter.setNodeProperty( nodeId, "a", true );
    inserter.setNodeProperty( nodeId, "a", finalValue1 );
    inserter.shutdown();

    GraphDatabaseService db = dbRule.getGraphDatabaseService();
    try(Transaction ignored = db.beginTx())
    {
        assertThat( db.getNodeById( nodeId ).getProperty( "a" ), equalTo( finalValue1 ) );
        assertThat( db.getNodeById( nodeId ).getProperty( "b" ), equalTo( finalValue2 ) );
    }
    finally
    {
        db.shutdown();
    }
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:28,代码来源:BatchInsertionIT.java

示例14: getBatchInserterInstance

import org.neo4j.unsafe.batchinsert.BatchInserter; //导入依赖的package包/类
/**
 * 
 * @return
 * @return
 */
private static BatchInserter getBatchInserterInstance()
{
  Map<String, String> config = new HashMap<>();
  config.put("dbms.pagecache.memory", "16G");

  return getBatchInserterInstance(config);
}
 
开发者ID:neo4art,项目名称:neo4art,代码行数:13,代码来源:Neo4ArtBatchInserterSingleton.java

示例15: createNode

import org.neo4j.unsafe.batchinsert.BatchInserter; //导入依赖的package包/类
/**
 * 
 * @param node
 * @return
 */
public static long createNode(Node node)
{
  BatchInserter batchInserter = getBatchInserterInstance();

  long nodeId = batchInserter.createNode(node.getProperties(), node.getLabels());
  
  node.setNodeId(nodeId);
  
  return nodeId;
}
 
开发者ID:neo4art,项目名称:neo4art,代码行数:16,代码来源:Neo4ArtBatchInserterSingleton.java


注:本文中的org.neo4j.unsafe.batchinsert.BatchInserter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。