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


Java GraphDatabaseService类代码示例

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


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

示例1: shouldTransformCypherAlbumsToJSONDoc

import org.neo4j.graphdb.GraphDatabaseService; //导入依赖的package包/类
@Test
	public void shouldTransformCypherAlbumsToJSONDoc() throws SQLException {
		
//		GraphDatabaseService database = new TestGraphDatabaseFactory().newImpermanentDatabase();
		GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabase(new File("/Applications/Development/Neo4j-2.3.2/neo4j-community-2.3.2/data/graph.db"));
		
		database.registerTransactionEventHandler(new Neo4jEventListener(database));
		
		String cypher = "MATCH (n) "
						+ "WHERE n.name = \"Volcano\" "
						+ "WITH n "
						+ "SET n.explicit = true "
						+ "RETURN n";
		
		try (Transaction tx = database.beginTx()) {

			database.execute(cypher);
			tx.success();
		}
	}
 
开发者ID:larusba,项目名称:neo4j-couchbase-connector,代码行数:21,代码来源:Neo4jEventHandlerTest.java

示例2: shouldBeAbleToMakeRepeatedCallsToSetNodeProperty

import org.neo4j.graphdb.GraphDatabaseService; //导入依赖的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: graphDatabaseService

import org.neo4j.graphdb.GraphDatabaseService; //导入依赖的package包/类
/**
 * Neo4j Server bean.
 * Runs Neo4j server for integration tests and returns {@link GraphDatabaseService} instance.
 *
 * @return {@link GraphDatabaseService}
 */
@Bean(destroyMethod = "shutdown")
public GraphDatabaseService graphDatabaseService() {
    String homeDir = "./target";
    String configFile = "./src/test/resources/neo4j.conf";
    ServerBootstrapper serverBootstrapper = new CommunityBootstrapper();
    int i = serverBootstrapper.start(new File(homeDir), Optional.of(new File(configFile)));
    switch (i) {
        case ServerBootstrapper.OK:
            logger.debug("Server started");
            break;
        case ServerBootstrapper.GRAPH_DATABASE_STARTUP_ERROR_CODE:
            logger.error("Server failed to start: graph database startup error");
            break;
        case ServerBootstrapper.WEB_SERVER_STARTUP_ERROR_CODE:
            logger.error("Server failed to start: web server startup error");
            break;
        default:
            logger.error("Server failed to start: unknown error");
            break;
    }
    NeoServer neoServer = serverBootstrapper.getServer();
    return neoServer.getDatabase().getGraph();
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:30,代码来源:TestConfig.java

示例4: weight

import org.neo4j.graphdb.GraphDatabaseService; //导入依赖的package包/类
@Override
public void weight(GraphDatabaseService graph) {
    requireNonNull(graph, "'graph' is null");

    int total = 0;
    try (Transaction tx = graph.beginTx()) {
        long elapsed = System.nanoTime();
        logger.debug("Computing weights between words...");
        for (Relationship follows : graph.getAllRelationships()) {
            if (follows.isType(FOLLOWS)) {
                double weight = 1.0 / (double) follows.getProperty("freq", 1.0);
                follows.setProperty("weight", weight);
                total += 1;
                if (total % 50 == 0) {
                    logger.debug("{} relationships analysed so far...", total);
                }
            }
        }
        elapsed = System.nanoTime() - elapsed;
        logger.info("{} relationship/s analysed in {} ms.",
                total, String.format("%,.3f", elapsed / 1_000_000_000.0));
        tx.success();
    }
}
 
开发者ID:stefano-bragaglia,项目名称:Multi-Sentence-Compression,代码行数:25,代码来源:NaiveGraphWeigher.java

示例5: setUp

import org.neo4j.graphdb.GraphDatabaseService; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws IOException, RepositoryException, RDFParseException {
	int port;
	try (final ServerSocket serverSocket = new ServerSocket(0)) {
		port = serverSocket.getLocalPort();
	}
	server = CommunityServerBuilder.server()
		.onPort(port)
		.withThirdPartyJaxRsPackage("de.unikiel.inf.comsys.neo4j", "/rdf")
		.build();
	server.start();
	GraphDatabaseService db = server.getDatabase().getGraph();
	Repository rep = RepositoryRegistry.getInstance(db).getRepository();
	conn = rep.getConnection();
	InputStream testdata = RDFServerExtensionTest.class.getResourceAsStream("/sp2b.n3");
	conn.add(testdata, "http://example.com/", RDFFormat.N3);
}
 
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:18,代码来源:RDFServerExtensionTest.java

示例6: insert_node_should_succeed_with_populated_index

import org.neo4j.graphdb.GraphDatabaseService; //导入依赖的package包/类
@Test
public void insert_node_should_succeed_with_populated_index() throws Exception {
    Neo4jBatchInserterNode nodeInserter = getNeo4jBatchInserterNode(false);

    // populate the db
    List<String> columns = DummyTalendPojo.getColumnList();
    for (int i = 0; i < 100; i++) {
        DummyTalendPojo pojo = DummyTalendPojo.getDummyTalendPojo();
        nodeInserter.create(pojo, columns);
    }
    nodeInserter.finish();

    // check if index size
    Assert.assertEquals(100, batchDb.batchInserterIndexes.get(INDEX_NAME).query("*:*").size());

    // check the database data
    batchDb.shutdown();
    // Testing it with real graphdb
    GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbPath);
    try (Transaction tx = graphDb.beginTx()) {
        String result = graphDb.execute("MATCH (n:" + LABEL_NAME + ") RETURN count(n) AS count").resultAsString();
        Assert.assertEquals("+-------+\n| count |\n+-------+\n| 100   |\n+-------+\n1 row\n", result);
    }
    graphDb.shutdown();
}
 
