Java 类org.neo4j.graphdb.index.UniqueFactory 实例源码

项目:neo4j-lucene5-index    文件:WorkThread.java   
public Future<Node> getOrCreate( final String key, final Object value, final Object initialValue ) throws Exception
{
    return executeDontWait( new WorkerCommand<CommandState, Node>()
    {
        @Override
        public Node doWork( CommandState state )
        {
            UniqueFactory.UniqueNodeFactory factory = new UniqueFactory.UniqueNodeFactory( state.index )
            {
                @Override
                protected void initialize( Node node, Map<String, Object> properties )
                {
                    node.setProperty( key, initialValue );
                }
            };
            return factory.getOrCreate( key, value );
        }
    } );
}
项目:FAIRsharing-Owl2Neo    文件:Owl2Neo4jLoader.java   
private Node getOrCreateWithUniqueFactory(String nodeName) {

        UniqueFactory<Node> factory = new UniqueFactory.UniqueNodeFactory(graphDb, "index") {
            @Override
            protected void initialize(Node created, Map<String, Object> properties) {
                created.setProperty("className", properties.get("name"));
            }
        };

        return factory.getOrCreate("name", nodeName);
    }
项目:neo4j-lucene5-index    文件:TestLuceneIndex.java   
@Test
public void getOrCreateNodeWithUniqueFactory() throws Exception
{
    final String key = "name";
    final String value = "Mattias";
    final String property = "counter";

    final Index<Node> index = nodeIndex( LuceneIndexImplementation.EXACT_CONFIG );
    final AtomicInteger counter = new AtomicInteger();
    UniqueFactory<Node> factory = new UniqueFactory.UniqueNodeFactory( index )
    {
        @Override
        protected void initialize( Node node, Map<String, Object> properties )
        {
            assertEquals( value, properties.get( key ) );
            assertEquals( 1, properties.size() );
            node.setProperty( property, counter.getAndIncrement() );
        }
    };
    Node unique = factory.getOrCreate( key, value );

    assertNotNull( unique );
    assertEquals( "not initialized", 0, unique.getProperty( property, null ) );
    assertEquals( unique, index.get( key, value ).getSingle() );

    assertEquals( unique, factory.getOrCreate( key, value ) );
    assertEquals( "initialized more than once", 0, unique.getProperty( property ) );
    assertEquals( unique, index.get( key, value ).getSingle() );
    finishTx( false );
}
项目:neo4j-lucene5-index    文件:TestLuceneIndex.java   
@Test
public void getOrCreateRelationshipWithUniqueFactory() throws Exception
{
    final String key = "name";
    final String value = "Mattias";

    final Node root = graphDb.createNode();
    final Index<Relationship> index = relationshipIndex( LuceneIndexImplementation.EXACT_CONFIG );
    final DynamicRelationshipType type = DynamicRelationshipType.withName( "SINGLE" );
    UniqueFactory<Relationship> factory = new UniqueFactory.UniqueRelationshipFactory( index )
    {
        @Override
        protected Relationship create( Map<String, Object> properties )
        {
            assertEquals( value, properties.get( key ) );
            assertEquals( 1, properties.size() );
            return root.createRelationshipTo( graphDatabase().createNode(), type );
        }
    };

    Relationship unique = factory.getOrCreate( key, value );
    assertEquals( unique, root.getSingleRelationship( type, Direction.BOTH ) );
    assertNotNull( unique );

    assertEquals( unique, index.get( key, value ).getSingle() );

    assertEquals( unique, factory.getOrCreate( key, value ) );
    assertEquals( unique, root.getSingleRelationship( type, Direction.BOTH ) );
    assertEquals( unique, index.get( key, value ).getSingle() );

    finishTx( false );
}
项目:graphify    文件:GraphManager.java   
/**
 * The node factory is used for caching.
 * @param db The Neo4j GraphDatabaseService that contains the pattern recognition hierarchy.
 */
private void createNodeFactory(GraphDatabaseService db) {
    if (patternFactory == null) {
        patternFactory = new UniqueFactory.UniqueNodeFactory(db, label) {
            @Override
            protected void initialize(Node created, Map<String, Object> properties) {
                created.setProperty(propertyKey, properties.get(propertyKey));
            }
        };
    }
}
项目:graphify    文件:ClassNodeManager.java   
private void createNodeFactory(GraphDatabaseService db) {
    if (classFactory == null) {
        classFactory = new UniqueFactory.UniqueNodeFactory(db, label) {
            @Override
            protected void initialize(Node created, Map<String, Object> properties) {
                created.setProperty(propertyKey, properties.get(propertyKey));
            }
        };
    }
}
项目:graphify    文件:DataNodeManager.java   
private void createNodeFactory(GraphDatabaseService db) {
    if (dataFactory == null) {
        dataFactory = new UniqueFactory.UniqueNodeFactory(db, label) {
            @Override
            protected void initialize(Node created, Map<String, Object> properties) {
                created.setProperty(propertyKey, properties.get(propertyKey));
            }
        };
    }
}