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


Java GraphDatabaseAPI类代码示例

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


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

示例1: failureToCreateAnIndexShouldNotLeaveConfigurationBehind

import org.neo4j.kernel.GraphDatabaseAPI; //导入依赖的package包/类
@Test
public void failureToCreateAnIndexShouldNotLeaveConfigurationBehind() throws Exception
{
    // WHEN
    try
    {
        // PerFieldAnalyzerWrapper is invalid since it has no public no-arg constructor
        nodeIndex( stringMap( "analyzer", PerFieldAnalyzerWrapper.class.getName() ) );
        fail( "Should have failed" );
    }
    catch ( RuntimeException e )
    {
        assertThat( e.getMessage(), CoreMatchers.containsString( PerFieldAnalyzerWrapper.class.getName() ) );
    }

    // THEN - assert that there's no index config about this index left behind
    assertFalse( "There should be no index config for index '" + currentIndexName() + "' left behind",
            ((GraphDatabaseAPI)graphDb).getDependencyResolver().resolveDependency( IndexConfigStore.class ).has(
                    Node.class, currentIndexName() ) );
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:21,代码来源:TestLuceneIndex.java

示例2: setUp

import org.neo4j.kernel.GraphDatabaseAPI; //导入依赖的package包/类
@Before
public void setUp() throws IOException, InterruptedException
{
    database = new TestGraphDatabaseFactory().newImpermanentDatabase();
    Runtime.getRuntime().addShutdownHook(new Thread()
    {
        @Override
        public void run()
        {
            database.shutdown();
        }
    });
    ServerConfigurator configurator = new ServerConfigurator((GraphDatabaseAPI) database);
    int port = neoServerPort();
    configurator.configuration().addProperty(Configurator.WEBSERVER_PORT_PROPERTY_KEY, port);
    configurator.configuration().addProperty("dbms.security.auth_enabled", false);
    bootstrapper = new WrappingNeoServerBootstrapper((GraphDatabaseAPI) database, configurator);
    bootstrapper.start();
    while (!bootstrapper.getServer().getDatabase().isRunning())
    {
        // It's ok to spin here.. it's not production code.
        Thread.sleep(250);
    }
    client = new Neo4jClient("http://localhost:" + port + "/db/data");
}
 
开发者ID:mangrish,项目名称:java-neo4j-client,代码行数:26,代码来源:EndToEndTests.java

示例3: DoBootstrap

import org.neo4j.kernel.GraphDatabaseAPI; //导入依赖的package包/类
/**
 * use this in web browser:
 * :config maxNeighbours: 200
 * */
@SuppressWarnings("deprecation")
private void DoBootstrap()
{
	ServerConfigurator config
		= new ServerConfigurator((GraphDatabaseAPI)graph_db);

	config.configuration()
		.setProperty(Configurator.WEBSERVER_ADDRESS_PROPERTY_KEY, "0.0.0.0");

	config.configuration()
		.setProperty(Configurator.WEBSERVER_PORT_PROPERTY_KEY, webserver_port);

	webserver = new WrappingNeoServerBootstrapper((GraphDatabaseAPI) graph_db, config);
	webserver.start();

	LOGGER.log(Level.INFO, "neo4j is accessible through the web");
}
 
开发者ID:srcc-msu,项目名称:octotron_core,代码行数:22,代码来源:Neo4jGraph.java

示例4: executeScript

import org.neo4j.kernel.GraphDatabaseAPI; //导入依赖的package包/类
@Name("execute_script")
@Description("execute a Gremlin script with 'g' set to the Neo4j2Graph and 'results' containing the results. Only results of one object type is supported.")
@PluginTarget(GraphDatabaseService.class)
public Representation executeScript(
        @Source final GraphDatabaseService neo4j,
        @Description("The Gremlin script") @Parameter(name = "script", optional = false) final String script,
        @Description("JSON Map of additional parameters for script variables") @Parameter(name = "params", optional = true) final Map params ) throws BadInputException
{
    Neo4j2Graph neo4jGraph = getOrCreateGremlin( (GraphDatabaseAPI) neo4j );
    try(Transaction tx = neo4j.beginTx())
    {
        engineReplacementDecision.beforeExecution( script );
        final Bindings bindings = createBindings(params, neo4jGraph);
        final Object result = engine().eval( script, bindings );
        Representation representation = GremlinObjectToRepresentationConverter.convert(result);
        tx.success();
        return representation;
    }
    catch ( final Exception e )
    {
     throw new BadInputException( e.getMessage(), e );
    }
}
 
开发者ID:neo4j-contrib,项目名称:gremlin-plugin,代码行数:24,代码来源:GremlinPlugin.java

示例5: getOrCreate

import org.neo4j.kernel.GraphDatabaseAPI; //导入依赖的package包/类
public Node getOrCreate(String nodeId)
{
    Node result = null;

    try(final Transaction tx = ((GraphDatabaseAPI) neo4jGraph).tx().unforced().begin())
    {
        try
        {
            String queryString = "MERGE (n:Node {nodeId: {nodeId}}) RETURN n";
            Map<String, Object> parameters = new HashMap<String, Object>();
            parameters.put("nodeId", nodeId);
            ResourceIterator<Node> resultIterator = engine.execute(queryString, parameters).columnAs("n");
            result = resultIterator.next();
            tx.success();
        }
        catch (Exception e)
        {
            tx.failure();
            throw new BenchmarkingException("unable to get or create node " + nodeId, e);
        }
    }

    return result;
}
 
开发者ID:socialsensor,项目名称:graphdb-benchmarks,代码行数:25,代码来源:Neo4jSingleInsertion.java

示例6: relateNodes

import org.neo4j.kernel.GraphDatabaseAPI; //导入依赖的package包/类
@Override
public void relateNodes(Node src, Node dest)
{
    try (final Transaction tx = ((GraphDatabaseAPI) neo4jGraph).tx().unforced().begin())
    {
        try
        {
            src.createRelationshipTo(dest, Neo4jGraphDatabase.RelTypes.SIMILAR);
            tx.success();
        }
        catch (Exception e)
        {
            tx.failure();
            throw new BenchmarkingException("unable to relate nodes", e);
        }
    }
}
 
开发者ID:socialsensor,项目名称:graphdb-benchmarks,代码行数:18,代码来源:Neo4jSingleInsertion.java

示例7: shouldLoadAndUseLuceneProvider

import org.neo4j.kernel.GraphDatabaseAPI; //导入依赖的package包/类
@Test
public void shouldLoadAndUseLuceneProvider() throws Exception
{
    // GIVEN
    File storeDir = testDirectory.graphDbDir();
    BatchInserter inserter = BatchInserters.inserter( storeDir );
    inserter.createDeferredSchemaIndex( LABEL ).on( "name" ).create();

    // WHEN
    inserter.createNode( map( "name", "Mattias" ), LABEL );
    inserter.shutdown();

    // THEN
    GraphDatabaseFactory graphDatabaseFactory = new TestGraphDatabaseFactory();
    GraphDatabaseAPI db = (GraphDatabaseAPI) graphDatabaseFactory.newEmbeddedDatabase( storeDir );
    DependencyResolver dependencyResolver = db.getDependencyResolver();
    SchemaIndexProvider schemaIndexProvider = dependencyResolver.resolveDependency(
            SchemaIndexProvider.class,
            SchemaIndexProvider.HIGHEST_PRIORITIZED_OR_NONE );

    // assert the indexProvider is a Lucene one
    try ( Transaction ignore = db.beginTx() )
    {
        IndexDefinition indexDefinition = single( db.schema().getIndexes( LABEL ) );
        assertThat( db.schema().getIndexState( indexDefinition ), is( Schema.IndexState.ONLINE ) );
        assertThat( schemaIndexProvider, instanceOf( LuceneSchemaIndexProvider.class ) );
    }

    // CLEANUP
    db.shutdown();
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:32,代码来源:TestLuceneSchemaBatchInsertIT.java

示例8: before

import org.neo4j.kernel.GraphDatabaseAPI; //导入依赖的package包/类
@Before
public void before()
{
    List<KernelExtensionFactory<?>> extensionFactories = new ArrayList<>();
    extensionFactories.add( kernelExtensionFactory );
    extensionFactories.add(new LuceneLabelScanStoreExtension());
    factory.setKernelExtensions( extensionFactories );
    db = (GraphDatabaseAPI) factory.newEmbeddedDatabase( storeDir.absolutePath() );
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:10,代码来源:UniqueIndexRecoveryTests.java

示例9: shouldNotLeaveLuceneIndexFilesHangingAroundIfConstraintCreationFails

import org.neo4j.kernel.GraphDatabaseAPI; //导入依赖的package包/类
@Test
public void shouldNotLeaveLuceneIndexFilesHangingAroundIfConstraintCreationFails()
{
    // given
    GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();

    try ( Transaction tx = db.beginTx() )
    {
        for ( int i = 0; i < 2; i++ )
        {
            Node node1 = db.createNode( LABEL );
            node1.setProperty( "prop", true );
        }

        tx.success();
    }

    // when
    try ( Transaction tx = db.beginTx() )
    {
        db.schema().constraintFor( LABEL ).assertPropertyIsUnique( "prop" ).create();
        fail("Should have failed with ConstraintViolationException");
        tx.success();
    }
    catch ( ConstraintViolationException ignored )  { }

    // then
    try(Transaction ignore = db.beginTx())
    {
        assertEquals(0, Iterables.count(db.schema().getIndexes() ));
    }

    File schemaStorePath = SchemaIndexProvider
            .getRootDirectory( new File( db.getStoreDir() ), LuceneSchemaIndexProviderFactory.KEY );

    String indexId = "1";
    File[] files = new File(schemaStorePath, indexId ).listFiles();
    assertNotNull( files );
    assertEquals(0, files.length);
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:41,代码来源:ConstraintCreationIT.java

示例10: findNodesOfAllEdges

import org.neo4j.kernel.GraphDatabaseAPI; //导入依赖的package包/类
@Override
public void findNodesOfAllEdges() {
    Object tx = null;
    if(GraphDatabaseType.NEO4J == type) {//TODO fix this
        tx = ((GraphDatabaseAPI) ((Neo4jGraphDatabase) this).neo4jGraph).tx().unforced().begin();
    }
    try {
        
        EdgeIteratorType edgeIterator;
        Timer.Context ctxt = getAllEdgesTimes.time();
        try {
            edgeIterator = this.getAllEdges();
        } finally {
            ctxt.stop();
        }
        
        while(edgeIteratorHasNext(edgeIterator)) {
            EdgeType edge;
            ctxt = nextEdgeTimes.time();
            try {
                edge = nextEdge(edgeIterator);
            } finally {
                ctxt.stop();
            }
            @SuppressWarnings("unused")
            VertexType source = this.getSrcVertexFromEdge(edge);
            @SuppressWarnings("unused")
            VertexType destination = this.getDestVertexFromEdge(edge);
        }
    } finally {//TODO fix this
        if(GraphDatabaseType.NEO4J == type) {
            ((Transaction) tx).close();
        }
    }
}
 
开发者ID:socialsensor,项目名称:graphdb-benchmarks,代码行数:36,代码来源:GraphDatabaseBase.java

示例11: before

import org.neo4j.kernel.GraphDatabaseAPI; //导入依赖的package包/类
@Before
public void before() throws Exception
{
    db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newEmbeddedDatabase( testDirectory.graphDbDir() );
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:6,代码来源:IndexCreationTest.java

示例12: startDb

import org.neo4j.kernel.GraphDatabaseAPI; //导入依赖的package包/类
@Before
public void startDb()
{
    graphDb = (GraphDatabaseAPI) new TestGraphDatabaseFactory().
            newImpermanentDatabaseBuilder().setConfig( getConfig() ).newGraphDatabase();
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:7,代码来源:TestAutoIndexing.java

示例13: doBefore

import org.neo4j.kernel.GraphDatabaseAPI; //导入依赖的package包/类
@BeforeClass
public static void doBefore() throws IOException
{
    FileUtils.deleteRecursively( new File( "target/test-data/deletion" ) );
    db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newEmbeddedDatabase( "target/test-data/deletion" );
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:7,代码来源:TestIndexDelectionFs.java

示例14: shouldNotAllowConcurrentViolationOfConstraint

import org.neo4j.kernel.GraphDatabaseAPI; //导入依赖的package包/类
@Test
public void shouldNotAllowConcurrentViolationOfConstraint() throws Exception
{
    // Given
    GraphDatabaseAPI graphDb = db.getGraphDatabaseAPI();

    Supplier<Statement> statementSupplier = graphDb.getDependencyResolver()
            .resolveDependency( ThreadToStatementContextBridge.class );

    Label label = label( "Foo" );
    String propertyKey = "bar";
    String conflictingValue = "baz";

    // a constraint
    try ( Transaction tx = graphDb.beginTx() )
    {
        graphDb.schema().constraintFor( label ).assertPropertyIsUnique( propertyKey ).create();
        tx.success();
    }

    // When
    try ( Transaction tx = graphDb.beginTx() )
    {
        // create a statement and perform a lookup
        Statement statement = statementSupplier.get();
        int labelId = statement.readOperations().labelGetForName( label.name() );
        int propertyKeyId = statement.readOperations().propertyKeyGetForName( propertyKey );
        statement.readOperations().nodesGetFromIndexSeek( new IndexDescriptor( labelId, propertyKeyId ),
                "The value is irrelevant, we just want to perform some sort of lookup against this index" );

        // then let another thread come in and create a node
        threads.execute( createNode( label, propertyKey, conflictingValue ), graphDb ).get();

        // before we create a node with the same property ourselves - using the same statement that we have
        // already used for lookup against that very same index
        long node = statement.dataWriteOperations().nodeCreate();
        statement.dataWriteOperations().nodeAddLabel( node, labelId );
        try
        {
            statement.dataWriteOperations().nodeSetProperty( node, property( propertyKeyId, conflictingValue ) );

            fail( "exception expected" );
        }
        // Then
        catch ( UniquePropertyConstraintViolationKernelException e )
        {
            assertEquals( labelId, e.labelId() );
            assertEquals( propertyKeyId, e.propertyKeyId() );
            assertEquals( conflictingValue, e.propertyValue() );
        }

        tx.success();
    }
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:55,代码来源:ConstraintIndexConcurrencyTest.java

示例15: beginUnforcedTransaction

import org.neo4j.kernel.GraphDatabaseAPI; //导入依赖的package包/类
private Transaction beginUnforcedTransaction() {
    final TransactionBuilder builder = ((GraphDatabaseAPI) neo4jGraph).tx().unforced();
    return builder.begin();
}
 
开发者ID:socialsensor,项目名称:graphdb-benchmarks,代码行数:5,代码来源:Neo4jGraphDatabase.java


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