Changeset 35350


Ignore:
Timestamp:
2021-09-08T13:58:35+12:00 (3 years ago)
Author:
davidb
Message:

Code rewritten to avoid try-resource code pattern, as this is not available in JDKs before 1.8

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/GoogleSigninJDBCRealm.java

    r35346 r35350  
    273273        // invalid login - the above is only used once.
    274274        int numberOfTries = 2;
     275
     276    // Note: The following code is based on that in JDBCRealm for running SQL queries,
     277    //       however, it has by changed from the try-resource code pattern to using
     278    //       to a more explictly laid out version so it is compatible with versions
     279    //       of JDK prior to 1.8
     280   
     281    ResultSet rs = null;
    275282        while (numberOfTries > 0) {
    276283            try {
     
    279286
    280287                PreparedStatement stmt = emailToUsername(dbConnection, email_address);
    281                 try (ResultSet rs = stmt.executeQuery()) {
    282                     if (rs.next()) {
    283                         dbUsername = rs.getString(1);
    284                     }
    285 
    286                     dbConnection.commit();
    287 
    288                     if (dbUsername != null) {
    289                         dbUsername = dbUsername.trim();
    290                     }
    291 
    292                     return dbUsername;
    293                 }
    294             } catch (SQLException e) {
     288        rs = stmt.executeQuery();
     289       
     290        if (rs.next()) {
     291            dbUsername = rs.getString(1);
     292        }
     293       
     294        dbConnection.commit();
     295       
     296        if (dbUsername != null) {
     297            dbUsername = dbUsername.trim();
     298        }
     299       
     300        rs.close();
     301        rs = null;
     302       
     303        return dbUsername;
     304        }
     305        catch (SQLException e) {
    295306                // Log the problem for posterity
    296307                containerLog.error(sm.getString("jdbcRealm.exception"), e);
     308       
    297309            }
     310
     311        if (rs != null) {
     312        try {
     313            rs.close();
     314        }
     315        catch (SQLException e) {
     316            containerLog.error(sm.getString("jdbcRealm.exception trying to close() ResultSet"), e);
     317        }
     318        rs = null;
     319        }
    298320
    299321            // Close the connection so that it gets reopened next time
Note: See TracChangeset for help on using the changeset viewer.