used try with resources

mssqlgeofencefix1
prathabanKavin 2 years ago
parent d49ab1c7f0
commit 79d49a0512

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. * Copyright (c) 2018-2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
* *
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License, * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
@ -51,8 +51,8 @@ public class SQLServerEventConfigDAOImpl extends AbstractEventConfigDAO {
"CREATED_TIMESTAMP, " + "CREATED_TIMESTAMP, " +
"TENANT_ID) " + "TENANT_ID) " +
"VALUES (?, ?, ?, ?, ?)"; "VALUES (?, ?, ?, ?, ?)";
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
List<Integer> generatedIds = new ArrayList<>(); List<Integer> generatedIds = new ArrayList<>();
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
for (EventConfig eventConfig : eventConfigList) { for (EventConfig eventConfig : eventConfigList) {
stmt.setString(1, eventConfig.getEventSource()); stmt.setString(1, eventConfig.getEventSource());
stmt.setString(2, eventConfig.getEventLogic()); stmt.setString(2, eventConfig.getEventLogic());
@ -60,13 +60,15 @@ public class SQLServerEventConfigDAOImpl extends AbstractEventConfigDAO {
stmt.setTimestamp(4, timestamp); stmt.setTimestamp(4, timestamp);
stmt.setInt(5, tenantId); stmt.setInt(5, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();
ResultSet generatedKeys = stmt.getGeneratedKeys();
try (ResultSet generatedKeys = stmt.getGeneratedKeys()) {
if (generatedKeys.next()) { if (generatedKeys.next()) {
generatedIds.add(generatedKeys.getInt(1)); generatedIds.add(generatedKeys.getInt(1));
} }
} }
return generatedIds;
} }
}
return generatedIds;
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while creating event configurations for the tenant id " + tenantId; String msg = "Error occurred while creating event configurations for the tenant id " + tenantId;
log.error(msg, e); log.error(msg, e);

Loading…
Cancel
Save