Permanent delete DAO fix

3.x.x
Amanda Randombage 5 years ago committed by Saad Sahibjan
parent 90fd12d876
commit becaf35546

@ -1744,8 +1744,8 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg ="Error occurred while deleting the devices: " + deviceIdentifiers; String msg = "Error occurred while deleting the devices: " + deviceIdentifiers;
log.error(msg,e); log.error(msg, e);
throw new DeviceManagementDAOException(msg, e); throw new DeviceManagementDAOException(msg, e);
} }
} }
@ -1759,9 +1759,14 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
private void removeDeviceDetail(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException { private void removeDeviceDetail(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException {
String sql = "DELETE FROM DM_DEVICE_DETAIL WHERE DEVICE_ID = ?"; String sql = "DELETE FROM DM_DEVICE_DETAIL WHERE DEVICE_ID = ?";
try { try {
executeBatchOperation(conn, sql, deviceIds); if (!executeBatchOperation(conn, sql, deviceIds)) {
String msg = "Failed to remove device details of devices with deviceIds : " + deviceIds +
" while executing batch operation";
log.error(msg);
throw new DeviceManagementDAOException(msg);
}
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while removing device details."; String msg = "SQL error occurred while removing device details of devices with deviceIds : " + deviceIds;
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementDAOException(msg, e); throw new DeviceManagementDAOException(msg, e);
} }
@ -1776,9 +1781,14 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
private void removeDeviceLocation(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException { private void removeDeviceLocation(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException {
String sql = "DELETE FROM DM_DEVICE_LOCATION WHERE DEVICE_ID = ?"; String sql = "DELETE FROM DM_DEVICE_LOCATION WHERE DEVICE_ID = ?";
try { try {
executeBatchOperation(conn, sql, deviceIds); if (!executeBatchOperation(conn, sql, deviceIds)) {
String msg = "Failed to remove locations of devices with deviceIds : " + deviceIds
+ " while executing batch operation";
log.error(msg);
throw new DeviceManagementDAOException(msg);
}
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while obtaining locations of devices."; String msg = "SQL error occurred while removing locations of devices with deviceIds : " + deviceIds;
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementDAOException(msg, e); throw new DeviceManagementDAOException(msg, e);
} }
@ -1793,9 +1803,14 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
private void removeDeviceInfo(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException { private void removeDeviceInfo(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException {
String sql = "DELETE FROM DM_DEVICE_INFO WHERE DEVICE_ID = ?"; String sql = "DELETE FROM DM_DEVICE_INFO WHERE DEVICE_ID = ?";
try { try {
executeBatchOperation(conn, sql, deviceIds); if (!executeBatchOperation(conn, sql, deviceIds)) {
String msg = "Failed to remove device info of devices with deviceIds : " + deviceIds
+ " while executing batch operation";
log.error(msg);
throw new DeviceManagementDAOException(msg);
}
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while removing device info."; String msg = "SQL error occurred while removing device info of devices with deviceIds : " + deviceIds;
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementDAOException(msg, e); throw new DeviceManagementDAOException(msg, e);
} }
@ -1810,9 +1825,14 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
private void removeDeviceNotification(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException { private void removeDeviceNotification(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException {
String sql = "DELETE FROM DM_NOTIFICATION WHERE DEVICE_ID = ?"; String sql = "DELETE FROM DM_NOTIFICATION WHERE DEVICE_ID = ?";
try { try {
executeBatchOperation(conn, sql, deviceIds); if (!executeBatchOperation(conn, sql, deviceIds)) {
String msg = "Failed to remove device notifications of devices with deviceIds : " + deviceIds +
" while executing batch operation";
log.error(msg);
throw new DeviceManagementDAOException(msg);
}
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while removing device notifications."; String msg = "SQL error occurred while removing device notifications of devices with deviceIds : " + deviceIds;
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementDAOException(msg, e); throw new DeviceManagementDAOException(msg, e);
} }
@ -1829,9 +1849,15 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
throws DeviceManagementDAOException { throws DeviceManagementDAOException {
String sql = "DELETE FROM DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID = ?"; String sql = "DELETE FROM DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID = ?";
try { try {
executeBatchOperation(conn, sql, deviceIds); if (!executeBatchOperation(conn, sql, deviceIds)) {
String msg = "Failed to remove device application mapping of of devices with deviceIds : " + deviceIds +
" while executing batch operation";
log.error(msg);
throw new DeviceManagementDAOException(msg);
}
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while removing device application mapping"; String msg = "SQL error occurred while removing device application mapping of devices with deviceIds : "
+ deviceIds;
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementDAOException(msg, e); throw new DeviceManagementDAOException(msg, e);
} }
@ -1847,9 +1873,14 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
throws DeviceManagementDAOException { throws DeviceManagementDAOException {
String sql = "DELETE FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ?"; String sql = "DELETE FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ?";
try { try {
executeBatchOperation(conn, sql, deviceIds); if (!executeBatchOperation(conn, sql, deviceIds)) {
String msg = "Failed to remove policies applied on devices with deviceIds : " + deviceIds +
" while executing batch operation";
log.error(msg);
throw new DeviceManagementDAOException(msg);
}
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while removing policies applied on devices"; String msg = "SQL error occurred while removing policies applied on devices with deviceIds : " + deviceIds;
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementDAOException(msg, e); throw new DeviceManagementDAOException(msg, e);
} }
@ -1864,9 +1895,14 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
private void removeDevicePolicy(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException { private void removeDevicePolicy(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException {
String sql = "DELETE FROM DM_DEVICE_POLICY WHERE DEVICE_ID = ?"; String sql = "DELETE FROM DM_DEVICE_POLICY WHERE DEVICE_ID = ?";
try { try {
executeBatchOperation(conn, sql, deviceIds); if (!executeBatchOperation(conn, sql, deviceIds)) {
String msg = "Failed to remove policies of devices with deviceIds : " + deviceIds +
" while executing batch operation";
log.error(msg);
throw new DeviceManagementDAOException(msg);
}
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while removing policies of devices"; String msg = "SQL error occurred while removing policies of devices with deviceIds : " + deviceIds;
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementDAOException(msg, e); throw new DeviceManagementDAOException(msg, e);
} }
@ -1882,9 +1918,15 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
throws DeviceManagementDAOException { throws DeviceManagementDAOException {
String sql = "DELETE FROM DM_DEVICE_DETAIL WHERE ENROLMENT_ID = ?"; String sql = "DELETE FROM DM_DEVICE_DETAIL WHERE ENROLMENT_ID = ?";
try { try {
executeBatchOperation(conn, sql, enrollmentIds); if (!executeBatchOperation(conn, sql, enrollmentIds)) {
String msg = "Failed to remove enrollment details of devices with enrollmentIds : " + enrollmentIds
+ " while executing batch operation";
log.error(msg);
throw new DeviceManagementDAOException(msg);
}
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while removing enrollment details of devices"; String msg = "SQL error occurred while removing enrollment details of devices with enrollmentIds : "
+ enrollmentIds;
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementDAOException(msg, e); throw new DeviceManagementDAOException(msg, e);
} }
@ -1900,9 +1942,15 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
throws DeviceManagementDAOException { throws DeviceManagementDAOException {
String sql = "DELETE FROM DM_DEVICE_LOCATION WHERE ENROLMENT_ID = ?"; String sql = "DELETE FROM DM_DEVICE_LOCATION WHERE ENROLMENT_ID = ?";
try { try {
executeBatchOperation(conn, sql, enrollmentIds); if (!executeBatchOperation(conn, sql, enrollmentIds)) {
String msg = "Failed to remove enrollment locations of devices with enrollmentIds : " + enrollmentIds
+ " while executing batch operation";
log.error(msg);
throw new DeviceManagementDAOException(msg);
}
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while removing enrollment locations of devices"; String msg = "SQL error occurred while removing enrollment locations of devices with enrollmentIds : "
+ enrollmentIds;
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementDAOException(msg, e); throw new DeviceManagementDAOException(msg, e);
} }
@ -1918,9 +1966,15 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
throws DeviceManagementDAOException { throws DeviceManagementDAOException {
String sql = "DELETE FROM DM_DEVICE_INFO WHERE ENROLMENT_ID = ?"; String sql = "DELETE FROM DM_DEVICE_INFO WHERE ENROLMENT_ID = ?";
try { try {
executeBatchOperation(conn, sql, enrollmentIds); if (!executeBatchOperation(conn, sql, enrollmentIds)) {
String msg = "Failed to remove enrollment info of devices with enrollmentIds : " + enrollmentIds
+ " while executing batch operation";
log.error(msg);
throw new DeviceManagementDAOException(msg);
}
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while removing enrollment info of devices"; String msg = "SQL error occurred while removing enrollment info of devices with enrollmentIds : "
+ enrollmentIds;
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementDAOException(msg, e); throw new DeviceManagementDAOException(msg, e);
} }
@ -1936,9 +1990,15 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
throws DeviceManagementDAOException { throws DeviceManagementDAOException {
String sql = "DELETE FROM DM_DEVICE_APPLICATION_MAPPING WHERE ENROLMENT_ID = ?"; String sql = "DELETE FROM DM_DEVICE_APPLICATION_MAPPING WHERE ENROLMENT_ID = ?";
try { try {
executeBatchOperation(conn, sql, enrollmentIds); if (!executeBatchOperation(conn, sql, enrollmentIds)) {
String msg = "Failed to remove enrollment device application mapping of devices with enrollmentIds : "
+ enrollmentIds + " while executing batch operation";
log.error(msg);
throw new DeviceManagementDAOException(msg);
}
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while removing enrollment device application mapping"; String msg = "SQL error occurred while removing enrollment device application mapping of devices with " +
"enrollmentIds : " + enrollmentIds;
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementDAOException(msg, e); throw new DeviceManagementDAOException(msg, e);
} }
@ -1954,9 +2014,15 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
throws DeviceManagementDAOException { throws DeviceManagementDAOException {
String sql = "DELETE FROM DM_DEVICE_OPERATION_RESPONSE WHERE ENROLMENT_ID = ?"; String sql = "DELETE FROM DM_DEVICE_OPERATION_RESPONSE WHERE ENROLMENT_ID = ?";
try { try {
executeBatchOperation(conn, sql, enrollmentIds); if (!executeBatchOperation(conn, sql, enrollmentIds)) {
String msg = "Failed to remove device operation response of devices with enrollmentIds : "
+ enrollmentIds + " while executing batch operation";
log.error(msg);
throw new DeviceManagementDAOException(msg);
}
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while removing device operation response"; String msg = "SQL error occurred while removing device operation response of devices with enrollmentIds : "
+ enrollmentIds;
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementDAOException(msg, e); throw new DeviceManagementDAOException(msg, e);
} }
@ -1972,9 +2038,15 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
throws DeviceManagementDAOException { throws DeviceManagementDAOException {
String sql = "DELETE FROM DM_ENROLMENT_OP_MAPPING WHERE ENROLMENT_ID = ?"; String sql = "DELETE FROM DM_ENROLMENT_OP_MAPPING WHERE ENROLMENT_ID = ?";
try { try {
executeBatchOperation(conn, sql, enrollmentIds); if (!executeBatchOperation(conn, sql, enrollmentIds)) {
String msg = "Failed to remove enrollment operation mapping of devices with enrollmentIds : "
+ enrollmentIds + " while executing batch operation";
log.error(msg);
throw new DeviceManagementDAOException(msg);
}
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while removing enrollment operation mapping"; String msg = "SQL error occurred while removing enrollment operation mapping of devices with enrollmentIds :"
+ enrollmentIds;
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementDAOException(msg, e); throw new DeviceManagementDAOException(msg, e);
} }
@ -1990,9 +2062,15 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
throws DeviceManagementDAOException { throws DeviceManagementDAOException {
String sql = "DELETE FROM DM_ENROLMENT WHERE DEVICE_ID = ?"; String sql = "DELETE FROM DM_ENROLMENT WHERE DEVICE_ID = ?";
try { try {
executeBatchOperation(conn, sql, enrollmentIds); if (!executeBatchOperation(conn, sql, enrollmentIds)) {
String msg = "Failed to remove enrollments of devices with enrollmentIds : " + enrollmentIds
+ " while executing batch operation";
log.error(msg);
throw new DeviceManagementDAOException(msg);
}
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while removing enrollments of devices"; String msg = "SQL error occurred while removing enrollments of devices with enrollmentIds : "
+ enrollmentIds;
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementDAOException(msg, e); throw new DeviceManagementDAOException(msg, e);
} }
@ -2007,9 +2085,15 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
private void removeDeviceGroupMapping(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException { private void removeDeviceGroupMapping(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException {
String sql = "DELETE FROM DM_DEVICE_GROUP_MAP WHERE DEVICE_ID = ?"; String sql = "DELETE FROM DM_DEVICE_GROUP_MAP WHERE DEVICE_ID = ?";
try { try {
executeBatchOperation(conn, sql, deviceIds); if (!executeBatchOperation(conn, sql, deviceIds)) {
String msg = "Failed to remove device group mapping of devices with deviceIds : " + deviceIds
+ " while executing batch operation";
log.error(msg);
throw new DeviceManagementDAOException(msg);
}
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while removing device group mapping"; String msg = "SQL error occurred while removing device group mapping of devices with deviceIds : "
+ deviceIds;
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementDAOException(msg, e); throw new DeviceManagementDAOException(msg, e);
} }
@ -2024,9 +2108,13 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
private void removeDevice(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException { private void removeDevice(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException {
String sql = "DELETE FROM DM_DEVICE WHERE ID = ?"; String sql = "DELETE FROM DM_DEVICE WHERE ID = ?";
try { try {
executeBatchOperation(conn, sql, deviceIds); if (!executeBatchOperation(conn, sql, deviceIds)) {
String msg = "Failed to remove devices with deviceIds : " + deviceIds + " while executing batch operation";
log.error(msg);
throw new DeviceManagementDAOException(msg);
}
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while removing devices."; String msg = "SQL error occurred while removing devices with deviceIds : " + deviceIds;
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementDAOException(msg, e); throw new DeviceManagementDAOException(msg, e);
} }
@ -2036,12 +2124,15 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
* This method executes batch operations for a given list of primary keys * This method executes batch operations for a given list of primary keys
* where the statement only has one param of type int, following the given pattern: * where the statement only has one param of type int, following the given pattern:
* DELETE FROM TABLE WHERE ID = ? * DELETE FROM TABLE WHERE ID = ?
*
* This method does not check if the number of rows affected by the executeBatch() method is 0
* because there can be tables with no records to delete.
* @param sql SQL statement * @param sql SQL statement
* @param conn Connection object * @param conn Connection object
* @param identifiers list of device ids (primary keys) * @param identifiers list of device ids (primary keys)
* @throws SQLException if deletion fails. * @throws SQLException if deletion fails.
*/ */
private void executeBatchOperation(Connection conn, String sql, List<Integer> identifiers) throws SQLException { private boolean executeBatchOperation(Connection conn, String sql, List<Integer> identifiers) throws SQLException {
try (PreparedStatement ps = conn.prepareStatement(sql)) { try (PreparedStatement ps = conn.prepareStatement(sql)) {
if (conn.getMetaData().supportsBatchUpdates()) { if (conn.getMetaData().supportsBatchUpdates()) {
for (int identifier : identifiers) { for (int identifier : identifiers) {
@ -2049,18 +2140,17 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
ps.addBatch(); ps.addBatch();
} }
for (int i : ps.executeBatch()) { for (int i : ps.executeBatch()) {
if (i == 0 || i == Statement.SUCCESS_NO_INFO || i == Statement.EXECUTE_FAILED) { if (i == Statement.SUCCESS_NO_INFO || i == Statement.EXECUTE_FAILED) {
break; return false;
} }
} }
} else { } else {
for (int enrollmentId : identifiers) { for (int identifier : identifiers) {
ps.setInt(1, enrollmentId); ps.setInt(1, identifier);
if (ps.executeUpdate() == 0) { ps.executeUpdate();
break;
}
} }
} }
} }
return true;
} }
} }

@ -523,7 +523,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override @Override
public boolean deleteDevices(List<String> deviceIdentifiers) throws DeviceManagementException, InvalidDeviceException { public boolean deleteDevices(List<String> deviceIdentifiers) throws DeviceManagementException, InvalidDeviceException {
List<Integer> deviceIds = new ArrayList<>(); HashSet<Integer> deviceIds = new HashSet<>();
List<Integer> enrollmentIds = new ArrayList<>(); List<Integer> enrollmentIds = new ArrayList<>();
Map<String, List<String>> deviceIdentifierMap = new HashMap<>(); Map<String, List<String>> deviceIdentifierMap = new HashMap<>();
Map<String, DeviceManager> deviceManagerMap = new HashMap<>(); Map<String, DeviceManager> deviceManagerMap = new HashMap<>();
@ -577,7 +577,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
} }
//deleting device from the core //deleting device from the core
deviceDAO.deleteDevices(deviceIdentifiers, deviceIds, enrollmentIds); deviceDAO.deleteDevices(deviceIdentifiers, new ArrayList<>(deviceIds), enrollmentIds);
for (Map.Entry<String, DeviceManager> entry : deviceManagerMap.entrySet()) { for (Map.Entry<String, DeviceManager> entry : deviceManagerMap.entrySet()) {
try { try {
// deleting device from the plugin level // deleting device from the plugin level

@ -220,7 +220,6 @@ public class DeviceTypePluginDAOImpl implements PluginDAO {
public boolean deleteDevices(List<String> deviceIdentifiers) throws DeviceTypeMgtPluginException { public boolean deleteDevices(List<String> deviceIdentifiers) throws DeviceTypeMgtPluginException {
try { try {
Connection conn = deviceTypeDAOHandler.getConnection(); Connection conn = deviceTypeDAOHandler.getConnection();
boolean status = true;
try (PreparedStatement ps = conn.prepareStatement(deleteDBQueryForDeleteDevice)) { try (PreparedStatement ps = conn.prepareStatement(deleteDBQueryForDeleteDevice)) {
if (conn.getMetaData().supportsBatchUpdates()) { if (conn.getMetaData().supportsBatchUpdates()) {
for (String deviceId : deviceIdentifiers) { for (String deviceId : deviceIdentifiers) {
@ -228,22 +227,18 @@ public class DeviceTypePluginDAOImpl implements PluginDAO {
ps.addBatch(); ps.addBatch();
} }
for (int i : ps.executeBatch()) { for (int i : ps.executeBatch()) {
if (i == 0 || i == Statement.SUCCESS_NO_INFO || i == Statement.EXECUTE_FAILED) { if (i == Statement.SUCCESS_NO_INFO || i == Statement.EXECUTE_FAILED) {
status = false; return false;
break;
} }
} }
} else { } else {
for (String deviceId : deviceIdentifiers) { for (String deviceId : deviceIdentifiers) {
ps.setString(1, deviceId); ps.setString(1, deviceId);
if (ps.executeUpdate() == 0) { ps.executeUpdate();
status = false;
break;
}
} }
} }
} }
return status; return true;
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while deleting the data in " String msg = "Error occurred while deleting the data in "
+ deviceDAODefinition.getDeviceTableName(); + deviceDAODefinition.getDeviceTableName();

@ -222,7 +222,6 @@ public class PropertyBasedPluginDAOImpl implements PluginDAO {
public boolean deleteDevices(List<String> deviceIdentifiers) throws DeviceTypeMgtPluginException { public boolean deleteDevices(List<String> deviceIdentifiers) throws DeviceTypeMgtPluginException {
try { try {
Connection conn = deviceTypeDAOHandler.getConnection(); Connection conn = deviceTypeDAOHandler.getConnection();
boolean status = true;
try (PreparedStatement ps = conn.prepareStatement("DELETE FROM DM_DEVICE_PROPERTIES WHERE DEVICE_IDENTIFICATION = ?")) { try (PreparedStatement ps = conn.prepareStatement("DELETE FROM DM_DEVICE_PROPERTIES WHERE DEVICE_IDENTIFICATION = ?")) {
if (conn.getMetaData().supportsBatchUpdates()) { if (conn.getMetaData().supportsBatchUpdates()) {
for (String deviceId : deviceIdentifiers) { for (String deviceId : deviceIdentifiers) {
@ -230,22 +229,18 @@ public class PropertyBasedPluginDAOImpl implements PluginDAO {
ps.addBatch(); ps.addBatch();
} }
for (int i : ps.executeBatch()) { for (int i : ps.executeBatch()) {
if (i == 0 || i == Statement.SUCCESS_NO_INFO || i == Statement.EXECUTE_FAILED) { if (i == Statement.SUCCESS_NO_INFO || i == Statement.EXECUTE_FAILED) {
status = false; return false;
break;
} }
} }
} else { } else {
for (String deviceId : deviceIdentifiers) { for (String deviceId : deviceIdentifiers) {
ps.setString(1, deviceId); ps.setString(1, deviceId);
if (ps.executeUpdate() == 0) { ps.executeUpdate();
status = false;
break;
}
} }
} }
} }
return status; return true;
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while deleting the data of the devices: '" + deviceIdentifiers + "'of type: " String msg = "Error occurred while deleting the data of the devices: '" + deviceIdentifiers + "'of type: "
+ deviceType; + deviceType;

Loading…
Cancel
Save