package eu.socialsensor.query;

import com.orientechnologies.orient.core.command.OBasicCommandContext;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.graph.sql.functions.OSQLFunctionShortestPath;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientExtendedGraph;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
import com.tinkerpop.gremlin.java.GremlinPipeline;
import com.tinkerpop.pipes.PipeFunction;
import com.tinkerpop.pipes.branch.LoopPipe.LoopBundle;

import eu.socialsensor.benchmarks.FindShortestPathBenchmark;

import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.List;

/**
 * Query implementation for OrientDB graph database
 * 
 * @author sotbeis
 * @email sotbeis@iti.gr
 */
public class OrientQuery implements Query {
	private OrientExtendedGraph orientGraph = null;

	public OrientQuery(OrientExtendedGraph orientGraph) {
		this.orientGraph = orientGraph;
	}

	public static void main(String args[]) {
	}

	@Override
	@SuppressWarnings("unused")
	public void findNeighborsOfAllNodes() {
		for (Vertex v : orientGraph.getVertices()) {
			for (Vertex vv : v.getVertices(Direction.BOTH, "similar")) {
			}
		}
	}

	@Override
	@SuppressWarnings("unused")
	public void findNodesOfAllEdges() {
		
		try {
			PrintWriter writer = new PrintWriter("orient");
			
			for(Edge e : orientGraph.getEdges()) {
				Vertex srcVertex = e.getVertex(Direction.OUT);
				Vertex dstVertex = e.getVertex(Direction.IN);
				
				writer.println(srcVertex.getProperty("nodeId") + "\t" + dstVertex.getProperty("nodeId"));
			}
			
			writer.close();
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public void findShortestPaths() {
		
		 OrientVertex v1 = (OrientVertex) orientGraph.getVertices("nodeId", 1).iterator().next();
	      for (int i : FindShortestPathBenchmark.generatedNodes) {
	        final OrientVertex v2 = (OrientVertex) orientGraph.getVertices("nodeId", i).iterator().next();

	        List<OIdentifiable> result = (List<OIdentifiable>) new OSQLFunctionShortestPath()
	        .execute(orientGraph, null, null, new Object[] { 
	        		v1.getRecord(), v2.getRecord(), Direction.OUT, 5 }, 
	        		new OBasicCommandContext());

	        int length = result.size();
	      }		
	}
}

@@ -494,283 +494,70 @@
 ex;%0A
-import com.tinkerpop.gremlin.java.GremlinPipeline;%0Aimport com.tinkerpop.pipes.PipeFunction;%0Aimport com.tinkerpop.pipes.branch.LoopPipe.LoopBundle;%0A%0Aimport eu.socialsensor.benchmarks.FindShortestPathBenchmark;%0A%0Aimport java.io.FileNotFoundException;%0Aimport java.io.PrintWriter;
+%0Aimport eu.socialsensor.benchmarks.FindShortestPathBenchmark;%0A
 %0Aimp
@@ -1206,75 +1206,8 @@
 %7B%0A%09%09
-%0A%09%09try %7B%0A%09%09%09PrintWriter writer = new PrintWriter(%22orient%22);%0A%09%09%09%0A%09%09%09
 for(
@@ -1240,25 +1240,24 @@
 ges()) %7B%0A%09%09%09
-%09
 Vertex srcVe
@@ -1294,17 +1294,16 @@
 UT);%0A%09%09%09
-%09
 Vertex d
@@ -1346,244 +1346,45 @@
 ;%0A%09%09
-%09%09%0A%09%09%09%09writer.println(srcVertex.getProperty(%22nodeId%22) + %22%5Ct%22 + dstVertex.getProperty(%22nodeId%22));%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09writer.close();%0A%09%09%09%0A%09%09%7D catch (FileNotFoundException e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%7D%0A
+%7D%0A%09%7D%0A%0A%09@SuppressWarnings(%22unchecked%22)
 %0A%09@O
@@ -1432,12 +1432,8 @@
 %7B%0A%09%09
-%0A%09%09 
 Orie
@@ -1518,22 +1518,20 @@
 ext();%0A%09
-      
+%09%0A%09%09
 for (int
@@ -1580,24 +1580,18 @@
 des) %7B%0A%09
-        
+%09%09
 final Or
@@ -1778,16 +1778,17 @@
         
+%09
 .execute
@@ -1840,16 +1840,17 @@
       %09%09
+%09
 v1.getRe
@@ -1905,16 +1905,17 @@
       %09%09
+%09
 new OBas
@@ -1945,16 +1945,47 @@
         
+@SuppressWarnings(%22unused%22)%0A%09%09%09
 int leng

remove trashes