Search in sources :

Example 11 with RowModel

use of org.neo4j.ogm.model.RowModel in project neo4j-ogm by neo4j.

the class ExecuteQueriesDelegate method countEntitiesOfType.

public long countEntitiesOfType(Class<?> entity) {
    ClassInfo classInfo = session.metaData().classInfo(entity.getName());
    if (classInfo == null) {
        return 0;
    }
    CypherQuery countStatement;
    if (classInfo.isRelationshipEntity()) {
        ClassInfo startNodeInfo = null;
        ClassInfo endNodeInfo = null;
        for (FieldInfo fieldInfo : classInfo.fieldsInfo().fields()) {
            if (fieldInfo.hasAnnotation(StartNode.class)) {
                startNodeInfo = session.metaData().classInfo(DescriptorMappings.getType(fieldInfo.getTypeDescriptor()).getName());
            } else if (fieldInfo.hasAnnotation(EndNode.class)) {
                endNodeInfo = session.metaData().classInfo(DescriptorMappings.getType(fieldInfo.getTypeDescriptor()).getName());
            }
            if (endNodeInfo != null && startNodeInfo != null) {
                break;
            }
        }
        String start = startNodeInfo.neo4jName();
        String end = endNodeInfo.neo4jName();
        String type = classInfo.neo4jName();
        countStatement = new CountStatements().countEdges(start, type, end);
    } else {
        Collection<String> labels = classInfo.staticLabels();
        if (labels.isEmpty()) {
            return 0;
        }
        countStatement = new CountStatements().countNodes(labels);
    }
    return session.doInTransaction(() -> {
        try (Response<RowModel> response = session.requestHandler().execute((RowModelRequest) countStatement)) {
            RowModel queryResult = response.next();
            return queryResult == null ? 0 : ((Number) queryResult.getValues()[0]).longValue();
        }
    }, Transaction.Type.READ_ONLY);
}
Also used : EndNode(org.neo4j.ogm.annotation.EndNode) RowModel(org.neo4j.ogm.model.RowModel) CypherQuery(org.neo4j.ogm.cypher.query.CypherQuery) CountStatements(org.neo4j.ogm.session.request.strategy.impl.CountStatements) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 12 with RowModel

use of org.neo4j.ogm.model.RowModel in project neo4j-ogm by neo4j.

the class JsonRowResponseTest method shouldParseDataInCustomQueryRowResponseCorrectly.

@Test
public void shouldParseDataInCustomQueryRowResponseCorrectly() throws IOException {
    when(entity.getContent()).thenReturn(customQueryRowResults());
    try (Response<RowModel> rsp = new RowModelResponse(response)) {
        RowModel rowModel = rsp.next();
        assertThat(rowModel).isNotNull();
        Object[] rows = rowModel.getValues();
        assertThat(rows.length).isEqualTo(3);
        Map obj1 = (Map) rows[0];
        assertThat(obj1.get("name")).isEqualTo("Betty");
        assertThat(((Map) rows[1])).isEmpty();
        assertThat((String) rows[2]).isEqualTo("Peter");
    }
}
Also used : RowModel(org.neo4j.ogm.model.RowModel) Map(java.util.Map) Test(org.junit.Test)

Example 13 with RowModel

use of org.neo4j.ogm.model.RowModel in project neo4j-ogm by neo4j.

the class AutoIndexManager method executeStatements.

private void executeStatements(List<Statement> statements) {
    DefaultRequest request = new DefaultRequest();
    request.setStatements(statements);
    session.doInTransaction(() -> {
        try (Response<RowModel> response = session.requestHandler().execute(request)) {
        // Success
        }
    }, READ_WRITE);
}
Also used : DefaultRequest(org.neo4j.ogm.session.request.DefaultRequest) RowModel(org.neo4j.ogm.model.RowModel)

Aggregations

RowModel (org.neo4j.ogm.model.RowModel)13 Statement (org.neo4j.ogm.request.Statement)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 List (java.util.List)3 Test (org.junit.Test)3 ClassInfo (org.neo4j.ogm.metadata.ClassInfo)3 CypherQuery (org.neo4j.ogm.cypher.query.CypherQuery)2 DefaultRowModelRequest (org.neo4j.ogm.cypher.query.DefaultRowModelRequest)2 RowModelRequest (org.neo4j.ogm.request.RowModelRequest)2 Response (org.neo4j.ogm.response.Response)2 PersistenceEvent (org.neo4j.ogm.session.event.PersistenceEvent)2 Serializable (java.io.Serializable)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Result (org.neo4j.driver.Result)1 ClientException (org.neo4j.driver.exceptions.ClientException)1