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 {