use of org.structr.bolt.SessionTransaction in project structr by structr.
the class NodeWrapper method removeLabel.
@Override
public void removeLabel(final Label label) {
assertNotStale();
final SessionTransaction tx = db.getCurrentTransaction();
final Map<String, Object> map = new HashMap<>();
final String tenantIdentifier = db.getTenantIdentifier();
map.put("id", id);
tx.set("MATCH (n" + (tenantIdentifier != null ? ":" + tenantIdentifier : "") + ") WHERE ID(n) = {id} REMOVE n:" + label.name(), map);
tx.modified(this);
}
use of org.structr.bolt.SessionTransaction 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.SessionTransaction in project structr by structr.
the class NodeWrapper method hasRelationshipTo.
@Override
public boolean hasRelationshipTo(final RelationshipType type, final Node targetNode) {
assertNotStale();
AssociationList list = (AssociationList) getList(Direction.OUTGOING, type);
if (list != null && !dontUseCache) {
return list.containsAssociation(this, type, targetNode);
} else {
list = (AssociationList) getList(Direction.INCOMING, type);
if (list != null && !dontUseCache) {
return list.containsAssociation(targetNode, type, this);
} else {
final SessionTransaction tx = db.getCurrentTransaction();
final Map<String, Object> params = new LinkedHashMap<>();
final String tenantIdentifier = db.getTenantIdentifier();
params.put("id1", getId());
params.put("id2", targetNode.getId());
try {
// try to fetch existing relationship by node ID(s)
// FIXME: this call can be very slow when lots of relationships exist
tx.getLong("MATCH (n" + (tenantIdentifier != null ? ":" + tenantIdentifier : "") + ")-[r:" + type.name() + "]->(m) WHERE id(n) = {id1} AND id(m) = {id2} RETURN id(r)", params);
// success
return true;
} catch (Throwable t) {
return false;
}
}
}
}
use of org.structr.bolt.SessionTransaction 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.SessionTransaction 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