Search in sources :

Example 1 with RelationshipRelationshipMapper

use of org.structr.bolt.mapper.RelationshipRelationshipMapper in project structr by structr.

the class BoltDatabaseService method getAllRelationships.

@Override
public QueryResult<Relationship> getAllRelationships() {
    final StringBuilder buf = new StringBuilder();
    buf.append("MATCH (");
    if (tenantId != null) {
        buf.append(":");
        buf.append(tenantId);
    }
    buf.append(")-[r]->(");
    if (tenantId != null) {
        buf.append(":");
        buf.append(tenantId);
    }
    buf.append(") RETURN r");
    return QueryUtils.map(new RelationshipRelationshipMapper(this), new RelationshipResultStream(this, new SimpleCypherQuery(buf.toString())));
}
Also used : SimpleCypherQuery(org.structr.bolt.index.SimpleCypherQuery) RelationshipResultStream(org.structr.bolt.index.RelationshipResultStream) RelationshipRelationshipMapper(org.structr.bolt.mapper.RelationshipRelationshipMapper)

Example 2 with RelationshipRelationshipMapper

use of org.structr.bolt.mapper.RelationshipRelationshipMapper in project structr by structr.

the class BoltDatabaseService method getRelationshipsByType.

@Override
public QueryResult<Relationship> getRelationshipsByType(final String type) {
    if (type == null) {
        return getAllRelationships();
    }
    final StringBuilder buf = new StringBuilder();
    buf.append("MATCH (");
    if (tenantId != null) {
        buf.append(":");
        buf.append(tenantId);
    }
    buf.append(")-[r:");
    buf.append(type);
    buf.append("]->(");
    if (tenantId != null) {
        buf.append(":");
        buf.append(tenantId);
    }
    buf.append(") RETURN r");
    return QueryUtils.map(new RelationshipRelationshipMapper(this), new RelationshipResultStream(this, new SimpleCypherQuery(buf.toString())));
}
Also used : SimpleCypherQuery(org.structr.bolt.index.SimpleCypherQuery) RelationshipResultStream(org.structr.bolt.index.RelationshipResultStream) RelationshipRelationshipMapper(org.structr.bolt.mapper.RelationshipRelationshipMapper)

Example 3 with RelationshipRelationshipMapper

use of org.structr.bolt.mapper.RelationshipRelationshipMapper in project structr by structr.

the class NodeWrapper method getRelationships.

@Override
public Iterable<Relationship> getRelationships(final Direction direction, final RelationshipType relationshipType) {
    assertNotStale();
    final RelationshipRelationshipMapper mapper = new RelationshipRelationshipMapper(db);
    final SessionTransaction tx = db.getCurrentTransaction();
    List<Relationship> list = getList(direction, relationshipType);
    if (list == null || dontUseCache) {
        final Map<String, Object> map = new HashMap<>();
        final String tenantIdentifier = db.getTenantIdentifier();
        map.put("id", id);
        switch(direction) {
            case BOTH:
                list = toList(Iterables.map(mapper, tx.getRelationships("MATCH (n" + (tenantIdentifier != null ? ":" + tenantIdentifier : "") + ")-[r:" + relationshipType.name() + "]-() WHERE ID(n) = {id} RETURN DISTINCT r", map)));
                break;
            case OUTGOING:
                list = toList(Iterables.map(mapper, tx.getRelationships("MATCH (n" + (tenantIdentifier != null ? ":" + tenantIdentifier : "") + ")-[r:" + relationshipType.name() + "]->() WHERE ID(n) = {id} RETURN DISTINCT r", map)));
                break;
            case INCOMING:
                list = toList(Iterables.map(mapper, tx.getRelationships("MATCH (n" + (tenantIdentifier != null ? ":" + tenantIdentifier : "") + ")<-[r:" + relationshipType.name() + "]-() WHERE ID(n) = {id} RETURN DISTINCT r", map)));
                break;
        }
        setList(direction, relationshipType, list);
    }
    return list;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SessionTransaction(org.structr.bolt.SessionTransaction) Relationship(org.structr.api.graph.Relationship) RelationshipRelationshipMapper(org.structr.bolt.mapper.RelationshipRelationshipMapper)

Example 4 with RelationshipRelationshipMapper

use of org.structr.bolt.mapper.RelationshipRelationshipMapper in project structr by structr.

the class NodeWrapper method getRelationships.

@Override
public Iterable<Relationship> getRelationships(final Direction direction) {
    assertNotStale();
    final RelationshipRelationshipMapper mapper = new RelationshipRelationshipMapper(db);
    final SessionTransaction tx = db.getCurrentTransaction();
    List<Relationship> list = getList(direction, null);
    if (list == null || dontUseCache) {
        final Map<String, Object> map = new HashMap<>();
        final String tenantIdentifier = db.getTenantIdentifier();
        map.put("id", id);
        switch(direction) {
            case BOTH:
                return getRelationships();
            case OUTGOING:
                list = toList(Iterables.map(mapper, tx.getRelationships("MATCH (n" + (tenantIdentifier != null ? ":" + tenantIdentifier : "") + ")-[r]->() WHERE ID(n) = {id} RETURN DISTINCT r", map)));
                break;
            case INCOMING:
                list = toList(Iterables.map(mapper, tx.getRelationships("MATCH (n" + (tenantIdentifier != null ? ":" + tenantIdentifier : "") + ")<-[r]-() WHERE ID(n) = {id} RETURN DISTINCT r", map)));
                break;
        }
        setList(direction, null, list);
    }
    return list;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SessionTransaction(org.structr.bolt.SessionTransaction) Relationship(org.structr.api.graph.Relationship) RelationshipRelationshipMapper(org.structr.bolt.mapper.RelationshipRelationshipMapper)

Example 5 with RelationshipRelationshipMapper

use of org.structr.bolt.mapper.RelationshipRelationshipMapper in project structr by structr.

the class NodeWrapper method getRelationships.

@Override
public Iterable<Relationship> getRelationships() {
    assertNotStale();
    final RelationshipRelationshipMapper mapper = new RelationshipRelationshipMapper(db);
    final SessionTransaction tx = db.getCurrentTransaction();
    List<Relationship> list = getList(null, null);
    if (list == null || dontUseCache) {
        final Map<String, Object> map = new HashMap<>();
        final String tenantIdentifier = db.getTenantIdentifier();
        map.put("id", id);
        list = toList(Iterables.map(mapper, tx.getRelationships("MATCH (n" + (tenantIdentifier != null ? ":" + tenantIdentifier : "") + ")-[r]-() WHERE ID(n) = {id} RETURN DISTINCT r", map)));
        // store in cache
        setList(null, null, list);
    }
    return list;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SessionTransaction(org.structr.bolt.SessionTransaction) Relationship(org.structr.api.graph.Relationship) RelationshipRelationshipMapper(org.structr.bolt.mapper.RelationshipRelationshipMapper)

Aggregations

RelationshipRelationshipMapper (org.structr.bolt.mapper.RelationshipRelationshipMapper)5 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Relationship (org.structr.api.graph.Relationship)3 SessionTransaction (org.structr.bolt.SessionTransaction)3 RelationshipResultStream (org.structr.bolt.index.RelationshipResultStream)2 SimpleCypherQuery (org.structr.bolt.index.SimpleCypherQuery)2