开发者ID:sim51,项目名称:neo4j-talend-component,代码行数:26,代码来源:Neo4jBatchInserterNodeTest.java

示例7: update_node_should_succeed

import org.neo4j.graphdb.GraphDatabaseService; //导入依赖的package包/类
@Test
public void update_node_should_succeed() throws Exception {
    // populate the db
    Neo4jBatchInserterNode nodeInserter = getNeo4jBatchInserterNode(false);
    List<String> columns = DummyTalendPojo.getColumnList();
    DummyTalendPojo pojo = DummyTalendPojo.getDummyTalendPojo();
    nodeInserter.create(pojo, columns);
    nodeInserter.finish();

    // By indexing the import id, I update the last node
    pojo.propString = "A new String";
    nodeInserter = getNeo4jBatchInserterNode(true);
    nodeInserter.create(pojo, columns);
    nodeInserter.finish();

    // check the result into the database
    batchDb.shutdown();
    GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbPath);
    try (Transaction tx = graphDb.beginTx()) {
        String result = graphDb.execute("MATCH (n:" + LABEL_NAME + ") WHERE exists(n.id) RETURN n.propString AS string").resultAsString();
        Assert.assertEquals("+----------------+\n| string         |\n+----------------+\n| \"A new String\" |\n+----------------+\n1 row\n", result);
    }
    graphDb.shutdown();
}
 
开发者ID:sim51,项目名称:neo4j-talend-component,代码行数:25,代码来源:Neo4jBatchInserterNodeTest.java

示例8: create_node_uniqueness_constraint_should_work

import org.neo4j.graphdb.GraphDatabaseService; //导入依赖的package包/类
@Test
public void create_node_uniqueness_constraint_should_work() {
    // Test const.
    String label = "Test";
    String property = "myProp";

    // crete the schema
    batchDb.createSchema("NODE_PROPERTY_UNIQUE", label, property);
    batchDb.shutdown();

    // Testing it with real graphdb
    GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbPath);
    try (Transaction tx = graphDb.beginTx()) {
        Assert.assertTrue(graphDb.schema().getConstraints(DynamicLabel.label(label)).iterator().hasNext());
    }
    graphDb.shutdown();
}
 
