Fix jdbc code: Both PreparedStatements must be closed in any case
Change-Id: Ie25aff78e9f74497a36faca97a38737c0d8f4b73
This commit is contained in:
		@@ -199,51 +199,40 @@ public class Schema_77 extends SchemaVersion {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  static LegacyLabelTypes getLegacyTypes(ReviewDb db) throws SQLException {
 | 
					  static LegacyLabelTypes getLegacyTypes(ReviewDb db) throws SQLException {
 | 
				
			||||||
    List<LegacyLabelType> types = Lists.newArrayListWithCapacity(2);
 | 
					    List<LegacyLabelType> types = Lists.newArrayListWithCapacity(2);
 | 
				
			||||||
    Statement catStmt = null;
 | 
					    Statement catStmt = ((JdbcSchema) db).getConnection().createStatement();
 | 
				
			||||||
    PreparedStatement valStmt = null;
 | 
					 | 
				
			||||||
    ResultSet catRs = null;
 | 
					 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      catStmt = ((JdbcSchema) db).getConnection().createStatement();
 | 
					      ResultSet catRs = catStmt.executeQuery(
 | 
				
			||||||
      catRs = catStmt.executeQuery(
 | 
					 | 
				
			||||||
          "SELECT category_id, name, abbreviated_name, function_name, "
 | 
					          "SELECT category_id, name, abbreviated_name, function_name, "
 | 
				
			||||||
          + " copy_min_score"
 | 
					          + " copy_min_score"
 | 
				
			||||||
          + " FROM approval_categories"
 | 
					          + " FROM approval_categories"
 | 
				
			||||||
          + " ORDER BY position, name");
 | 
					          + " ORDER BY position, name");
 | 
				
			||||||
      valStmt = ((JdbcSchema) db).getConnection().prepareStatement(
 | 
					      PreparedStatement valStmt = ((JdbcSchema) db).getConnection().prepareStatement(
 | 
				
			||||||
          "SELECT value, name"
 | 
					              "SELECT value, name"
 | 
				
			||||||
          + " FROM approval_category_values"
 | 
					                      + " FROM approval_category_values"
 | 
				
			||||||
          + " WHERE category_id = ?");
 | 
					                      + " WHERE category_id = ?");
 | 
				
			||||||
      while (catRs.next()) {
 | 
					      try {
 | 
				
			||||||
        String id = catRs.getString("category_id");
 | 
					        while (catRs.next()) {
 | 
				
			||||||
        valStmt.setString(1, id);
 | 
					          String id = catRs.getString("category_id");
 | 
				
			||||||
        List<LabelValue> values = Lists.newArrayListWithCapacity(5);
 | 
					          valStmt.setString(1, id);
 | 
				
			||||||
        ResultSet valRs = valStmt.executeQuery();
 | 
					          List<LabelValue> values = Lists.newArrayListWithCapacity(5);
 | 
				
			||||||
        try {
 | 
					          ResultSet valRs = valStmt.executeQuery();
 | 
				
			||||||
          while (valRs.next()) {
 | 
					          while (valRs.next()) {
 | 
				
			||||||
            values.add(new LabelValue(
 | 
					            values.add(new LabelValue(
 | 
				
			||||||
                valRs.getShort("value"), valRs.getString("name")));
 | 
					                valRs.getShort("value"), valRs.getString("name")));
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        } finally {
 | 
					          LegacyLabelType type =
 | 
				
			||||||
          valRs.close();
 | 
					              new LegacyLabelType(getLabelName(catRs.getString("name")), values);
 | 
				
			||||||
 | 
					          type.setId(id);
 | 
				
			||||||
 | 
					          type.setAbbreviation(catRs.getString("abbreviated_name"));
 | 
				
			||||||
 | 
					          type.setFunctionName(catRs.getString("function_name"));
 | 
				
			||||||
 | 
					          type.setCopyMinScore("Y".equals(catRs.getString("copy_min_score")));
 | 
				
			||||||
 | 
					          types.add(type);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        LegacyLabelType type =
 | 
					      } finally {
 | 
				
			||||||
            new LegacyLabelType(getLabelName(catRs.getString("name")), values);
 | 
					 | 
				
			||||||
        type.setId(id);
 | 
					 | 
				
			||||||
        type.setAbbreviation(catRs.getString("abbreviated_name"));
 | 
					 | 
				
			||||||
        type.setFunctionName(catRs.getString("function_name"));
 | 
					 | 
				
			||||||
        type.setCopyMinScore("Y".equals(catRs.getString("copy_min_score")));
 | 
					 | 
				
			||||||
        types.add(type);
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    } finally {
 | 
					 | 
				
			||||||
      if (valStmt != null) {
 | 
					 | 
				
			||||||
        valStmt.close();
 | 
					        valStmt.close();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      if (catRs != null) {
 | 
					    } finally {
 | 
				
			||||||
        catRs.close();
 | 
					      catStmt.close();
 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      if (catStmt != null) {
 | 
					 | 
				
			||||||
        catStmt.close();
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return new LegacyLabelTypes(types);
 | 
					    return new LegacyLabelTypes(types);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user