use of org.neo4j.ogm.model.RowModel in project neo4j-ogm by neo4j.
the class BoltRequest method execute.
@Override
public Response<RowModel> execute(DefaultRequest query) {
final List<RowModel> rowModels = new ArrayList<>();
String[] columns = null;
for (Statement statement : query.getStatements()) {
Result result = executeRequest(statement);
if (columns == null) {
try {
List<String> columnSet = result.keys();
columns = columnSet.toArray(new String[columnSet.size()]);
} catch (ClientException e) {
throw new CypherException(e.code(), e.getMessage(), e);
}
}
try (RowModelResponse rowModelResponse = new RowModelResponse(result, entityAdapter)) {
RowModel model;
while ((model = rowModelResponse.next()) != null) {
rowModels.add(model);
}
result.consume();
} catch (ClientException e) {
throw new CypherException(e.code(), e.getMessage(), e);
}
}
return new MultiStatementBasedResponse(columns, rowModels);
}
use of org.neo4j.ogm.model.RowModel in project neo4j-ogm by neo4j.
the class ExecuteQueriesDelegate method mapScalarResponse.
private static <T> Iterable<T> mapScalarResponse(Class<T> type, Response<RowModel> response) {
// We need to execute the request in any case, but can skip processing the result when
// it's not assignable to the requested type.
Collection<T> result;
if (VOID_TYPES.contains(type)) {
result = Collections.emptyList();
} else {
result = new ArrayList<>();
RowModel model;
while ((model = response.next()) != null) {
result.add(extractColumnValue(type, model));
}
}
return result;
}
use of org.neo4j.ogm.model.RowModel in project neo4j-ogm by neo4j.
the class JsonRowResponseTest method shouldParseDataInCreateRowResponseCorrectly.
@Test
public void shouldParseDataInCreateRowResponseCorrectly() throws IOException {
when(entity.getContent()).thenReturn(createRowResults());
try (Response<RowModel> rsp = new RowModelResponse(response)) {
RowModel rowModel = rsp.next();
assertThat(rowModel).isNotNull();
Object[] rows = rowModel.getValues();
assertThat(rows.length).isEqualTo(4);
assertThat(rows[0]).isEqualTo(388L);
assertThat(rows[1]).isEqualTo(527L);
assertThat(rows[2]).isEqualTo(389L);
assertThat(rows[3]).isEqualTo(528L);
}
}
use of org.neo4j.ogm.model.RowModel in project neo4j-ogm by neo4j.
the class JsonRowResponseTest method shouldParseDataInRowResponseCorrectly.
@Test
public void shouldParseDataInRowResponseCorrectly() throws IOException {
when(entity.getContent()).thenReturn(rowResultsAndNoErrors());
try (Response<RowModel> rsp = new RowModelResponse(response)) {
RowModel rowModel = rsp.next();
assertThat(rowModel).isNotNull();
Object[] rows = rowModel.getValues();
assertThat(rows.length).isEqualTo(1);
List<List<Map>> data = (List<List<Map>>) rows[0];
assertThat(data.get(0).get(0).get("name")).isEqualTo("My Test");
}
}
use of org.neo4j.ogm.model.RowModel in project neo4j-ogm by neo4j.
the class RequestExecutor method registerEntityIds.
/**
* Register ids of nodes created or updated back into the compile context. New identities are required for use
* in other parts of the query that depend upon these new entities. New relationships, for example, may require
* the IDs of nodes created in the same request. Existing entity ids are registered because they
* will need to be updated in the mapping context
* Note that the mapping context is not updated at this point.
*
* @param context the compile context
* @param response query response
* @param entityRefMappings mapping of entity reference used in the compile context and the entity id from the database
*/
private void registerEntityIds(CompileContext context, List<RowModel> response, List<ReferenceMapping> entityRefMappings, List<ReferenceMapping> relEntityRefMappings) {
for (RowModel rowModel : response) {
Object[] results = rowModel.getValues();
String[] variables = rowModel.variables();
Long entityRef = null;
Long entityId = null;
String type = null;
for (int i = 0; i < variables.length; i++) {
if (variables[i].equals("id")) {
entityId = ((Number) results[i]).longValue();
}
if (variables[i].equals("ref")) {
entityRef = ((Number) results[i]).longValue();
}
if (variables[i].equals("type")) {
type = (String) results[i];
}
}
if (type != null && type.equals("node")) {
entityRefMappings.add(new ReferenceMapping(entityRef, entityId));
if (entityRef != null && entityRef.equals(entityId)) {
LOGGER.debug("to update: nodeEntity {}:{}", entityRef, entityId);
} else {
LOGGER.debug("to create: nodeEntity {}:{}", entityRef, entityId);
context.registerNewId(entityRef, entityId);
}
} else if (type != null && type.equals("rel")) {
relEntityRefMappings.add(new ReferenceMapping(entityRef, entityId));
if (entityRef != null && entityRef.equals(entityId)) {
LOGGER.debug("to (maybe) update: relEntity {}:{}", entityRef, entityId);
} else {
LOGGER.debug("to (maybe) create: relEntity {}:{}", entityRef, entityId);
context.registerNewId(entityRef, entityId);
}
}
}
}
Aggregations