Ejemplo n.º 1
0
  public void attachSQLiteDatabase(String sqliteDBFile) throws DBException {

    SQLiteAccess query = new SQLiteAccess(sqliteDBFile);

    Collection<String> tableList = query.getTableList();
    List<String> infoTableList =
        CollectionUtil.select(
            tableList,
            new Predicate<String>() {
              public boolean apply(String input) {
                return isInfoTable(input);
              }
            });
    List<String> dataTableList =
        CollectionUtil.select(
            tableList,
            new Predicate<String>() {
              public boolean apply(String input) {
                return !isInfoTable(input);
              }
            });

    // HashMap<String, HashMap<String, String>>
    for (String infoTable : infoTableList) {
      for (DataModelInfo info : query.amoebaQuery(DataModelInfo.class, infoTable)) {}
    }

    for (String dataTable : dataTableList) {
      Relation relation = new Relation();
      for (SQLiteDataTypeInfo dataType : query.getSQLiteDataTypeInfo(dataTable)) {
        relation.add(Relation.getDataType(dataType.getName(), dataType.getType()));
      }
      addRelation(relation);
    }
  }
Ejemplo n.º 2
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);
  }