You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2015/08/03 23:45:05 UTC
[06/13] git commit: updated refs/heads/master to d32d6a2
CLOUDSTACK-8656: try with resource te eliminate empty catch clauses
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/39bf1fed
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/39bf1fed
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/39bf1fed
Branch: refs/heads/master
Commit: 39bf1fed6867c4de673575b8b0925337015088ee
Parents: 04e9083
Author: Daan Hoogland <da...@onecht.net>
Authored: Sun Aug 2 19:48:58 2015 +0200
Committer: Daan Hoogland <da...@onecht.net>
Committed: Sun Aug 2 19:48:58 2015 +0200
----------------------------------------------------------------------
.../image/db/SnapshotDataStoreDaoImpl.java | 72 ++++++++------------
1 file changed, 27 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/39bf1fed/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
index ea73ecd..142cd66 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
@@ -221,26 +221,20 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
@Override
public SnapshotDataStoreVO findLatestSnapshotForVolume(Long volumeId, DataStoreRole role) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
- PreparedStatement pstmt = null;
- ResultSet rs = null;
- try {
- pstmt = txn.prepareStatement(findLatestSnapshot);
+ try (
+ PreparedStatement pstmt = txn.prepareStatement(findLatestSnapshot);
+ ){
pstmt.setString(1, role.toString());
pstmt.setLong(2, volumeId);
- rs = pstmt.executeQuery();
- while (rs.next()) {
- long sid = rs.getLong(1);
- long snid = rs.getLong(3);
- return findByStoreSnapshot(role, sid, snid);
+ try (ResultSet rs = pstmt.executeQuery();) {
+ while (rs.next()) {
+ long sid = rs.getLong(1);
+ long snid = rs.getLong(3);
+ return findByStoreSnapshot(role, sid, snid);
+ }
}
} catch (SQLException e) {
s_logger.debug("Failed to find latest snapshot for volume: " + volumeId + " due to: " + e.toString());
- } finally {
- try {
- if (pstmt != null)
- pstmt.close();
- } catch (SQLException e) {
- }
}
return null;
}
@@ -248,26 +242,20 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
@Override
public SnapshotDataStoreVO findOldestSnapshotForVolume(Long volumeId, DataStoreRole role) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
- PreparedStatement pstmt = null;
- ResultSet rs = null;
- try {
- pstmt = txn.prepareStatement(findOldestSnapshot);
+ try (
+ PreparedStatement pstmt = txn.prepareStatement(findOldestSnapshot);
+ ){
pstmt.setString(1, role.toString());
pstmt.setLong(2, volumeId);
- rs = pstmt.executeQuery();
- while (rs.next()) {
- long sid = rs.getLong(1);
- long snid = rs.getLong(3);
- return findByStoreSnapshot(role, sid, snid);
+ try (ResultSet rs = pstmt.executeQuery();) {
+ while (rs.next()) {
+ long sid = rs.getLong(1);
+ long snid = rs.getLong(3);
+ return findByStoreSnapshot(role, sid, snid);
+ }
}
} catch (SQLException e) {
s_logger.debug("Failed to find oldest snapshot for volume: " + volumeId + " due to: " + e.toString());
- } finally {
- try {
- if (pstmt != null)
- pstmt.close();
- } catch (SQLException e) {
- }
}
return null;
}
@@ -276,27 +264,21 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
@DB
public SnapshotDataStoreVO findParent(DataStoreRole role, Long storeId, Long volumeId) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
- PreparedStatement pstmt = null;
- ResultSet rs = null;
- try {
- pstmt = txn.prepareStatement(parentSearch);
+ try (
+ PreparedStatement pstmt = txn.prepareStatement(parentSearch);
+ ){
pstmt.setLong(1, storeId);
pstmt.setString(2, role.toString());
pstmt.setLong(3, volumeId);
- rs = pstmt.executeQuery();
- while (rs.next()) {
- long sid = rs.getLong(1);
- long snid = rs.getLong(3);
- return findByStoreSnapshot(role, sid, snid);
+ try (ResultSet rs = pstmt.executeQuery();) {
+ while (rs.next()) {
+ long sid = rs.getLong(1);
+ long snid = rs.getLong(3);
+ return findByStoreSnapshot(role, sid, snid);
+ }
}
} catch (SQLException e) {
s_logger.debug("Failed to find parent snapshot: " + e.toString());
- } finally {
- try {
- if (pstmt != null)
- pstmt.close();
- } catch (SQLException e) {
- }
}
return null;
}