SQLiteJob<StorableGraph> job = this.currConnection.execute(new SQLiteJob<StorableGraph>() {
protected StorableGraph job(SQLiteConnection connection) throws Throwable {
String request = "select * " +
"from com_graph_subgraph s1 " +
"where s1.db_id_graph = " + Integer.valueOf(graphId).toString() + ";";
SQLiteStatement currStatement = connection.prepare(request,false);
ArrayList<StorableSubGraph>subGraphs = new ArrayList<StorableSubGraph>();
while(currStatement.step()) {
//getting of subgraph------------
int id_subgraph = currStatement.columnInt(2);
boolean directed = false;
String id = null;
String name = null;
SQLiteStatement subgraphStatement = null;
request = "select *" +
"from subgraph s1 " +
"where s1.db_id = " + Integer.valueOf(id_subgraph).toString() + ";";
subgraphStatement = connection.prepare(request,false);
if(subgraphStatement.step()) {
String buf = subgraphStatement.columnString(3);
if(buf != null && buf.equals("true")) {
directed = true;
} else {
directed = false;
}
id = subgraphStatement.columnString(1);
name = subgraphStatement.columnString(2);
}
subgraphStatement.dispose();
//vertexes-----------------------
ArrayList<StorableVertex>listVertex = new ArrayList<StorableVertex>();
SQLiteStatement vertexStatement = null;
request = "select s2.db_id, s2.id, s2.db_id_inner_graph " +
"from com_subgraph_vertex s1, vertex s2 " +
"where s1.db_id_subgraph = " + Integer.valueOf(id_subgraph).toString() + " and s2.db_id = s1.db_id_vertex;";
vertexStatement = connection.prepare(request,false);
while(vertexStatement.step()) {
int db_id_vertex = vertexStatement.columnInt(0);
String id_vertex = vertexStatement.columnString(1);
Integer db_id_innder_graph = (Integer)vertexStatement.columnValue(2);
StorableVertex v = new StorableVertex(db_id_vertex, id_vertex);
v.setInnerGraph(db_id_innder_graph);
listVertex.add(v);
//attributes-----------------
SQLiteStatement attrStatement = null;
request = "select s2.db_id, s2.name, s2.value, s2.value_type " +
"from com_vertex_attribute s1, attribute s2 " +
"where s1.db_id_vertex = " + Integer.valueOf(db_id_vertex).toString() + " and s2.db_id = s1.db_id_attribute;";
attrStatement = connection.prepare(request,false);
while(attrStatement.step()) {
int db_id_attr = attrStatement.columnInt(0);
String db_name = attrStatement.columnString(1);
String db_value = attrStatement.columnString(2);
String db_type = attrStatement.columnString(3);
v.addStorableAttribute(new StorableAttribute(db_id_attr, db_name, db_value, db_type));
}
attrStatement.dispose();
}
vertexStatement.dispose();
//edges--------------------------
ArrayList<StorableEdge>listEdge = new ArrayList<StorableEdge>();
SQLiteStatement edgeStatement = null;
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 = " + Integer.valueOf(id_subgraph).toString() + " and s2.db_id = s1.db_id_edge;";
edgeStatement = connection.prepare(request,false);
while(edgeStatement.step()) {
int db_id_edge = edgeStatement.columnInt(0);
String id_edge = edgeStatement.columnString(1);
Integer db_id_source = (Integer)edgeStatement.columnValue(2);
Integer db_id_target = (Integer)edgeStatement.columnValue(3);
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-----------------
SQLiteStatement attrStatement = null;
request = "select s2.db_id, s2.name, s2.value, s2.value_type " +
"from com_edge_attribute s1, attribute s2 " +
"where s1.db_id_edge = " + Integer.valueOf(db_id_edge).toString() + " and s2.db_id = s1.db_id_attribute;";
attrStatement = connection.prepare(request,false);
while(attrStatement.step()) {
int db_id_attr = attrStatement.columnInt(0);
String db_name = attrStatement.columnString(1);
String db_value = attrStatement.columnString(2);
String db_type = attrStatement.columnString(3);
e.addStorableAttribute(new StorableAttribute(db_id_attr, db_name, db_value, db_type));
}
attrStatement.dispose();
} else {
VisualGraph.log.printError("[" + this.getClass().getName() + ".getStorableGraph] [BAD] Source edge = null || target edge = null.(" + db_id_source + "," + db_id_target + ")");
}
}
}
edgeStatement.dispose();
//build subgraph-----------------
StorableSubGraph ssg = new StorableSubGraph(id_subgraph, id, name, listVertex, listEdge, directed);
subGraphs.add(ssg);
}
//getting of graph-------------------
SQLiteStatement graphStatement = null;
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();