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())));
}
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())));
}
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;
}
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;
}
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;
}
Aggregations