Minor code improvements

This commit is contained in:
Graham Triggs 2017-09-18 10:57:49 +01:00
parent 60017600a3
commit d87bb782eb
4 changed files with 58 additions and 116 deletions

View file

@ -46,19 +46,21 @@ public class OperationUtils {
}
}
Object[] arglist = new Object[1];
if (isInt)
arglist[0] = Integer.decode(value);
else if (isBoolean)
arglist[0] = (value.equalsIgnoreCase("TRUE"));
else
arglist[0] = value;
try {
setterMethod.invoke(newObj, arglist);
} catch (Exception e) {
log.error("Couldn't invoke method");
log.error(e.getMessage());
log.error(field + " " + arglist[0]);
if (setterMethod != null) {
Object[] arglist = new Object[1];
if (isInt)
arglist[0] = Integer.decode(value);
else if (isBoolean)
arglist[0] = (value.equalsIgnoreCase("TRUE"));
else
arglist[0] = value;
try {
setterMethod.invoke(newObj, arglist);
} catch (Exception e) {
log.error("Couldn't invoke method");
log.error(e.getMessage());
log.error(field + " " + arglist[0]);
}
}
}

View file

@ -480,7 +480,7 @@ class Stemmer
outputStr.append(u);
}
return outputStr == null || outputStr.length() == 0 ? null : outputStr.toString().trim();
return outputStr.length() == 0 ? null : outputStr.toString().trim();
}
/*

View file

@ -32,36 +32,20 @@ public class GadgetSpec {
// Load gadgets from the DB first
if (!unknownGadget) {
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
try {
String sqlCommand = "select page, viewer_req, owner_req, view, chromeId, opt_params, display_order from orng_app_views where appId = "
+ appId;
conn = ds.getConnection();
stmt = conn.createStatement();
rset = stmt.executeQuery(sqlCommand);
while (rset.next()) {
viewRequirements.put(
rset.getString(1),
new GadgetViewRequirements(rset.getString(1), rset
.getString(2), rset.getString(3), rset
.getString(4), rset.getString(5), rset
.getString(6), rset.getInt(7)));
}
} finally {
try {
rset.close();
} catch (Exception e) {
}
try {
stmt.close();
} catch (Exception e) {
}
try {
conn.close();
} catch (Exception e) {
String sqlCommand = "select page, viewer_req, owner_req, view, chromeId, opt_params, display_order from orng_app_views where appId = " + appId;
try (Connection conn = ds.getConnection()) {
try (Statement stmt = conn.createStatement()) {
try (ResultSet rset = stmt.executeQuery(sqlCommand)) {
while (rset.next()) {
viewRequirements.put(
rset.getString(1),
new GadgetViewRequirements(rset.getString(1), rset
.getString(2), rset.getString(3), rset
.getString(4), rset.getString(5), rset
.getString(6), rset.getInt(7)));
}
}
}
}
}
@ -127,31 +111,15 @@ public class GadgetSpec {
throws SQLException {
int count = 0;
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
String sqlCommand = "select count(*) from orng_app_registry where appId = " + getAppId() + " and personId = '" + personId + "';";
try {
String sqlCommand = "select count(*) from orng_app_registry where appId = "
+ getAppId() + " and personId = '" + personId + "';";
conn = ds.getConnection();
stmt = conn.createStatement();
rset = stmt.executeQuery(sqlCommand);
while (rset.next()) {
count = rset.getInt(1);
}
} finally {
try {
rset.close();
} catch (Exception e) {
}
try {
stmt.close();
} catch (Exception e) {
}
try {
conn.close();
} catch (Exception e) {
try (Connection conn = ds.getConnection()) {
try (Statement stmt = conn.createStatement()) {
try (ResultSet rset = stmt.executeQuery(sqlCommand)) {
while (rset.next()) {
count = rset.getInt(1);
}
}
}
}

View file

@ -294,28 +294,17 @@ public class OpenSocialManager {
public void postActivity(int userId, String title, String body,
String xtraId1Type, String xtraId1Value) throws SQLException {
Connection conn = null;
Statement stmt = null;
String sqlCommand = "INSERT INTO orng_activity (userId, activity, xtraId1Type, xtraId1Value) VALUES ('"
+ userId + "','<activity xmlns=\"http://ns.opensocial.org/2008/opensocial\"><postedTime>"
+ System.currentTimeMillis() + "</postedTime><title>" + title + "</title>"
+ (body != null ? "<body>" + body + "</body>" : "") + "</activity>','"
+ xtraId1Type + "','" + xtraId1Value + "');";
try {
conn = dataSource.getConnection();
stmt = conn.createStatement();
stmt.executeUpdate(sqlCommand);
} finally {
try {
stmt.close();
} catch (Exception e) {
}
try {
conn.close();
} catch (Exception e) {
try (Connection conn = dataSource.getConnection()) {
try (Statement stmt = conn.createStatement()) {
stmt.executeUpdate(sqlCommand);
}
}
}
private String socketSendReceive(String viewer, String owner, String gadget)
@ -388,41 +377,24 @@ public class OpenSocialManager {
Map<String, GadgetSpec> allDBGadgets = useCache ? gadgetCache : null;
if (allDBGadgets == null) {
allDBGadgets = new HashMap<String, GadgetSpec>();
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
try {
String sqlCommand = "select appId, name, url, channels, enabled from orng_apps";
String sqlCommand = "select appId, name, url, channels, enabled from orng_apps";
try (Connection conn = dataSource.getConnection()) {
try (Statement stmt = conn.createStatement()) {
try (ResultSet rset = stmt.executeQuery(sqlCommand)) {
while (rset.next()) {
String channelsStr = rset.getString(4);
List<String> channels = Arrays.asList(channelsStr != null && channelsStr.length() > 0 ? channelsStr.split(" ") : new String[0]);
GadgetSpec spec = new GadgetSpec(rset.getInt(1),
rset.getString(2), rset.getString(3), channels, dataSource, rset.getBoolean(5), false);
String gadgetFileName = getGadgetFileNameFromURL(rset.getString(3));
conn = dataSource.getConnection();
stmt = conn.createStatement();
rset = stmt.executeQuery(sqlCommand);
while (rset.next()) {
String channelsStr = rset.getString(4);
List<String> channels = Arrays.asList(channelsStr != null && channelsStr.length() > 0 ? channelsStr.split(" ") : new String[0]);
GadgetSpec spec = new GadgetSpec(rset.getInt(1),
rset.getString(2), rset.getString(3), channels, dataSource, rset.getBoolean(5), false);
String gadgetFileName = getGadgetFileNameFromURL(rset.getString(3));
allDBGadgets.put(gadgetFileName, spec);
}
}
finally {
try {
rset.close();
} catch (Exception e) {
}
try {
stmt.close();
} catch (Exception e) {
}
try {
conn.close();
} catch (Exception e) {
allDBGadgets.put(gadgetFileName, spec);
}
}
}
}
if (useCache) {
gadgetCache = allDBGadgets;
}