Change next operations to join profile operations

revert-70aa11f8
manoj 10 years ago
parent 76c697453e
commit 9b5f6bc171

@ -466,39 +466,66 @@ public class OperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
ByteArrayInputStream bais;
ObjectInputStream ois;
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement( stmt = connection.prepareStatement(
"SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS,o.OPERATION_CODE " + "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE, " +
" FROM DM_OPERATION o " + "po.OPERATION_DETAILS,co.ENABLED from " +
"INNER JOIN (SELECT dom.OPERATION_ID AS OP_ID FROM (SELECT d.ID " + "(SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS, " +
"FROM DM_DEVICE d INNER JOIN DM_DEVICE_TYPE dm ON d.DEVICE_TYPE_ID = dm.ID AND " + "OPERATION_CODE FROM DM_OPERATION WHERE STATUS=?) o " +
"dm.NAME = ? AND d.DEVICE_IDENTIFICATION = ?) d1 INNER JOIN " + "INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " +
"DM_DEVICE_OPERATION_MAPPING dom ON d1.ID = dom.DEVICE_ID) ois ON o.STATUS=? AND" + "where dm.DEVICE_ID=?) om ON o.ID = om.OPERATION_ID LEFT OUTER JOIN DM_PROFILE_OPERATION " +
" o.ID = ois.OP_ID " + "po ON " +
"o.ID =po.OPERATION_ID LEFT OUTER JOIN DM_COMMAND_OPERATION co ON co.OPERATION_ID=o.ID " +
"ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1"); "ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1");
stmt.setString(1, deviceId.getType()); stmt.setString(1, deviceId.getType());
stmt.setString(2, deviceId.getId()); stmt.setString(2, deviceId.getId());
stmt.setString(3, Operation.Status.PENDING.toString()); stmt.setString(3, Operation.Status.PENDING.toString());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
Operation operation = null; Operation operation = null;
if (rs.next()) { if (rs.next()) {
operation = new Operation(); if (rs.getBytes("OPERATION_DETAILS") != null) {
operation.setType(this.getType(rs.getString("TYPE"))); byte[] operationDetails;
operation.setStatus(this.getStatus(rs.getString("STATUS"))); operationDetails = rs.getBytes("OPERATION_DETAILS");
operation.setId(rs.getInt("ID")); bais = new ByteArrayInputStream(operationDetails);
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); ois = new ObjectInputStream(bais);
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) { operation = (ProfileOperation) ois.readObject();
operation.setReceivedTimeStamp("");
} else { } else {
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString()); operation = new Operation();
operation.setType(this.getType(rs.getString("TYPE")));
operation.setStatus(this.getStatus(rs.getString("STATUS")));
operation.setId(rs.getInt("ID"));
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
operation.setReceivedTimeStamp("");
} else {
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
}
operation.setCode(rs.getString("OPERATION_CODE"));
if (rs.getObject("ENABLED") != null) {
operation.setEnabled(rs.getBoolean("ENABLED"));
}
} }
operation.setCode(rs.getString("OPERATION_CODE"));
} }
return operation; return operation;
} catch (SQLException e) { } catch (IOException ex) {
String errorMsg = "IO error occurred while de serializing the next profile operation available for the " +
"device:" + deviceId;
log.error(errorMsg);
throw new OperationManagementDAOException(errorMsg, ex);
} catch (ClassNotFoundException ex) {
String errorMsg = "class not found error occurred while de serializing the profile operation available " +
"for the device:" + deviceId;
log.error(errorMsg);
throw new OperationManagementDAOException(errorMsg, ex);
}catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e); throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);

Loading…
Cancel
Save