use of org.structr.api.graph.Relationship 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.api.graph.Relationship 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.api.graph.Relationship 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;
}
use of org.structr.api.graph.Relationship in project structr by structr.
the class NodeWrapperTest method testDeleteException.
@Test
public void testDeleteException() {
try {
Settings.DatabasePath.setValue(Files.createTempDirectory("structr-test").toFile().getAbsolutePath());
Settings.ConnectionUrl.setValue(Settings.TestingConnectionUrl.getValue());
} catch (IOException ioex) {
logger.warn("", ioex);
}
final BoltDatabaseService s = new BoltDatabaseService();
s.initialize();
// create new node
try (final Transaction tx = s.beginTx()) {
final Node node1 = s.createNode(Collections.EMPTY_SET, Collections.EMPTY_MAP);
final Node node2 = s.createNode(Collections.EMPTY_SET, Collections.EMPTY_MAP);
final Relationship rel = node1.createRelationshipTo(node2, s.forName(RelationshipType.class, "TEST"));
rel.delete();
tx.success();
} catch (Throwable t) {
t.printStackTrace();
fail("Unexpected exception.");
}
s.shutdown();
}
use of org.structr.api.graph.Relationship in project structr by structr.
the class Synchronize method onRequest.
@Override
public void onRequest(final CloudConnection serverConnection) throws IOException, FrameworkException {
final DatabaseService graphDb = StructrApp.getInstance().getDatabaseService();
final String uuidPropertyName = GraphObject.id.dbName();
final Set<Long> visitedObjectIDs = new HashSet<>();
for (final Node node : graphDb.getAllNodes()) {
if (!visitedObjectIDs.contains(node.getId())) {
final String hash = contentHashCode(node, visitedObjectIDs);
final Object uuid = node.getProperty(uuidPropertyName, null);
if (uuid != null && uuid instanceof String) {
serverConnection.send(new Diff(uuid.toString(), hash));
}
}
}
// clear set of visited objects because node and relationship IDs are offsets and can overlap.
visitedObjectIDs.clear();
for (final Relationship relationship : graphDb.getAllRelationships()) {
if (!visitedObjectIDs.contains(relationship.getId())) {
final String hash = contentHashCode(relationship, visitedObjectIDs);
final Object uuid = relationship.getProperty(uuidPropertyName, null);
if (uuid != null && uuid instanceof String) {
serverConnection.send(new Diff(uuid.toString(), hash));
}
}
}
serverConnection.send(new Finish());
}
Aggregations