本文整理汇总了Java中org.neo4j.graphdb.schema.IndexDefinition类的典型用法代码示例。如果您正苦于以下问题:Java IndexDefinition类的具体用法?Java IndexDefinition怎么用?Java IndexDefinition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IndexDefinition类属于org.neo4j.graphdb.schema包,在下文中一共展示了IndexDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertIndexToConstraint
import org.neo4j.graphdb.schema.IndexDefinition; //导入依赖的package包/类
@Test
public void convertIndexToConstraint()
{
try( Transaction tx = graphDb.beginTx() )
{
graphDb.schema().indexFor( LABEL ).on( PROPERTY_KEY ).create();
tx.success();
}
try( Transaction tx = graphDb.beginTx() )
{
IndexDefinition index = first( graphDb.schema().getIndexes( LABEL ) );
index.drop();
graphDb.schema().constraintFor( LABEL ).assertPropertyIsUnique( PROPERTY_KEY ).create();
tx.success();
}
// assert no exception is thrown
}
示例2: getIndex
import org.neo4j.graphdb.schema.IndexDefinition; //导入依赖的package包/类
private IndexDefinition getIndex( Label label, String propertyKey )
{
try ( Transaction tx = graphDb.beginTx() )
{
IndexDefinition found = null;
for ( IndexDefinition index : graphDb.schema().getIndexes( label ) )
{
if ( propertyKey.equals( single( index.getPropertyKeys() ) ) )
{
assertNull( "Found multiple indexes.", found );
found = index;
}
}
tx.success();
return found;
}
}
示例3: changeShouldBeIdempotentWhenDoingRecovery
import org.neo4j.graphdb.schema.IndexDefinition; //导入依赖的package包/类
@Test
public void changeShouldBeIdempotentWhenDoingRecovery() throws Exception
{
// Given
startDb( createLuceneIndexFactory() );
IndexDefinition indexDefinition = createIndex( myLabel );
waitForIndex( indexDefinition );
long node = createNode( myLabel, 12 );
rotateLogsAndCheckPoint();
updateNode( node, 13 );
// And Given
killDb();
// When
startDb( createLuceneIndexFactory() );
// Then
assertEquals( 0, doIndexLookup( myLabel, 12 ).size() );
assertEquals( 1, doIndexLookup( myLabel, 13 ).size() );
}
示例4: removeShouldBeIdempotentWhenDoingRecovery
import org.neo4j.graphdb.schema.IndexDefinition; //导入依赖的package包/类
@Test
public void removeShouldBeIdempotentWhenDoingRecovery() throws Exception
{
// Given
startDb( createLuceneIndexFactory() );
IndexDefinition indexDefinition = createIndex( myLabel );
waitForIndex( indexDefinition );
long node = createNode( myLabel, 12 );
rotateLogsAndCheckPoint();
deleteNode( node );
// And Given
killDb();
// When
startDb( createLuceneIndexFactory() );
// Then
assertEquals( 0, doIndexLookup( myLabel, 12 ).size() );
}
示例5: shouldNotUpdateTwiceDuringRecovery
import org.neo4j.graphdb.schema.IndexDefinition; //导入依赖的package包/类
@Test
public void shouldNotUpdateTwiceDuringRecovery() throws Exception
{
// Given
startDb( createLuceneIndexFactory() );
IndexDefinition indexDefinition = createIndex( myLabel );
waitForIndex( indexDefinition );
long nodeId = createNode( myLabel, 12 );
updateNode( nodeId, 14 );
// And Given
killDb();
// When
startDb( createLuceneIndexFactory() );
// Then
assertEquals( 0, doIndexLookup( myLabel, 12 ).size() );
assertEquals( 1, doIndexLookup( myLabel, 14 ).size() );
}
示例6: recoveryAfterCreateAndDropIndex
import org.neo4j.graphdb.schema.IndexDefinition; //导入依赖的package包/类
@Test
public void recoveryAfterCreateAndDropIndex() throws Exception
{
// GIVEN
IndexDefinition indexDefinition = createIndex( db, label, propertyKey );
createSomeData( label, propertyKey );
doStuff( db, label, propertyKey );
dropIndex( indexDefinition );
doStuff( db, label, propertyKey );
// WHEN
crashAndRestart();
// THEN
assertThat( getIndexes( db, label ), isEmpty() );
}
示例7: setupSchemaIndexes
import org.neo4j.graphdb.schema.IndexDefinition; //导入依赖的package包/类
public static void setupSchemaIndexes(GraphDatabaseService graphDb, Neo4jConfiguration config) {
Map<String, Set<String>> schemaIndexes = config.getSchemaIndexes();
for (Map.Entry<String, Set<String>> entry : schemaIndexes.entrySet()) {
Label label = Label.label(entry.getKey());
for (String property : entry.getValue()) {
try (Transaction tx = graphDb.beginTx()) {
Schema schema = graphDb.schema();
IndexDefinition indexDefinition = schema.indexFor(label).on(property).create();
tx.success();
tx.close();
Transaction tx2 = graphDb.beginTx();
schema.awaitIndexOnline(indexDefinition, 2, TimeUnit.MINUTES);
tx2.success();
tx2.close();
}
}
}
}
示例8: WikiNerGraphConnector
import org.neo4j.graphdb.schema.IndexDefinition; //导入依赖的package包/类
private WikiNerGraphConnector(String dbDir) {
graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbDir);
IndexDefinition indexDefinition;
Schema schema;
Transaction tx = graphDb.beginTx();
schema = graphDb.schema();
IndexManager index = graphDb.index();
entities = index.forNodes(entityLabel.name());
cities = index.forNodes(cityLabel.name());
try{
indexDefinition = schema.indexFor( entityLabel ).on( "nameType" ).create();
}catch(Exception e){
}
tx.success();
tx.close();
}
示例9: run
import org.neo4j.graphdb.schema.IndexDefinition; //导入依赖的package包/类
public NeoProfile run(NeoProfiler parent) {
SchemaProfile p = new SchemaProfile();
try(Transaction tx = parent.getDB().beginTx()) {
Schema schema = parent.getDB().schema();
Iterator<ConstraintDefinition> constraints = schema.getConstraints().iterator();
while(constraints.hasNext()) {
ConstraintDefinition c = constraints.next();
p.addConstraint(new NeoConstraint(true, false, c.getPropertyKeys(), c.getLabel(), c.getConstraintType()));
}
Iterator<IndexDefinition> idxs = schema.getIndexes().iterator();
while(idxs.hasNext()) {
IndexDefinition idx = idxs.next();
p.addConstraint(new NeoConstraint(idx.isConstraintIndex(), true, idx.getPropertyKeys(), idx.getLabel(), null));
}
}
return p;
}
示例10: doesIndexExist
import org.neo4j.graphdb.schema.IndexDefinition; //导入依赖的package包/类
private boolean doesIndexExist(Iterable<IndexDefinition> indexes, String name, String on) {
for (IndexDefinition index : indexes) {
if (index.getLabel().equals(Label.label(name))
&& StreamSupport.stream(index.getPropertyKeys().spliterator(), false).anyMatch(on::equals)) {
return true;
}
}
return false;
}
示例11: shouldLoadAndUseLuceneProvider
import org.neo4j.graphdb.schema.IndexDefinition; //导入依赖的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();
}
示例12: convertIndexToConstraintWithExistingData
import org.neo4j.graphdb.schema.IndexDefinition; //导入依赖的package包/类
@Test
public void convertIndexToConstraintWithExistingData()
{
try( Transaction tx = graphDb.beginTx() )
{
for ( int i = 0; i < 2000; i++)
{
Node node = graphDb.createNode( LABEL );
node.setProperty( PROPERTY_KEY, i );
}
tx.success();
}
try( Transaction tx = graphDb.beginTx() )
{
graphDb.schema().indexFor( LABEL ).on( PROPERTY_KEY ).create();
tx.success();
}
try( Transaction tx = graphDb.beginTx() )
{
IndexDefinition index = first( graphDb.schema().getIndexes( LABEL ) );
index.drop();
graphDb.schema().constraintFor( LABEL ).assertPropertyIsUnique( PROPERTY_KEY ).create();
tx.success();
}
// assert no exception is thrown
}
示例13: recreate
import org.neo4j.graphdb.schema.IndexDefinition; //导入依赖的package包/类
private IndexDefinition recreate( IndexDefinition index, int times )
{
for ( int i = 0; i < times; i++ )
{
index.drop();
index = graphDb.schema()
.indexFor( index.getLabel() )
.on( single( index.getPropertyKeys() ) )
.create();
}
return index;
}
示例14: addShouldBeIdempotentWhenDoingRecovery
import org.neo4j.graphdb.schema.IndexDefinition; //导入依赖的package包/类
@Test
public void addShouldBeIdempotentWhenDoingRecovery() throws Exception
{
// Given
startDb( createLuceneIndexFactory() );
IndexDefinition index = createIndex( myLabel );
waitForIndex( index );
long nodeId = createNode( myLabel, 12 );
try(Transaction tx = db.beginTx())
{
assertNotNull( db.getNodeById( nodeId ) );
}
assertEquals( 1, doIndexLookup( myLabel, 12 ).size() );
// And Given
killDb();
// When
startDb( createLuceneIndexFactory() );
// Then
try(Transaction tx = db.beginTx())
{
assertNotNull( db.getNodeById( nodeId ) );
}
assertEquals( 1, doIndexLookup( myLabel, 12 ).size() );
}
示例15: shouldNotAddTwiceDuringRecoveryIfCrashedDuringPopulation
import org.neo4j.graphdb.schema.IndexDefinition; //导入依赖的package包/类
@Test
public void shouldNotAddTwiceDuringRecoveryIfCrashedDuringPopulation() throws Exception
{
// Given
startDb( createAlwaysInitiallyPopulatingLuceneIndexFactory() );
IndexDefinition indexDefinition = createIndex( myLabel );
waitForIndex( indexDefinition );
long nodeId = createNode( myLabel, 12 );
assertEquals( 1, doIndexLookup( myLabel, 12 ).size() );
// And Given
killDb();
// When
startDb( createAlwaysInitiallyPopulatingLuceneIndexFactory() );
try ( Transaction tx = db.beginTx() )
{
IndexDefinition index = db.schema().getIndexes().iterator().next();
waitForIndex( index );
// Then
assertEquals( 12, db.getNodeById( nodeId ).getProperty( NUM_BANANAS_KEY ) );
assertEquals( 1, doIndexLookup( myLabel, 12 ).size() );
}
}