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


Java ThreadToStatementContextBridge类代码示例

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


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

示例1: compute

import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; //导入依赖的package包/类
@Override
public void compute(String label, String type, int iterations) {
    degree = new int[nodeCount];
    Arrays.fill(degree, -1);

    try ( Transaction tx = db.beginTx()) {
        ThreadToStatementContextBridge ctx = this.db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
        ReadOperations ops = ctx.get().readOperations();
        int labelId = ops.labelGetForName(label);
        int relationshipTypeId = ops.relationshipTypeGetForName(type);

        PrimitiveLongIterator it = ops.nodesGetForLabel(labelId);
        int totalCount = nodeCount;
        runOperations(pool, it, totalCount, ops, new OpsRunner() {
            public void run(int id) throws EntityNotFoundException {
                degree[id] = ops.nodeGetDegree(id, direction, relationshipTypeId);
            }
        });

        tx.success();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:maxdemarzi,项目名称:graph_processing,代码行数:25,代码来源:DegreeArrayStorageParallelSPI.java

示例2: performSearch

import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; //导入依赖的package包/类
private static ArrayList<Long> performSearch(String term) throws SchemaRuleNotFoundException, IndexNotFoundKernelException {
    ThreadToStatementContextBridge ctx = dbapi.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
    KernelStatement st = (KernelStatement)ctx.get();
    ReadOperations ops = st.readOperations();
    IndexDescriptor descriptor = ops.indexGetForLabelAndPropertyKey(postLabelId, statusPropertyId);
    IndexReader reader = st.getStoreStatement().getIndexReader(descriptor);

    PrimitiveLongIterator hits = reader.containsString(term);
    ArrayList<Long> results = new ArrayList<>();
    while(hits.hasNext()) {
        results.add(hits.next());
    }
    return results;
}
 
开发者ID:maxdemarzi,项目名称:grittier_ext,代码行数:15,代码来源:Search.java

示例3: Search

import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; //导入依赖的package包/类
public Search(@Context GraphDatabaseService db) throws NoSuchMethodException {
    this.dbapi = (GraphDatabaseAPI) db;
    try (Transaction tx = db.beginTx()) {
        ThreadToStatementContextBridge ctx = dbapi.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
        ReadOperations ops = ctx.get().readOperations();
        postLabelId = ops.labelGetForName(Labels.Post.name());
        statusPropertyId = ops.propertyKeyGetForName(STATUS);
        tx.success();
    }
}
 
开发者ID:maxdemarzi,项目名称:grittier_ext,代码行数:11,代码来源:Search.java

示例4: Energization

import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; //导入依赖的package包/类
public Energization(@Context GraphDatabaseService db) {
    this.dbapi = (GraphDatabaseAPI) db;
    try (Transaction tx = db.beginTx()) {
        ThreadToStatementContextBridge ctx = dbapi.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
        ReadOperations ops = ctx.get().readOperations();
        equipmentLabelId = ops.labelGetForName(Labels.Equipment.name());
        propertyEquipmentId = ops.propertyKeyGetForName("equipment_id");
        propertyIncomingSwitchOn = ops.propertyKeyGetForName("incoming_switch_on");
        propertyOutgoingSwitchOn = ops.propertyKeyGetForName("outgoing_switch_on");
        propertyVoltage = ops.propertyKeyGetForName("voltage");
        tx.success();
    }
}
 
开发者ID:maxdemarzi,项目名称:power_grid,代码行数:14,代码来源:Energization.java

示例5: getPropertyNameId

import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; //导入依赖的package包/类
private int getPropertyNameId(GraphDatabaseService db, Algorithm algorithm, ThreadToStatementContextBridge ctx) {
    int propertyNameId;
    try (Transaction tx = db.beginTx()) {
        propertyNameId = ctx.get().tokenWriteOperations().propertyKeyGetOrCreateForName(algorithm.getPropertyName());
        tx.success();
    } catch (IllegalTokenNameException e) {
        throw new RuntimeException(e);
    }
    return propertyNameId;
}
 
开发者ID:maxdemarzi,项目名称:pagerank_spi,代码行数:11,代码来源:Service.java

示例6: compute

import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; //导入依赖的package包/类
@Override
public void compute(int iterations) {

    final int[] src = new int[nodeCount];
    dst = new AtomicIntegerArray(nodeCount);

    try ( Transaction tx = db.beginTx()) {

        ThreadToStatementContextBridge ctx = this.db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
        final ReadOperations ops = ctx.get().readOperations();

        int[] degrees = computeDegrees(ops);

        final RelationshipVisitor<RuntimeException> visitor = new RelationshipVisitor<RuntimeException>() {
            public void visit(long relId, int relTypeId, long startNode, long endNode) throws RuntimeException {
                dst.addAndGet(((int) endNode), src[(int) startNode]);
            }
       };

        for (int iteration = 0; iteration < iterations; iteration++) {
            startIteration(src, dst, degrees);

            PrimitiveLongIterator rels = ops.relationshipsGetAll();
            runOperations(pool, rels, relCount , ops, new OpsRunner() {
                public void run(int id) throws EntityNotFoundException {
                    ops.relationshipVisit(id, visitor);
                }
            });
        }
        tx.success();
    } catch (EntityNotFoundException e) {
        e.printStackTrace();
    }
}
 
开发者ID:maxdemarzi,项目名称:pagerank_spi,代码行数:35,代码来源:PageRankArrayStorageParallelSPI.java

示例7: compute

import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; //导入依赖的package包/类
@Override
public void compute(String label, String type, int iterations) {

    int[] src = new int[nodeCount];
    dst = new AtomicIntegerArray(nodeCount);

    try ( Transaction tx = db.beginTx()) {

        ThreadToStatementContextBridge ctx = this.db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
        ReadOperations ops = ctx.get().readOperations();
        int labelId = ops.labelGetForName(label);
        int typeId = ops.relationshipTypeGetForName(type);

        int[] degrees = computeDegrees(ops,labelId, typeId);

        RelationshipVisitor<RuntimeException> visitor = new RelationshipVisitor<RuntimeException>() {
            public void visit(long relId, int relTypeId, long startNode, long endNode) throws RuntimeException {
                if (relTypeId == typeId) {
                    dst.addAndGet(((int) endNode),src[(int) startNode]);
                }
            }
        };

        for (int iteration = 0; iteration < iterations; iteration++) {
            startIteration(src, dst, degrees);

            PrimitiveLongIterator rels = ops.relationshipsGetAll();
            runOperations(pool, rels, relCount , ops, new OpsRunner() {
                public void run(int id) throws EntityNotFoundException {
                    ops.relationshipVisit(id, visitor);
                }
            });
        }
        tx.success();
    } catch (EntityNotFoundException e) {
        e.printStackTrace();
    }
}
 
开发者ID:maxdemarzi,项目名称:graph_processing,代码行数:39,代码来源:PageRankArrayStorageParallelSPI.java

示例8: compute

import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; //导入依赖的package包/类
@Override
public void compute(String label, String type, int iterations) {

    float[] src = new float[nodes];
    dst = new float[nodes];

    try ( Transaction tx = db.beginTx()) {

        ThreadToStatementContextBridge ctx = this.db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
        ReadOperations ops = ctx.get().readOperations();
        int labelId = ops.labelGetForName(label);
        int typeId = ops.relationshipTypeGetForName(type);

        int[] degrees = computeDegrees(ops,labelId, typeId);

        RelationshipVisitor<RuntimeException> visitor = new RelationshipVisitor<RuntimeException>() {
            public void visit(long relId, int relTypeId, long startNode, long endNode) throws RuntimeException {
                if (relTypeId == typeId) {
                    dst[((int) endNode)] += src[(int) startNode];
                }
            }
        };

        for (int iteration = 0; iteration < iterations; iteration++) {
            startIteration(src, dst, degrees);

            PrimitiveLongIterator rels = ops.relationshipsGetAll();
            while (rels.hasNext()) {
                ops.relationshipVisit(rels.next(), visitor);
            }
        }
        tx.success();
    } catch (EntityNotFoundException e) {
        e.printStackTrace();
    }
}
 
开发者ID:maxdemarzi,项目名称:graph_processing,代码行数:37,代码来源:PageRankArrayStorageSPI.java

示例9: energizationSPI

import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; //导入依赖的package包/类
@POST
@Path("/spi")
public Response energizationSPI(String body, @Context GraphDatabaseService db) throws IndexNotFoundKernelException, IOException, SchemaRuleNotFoundException, IndexBrokenKernelException, EntityNotFoundException {
    HashMap input = Validators.getValidEquipmentIds(body);
    HashSet<String> results = new HashSet<>();

    try (Transaction tx = db.beginTx()) {
        ThreadToStatementContextBridge ctx = dbapi.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
        ReadOperations ops = ctx.get().readOperations();
        IndexDescriptor descriptor = ops.indexGetForLabelAndPropertyKey(equipmentLabelId, propertyEquipmentId);

        HashMap<Long, Double> equipmentMap = new HashMap<>();
        for (String equipmentId : (Collection<String>) input.get("ids")) {
            Cursor<NodeItem> nodes = ops.nodeCursorGetFromUniqueIndexSeek(descriptor, equipmentId);
            if (nodes.next()) {
                long equipmentNodeId = nodes.get().id();
                energized.add((int) equipmentNodeId);
                results.add(equipmentId);
                equipmentMap.put(equipmentNodeId, (double) ops.nodeGetProperty(equipmentNodeId, propertyVoltage));

                while (!equipmentMap.isEmpty()) {
                    Map.Entry<Long, Double> entry = equipmentMap.entrySet().iterator().next();
                    equipmentMap.remove(entry.getKey());
                    RelationshipIterator relationshipIterator = ops.nodeGetRelationships(entry.getKey(), org.neo4j.graphdb.Direction.BOTH);
                    Cursor<RelationshipItem> c;

                    while (relationshipIterator.hasNext()) {
                        c = ops.relationshipCursor(relationshipIterator.next());
                        if (c.next() && (boolean) c.get().getProperty(propertyIncomingSwitchOn) && (boolean) c.get().getProperty(propertyOutgoingSwitchOn)) {
                            long otherNodeId = c.get().otherNode(entry.getKey());
                            if (!energized.contains((int) otherNodeId)) {
                                double newVoltage = (double) ops.nodeGetProperty(otherNodeId, propertyVoltage);
                                if (newVoltage <= entry.getValue()) {
                                    results.add( (String)ops.nodeGetProperty(otherNodeId, propertyEquipmentId));
                                    energized.add((int) otherNodeId);
                                    equipmentMap.put(otherNodeId, newVoltage);
                                }
                            }
                        }
                    }
                }
            } else {
                System.out.println("none found");
            }
            nodes.close();
        }
        tx.success();
    }

    return Response.ok().entity(objectMapper.writeValueAsString(results)).build();
}
 
开发者ID:maxdemarzi,项目名称:power_grid,代码行数:52,代码来源:Energization.java

示例10: energizationStreaming

import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; //导入依赖的package包/类
@POST
@Path("/streaming")
public Response energizationStreaming(String body, @Context GraphDatabaseService db) throws IndexNotFoundKernelException, IOException, SchemaRuleNotFoundException, IndexBrokenKernelException, EntityNotFoundException {
    HashMap input = Validators.getValidEquipmentIds(body);
    StreamingOutput stream = os -> {
        JsonGenerator jg = objectMapper.getJsonFactory().createJsonGenerator(os, JsonEncoding.UTF8);
        jg.writeStartArray();

        try (Transaction tx = db.beginTx()) {
            ThreadToStatementContextBridge ctx = dbapi.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
            ReadOperations ops = ctx.get().readOperations();
            IndexDescriptor descriptor = ops.indexGetForLabelAndPropertyKey(equipmentLabelId, propertyEquipmentId);

            HashMap<Long, Double> equipmentMap = new HashMap<>();
            for (String equipmentId : (Collection<String>) input.get("ids")) {
                Cursor<NodeItem> nodes = ops.nodeCursorGetFromUniqueIndexSeek(descriptor, equipmentId);
                if (nodes.next()) {
                    long equipmentNodeId = nodes.get().id();
                    energized.add((int) equipmentNodeId);
                    jg.writeString(equipmentId);
                    equipmentMap.put(equipmentNodeId, (double) ops.nodeGetProperty(equipmentNodeId, propertyVoltage));

                    while (!equipmentMap.isEmpty()) {
                        Map.Entry<Long, Double> entry = equipmentMap.entrySet().iterator().next();
                        equipmentMap.remove(entry.getKey());
                        RelationshipIterator relationshipIterator = ops.nodeGetRelationships(entry.getKey(), org.neo4j.graphdb.Direction.BOTH);
                        Cursor<RelationshipItem> c;

                        while (relationshipIterator.hasNext()) {
                            c = ops.relationshipCursor(relationshipIterator.next());
                            if (c.next() && (boolean) c.get().getProperty(propertyIncomingSwitchOn) && (boolean) c.get().getProperty(propertyOutgoingSwitchOn)) {
                                long otherNodeId = c.get().otherNode(entry.getKey());
                                if (!energized.contains((int) otherNodeId)) {
                                    double newVoltage = (double) ops.nodeGetProperty(otherNodeId, propertyVoltage);
                                    if (newVoltage <= entry.getValue()) {
                                        jg.writeString((String) ops.nodeGetProperty(otherNodeId, propertyEquipmentId));
                                        energized.add((int) otherNodeId);
                                        equipmentMap.put(otherNodeId, newVoltage);
                                    }
                                }
                            }
                        }
                    }
                }
                nodes.close();
            }
            tx.success();
        } catch (Exception e) {
            e.printStackTrace();
        }

        jg.writeEndArray();
        jg.flush();
        jg.close();
    };
    return Response.ok().entity(stream).type(MediaType.APPLICATION_JSON).build();
}
 
开发者ID:maxdemarzi,项目名称:power_grid,代码行数:58,代码来源:Energization.java

示例11: shouldNotAllowConcurrentViolationOfConstraint

import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; //导入依赖的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.impl.core.ThreadToStatementContextBridge类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。