當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。