org.neo4j.server.database.Database类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(179)

本文整理了Java中org.neo4j.server.database.Database类的一些代码示例,展示了Database类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Database类的具体详情如下:
包路径:org.neo4j.server.database.Database
类名称:Database

Database介绍

暂无

代码示例

代码示例来源:origin: neo4j/neo4j

  1. private long createNode( Map<String, Object> properties )
  2. {
  3. long nodeId;
  4. try ( Transaction tx = database.getGraph().beginTx() )
  5. {
  6. Node node = database.getGraph().createNode( LABEL );
  7. for ( Map.Entry<String, Object> entry : properties.entrySet() )
  8. {
  9. node.setProperty( entry.getKey(), entry.getValue() );
  10. }
  11. nodeId = node.getId();
  12. tx.success();
  13. }
  14. return nodeId;
  15. }

代码示例来源:origin: neo4j/neo4j

  1. private static void removeLogs( NeoServer server )
  2. {
  3. File logDir = new File( server.getDatabase().getLocation() + File.separator + ".." + File.separator + "log" );
  4. try
  5. {
  6. FileUtils.deleteDirectory( logDir );
  7. }
  8. catch ( IOException e )
  9. {
  10. throw new RuntimeException( e );
  11. }
  12. }

代码示例来源:origin: neo4j/neo4j

  1. public boolean isRunning()
  2. {
  3. return server != null && server.getDatabase() != null && server.getDatabase().isRunning();
  4. }

代码示例来源:origin: neo4j/neo4j

  1. @Test
  2. public void shouldBeAbleToGetLocation() throws Throwable
  3. {
  4. theDatabase.start();
  5. assertThat( theDatabase.getLocation().getAbsolutePath(),
  6. is( dbConfig.get( GraphDatabaseSettings.database_path ).getAbsolutePath() ) );
  7. }
  8. }

代码示例来源:origin: neo4j/neo4j

  1. public Index<Node> createNodeIndex( String named )
  2. {
  3. try ( Transaction transaction = database.getGraph().beginTransaction( implicit, AUTH_DISABLED ) )
  4. {
  5. Index<Node> nodeIndex = database.getGraph().index()
  6. .forNodes( named );
  7. transaction.success();
  8. return nodeIndex;
  9. }
  10. }

代码示例来源:origin: neo4j/neo4j

  1. public long createNode( Label... labels )
  2. {
  3. try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.writeToken() ) )
  4. {
  5. Node node = database.getGraph().createNode( labels );
  6. tx.success();
  7. return node.getId();
  8. }
  9. }

代码示例来源:origin: neo4j/neo4j

  1. @Test
  2. public void shouldOverwriteExistingProperties() throws PropertyValueException,
  3. NodeNotFoundException
  4. {
  5. long nodeId;
  6. try ( Transaction tx = database.getGraph().beginTx() )
  7. {
  8. Node node = database.getGraph().createNode();
  9. node.setProperty( "remove me", "trash" );
  10. nodeId = node.getId();
  11. tx.success();
  12. }
  13. Map<String, Object> properties = new HashMap<>();
  14. properties.put( "foo", "bar" );
  15. properties.put( "baz", 17 );
  16. actions.setAllNodeProperties( nodeId, properties );
  17. try ( Transaction tx = database.getGraph().beginTx() )
  18. {
  19. Node node = database.getGraph().getNodeById( nodeId );
  20. assertHasProperties( node, properties );
  21. assertNull( node.getProperty( "remove me", null ) );
  22. }
  23. }

代码示例来源:origin: neo4j/neo4j

  1. @Override
  2. public void start()
  3. {
  4. DependencyResolver resolver = database.getGraph().getDependencyResolver();
  5. this.executionEngine = (ExecutionEngine) resolver.resolveDependency( QueryExecutionEngine.class );
  6. this.service = resolver.resolveDependency( GraphDatabaseQueryService.class );
  7. this.contextFactory = Neo4jTransactionalContextFactory.create( this.service, locker );
  8. }

代码示例来源:origin: neo4j/neo4j

  1. @Test
  2. public void shouldBeAbleToRemoveNodeProperty() throws Exception
  3. {
  4. Map<String, Object> properties = new HashMap<>();
  5. properties.put( "foo", "bar" );
  6. properties.put( "number", 15 );
  7. long nodeId = createNode( properties );
  8. actions.removeNodeProperty( nodeId, "foo" );
  9. try ( Transaction tx = database.getGraph().beginTx() )
  10. {
  11. Node node = database.getGraph().getNodeById( nodeId );
  12. assertEquals( 15, node.getProperty( "number" ) );
  13. assertFalse( node.hasProperty( "foo" ) );
  14. tx.success();
  15. }
  16. }

代码示例来源:origin: neo4j/neo4j

  1. @Test
  2. public void shouldWorkWithPoint2DArrays() throws Exception
  3. {
  4. HTTP.Response response =
  5. runQuery( "create (:Node {points: [point({x:1, y:1}), point({x:2, y:2}), point({x: 3.0, y: 3.0})]})" );
  6. assertEquals( 200, response.status() );
  7. assertNoErrors( response );
  8. GraphDatabaseFacade db = server().getDatabase().getGraph();
  9. try ( Transaction tx = db.beginTx() )
  10. {
  11. for ( Node node : db.getAllNodes() )
  12. {
  13. if ( node.hasLabel( label( "Node" ) ) && node.hasProperty( "points" ) )
  14. {
  15. Point[] points = (Point[]) node.getProperty( "points" );
  16. verifyPoint( points[0], Cartesian, 1.0, 1.0 );
  17. verifyPoint( points[1], Cartesian, 2.0, 2.0 );
  18. verifyPoint( points[2], Cartesian, 3.0, 3.0 );
  19. }
  20. }
  21. tx.success();
  22. }
  23. }

