|
|
|
@ -55,6 +55,44 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
|
|
|
|
return operationId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Operation getOperation(int id) throws OperationManagementDAOException {
|
|
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
Operation operation = null;
|
|
|
|
|
try {
|
|
|
|
|
Connection conn = OperationManagementDAOFactory.openConnection();
|
|
|
|
|
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATIONCODE," +
|
|
|
|
|
"co.ENABLED FROM DM_OPERATION o INNER JOIN DM_COMMAND_OPERATION co ON " +
|
|
|
|
|
"co.OPERATION_ID = o.ID WHERE o.ID=?";
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
stmt.setInt(1, id);
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
operation = new Operation();
|
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
|
|
|
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
|
} else {
|
|
|
|
|
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
|
|
|
|
}
|
|
|
|
|
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
operation.setCode(rs.getString("OPERATIONCODE"));
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new OperationManagementDAOException("Error occurred while retrieving the operation object " +
|
|
|
|
|
"available for the id '" + id + "'", e);
|
|
|
|
|
} finally {
|
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
return operation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<? extends Operation> getOperations(DeviceIdentifier deviceId,
|
|
|
|
|
Operation.Status status) throws OperationManagementDAOException {
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
@ -64,8 +102,10 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
|
|
|
|
try {
|
|
|
|
|
Connection conn = OperationManagementDAOFactory.openConnection();
|
|
|
|
|
String sql = "SELECT po.OPERATION_ID, po.TYPE, po.CREATED_TIMESTAMP, po.RECEIVED_TIMESTAMP, po.STATUS, " +
|
|
|
|
|
"co.ENABLED,o.OPERATIONCODE FROM DM_COMMAND_OPERATION co INNER JOIN (SELECT o.ID AS OPERATION_ID, o.TYPE, " +
|
|
|
|
|
"o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATIONCODE FROM DM_OPERATION o INNER JOIN (" +
|
|
|
|
|
"co.ENABLED,o.OPERATIONCODE FROM DM_COMMAND_OPERATION co INNER JOIN (SELECT o.ID AS OPERATION_ID, o.TYPE, "
|
|
|
|
|
+
|
|
|
|
|
"o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATIONCODE FROM DM_OPERATION o INNER JOIN ("
|
|
|
|
|
+
|
|
|
|
|
"SELECT dom.OPERATION_ID AS OP_ID FROM (SELECT d.ID FROM DM_DEVICE d INNER JOIN " +
|
|
|
|
|
"DM_DEVICE_TYPE dm ON d.DEVICE_TYPE_ID = dm.ID AND dm.NAME = ? AND " +
|
|
|
|
|
"d.DEVICE_IDENTIFICATION = ?) d1 INNER JOIN DM_DEVICE_OPERATION_MAPPING dom ON d1.ID = " +
|
|
|
|
@ -78,12 +118,17 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
|
|
|
|
stmt.setString(3, status.toString());
|
|
|
|
|
rs = stmt.executeQuery(sql);
|
|
|
|
|
|
|
|
|
|
while(rs.next()){
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
operation = new Operation();
|
|
|
|
|
operation.setId(rs.getInt("OPERATION_ID"));
|
|
|
|
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
|
|
|
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
|
|
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
|
|
|
|
operation.setCreatedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
|
|
|
|
} else {
|
|
|
|
|
operation.setCreatedTimeStamp(null);
|
|
|
|
|
}
|
|
|
|
|
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
operation.setEnabled(rs.getBoolean("ENABLED"));
|
|
|
|
|
operation.setCode(rs.getString("OPERATIONCODE"));
|
|
|
|
@ -107,8 +152,10 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
|
|
|
|
try {
|
|
|
|
|
Connection conn = OperationManagementDAOFactory.openConnection();
|
|
|
|
|
String sql = "SELECT po.OPERATION_ID, po.TYPE, po.CREATED_TIMESTAMP, po.RECEIVED_TIMESTAMP, po.STATUS, " +
|
|
|
|
|
"co.ENABLED.o.OPERATIONCODE FROM DM_COMMAND_OPERATION co INNER JOIN (SELECT o.ID AS OPERATION_ID, o.TYPE, " +
|
|
|
|
|
"o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATIONCODE FROM DM_OPERATION o INNER JOIN (" +
|
|
|
|
|
"co.ENABLED.o.OPERATIONCODE FROM DM_COMMAND_OPERATION co INNER JOIN (SELECT o.ID AS OPERATION_ID, o.TYPE, "
|
|
|
|
|
+
|
|
|
|
|
"o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATIONCODE FROM DM_OPERATION o INNER JOIN ("
|
|
|
|
|
+
|
|
|
|
|
"SELECT dom.OPERATION_ID AS OP_ID FROM (SELECT d.ID FROM DM_DEVICE d INNER JOIN " +
|
|
|
|
|
"DM_DEVICE_TYPE dm ON d.DEVICE_TYPE_ID = dm.ID AND dm.NAME = ? AND " +
|
|
|
|
|
"d.DEVICE_IDENTIFICATION = ?) d1 INNER JOIN DM_DEVICE_OPERATION_MAPPING dom ON d1.ID = " +
|
|
|
|
@ -117,7 +164,7 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
stmt.setString(1, deviceId.getType());
|
|
|
|
|
stmt.setString(1, deviceId.getId());
|
|
|
|
|
stmt.setString(2, deviceId.getId());
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
List<CommandOperation> operations = new ArrayList<CommandOperation>();
|
|
|
|
@ -125,6 +172,13 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
|
|
|
|
CommandOperation operation = new CommandOperation();
|
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
|
|
|
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
|
|
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
|
|
|
|
operation.setReceivedTimeStamp(null);
|
|
|
|
|
} else {
|
|
|
|
|
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
|
|
|
|
}
|
|
|
|
|
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
operation.setEnabled(Boolean.parseBoolean(rs.getString("ENABLED")));
|
|
|
|
|
operation.setCode(rs.getString("OPERATIONCODE"));
|
|
|
|
@ -149,7 +203,7 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
|
|
|
|
stmt = connection.prepareStatement(
|
|
|
|
|
"UPDATE DM_COMMAND_OPERATION O SET O.ENABLED=? WHERE O.OPERATION_ID=?");
|
|
|
|
|
|
|
|
|
|
stmt.setBoolean(1,operation.isEnabled());
|
|
|
|
|
stmt.setBoolean(1, operation.isEnabled());
|
|
|
|
|
stmt.setInt(2, operation.getId());
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
@ -168,7 +222,7 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
try {
|
|
|
|
|
Connection connection = OperationManagementDAOFactory.openConnection();
|
|
|
|
|
stmt = connection.prepareStatement("DELETE DM_COMMAND_OPERATION WHERE OPERATION_ID=?") ;
|
|
|
|
|
stmt = connection.prepareStatement("DELETE DM_COMMAND_OPERATION WHERE OPERATION_ID=?");
|
|
|
|
|
stmt.setInt(1, id);
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|