Package vg.core.storableGraph

Examples of vg.core.storableGraph.StorableGraph


       
        request = "select * " +
                "from graph s1 " +
                "where s1.db_id = " + Integer.valueOf(graphId).toString() + ";";
        graphStatement = connection.prepare(request,false);
        StorableGraph sg = null;
        if(graphStatement.step()) {
          Integer rootKey = graphStatement.columnInt(1);
          String name = graphStatement.columnString(2);
          sg = new StorableGraph(graphId, name, subGraphs, rootKey);
        } else {
          sg = new StorableGraph(graphId, "Untitle", subGraphs, null);
        }
        graphStatement.dispose();
        return(sg);
      }
    });
    StorableGraph result = job.complete();
    Throwable ex = job.getError();
    if (ex != null) {
        VisualGraph.log.printError("[" + this.getClass().getName() + ".getStorableGraph] [BAD] Getting of graph. Exception : " + ex.getMessage());
        VisualGraph.log.printException(ex);
      VisualGraph.windowMessage.warningMessage("Exception : " + ex.getMessage(), "Get graph");
View Full Code Here


  }
  public synchronized void closeGraph(int number) {
   
  }
  public synchronized Graph getGraph(int number) {
    StorableGraph sg = dbGetStorableGraph(number);
    if(sg != null) {
      return(sg.getGraph());
    }
    return(null);
  }
View Full Code Here

      currStatement = this.currConnection.createStatement();
      String request = "select * " +
                   "from com_graph_subgraph s1 " +
                   "where s1.db_id_graph = " + (new Integer(number)).toString() + ";";
      ResultSet resultComSubGraph = currStatement.executeQuery(request);
      StorableGraph sg = new StorableGraph(number);
      while(resultComSubGraph.next()) {
        //getting of subgraph------------
        int id_subgraph = resultComSubGraph.getInt(3);
        boolean directed = false;
        String id = null;
        String name = null;
        Statement subgraphStatement = null;
        try {
          subgraphStatement = this.currConnection.createStatement();
          request = "select *" +
                    "from subgraph s1 " +
                    "where s1.db_id = " + (new Integer(id_subgraph)).toString() + ";";
          ResultSet resultSubGraph = subgraphStatement.executeQuery(request);
          if(resultSubGraph.next()) {
            String buf = resultSubGraph.getString(4);
            if(buf != null && buf.equals("true")) {
              directed = true;
            } else {
              directed = false;
            }
            id = resultSubGraph.getString(2);
            name = resultSubGraph.getString(3);
          }
        } catch(SQLException ex) {
           VisualGraph.log.printException(ex);
        } finally {
          if(subgraphStatement != null) {
              try {
                subgraphStatement.close();
              } catch(SQLException ex) {
                VisualGraph.log.printException(ex);
              }
          }
        }
        //vertexes-----------------------
        ArrayList<StorableVertex>listVertex = new ArrayList<StorableVertex>();
        Statement vertexStatement = null;
        try {
          vertexStatement = this.currConnection.createStatement();
          request = "select s2.db_id, s2.id, s2.db_id_inner_graph " +
                "from com_subgraph_vertex s1, vertex s2 " +
                "where s1.db_id_subgraph = " + (new Integer(id_subgraph)).toString() + " and s2.db_id = s1.db_id_vertex;";
          ResultSet resultVertex = vertexStatement.executeQuery(request);
          while(resultVertex.next()) {
            int db_id_vertex = resultVertex.getInt(1);
            String id_vertex = resultVertex.getString(2);
            Integer db_id_innder_graph = (Integer)resultVertex.getObject(3);
            StorableVertex v = new StorableVertex(db_id_vertex, id_vertex);
            v.setInnerGraph(db_id_innder_graph);
            listVertex.add(v);
            //attributes-----------------
            Statement attrStatement = null;
            try {
              attrStatement = this.currConnection.createStatement();
              request = "select s2.db_id, s2.name, s2.value " +
                        "from com_vertex_attribute s1, attribute s2 " +
                        "where s1.db_id_vertex = " + (new Integer(db_id_vertex)).toString() + " and s2.db_id = s1.db_id_attribute;";
              ResultSet resultAttribute = attrStatement.executeQuery(request);
              while(resultAttribute.next()) {
                int db_id_attr = resultAttribute.getInt(1);
                String db_name = resultAttribute.getString(2);
                String db_value = resultAttribute.getString(3);
                v.addStorableAttribute(new StorableAttribute(db_id_attr, db_name, db_value));
              }
            } catch(SQLException ex) {
              VisualGraph.log.printException(ex);
            } finally {
              if(attrStatement != null) {
                  try {
                    attrStatement.close();
                  } catch(SQLException ex) {
                    VisualGraph.log.printException(ex);
                  }
              }
            }
          }
        } catch (SQLException ex) {
           VisualGraph.log.printException(ex);
        } finally {
          if(vertexStatement != null) {
              try {
                vertexStatement.close();
              } catch(SQLException ex) {
                VisualGraph.log.printException(ex);
              }
          }
        }
        //edges--------------------------
        ArrayList<StorableEdge>listEdge = new ArrayList<StorableEdge>();
        Statement edgeStatement = null;
        try {
          edgeStatement = this.currConnection.createStatement();
          request = "select s2.db_id, s2.id, s2.db_id_source, db_id_target " +
                    "from com_subgraph_edge s1, edge s2 " +
                    "where s1.db_id_subgraph = " + (new Integer(id_subgraph)).toString() + " and s2.db_id = s1.db_id_edge;";
          ResultSet resultEdge = edgeStatement.executeQuery(request);
          while(resultEdge.next()) {
            int db_id_edge = resultEdge.getInt(1);
            String id_edge = resultEdge.getString(2);
            Integer db_id_source = (Integer)resultEdge.getObject(3);
            Integer db_id_target = (Integer)resultEdge.getObject(4);
            if(db_id_source != null && db_id_target != null) {
              StorableVertex source = null, target = null;
              for(StorableVertex bufVertex : listVertex) {
                if(bufVertex.getStorableId() == db_id_source) {
                  source = bufVertex;
                }
                if(bufVertex.getStorableId() == db_id_target) {
                  target = bufVertex;
                }
              }
              if(source != null && target != null) {
                StorableEdge e = new StorableEdge(db_id_edge, source, target, id_edge);
                listEdge.add(e);
                //attributes-----------------
                Statement attrStatement = null;
                try {
                  attrStatement = this.currConnection.createStatement();
                  request = "select s2.db_id, s2.name, s2.value " +
                            "from com_edge_attribute s1, attribute s2 " +
                            "where s1.db_id_edge = " + (new Integer(db_id_edge)).toString() + " and s2.db_id = s1.db_id_attribute;";
                  ResultSet resultAttribute = attrStatement.executeQuery(request);
                  while(resultAttribute.next()) {
                    int db_id_attr = resultAttribute.getInt(1);
                    String db_name = resultAttribute.getString(2);
                    String db_value = resultAttribute.getString(3);
                    e.addStorableAttribute(new StorableAttribute(db_id_attr, db_name, db_value));
                  }
                } catch (SQLException ex) {
                  VisualGraph.log.printException(ex);
                } finally {
                  if(attrStatement != null) {
                      try {
                        attrStatement.close();
                      } catch(SQLException ex) {
                        VisualGraph.log.printException(ex);
                      }
                  }
                }
              } else {
                VisualGraph.log.printError("[" + this.getClass().getName() + ".getGraph] [BAD] Source edge = null || target edge = null.(" + db_id_source + "," + db_id_target + ")");
              }
            }
          }
        } catch (SQLException ex) {
          VisualGraph.log.printException(ex);
        } finally {
          if(edgeStatement != null) {
              try {
                edgeStatement.close();
              } catch(SQLException ex) {
                VisualGraph.log.printException(ex);
              }
          }
        }
        //build subgraph-----------------
        StorableSubGraph ssg = new StorableSubGraph(id_subgraph, id, name, listVertex, listEdge, directed);
        sg.addSubGraph(ssg);
      }
      //getting of graph-------------------
      Statement graphStatement = null;
      try {
        graphStatement = this.currConnection.createStatement();
        request = "select * " +
                "from graph s1 " +
                "where s1.db_id = " + (new Integer(number)).toString() + ";";
        ResultSet resultGraph = currStatement.executeQuery(request);
        if(resultGraph.next()) {
          Integer rootKey = resultGraph.getInt(2);
          String name = resultGraph.getString(3);
          if(rootKey != null) {
            sg.setRoot(rootKey);
          }
          if(name != null) {
            sg.setName(name);
          }
        }
      } catch (Exception ex) {
          VisualGraph.log.printException(ex);       
      } finally {
View Full Code Here

        @Override
        public void endDocument() throws SAXException {
            // now create the graph
            int root = subgraphIDs.get(subgraphIDs.size() - 1);
            m_graph = new StorableGraph(graphName, null, root);
            model.addStorableGraph(m_graph, subgraphIDs);
        }
View Full Code Here

  }
  public synchronized StorableSubGraph getStorableSubGraph(ArrayList<Integer> vertexId) {
    return(this.dataBase.getStorableSubGraph(vertexId));
  }
  public synchronized Graph getGraph(int graphId) {
    StorableGraph sg = this.dataBase.getStorableGraph(graphId);
    if(sg != null) {
      return(sg.getGraph());
    }
    return(null);
  }
