Code Review
/
dmaap
/
datarouter.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Fixed 13 blockers in Subscription.java
[dmaap/datarouter.git]
/
datarouter-prov
/
src
/
main
/
java
/
org
/
onap
/
dmaap
/
datarouter
/
provisioning
/
beans
/
Subscription.java
diff --git
a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java
b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java
index
027d859
..
1333b55
100644
(file)
--- a/
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java
+++ b/
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java
@@
-29,18
+29,13
@@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
\r
import java.sql.SQLException;
\r
import java.sql.Statement;
\r
import java.sql.ResultSet;
\r
import java.sql.SQLException;
\r
import java.sql.Statement;
\r
-import java.util.ArrayList;
\r
-import java.util.Collection;
\r
-import java.util.Date;
\r
-import java.util.List;
\r
+import java.util.*;
\r
\r
import org.apache.log4j.Logger;
\r
import org.json.JSONObject;
\r
import org.onap.dmaap.datarouter.provisioning.utils.DB;
\r
import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
\r
\r
\r
import org.apache.log4j.Logger;
\r
import org.json.JSONObject;
\r
import org.onap.dmaap.datarouter.provisioning.utils.DB;
\r
import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
\r
\r
-import java.util.Properties;
\r
-
\r
/**
\r
* The representation of a Subscription. Subscriptions can be retrieved from the DB, or stored/updated in the DB.
\r
*
\r
/**
\r
* The representation of a Subscription. Subscriptions can be retrieved from the DB, or stored/updated in the DB.
\r
*
\r
@@
-93,14
+88,14
@@
public class Subscription extends Syncable {
DB db = new DB();
\r
@SuppressWarnings("resource")
\r
Connection conn = db.getConnection();
\r
DB db = new DB();
\r
@SuppressWarnings("resource")
\r
Connection conn = db.getConnection();
\r
- Statement stmt = conn.createStatement();
\r
- ResultSet rs = stmt.executeQuery(sql);
\r
- while (rs.next()) {
\r
- Subscription sub = new Subscription(rs);
\r
- list.add(sub);
\r
+ try(Statement stmt = conn.createStatement()) {
\r
+ try(ResultSet rs = stmt.executeQuery(sql)) {
\r
+ while (rs.next()) {
\r
+ Subscription sub = new Subscription(rs);
\r
+ list.add(sub);
\r
+ }
\r
+ }
\r
}
\r
}
\r
- rs.close();
\r
- stmt.close();
\r
db.release(conn);
\r
} catch (SQLException e) {
\r
e.printStackTrace();
\r
db.release(conn);
\r
} catch (SQLException e) {
\r
e.printStackTrace();
\r
@@
-114,13
+109,13
@@
public class Subscription extends Syncable {
DB db = new DB();
\r
@SuppressWarnings("resource")
\r
Connection conn = db.getConnection();
\r
DB db = new DB();
\r
@SuppressWarnings("resource")
\r
Connection conn = db.getConnection();
\r
- Statement stmt = conn.createStatement();
\r
- ResultSet rs = stmt.executeQuery("select MAX(subid) from SUBSCRIPTIONS");
\r
- if (rs.next()) {
\r
- max = rs.getInt(1);
\r
+ try(Statement stmt = conn.createStatement()) {
\r
+ try(ResultSet rs = stmt.executeQuery("select MAX(subid) from SUBSCRIPTIONS")) {
\r
+ if (rs.next()) {
\r
+ max = rs.getInt(1);
\r
+ }
\r
+ }
\r
}
\r
}
\r
- rs.close();
\r
- stmt.close();
\r
db.release(conn);
\r
} catch (SQLException e) {
\r
intlogger.info("getMaxSubID: " + e.getMessage());
\r
db.release(conn);
\r
} catch (SQLException e) {
\r
intlogger.info("getMaxSubID: " + e.getMessage());
\r
@@
-136,14
+131,14
@@
public class Subscription extends Syncable {
DB db = new DB();
\r
@SuppressWarnings("resource")
\r
Connection conn = db.getConnection();
\r
DB db = new DB();
\r
@SuppressWarnings("resource")
\r
Connection conn = db.getConnection();
\r
- Statement stmt = conn.createStatement();
\r
- ResultSet rs = stmt.executeQuery(sql);
\r
- while (rs.next()) {
\r
- int subid = rs.getInt("SUBID");
\r
- list.add(URLUtilities.generateSubscriptionURL(subid));
\r
+ try(Statement stmt = conn.createStatement()) {
\r
+ try(ResultSet rs = stmt.executeQuery(sql)) {
\r
+ while (rs.next()) {
\r
+ int subid = rs.getInt("SUBID");
\r
+ list.add(URLUtilities.generateSubscriptionURL(subid));
\r
+ }
\r
+ }
\r
}
\r
}
\r
- rs.close();
\r
- stmt.close();
\r
db.release(conn);
\r
} catch (SQLException e) {
\r
e.printStackTrace();
\r
db.release(conn);
\r
} catch (SQLException e) {
\r
e.printStackTrace();
\r
@@
-162,13
+157,13
@@
public class Subscription extends Syncable {
DB db = new DB();
\r
@SuppressWarnings("resource")
\r
Connection conn = db.getConnection();
\r
DB db = new DB();
\r
@SuppressWarnings("resource")
\r
Connection conn = db.getConnection();
\r
- Statement stmt = conn.createStatement();
\r
- ResultSet rs = stmt.executeQuery("select count(*) from SUBSCRIPTIONS");
\r
- if (rs.next()) {
\r
- count = rs.getInt(1);
\r
+ try(Statement stmt = conn.createStatement()) {
\r
+ try(ResultSet rs = stmt.executeQuery("select count(*) from SUBSCRIPTIONS")) {
\r
+ if (rs.next()) {
\r
+ count = rs.getInt(1);
\r
+ }
\r
+ }
\r
}
\r
}
\r
- rs.close();
\r
- stmt.close();
\r
db.release(conn);
\r
} catch (SQLException e) {
\r
intlogger.warn("PROV0008 countActiveSubscriptions: " + e.getMessage());
\r
db.release(conn);
\r
} catch (SQLException e) {
\r
intlogger.warn("PROV0008 countActiveSubscriptions: " + e.getMessage());
\r
@@
-391,11
+386,6
@@
public class Subscription extends Syncable {
ps.setInt(10, groupid); //New field is added - Groups feature Rally:US708115 - 1610
\r
ps.execute();
\r
ps.close();
\r
ps.setInt(10, groupid); //New field is added - Groups feature Rally:US708115 - 1610
\r
ps.execute();
\r
ps.close();
\r
-// ResultSet rs = ps.getGeneratedKeys();
\r
-// rs.first();
\r
-// setSubid(rs.getInt(1)); // side effect - sets the link URLs
\r
-// ps.close();
\r
-
\r
// Update the row to set the URLs
\r
sql = "update SUBSCRIPTIONS set SELF_LINK = ?, LOG_LINK = ? where SUBID = ?";
\r
ps = c.prepareStatement(sql);
\r
// Update the row to set the URLs
\r
sql = "update SUBSCRIPTIONS set SELF_LINK = ?, LOG_LINK = ? where SUBID = ?";
\r
ps = c.prepareStatement(sql);
\r
@@
-410,7
+400,9
@@
public class Subscription extends Syncable {
e.printStackTrace();
\r
} finally {
\r
try {
\r
e.printStackTrace();
\r
} finally {
\r
try {
\r
- ps.close();
\r
+ if(ps!=null) {
\r
+ ps.close();
\r
+ }
\r
} catch (SQLException e) {
\r
e.printStackTrace();
\r
}
\r
} catch (SQLException e) {
\r
e.printStackTrace();
\r
}
\r
@@
-440,7
+432,9
@@
public class Subscription extends Syncable {
e.printStackTrace();
\r
} finally {
\r
try {
\r
e.printStackTrace();
\r
} finally {
\r
try {
\r
- ps.close();
\r
+ if(ps!=null) {
\r
+ ps.close();
\r
+ }
\r
} catch (SQLException e) {
\r
e.printStackTrace();
\r
}
\r
} catch (SQLException e) {
\r
e.printStackTrace();
\r
}
\r
@@
-473,7
+467,9
@@
public class Subscription extends Syncable {
e.printStackTrace();
\r
} finally {
\r
try {
\r
e.printStackTrace();
\r
} finally {
\r
try {
\r
- ps.close();
\r
+ if(ps!=null) {
\r
+ ps.close();
\r
+ }
\r
} catch (SQLException e) {
\r
e.printStackTrace();
\r
}
\r
} catch (SQLException e) {
\r
e.printStackTrace();
\r
}
\r
@@
-497,7
+493,9
@@
public class Subscription extends Syncable {
e.printStackTrace();
\r
} finally {
\r
try {
\r
e.printStackTrace();
\r
} finally {
\r
try {
\r
- ps.close();
\r
+ if(ps!=null) {
\r
+ ps.close();
\r
+ }
\r
} catch (SQLException e) {
\r
e.printStackTrace();
\r
}
\r
} catch (SQLException e) {
\r
e.printStackTrace();
\r
}
\r
@@
-534,6
+532,11
@@
public class Subscription extends Syncable {
return true;
\r
}
\r
\r
return true;
\r
}
\r
\r
+ @Override
\r
+ public int hashCode() {
\r
+ return Objects.hash(subid, feedid, groupid, delivery, metadataOnly, subscriber, links, suspended, last_mod, created_date);
\r
+ }
\r
+
\r
@Override
\r
public String toString() {
\r
return "SUB: subid=" + subid + ", feedid=" + feedid;
\r
@Override
\r
public String toString() {
\r
return "SUB: subid=" + subid + ", feedid=" + feedid;
\r