本文整理汇总了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();
}
}
示例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();
}
}
示例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();
}
示例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();
}
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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());
}
示例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);
}
示例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;
}