Few fixes and local optimizations:
 * Add missing op.rollback() calls
 * Use local variables (dpid and port number) that were used to search
   the database for items, instead of accessing database attributes
   to obtain those values again.
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java b/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java
index c47ce68..7a3d43e 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java
@@ -131,6 +131,7 @@
 				op.rollback();
 			}
 		} catch (Exception e) {
+			op.rollback();
 			e.printStackTrace();
 			log.error("LinkStorageImpl:addLink link:{} linfo:{} failed", link, linfo);
 		}
@@ -157,6 +158,7 @@
 			op.commit();
 			success = true;
 		} catch (Exception e) {
+			op.rollback();
 			e.printStackTrace();
 			log.error("LinkStorageImpl:addLinks link:s{} failed", links);
 		}
@@ -239,8 +241,7 @@
 	    for(IPortObject dstPort : srcPort.getLinkedPorts()) {
 		ISwitchObject dstSw = dstPort.getSwitch();
 		if (dstSw != null) {
-		    Link link = new Link(HexString.toLong(srcSw.getDPID()),
-					 srcPort.getNumber(),
+		    Link link = new Link(dpid, port,
 					 HexString.toLong(dstSw.getDPID()),
 					 dstPort.getNumber());
 		    links.add(link);
@@ -271,8 +272,7 @@
 		if (dstSw != null) {
 		    Link link = new Link(HexString.toLong(dstSw.getDPID()),
 					 dstPort.getNumber(),
-					 HexString.toLong(srcSw.getDPID()),
-					 srcPort.getNumber());
+					 dpid, port);
 		    links.add(link);
 		}
 	    }
@@ -324,10 +324,10 @@
 				for(IPortObject dstPort : srcPort.getLinkedPorts()) {
 					ISwitchObject dstSw = dstPort.getSwitch();
 					if(dstSw != null) {
-		        		Link link = new Link(HexString.toLong(srcSw.getDPID()),
+					    Link link = new Link(HexString.toLong(dpid),
 		        				srcPort.getNumber(),
 		        				HexString.toLong(dstSw.getDPID()),
-		        				dstPort.getNumber());
+							dstPort.getNumber());
 		        		links.add(link);
 					}
 				}
@@ -358,7 +358,7 @@
 							HexString.toLong(dstSw.getDPID()),
 							dstPort.getNumber(),
 					
-							HexString.toLong(srcSw.getDPID()),
+							HexString.toLong(dpid),
 							srcPort.getNumber());
 		        		links.add(link);
 					}