Optimize source code
diff --git a/src/main/java/net/onrc/onos/graph/DBOperation.java b/src/main/java/net/onrc/onos/graph/DBOperation.java
index 2410ed7..9b89bed 100644
--- a/src/main/java/net/onrc/onos/graph/DBOperation.java
+++ b/src/main/java/net/onrc/onos/graph/DBOperation.java
@@ -41,8 +41,9 @@
return null;
}
- public ISwitchObject newSwitch(final String dpid, final FramedGraph fg) {
- ISwitchObject obj = (ISwitchObject) fg.addVertex(null, ISwitchObject.class);
+ @Override
+ public ISwitchObject newSwitch(final String dpid) {
+ ISwitchObject obj = (ISwitchObject) conn.getFramedGraph().addVertex(null, ISwitchObject.class);
if (obj != null) {
obj.setType("switch");
obj.setDPID(dpid);
@@ -81,8 +82,9 @@
conn.getFramedGraph().removeVertex(sw.asVertex());
}
- public IPortObject newPort(String dpid, Short portNum, final FramedGraph fg) {
- IPortObject obj = (IPortObject) fg.addVertex(null, IPortObject.class);
+ @Override
+ public IPortObject newPort(String dpid, Short portNum) {
+ IPortObject obj = (IPortObject) conn.getFramedGraph().addVertex(null, IPortObject.class);
if (obj != null) {
obj.setType("port");
String id = dpid + portNum.toString();
@@ -107,15 +109,17 @@
return obj;
}
- public IPortObject searchPort(String dpid, Short number, final FramedGraph fg) {
+ @Override
+ public IPortObject searchPort(String dpid, Short number) {
String id = dpid + number.toString();
- return (fg != null && fg.getVertices("port_id", id).iterator().hasNext())
- ? (IPortObject) fg.getVertices("port_id", id, IPortObject.class).iterator().next() : null;
+ return (conn.getFramedGraph() != null && conn.getFramedGraph().getVertices("port_id", id).iterator().hasNext())
+ ? (IPortObject) conn.getFramedGraph().getVertices("port_id", id, IPortObject.class).iterator().next() : null;
}
- public IDeviceObject newDevice(final FramedGraph fg) {
- IDeviceObject obj = (IDeviceObject) fg.addVertex(null, IDeviceObject.class);
+ @Override
+ public IDeviceObject newDevice() {
+ IDeviceObject obj = (IDeviceObject) conn.getFramedGraph().addVertex(null, IDeviceObject.class);
if (obj != null) {
obj.setType("device");
}
@@ -145,14 +149,20 @@
}
-
- protected ISwitchObject searchSwitch(final String dpid, final FramedGraph fg) {
- return (fg != null && fg.getVertices("dpid", dpid).iterator().hasNext())
- ? (ISwitchObject) (fg.getVertices("dpid", dpid, ISwitchObject.class).iterator().next()) : null;
+ /**
+ * Search and get a switch object with DPID.
+ *
+ * @param dpid DPID of the switch
+ */
+ @Override
+ public ISwitchObject searchSwitch(final String dpid) {
+ return (conn.getFramedGraph() != null && conn.getFramedGraph().getVertices("dpid", dpid).iterator().hasNext())
+ ? (ISwitchObject) (conn.getFramedGraph().getVertices("dpid", dpid, ISwitchObject.class).iterator().next()) : null;
}
- protected Iterable<ISwitchObject> getActiveSwitches(final FramedGraph fg) {
- Iterable<ISwitchObject> switches = fg.getVertices("type", "switch", ISwitchObject.class);
+ @Override
+ public Iterable<ISwitchObject> getActiveSwitches() {
+ Iterable<ISwitchObject> switches = conn.getFramedGraph().getVertices("type", "switch", ISwitchObject.class);
List<ISwitchObject> activeSwitches = new ArrayList<ISwitchObject>();
for (ISwitchObject sw : switches) {
@@ -244,4 +254,9 @@
conn.getFramedGraph().removeVertex(ipv4Address.asVertex());
}
+
+ @Override
+ public IDBConnection getDBConnection() {
+ return conn;
+ }
}
diff --git a/src/main/java/net/onrc/onos/graph/RamCloudDBOperation.java b/src/main/java/net/onrc/onos/graph/RamCloudDBOperation.java
index 66878d7..68226d1 100644
--- a/src/main/java/net/onrc/onos/graph/RamCloudDBOperation.java
+++ b/src/main/java/net/onrc/onos/graph/RamCloudDBOperation.java
@@ -26,31 +26,11 @@
}
@Override
- public ISwitchObject searchSwitch(String dpid) {
- final FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
-
- return searchSwitch(dpid, fg);
- }
-
- @Override
- public Iterable<ISwitchObject> getActiveSwitches() {
- final FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
-
- return getActiveSwitches(fg);
- }
-
- @Override
public Iterable<ISwitchObject> getAllSwitches() {
return getAllSwitches(conn.getFramedGraph());
}
@Override
- public IPortObject searchPort(String dpid, Short number) {
- final FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
- return searchPort(dpid, number, fg);
- }
-
- @Override
public void removePort(INetMapTopologyObjects.IPortObject port) {
FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
if (fg != null) {
@@ -120,11 +100,6 @@
}
@Override
- public IDBConnection getDBConnection() {
- return conn;
- }
-
- @Override
public void commit() {
conn.commit();
}
@@ -138,22 +113,4 @@
public void close() {
conn.close();
}
-
- @Override
- public ISwitchObject newSwitch(final String dpid) {
- FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
- return super.newSwitch(dpid, fg);
- }
-
- @Override
- public IDeviceObject newDevice() {
- FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
- return super.newDevice(fg);
- }
-
- @Override
- public IPortObject newPort(String dpid, Short portNum) {
- FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
- return super.newPort(dpid, portNum, fg);
- }
}
diff --git a/src/main/java/net/onrc/onos/graph/TitanDBOperation.java b/src/main/java/net/onrc/onos/graph/TitanDBOperation.java
index c2152cc..9362753 100644
--- a/src/main/java/net/onrc/onos/graph/TitanDBOperation.java
+++ b/src/main/java/net/onrc/onos/graph/TitanDBOperation.java
@@ -23,32 +23,6 @@
*/
public class TitanDBOperation extends DBOperation {
- /**
- * Search and get a switch object with DPID.
- *
- * @param dpid DPID of the switch
- */
- @Override
- public ISwitchObject searchSwitch(String dpid) {
- final FramedGraph<TitanGraph> fg = conn.getFramedGraph();
-
- return searchSwitch(dpid, fg);
- }
-
- @Override
- public Iterable<ISwitchObject> getActiveSwitches() {
- final FramedGraph<TitanGraph> fg = conn.getFramedGraph();
-
- return getActiveSwitches(fg);
- }
-
- @Override
- public IPortObject searchPort(String dpid, Short number) {
- final FramedGraph<TitanGraph> fg = conn.getFramedGraph();
- return searchPort(dpid, number, fg);
- }
-
-
@Override
public void removePort(IPortObject port) {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
@@ -57,7 +31,6 @@
}
}
-
@Override
public IDeviceObject searchDevice(String macAddr) {
// TODO Auto-generated method stub
@@ -121,12 +94,6 @@
}
@Override
- public IDBConnection getDBConnection() {
- System.out.println("TitangetDBConnection");
- return conn;
- }
-
- @Override
public void commit() {
conn.commit();
}
@@ -140,23 +107,4 @@
public void close() {
conn.close();
}
-
- @Override
- public ISwitchObject newSwitch(final String dpid) {
- FramedGraph<TitanGraph> fg = conn.getFramedGraph();
- return super.newSwitch(dpid, fg);
- }
-
- @Override
- public IDeviceObject newDevice() {
- FramedGraph<TitanGraph> fg = conn.getFramedGraph();
- return super.newDevice(fg);
- }
-
- @Override
- public IPortObject newPort(String dpid, Short portNum) {
- FramedGraph<TitanGraph> fg = conn.getFramedGraph();
- return super.newPort(dpid, portNum, fg);
- }
-
}
\ No newline at end of file