mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Implement operation DAO get next operation method
This commit is contained in:
parent
1f77183bb5
commit
a4b83a4737
@ -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.OperationManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -96,10 +92,13 @@ public class OperationDAOImpl implements OperationDAO {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS FROM DM_OPERATION o " +
|
String sql =
|
||||||
"INNER JOIN (SELECT dom.OPERATION_ID AS OP_ID FROM (SELECT d.ID FROM DM_DEVICE d INNER JOIN " +
|
"SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS FROM DM_OPERATION o " +
|
||||||
"DM_DEVICE_TYPE dm ON d.DEVICE_TYPE_ID = dm.ID AND dm.NAME = ? AND d.DEVICE_IDENTIFICATION = ?) d1 " +
|
"INNER JOIN (SELECT dom.OPERATION_ID AS OP_ID FROM (SELECT d.ID FROM DM_DEVICE d INNER JOIN "
|
||||||
"INNER JOIN DM_DEVICE_OPERATION_MAPPING dom ON d1.ID = dom.DEVICE_ID) ois ON o.ID = ois.OP_ID";
|
+
|
||||||
|
"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 = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, deviceId.getType());
|
stmt.setString(1, deviceId.getType());
|
||||||
stmt.setString(2, deviceId.getId());
|
stmt.setString(2, deviceId.getId());
|
||||||
@ -121,7 +120,7 @@ public class OperationDAOImpl implements OperationDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<? extends Operation> getOperations(DeviceIdentifier deviceId,
|
public List<? extends Operation> getOperations(DeviceIdentifier deviceId,
|
||||||
Operation.Status status) throws OperationManagementDAOException {
|
Operation.Status status) throws OperationManagementDAOException {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,5 +169,4 @@ public class OperationDAOImpl implements OperationDAO {
|
|||||||
return Operation.Type.valueOf(type);
|
return Operation.Type.valueOf(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,7 +32,6 @@ import java.sql.Connection;
|
|||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
||||||
|
|
||||||
@ -134,13 +133,18 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
|||||||
ByteArrayInputStream bais;
|
ByteArrayInputStream bais;
|
||||||
ObjectInputStream ois;
|
ObjectInputStream ois;
|
||||||
int operationId = 0;
|
int operationId = 0;
|
||||||
|
|
||||||
String operationType = "";
|
String operationType = "";
|
||||||
|
String createdTime;
|
||||||
|
String receivedTime;
|
||||||
|
String operationStatus = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||||
stmt = connection.prepareStatement(
|
stmt = connection.prepareStatement(
|
||||||
"SELECT o.ID AS OPERATION_ID, o.CREATED_TIMESTAMP AS CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP AS " +
|
"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 (" +
|
"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 " +
|
"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 " +
|
"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];
|
byte[] payload = new byte[0];
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
payload = rs.getBytes("PAYLOAD");
|
|
||||||
operationId = rs.getInt("OPERATION_ID");
|
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");
|
operationType = rs.getString("TYPE");
|
||||||
|
operationStatus = rs.getString("STATUS");
|
||||||
}
|
}
|
||||||
bais = new ByteArrayInputStream(payload);
|
bais = new ByteArrayInputStream(payload);
|
||||||
ois = new ObjectInputStream(bais);
|
ois = new ObjectInputStream(bais);
|
||||||
ProfileOperation profileOperation = (ProfileOperation) ois.readObject();
|
ProfileOperation profileOperation = new ProfileOperation();
|
||||||
|
profileOperation.setPayload(ois.readObject());
|
||||||
profileOperation.setId(operationId);
|
profileOperation.setId(operationId);
|
||||||
profileOperation.setType(Operation.Type.valueOf(operationType));
|
profileOperation.setType(Operation.Type.valueOf(operationType));
|
||||||
|
profileOperation.setStatus(Operation.Status.valueOf(operationStatus));
|
||||||
return profileOperation;
|
return profileOperation;
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
|
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
@ -173,5 +183,4 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
|||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user