package net.floodlightcontroller.core.internal;

import net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject;
import net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject;
import net.floodlightcontroller.core.INetMapTopologyService.ITopoSwitchService;
import net.onrc.onos.util.GraphDBConnection;
import net.onrc.onos.util.GraphDBConnection.Transaction;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TopoSwitchServiceImpl implements ITopoSwitchService {
	
	private GraphDBConnection conn;
	protected static Logger log = LoggerFactory.getLogger(TopoSwitchServiceImpl.class);


	public void finalize() {
		close();
	}
	
	@Override
	public void close() {

		conn.close();
	}
	
	@Override
	public Iterable<ISwitchObject> getActiveSwitches() {
		// TODO Auto-generated method stub
		conn = GraphDBConnection.getInstance("/tmp/cassandra.titan");
		conn.close(); //Commit to ensure we see latest data
		return conn.utils().getActiveSwitches(conn);
	}

	@Override
	public Iterable<ISwitchObject> getAllSwitches() {
		// TODO Auto-generated method stub
		conn = GraphDBConnection.getInstance("/tmp/cassandra.titan");
		conn.close(); //Commit to ensure we see latest data
		return conn.utils().getAllSwitches(conn);
	}

	@Override
	public Iterable<ISwitchObject> getInactiveSwitches() {
		// TODO Auto-generated method stub
		conn = GraphDBConnection.getInstance("/tmp/cassandra.titan");
		conn.close(); //Commit to ensure we see latest data
		return conn.utils().getInactiveSwitches(conn);
	}

	@Override
	public Iterable<IPortObject> getPortsOnSwitch(String dpid) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public IPortObject getPortOnSwitch(String dpid, short port_num) {
		// TODO Auto-generated method stub
		return null;
	}	
}

@@ -352,26 +352,13 @@
 phDB
-Connection.Transac
+Opera
 tion
@@ -507,23 +507,20 @@
 phDB
-Connec
+Opera
 tion 
-conn
+op
 ;%0A%09p
@@ -603,16 +603,201 @@
 lass);%0A%0A
+%09public TopoSwitchServiceImpl(String conf) %7B%0A%09%09op = new GraphDBOperation(GraphDBConnection.getInstance(conf));%0A%09%7D%0A%0A%09public TopoSwitchServiceImpl() %7B%0A%09%09this(%22/tmp/cassandra.titan%22);%0A%09%7D%0A%09
 %0A%09public
@@ -865,23 +865,20 @@
 ose() %7B%0A
-%0A
 %09%09
-conn
+op
 .close()
@@ -992,76 +992,10 @@
 b%0A%09%09
-conn = GraphDBConnection.getInstance(%22/tmp/cassandra.titan%22);%0A%09%09conn
+op
 .clo
@@ -1043,36 +1043,26 @@
 ta%0A%09%09return 
-conn.utils()
+op
 .getActiveSw
@@ -1060,36 +1060,32 @@
 tActiveSwitches(
-conn
 );%0A%09%7D%0A%0A%09@Overrid
@@ -1180,76 +1180,10 @@
 b%0A%09%09
-conn = GraphDBConnection.getInstance(%22/tmp/cassandra.titan%22);%0A%09%09conn
+op
 .clo
@@ -1231,36 +1231,26 @@
 ta%0A%09%09return 
-conn.utils()
+op
 .getAllSwitc
@@ -1245,36 +1245,32 @@
 .getAllSwitches(
-conn
 );%0A%09%7D%0A%0A%09@Overrid
@@ -1370,76 +1370,10 @@
 b%0A%09%09
-conn = GraphDBConnection.getInstance(%22/tmp/cassandra.titan%22);%0A%09%09conn
+op
 .clo
@@ -1429,20 +1429,10 @@
 urn 
-conn.utils()
+op
 .get
@@ -1452,12 +1452,8 @@
 hes(
-conn
 );%0A%09

refactor TopoSwitchServiceImpl to use GraphDBOperation.