Search in sources :

Example 1 with DefaultGraphModel

use of org.neo4j.ogm.response.model.DefaultGraphModel in project neo4j-ogm by neo4j.

the class GraphModelAdapter method adapt.

/**
 * Parses a row from the result object and transforms it into a GraphModel
 *
 * @param data the data to transform, given as a map
 * @return the data transformed to an {@link GraphModel}
 */
@Override
public GraphModel adapt(Map<String, Object> data) {
    // These two sets keep track of which nodes and edges have already been built, so we don't redundantly
    // write the same node or relationship entity many times.
    final Set<Long> nodeIdentities = new HashSet<>();
    final Set<Long> edgeIdentities = new HashSet<>();
    DefaultGraphModel graphModel = new DefaultGraphModel();
    for (Map.Entry<String, Object> mapEntry : data.entrySet()) {
        final Object value = mapEntry.getValue();
        String resultKey = mapEntry.getKey();
        boolean generatedNodes = ResultAdapter.describesGeneratedNode(resultKey);
        adaptInternal(nodeIdentities, edgeIdentities, graphModel, value, generatedNodes);
    }
    return graphModel;
}
Also used : Map(java.util.Map) DefaultGraphModel(org.neo4j.ogm.response.model.DefaultGraphModel) HashSet(java.util.HashSet)

Example 2 with DefaultGraphModel

use of org.neo4j.ogm.response.model.DefaultGraphModel in project neo4j-ogm by neo4j.

the class GraphRowModelAdapter method adapt.

/**
 * Reads the next row from the result object and transforms it into a RowModel object
 *
 * @param data the data to transform, given as a map
 * @return the data transformed to an {@link RowModel}
 */
public GraphRowModel adapt(Map<String, Object> data) {
    if (columns == null) {
        throw new ResultProcessingException("Result columns should not be null");
    }
    Set<Long> nodeIdentities = new HashSet<>();
    Set<Long> edgeIdentities = new HashSet<>();
    DefaultGraphModel graphModel = new DefaultGraphModel();
    List<String> variables = new ArrayList<>();
    List<Object> values = new ArrayList<>();
    // there is no guarantee that the objects in the data are ordered the same way as required by the columns
    // so we use the columns information to extract them in the correct order for post-processing.
    Iterator<String> iterator = columns.iterator();
    adapt(iterator, data, graphModel, variables, values, nodeIdentities, edgeIdentities);
    DefaultRowModel rowModel = new DefaultRowModel(values.toArray(new Object[] {}), variables.toArray(new String[] {}));
    return new DefaultGraphRowModel(graphModel, rowModel.getValues());
}
Also used : ResultProcessingException(org.neo4j.ogm.exception.ResultProcessingException) ArrayList(java.util.ArrayList) DefaultRowModel(org.neo4j.ogm.response.model.DefaultRowModel) DefaultGraphRowModel(org.neo4j.ogm.response.model.DefaultGraphRowModel) DefaultGraphModel(org.neo4j.ogm.response.model.DefaultGraphModel) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)2 DefaultGraphModel (org.neo4j.ogm.response.model.DefaultGraphModel)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ResultProcessingException (org.neo4j.ogm.exception.ResultProcessingException)1 DefaultGraphRowModel (org.neo4j.ogm.response.model.DefaultGraphRowModel)1 DefaultRowModel (org.neo4j.ogm.response.model.DefaultRowModel)1