Esempio n. 1
0
  public void save(SQLiteAccess query) throws DBException {
    if (query.hasTable("node")) query.dropTable("node");
    if (query.hasTable("edge")) query.dropTable("edge");

    Relation nodeRelation = new Relation();
    nodeRelation.add(new DataTypeBase("id", TypeName.INTEGER, true, true));
    nodeRelation.add(new DataTypeBase("name", TypeName.STRING));
    query.createTable("node", nodeRelation);

    Relation edgeRelation = new Relation();
    edgeRelation.add(new DataTypeBase("id", TypeName.INTEGER, true, true));
    edgeRelation.add(new DataTypeBase("src", TypeName.INTEGER));
    edgeRelation.add(new DataTypeBase("dest", TypeName.INTEGER));
    edgeRelation.add(new DataTypeBase("relationship", TypeName.INTEGER));
    query.createTable("edge", edgeRelation);

    Vector<NodeData> nodeList = new Vector<NodeData>();
    for (int nodeID : _graph.getNodeIDSet()) {
      nodeList.add(new NodeData(nodeID, _graph.getNodeLabel(nodeID)));
    }

    Vector<EdgeData> edgeList = new Vector<EdgeData>();
    for (Edge edge : _graph.getEdgeSet()) {
      edgeList.add(
          new EdgeData(
              _graph.getEdgeID(edge),
              edge.getSourceNodeID(),
              edge.getDestNodeID(),
              _graph.getEdgeLabel(edge)));
    }

    for (NodeData node : nodeList) query.insert("node", node);
    for (EdgeData edge : edgeList) query.insert("edge", edge);
  }