prabathabey 10 years ago
commit bf88170668

@ -25,11 +25,7 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOE
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;
import java.sql.Timestamp;
import java.sql.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -96,10 +92,13 @@ public class OperationDAOImpl implements OperationDAO {
ResultSet rs = null;
try {
Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS 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 = dom.DEVICE_ID) ois ON o.ID = ois.OP_ID";
String sql =
"SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS 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 = dom.DEVICE_ID) ois ON o.ID = ois.OP_ID";
stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceId.getType());
stmt.setString(2, deviceId.getId());
@ -121,7 +120,7 @@ public class OperationDAOImpl implements OperationDAO {
@Override
public List<? extends Operation> getOperations(DeviceIdentifier deviceId,
Operation.Status status) throws OperationManagementDAOException {
Operation.Status status) throws OperationManagementDAOException {
return null;
}
@ -170,5 +169,4 @@ public class OperationDAOImpl implements OperationDAO {
return Operation.Type.valueOf(type);
}
}

@ -32,7 +32,6 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
public class ProfileOperationDAOImpl extends OperationDAOImpl {
@ -134,13 +133,18 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
ByteArrayInputStream bais;
ObjectInputStream ois;
int operationId = 0;
String operationType = "";
String createdTime;
String receivedTime;
String operationStatus = "";
try {
Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement(
"SELECT o.ID AS OPERATION_ID, o.CREATED_TIMESTAMP AS CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP AS " +
"RECEIVED_TIMESTAMP, po.PAYLOAD AS PAYLOAD,o.TYPE AS TYPE FROM DM_OPERATION o " +
"RECEIVED_TIMESTAMP, po.PAYLOAD AS PAYLOAD,o.TYPE AS TYPE,o.STATUS as STATUS " +
"FROM DM_OPERATION o " +
"INNER JOIN DM_PROFILE_OPERATION po ON o.ID = po.OPERATION_ID AND o.ID IN (" +
"SELECT dom.OPERATION_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 " +
@ -152,16 +156,22 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
byte[] payload = new byte[0];
if (rs.next()) {
payload = rs.getBytes("PAYLOAD");
operationId = rs.getInt("OPERATION_ID");
createdTime = rs.getTimestamp("CREATED_TIMESTAMP").toString();
receivedTime = rs.getTimestamp("RECEIVED_TIMESTAMP").toString();
payload = rs.getBytes("PAYLOAD");
operationType = rs.getString("TYPE");
operationStatus = rs.getString("STATUS");
}
bais = new ByteArrayInputStream(payload);
ois = new ObjectInputStream(bais);
ProfileOperation profileOperation = (ProfileOperation) ois.readObject();
ProfileOperation profileOperation = new ProfileOperation();
profileOperation.setPayload(ois.readObject());
profileOperation.setId(operationId);
profileOperation.setType(Operation.Type.valueOf(operationType));
profileOperation.setStatus(Operation.Status.valueOf(operationStatus));
return profileOperation;
} catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
} catch (ClassNotFoundException e) {
@ -173,5 +183,4 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
OperationManagementDAOUtil.cleanupResources(stmt, rs);
}
}
}

Loading…
Cancel
Save