Update operation method DAO implementation

revert-70aa11f8
manoj 10 years ago
parent 4312d528dd
commit 465f421aa8

@ -39,6 +39,8 @@ public class Operation {
private int id;
private String payLoad;
private Status status;
private String receivedTimeStamp;
private String createdTimeStamp;
@XmlElement
public String getCode() {
@ -91,4 +93,20 @@ public class Operation {
this.status = status;
}
public String getReceivedTimeStamp() {
return receivedTimeStamp;
}
public void setReceivedTimeStamp(String receivedTimeStamp) {
this.receivedTimeStamp = receivedTimeStamp;
}
public String getCreatedTimeStamp() {
return createdTimeStamp;
}
public void setCreatedTimeStamp(String createdTimeStamp) {
this.createdTimeStamp = createdTimeStamp;
}
}

@ -19,13 +19,35 @@
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.operation.mgt.ConfigOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class ConfigOperationDAOImpl extends OperationDAOImpl {
@Override
public int addOperation(Operation operation) throws OperationManagementDAOException {
return 0;
}
int operationId = super.addOperation(operation);
ConfigOperation commandOp = (ConfigOperation) operation;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
Connection conn = OperationManagementDAOFactory.getConnection();
stmt = conn.prepareStatement("INSERT INTO DM_CONFIG_OPERATION(OPERATION_ID) VALUES(?)");
stmt.setInt(1, operationId);
stmt.executeUpdate();
} catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while adding command operation", e);
} finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs);
}
return operationId;
}
}

@ -24,7 +24,6 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
import java.sql.*;
import java.util.ArrayList;
import java.util.Date;
@ -33,6 +32,7 @@ import java.util.List;
public class OperationDAOImpl implements OperationDAO {
public int addOperation(Operation operation) throws OperationManagementDAOException {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@ -60,7 +60,30 @@ public class OperationDAOImpl implements OperationDAO {
@Override
public int updateOperation(Operation operation) throws OperationManagementDAOException {
return 0;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement(
"UPDATE DM_OPERATION O SET O.RECEIVED_TIMESTAMP=?,O.STATUS=? WHERE O.ID=?");
stmt.setTimestamp(1, new Timestamp(new Date().getTime()));
stmt.setString(2, operation.getStatus().toString());
stmt.setInt(3,operation.getId());
stmt.executeUpdate();
rs = stmt.getGeneratedKeys();
int id = -1;
if (rs.next()) {
id = rs.getInt(1);
}
return id;
} catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
} finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs);
}
}
@Override

Loading…
Cancel
Save