View Full Code Here

   
//------------------------------------------------------------------------------
    private Integer decodeGMLFile() throws CoreException{
      String str;   
    StorableGraph graph = null;
   
    try{
      File f = new File(fileName);
      final long fileSize = (int) f.length()
      final FileInputStream fis = new FileInputStream(f);
      BufferedReader input=new BufferedReader(new InputStreamReader(fis));
            IProgressTask task = new IProgressTask() {
       
        @Override
        public long getValue() {
                if (fis.getChannel() != null)
            try {
              return fis.getChannel().position();
            } catch (IOException e) {
           
            }
          return getLength();
        }
       
        @Override
        public long getLength() {
          return fileSize;
        }
      };
      VisualGraph.progressManager.addTask(task);
      int i;
      final String gmlID = "graph";
      do {
        str = input.readLine();
        i = str.indexOf(gmlID);
      } while (i == -1);
      StorableSubGraph ssg = readGraph(input, str.substring(i + gmlID.length()));
      model.addStorableSubGraph(ssg);
     
      ArrayList<Integer> subgraphIds = new ArrayList<Integer>();
      subgraphIds.add(ssg.getStorableId());
      graph = new StorableGraph(graphName, null, ssg.getStorableId());
      model.addStorableGraph(graph, subgraphIds);
      VisualGraph.progressManager.removeTask(task);
    } catch (IOException e) {
      VisualGraph.log.printStackTrace(e.getStackTrace());
      throw new CoreException(e.getMessage(), EnumCriticalityException.FAILED);
    }   
    return(graph.getStorableId());
  }
View Full Code Here

TOP

Related Classes of vg.core.storableGraph.StorableGraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.