Skip to content

Commit

Permalink
issue #3507 - update PostgresResourceNoProcDAO to match the derby one
Browse files Browse the repository at this point in the history
per review feedback

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
  • Loading branch information
lmsurpre committed Mar 30, 2022
1 parent c7aa04d commit 15f26d2
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,10 @@ public long storeResource(String tablePrefix, List<ExtractedParameterValue> para
if (logger.isLoggable(Level.FINEST)) {
logger.finest("Getting LOGICAL_RESOURCES row lock for: " + v_resource_type + "/" + p_logical_id);
}
final String SELECT_FOR_UPDATE = "SELECT logical_resource_id, parameter_hash, is_deleted FROM logical_resources WHERE resource_type_id = ? AND logical_id = ? FOR UPDATE WITH RS";
final String SELECT_FOR_UPDATE = "SELECT logical_resource_id, parameter_hash, is_deleted"
+ " FROM logical_resources"
+ " WHERE resource_type_id = ? AND logical_id = ?"
+ " FOR UPDATE WITH RS";
try (PreparedStatement stmt = conn.prepareStatement(SELECT_FOR_UPDATE)) {
stmt.setInt(1, v_resource_type_id);
stmt.setString(2, p_logical_id);
Expand Down Expand Up @@ -289,7 +292,6 @@ public long storeResource(String tablePrefix, List<ExtractedParameterValue> para
try (ResultSet res = stmt.executeQuery()) {
if (res.next()) {
v_logical_resource_id = res.getLong(1);
res.next();
}
else {
// not going to happen, unless someone butchers the statement being executed
Expand All @@ -298,26 +300,24 @@ public long storeResource(String tablePrefix, List<ExtractedParameterValue> para
}
}

try {
// insert the system-wide logical resource record.
if (logger.isLoggable(Level.FINEST)) {
logger.finest("Creating new logical_resources row for: " + v_resource_type + "/" + p_logical_id);
}
final String sql4 = "INSERT INTO logical_resources (logical_resource_id, resource_type_id, logical_id, reindex_tstamp, is_deleted, last_updated, parameter_hash) VALUES (?, ?, ?, ?, ?, ?, ?)";
try (PreparedStatement stmt = conn.prepareStatement(sql4)) {
// bind parameters
stmt.setLong(1, v_logical_resource_id);
stmt.setInt(2, v_resource_type_id);
stmt.setString(3, p_logical_id);
stmt.setTimestamp(4, Timestamp.valueOf(DEFAULT_VALUE_REINDEX_TSTAMP), UTC);
stmt.setString(5, p_is_deleted ? "Y" : "N"); // from V0014
stmt.setTimestamp(6, p_last_updated, UTC); // from V0014
stmt.setString(7, p_parameterHashB64); // from V0015
stmt.executeUpdate();
// insert the system-wide logical resource record
final String sql4 = "INSERT INTO logical_resources (logical_resource_id, resource_type_id, logical_id, reindex_tstamp, is_deleted, last_updated, parameter_hash) VALUES (?, ?, ?, ?, ?, ?, ?)";
if (logger.isLoggable(Level.FINEST)) {
logger.finest("Creating new logical_resources row for: " + v_resource_type + "/" + p_logical_id);
}
try (PreparedStatement stmt = conn.prepareStatement(sql4)) {
// bind parameters
stmt.setLong(1, v_logical_resource_id);
stmt.setInt(2, v_resource_type_id);
stmt.setString(3, p_logical_id);
stmt.setTimestamp(4, Timestamp.valueOf(DEFAULT_VALUE_REINDEX_TSTAMP), UTC);
stmt.setString(5, p_is_deleted ? "Y" : "N"); // from V0014
stmt.setTimestamp(6, p_last_updated, UTC); // from V0014
stmt.setString(7, p_parameterHashB64); // from V0015
stmt.executeUpdate();

if (logger.isLoggable(Level.FINEST)) {
logger.finest("Created logical_resources row for: " + v_resource_type + "/" + p_logical_id);
}
if (logger.isLoggable(Level.FINEST)) {
logger.finest("Created logical_resources row for: " + v_resource_type + "/" + p_logical_id);
}
} catch (SQLException e) {
if (translator.isDuplicate(e)) {
Expand Down Expand Up @@ -352,7 +352,6 @@ public long storeResource(String tablePrefix, List<ExtractedParameterValue> para
v_logical_resource_id = res.getLong(1);
currentParameterHash = res.getString(2);
v_currently_deleted = "Y".equals(res.getString(3));
res.next();
} else {
// Extremely unlikely as we should never delete logical resource records
throw new IllegalStateException("Logical resource was deleted: " + tablePrefix + "/" + p_logical_id);
Expand Down Expand Up @@ -392,7 +391,9 @@ public long storeResource(String tablePrefix, List<ExtractedParameterValue> para
if (logger.isLoggable(Level.FINEST)) {
logger.finest("Getting version info from " + tablePrefix + "_logical_resources for: " + v_resource_type + "/" + p_logical_id);
}
final String sql3 = "SELECT version_id FROM " + tablePrefix + "_logical_resources WHERE logical_resource_id = ?";
final String sql3 = "SELECT version_id"
+ " FROM " + tablePrefix + "_logical_resources"
+ " WHERE logical_resource_id = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql3)) {
stmt.setLong(1, v_logical_resource_id);
try (ResultSet rs = stmt.executeQuery()) {
Expand Down
Loading

0 comments on commit 15f26d2

Please sign in to comment.