@Override
  public void deleteByRelation(INode node) {
    // delete source reference pointing to relation node
    OSQLSynchQuery<ODocument> query =
        new OSQLSynchQuery<>(
            "select * from Relation where relationLink.in = "
                + node.getId()
                + " OR relationLink.out = "
                + node.getId());
    List<ODocument> result = db.command(query).execute();

    // remove relation and link
    for (ODocument document : result) {
      ODocument relationLink = getRelationLink(document, true);
      if (relationLink != null && db.load(relationLink.getIdentity()) != null)
        relationLink.delete();

      document.delete();
    }
  }
  @Override
  public List<IRelation> findByRelation(INode node) {
    List<IRelation> list = new LinkedList<>();

    // no NPEs
    if (node == null) return list;

    initDb();

    // execute query
    OSQLSynchQuery<ODocument> query =
        new OSQLSynchQuery<>(
            "select * from Relation where relationLink.in = "
                + node.getId()
                + " OR relationLink.out = "
                + node.getId());
    List<ODocument> result = db.command(query).execute();

    // populate set
    for (ODocument document : result) list.add(convertToEntity(document));

    return list;
  }