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


Java GraphDatabaseAPI.beginTx方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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


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