代码示例来源:origin: neo4j/neo4j

  1. public long createRelationship( String type, long startNodeId, long endNodeId )
  2. {
  3. try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.writeToken() ) )
  4. {
  5. Node startNode = database.getGraph().getNodeById( startNodeId );
  6. Node endNode = database.getGraph().getNodeById( endNodeId );
  7. Relationship relationship = startNode.createRelationshipTo( endNode, RelationshipType.withName( type ) );
  8. tx.success();
  9. return relationship.getId();
  10. }
  11. }

代码示例来源:origin: neo4j/neo4j

  1. public long createRelationship( String type )
  2. {
  3. try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.writeToken() ) )
  4. {
  5. Node startNode = database.getGraph().createNode();
  6. Node endNode = database.getGraph().createNode();
  7. Relationship relationship = startNode.createRelationshipTo( endNode,
  8. RelationshipType.withName( type ) );
  9. tx.success();
  10. return relationship.getId();
  11. }
  12. }

代码示例来源:origin: neo4j/neo4j

  1. public void setNodeProperties( long nodeId, Map<String, Object> properties )
  2. {
  3. try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.writeToken() ) )
  4. {
  5. Node node = database.getGraph().getNodeById( nodeId );
  6. for ( Map.Entry<String, Object> propertyEntry : properties.entrySet() )
  7. {
  8. node.setProperty( propertyEntry.getKey(), propertyEntry.getValue() );
  9. }
  10. tx.success();
  11. }
  12. }

代码示例来源:origin: neo4j/neo4j

  1. public Index<Relationship> createRelationshipIndex( String named )
  2. {
  3. try ( Transaction transaction = database.getGraph().beginTransaction( implicit, AUTH_DISABLED ) )
  4. {
  5. RelationshipIndex relationshipIndex = database.getGraph().index()
  6. .forRelationships( named );
  7. transaction.success();
  8. return relationshipIndex;
  9. }
  10. }

代码示例来源:origin: neo4j/neo4j

  1. @Test
  2. public void shouldBeAbleToGetPropertiesOnRelationship() throws Exception
  3. {
  4. long relationshipId;
  5. Map<String, Object> properties = new HashMap<>();
  6. properties.put( "foo", "bar" );
  7. properties.put( "neo", "Thomas A. Anderson" );
  8. properties.put( "number", 15L );
  9. try ( Transaction tx = database.getGraph().beginTx() )
  10. {
  11. Node startNode = database.getGraph().createNode();
  12. Node endNode = database.getGraph().createNode();
  13. Relationship relationship = startNode.createRelationshipTo( endNode,
  14. RelationshipType.withName( "knows" ) );
  15. for ( Map.Entry<String, Object> entry : properties.entrySet() )
  16. {
  17. relationship.setProperty( entry.getKey(), entry.getValue() );
  18. }
  19. relationshipId = relationship.getId();
  20. tx.success();
  21. }
  22. try ( Transaction transaction = graph.beginTx() )
  23. {
  24. assertEquals( properties, serialize( actions.getAllRelationshipProperties( relationshipId ) ) );
  25. }
  26. }

代码示例来源:origin: neo4j/neo4j

  1. private long createNode()
  2. {
  3. GraphDatabaseService graphdb = server().getDatabase().getGraph();
  4. try ( Transaction tx = graphdb.beginTx() )
  5. {
  6. Node node = graphdb.createNode();
  7. tx.success();
  8. return node.getId();
  9. }
  10. }

代码示例来源:origin: neo4j/neo4j

  1. public void deleteNode( long id )
  2. {
  3. try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.write() ) )
  4. {
  5. Node node = database.getGraph().getNodeById( id );
  6. node.delete();
  7. tx.success();
  8. }
  9. }

代码示例来源:origin: neo4j/neo4j

  1. public Relationship getRelationship( long relationshipId )
  2. {
  3. try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.read() ) )
  4. {
  5. Relationship relationship = database.getGraph().getRelationshipById( relationshipId );
  6. tx.success();
  7. return relationship;
  8. }
  9. }

代码示例来源:origin: neo4j/neo4j

  1. public IndexDefinition createSchemaIndex( String labelName, String propertyKey )
  2. {
  3. try ( Transaction tx = database.getGraph().beginTransaction( implicit, AUTH_DISABLED ) )
  4. {
  5. IndexDefinition index = database.getGraph().schema().indexFor( label( labelName ) ).on( propertyKey ).create();
  6. tx.success();
  7. return index;
  8. }
  9. }

代码示例来源:origin: neo4j/neo4j

  1. public void addLabelToNode( long node, String labelName )
  2. {
  3. try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.writeToken() ) )
  4. {
  5. database.getGraph().getNodeById( node ).addLabel( label( labelName ) );
  6. tx.success();
  7. }
  8. }

相关文章