开发者ID:sim51,项目名称:neo4j-talend-component,代码行数:18,代码来源:Neo4jBatchDatabaseTest.java

示例9: create_node_index_should_work

import org.neo4j.graphdb.GraphDatabaseService; //导入依赖的package包/类
@Test
public void create_node_index_should_work() {
    // Test const.
    String label = "Test";
    String property = "myProp";

    // crete the schema
    batchDb.createSchema("NODE_PROPERTY_INDEX", label, property);
    batchDb.shutdown();

    // Testing it with real graphdb
    GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbPath);
    try (Transaction tx = graphDb.beginTx()) {
        Assert.assertTrue(graphDb.schema().getIndexes(DynamicLabel.label(label)).iterator().hasNext());
    }
    graphDb.shutdown();

}
 
开发者ID:sim51,项目名称:neo4j-talend-component,代码行数:19,代码来源:Neo4jBatchDatabaseTest.java

示例10: aggregate

import org.neo4j.graphdb.GraphDatabaseService; //导入依赖的package包/类
@Override
protected void aggregate(MavenProject rootModule, List<MavenProject> projects, Store store) throws MojoExecutionException, MojoFailureException {
    File file = ProjectResolver.getOutputFile(rootModule, exportFile, EXPORT_FILE);
    getLog().info("Exporting database to '" + file.getAbsolutePath() + "'");
    EmbeddedGraphStore graphStore = (EmbeddedGraphStore) store;
    store.beginTransaction();
    try {
        GraphDatabaseService databaseService = graphStore.getGraphDatabaseService();
        SubGraph graph = DatabaseSubGraph.from(databaseService);
        new SubGraphExporter(graph).export(new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8")));
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot export database.", e);
    } finally {
        store.commitTransaction();
    }
}
 
开发者ID:buschmais,项目名称:jqa-maven-plugin,代码行数:17,代码来源:ExportDatabaseMojo.java

示例11: run

import org.neo4j.graphdb.GraphDatabaseService; //导入依赖的package包/类
public void run(GraphDatabaseService db) {
    this.db = db;
    codeIndexes = new CodeIndexes(db);
    try (Transaction tx=db.beginTx()){
    	for (Node node:db.getAllNodes()){
    		if (!node.hasProperty(TextExtractor.IS_TEXT)||!(boolean)node.getProperty(TextExtractor.IS_TEXT))
                continue;
    		if (node.hasLabel(Label.label(JavaCodeExtractor.CLASS)))
    			continue;
    		if (node.hasLabel(Label.label(JavaCodeExtractor.METHOD)))
    			continue;
    		if (node.hasLabel(Label.label(JavaCodeExtractor.INTERFACE)))
    			continue;
    		if (node.hasLabel(Label.label(JavaCodeExtractor.FIELD)))
    			continue;
    		textNodes.add(node);
    	}
    	fromHtmlToCodeElement();
    	fromTextToJira();
    	fromDiffToCodeElement();
    	tx.success();
    }
}
 
开发者ID:linzeqipku,项目名称:SnowGraph,代码行数:24,代码来源:ReferenceExtractor.java

示例12: run

import org.neo4j.graphdb.GraphDatabaseService; //导入依赖的package包/类
public void run(GraphDatabaseService db) {
    this.db = db;
    MboxHandler myHandler = new MboxHandler();
    myHandler.setDb(db);
    MimeConfig config=new MimeConfig();
    config.setMaxLineLen(-1);
    parser = new MimeStreamParser(config);
    parser.setContentHandler(myHandler);
    parse(new File(mboxPath));
    try (Transaction tx = db.beginTx()) {
        for (String address : myHandler.getMailUserNameMap().keySet()) {
            Node node = myHandler.getMailUserMap().get(address);
            node.setProperty(MAILUSER_NAMES, String.join(", ", myHandler.getMailUserNameMap().get(address)));
        }
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        for (String mailId : myHandler.getMailReplyMap().keySet()) {
            Node mailNode = myHandler.getMailMap().get(mailId);
            Node replyNode = myHandler.getMailMap().get(myHandler.getMailReplyMap().get(mailId));
            if (mailNode != null & replyNode != null)
                mailNode.createRelationshipTo(replyNode, RelationshipType.withName(MailListExtractor.MAIL_IN_REPLY_TO));
        }
        tx.success();
    }
}
 
开发者ID:linzeqipku,项目名称:SnowGraph,代码行数:27,代码来源:MailListExtractor.java

示例13: readData

import org.neo4j.graphdb.GraphDatabaseService; //导入依赖的package包/类
public void readData(GraphDatabaseService db) {
    Graph graph = CsnExtractor.extract(db);
    graph.getVertexes().forEachRemaining(v1->{
        v1.getNeighbors(true,true).stream().forEach(v2->{
            double weight=v1.weightTo(v2,true,true);
            edges.add(new EmbeddingRelation(v1.getId(),v2.getId(),weight));
            EmbeddingPoint v1p;
            if (vertex.containsKey(v1.getId()))
                v1p=vertex.get(v1.getId());
            else {
                v1p = new EmbeddingPoint(0.0);
                vertex.put(v1.getId(),v1p);
            }
            v1p.degree += weight;
        });
    });
    System.out.println("Vertex count: "+vertex.size());
    System.out.print("Edge count: "+edges.size());
}
 
开发者ID:linzeqipku,项目名称:SnowGraph,代码行数:20,代码来源:LINE.java

示例14: newContext

import org.neo4j.graphdb.GraphDatabaseService; //导入依赖的package包/类
/**
 * Get current configuration manager
 * @return
 */
public static DocumentGrapherExecutionContext newContext(GraphDatabaseService db, Log log)
{
	
	if(instance == null)
	{
		Node configurationNode = db.findNode(Label.label("JSON_CONFIG"), "configuration", "byNode");
		if(configurationNode == null)
		{
			log.info("Load default configuration: "+JsonHelperConfigurationDefault.class);
			instance = new JsonHelperConfigurationDefault();				
		}else
		{
			log.info("Load configuration from node: "+JsonHelperConfigurationByNode.class);
			instance = new JsonHelperConfigurationByNode(configurationNode);	
		}
	}
	
	return instance.buildContext(db, log);
}
 
开发者ID:larusba,项目名称:doc2graph,代码行数:24,代码来源:JsonHelperConfiguration.java

示例15: buildContext

import org.neo4j.graphdb.GraphDatabaseService; //导入依赖的package包/类
@Override
public DocumentGrapherExecutionContext buildContext(GraphDatabaseService db, Log log) {
	DocumentGrapherExecutionContext context = new DocumentGrapherExecutionContext();
	
	context.setRootNodeKeyProperty("_document_key");
	context.setDocumentIdBuilder(new DocumentIdBuilderTypeId());
	
	DocumentRelationBuilderHasTypeArrayKey relBuilder = new DocumentRelationBuilderHasTypeArrayKey();
	relBuilder.setDb(db);
	relBuilder.setLog(log);
	
	context.setDocumentRelationBuilder(relBuilder);
	DocumentLabelBuilderByType documentLabelBuilder = new DocumentLabelBuilderByType();
	documentLabelBuilder.setDefaultLabel("DocNode");
	context.setDocumentLabelBuilder(documentLabelBuilder);
	context.setDb(db);
	context.setLog(log);
	context.setLogDiscard(false);
	
	return context;
}
 
开发者ID:larusba,项目名称:doc2graph,代码行数:22,代码来源:JsonHelperConfigurationDefault.java


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